mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-21 09:11:49 +00:00
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:
@@ -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) {
|
||||
|
@@ -142,6 +142,11 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des
|
||||
SDL_InvalidParamError("desc");
|
||||
return 0;
|
||||
}
|
||||
if (desc->version < sizeof(*desc)) {
|
||||
// Update this to handle older versions of this interface
|
||||
SDL_SetError("Invalid desc, should be initialized with SDL_INIT_INTERFACE()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
hwdata = (joystick_hwdata *)SDL_calloc(1, sizeof(joystick_hwdata));
|
||||
if (!hwdata) {
|
||||
|
@@ -153,6 +153,11 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *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;
|
||||
}
|
||||
|
||||
storage = (SDL_Storage *)SDL_calloc(1, sizeof(*storage));
|
||||
if (storage) {
|
||||
|
@@ -182,6 +182,7 @@ static Uint64 GENERIC_GetStorageSpaceRemaining(void *userdata)
|
||||
}
|
||||
|
||||
static const SDL_StorageInterface GENERIC_title_iface = {
|
||||
sizeof(SDL_StorageInterface),
|
||||
GENERIC_CloseStorage,
|
||||
NULL, // ready
|
||||
GENERIC_EnumerateStorageDirectory,
|
||||
@@ -224,6 +225,7 @@ TitleStorageBootStrap GENERIC_titlebootstrap = {
|
||||
};
|
||||
|
||||
static const SDL_StorageInterface GENERIC_user_iface = {
|
||||
sizeof(SDL_StorageInterface),
|
||||
GENERIC_CloseStorage,
|
||||
NULL, // ready
|
||||
GENERIC_EnumerateStorageDirectory,
|
||||
@@ -259,6 +261,7 @@ UserStorageBootStrap GENERIC_userbootstrap = {
|
||||
};
|
||||
|
||||
static const SDL_StorageInterface GENERIC_file_iface = {
|
||||
sizeof(SDL_StorageInterface),
|
||||
GENERIC_CloseStorage,
|
||||
NULL, // ready
|
||||
GENERIC_EnumerateStorageDirectory,
|
||||
|
@@ -129,6 +129,7 @@ static Uint64 STEAM_GetStorageSpaceRemaining(void *userdata)
|
||||
}
|
||||
|
||||
static const SDL_StorageInterface STEAM_user_iface = {
|
||||
sizeof(SDL_StorageInterface),
|
||||
STEAM_CloseStorage,
|
||||
STEAM_StorageReady,
|
||||
NULL, // enumerate
|
||||
|
Reference in New Issue
Block a user