Initialize interface structures so they can be extended in the future

We guarantee that we will only add to the end of these interfaces, and any new fields will be optional.
This commit is contained in:
Sam Lantinga 2024-09-05 16:28:48 -07:00
parent 434193d153
commit 702ed83f72
13 changed files with 130 additions and 22 deletions

View file

@ -419,7 +419,7 @@ static SDL_IOStream *SDL_IOFromFP(FILE *fp, bool autoclose)
}
SDL_IOStreamInterface iface;
SDL_zero(iface);
SDL_INIT_INTERFACE(&iface);
// There's no stdio_size because SDL_GetIOSize emulates it the same way we'd do it for stdio anyhow.
iface.seek = stdio_seek;
iface.read = stdio_read;
@ -607,7 +607,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
}
SDL_IOStreamInterface iface;
SDL_zero(iface);
SDL_INIT_INTERFACE(&iface);
iface.size = Android_JNI_FileSize;
iface.seek = Android_JNI_FileSeek;
iface.read = Android_JNI_FileRead;
@ -636,7 +636,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
}
SDL_IOStreamInterface iface;
SDL_zero(iface);
SDL_INIT_INTERFACE(&iface);
iface.size = windows_file_size;
iface.seek = windows_file_seek;
iface.read = windows_file_read;
@ -698,7 +698,7 @@ SDL_IOStream *SDL_IOFromMem(void *mem, size_t size)
}
SDL_IOStreamInterface iface;
SDL_zero(iface);
SDL_INIT_INTERFACE(&iface);
iface.size = mem_size;
iface.seek = mem_seek;
iface.read = mem_read;
@ -732,7 +732,7 @@ SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
}
SDL_IOStreamInterface iface;
SDL_zero(iface);
SDL_INIT_INTERFACE(&iface);
iface.size = mem_size;
iface.seek = mem_seek;
iface.read = mem_read;
@ -832,7 +832,7 @@ SDL_IOStream *SDL_IOFromDynamicMem(void)
}
SDL_IOStreamInterface iface;
SDL_zero(iface);
SDL_INIT_INTERFACE(&iface);
iface.size = dynamic_mem_size;
iface.seek = dynamic_mem_seek;
iface.read = dynamic_mem_read;
@ -868,6 +868,11 @@ SDL_IOStream *SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
SDL_InvalidParamError("iface");
return NULL;
}
if (iface->version < sizeof(*iface)) {
// Update this to handle older versions of this interface
SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
return NULL;
}
SDL_IOStream *iostr = (SDL_IOStream *)SDL_calloc(1, sizeof(*iostr));
if (iostr) {