Simple Directmedia Layer
at main 34 kB view raw
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_build_config.h" 23#include "SDL_dynapi.h" 24#include "SDL_dynapi_unsupported.h" 25 26#if SDL_DYNAMIC_API 27 28#define SDL_DYNAMIC_API_ENVVAR "SDL3_DYNAMIC_API" 29#define SDL_SLOW_MEMCPY 30#define SDL_SLOW_MEMMOVE 31#define SDL_SLOW_MEMSET 32 33#ifdef HAVE_STDIO_H 34#include <stdio.h> 35#endif 36 37#include <SDL3/SDL.h> 38#define SDL_MAIN_NOIMPL // don't drag in header-only implementation of SDL_main 39#include <SDL3/SDL_main.h> 40 41 42// These headers have system specific definitions, so aren't included above 43#include <SDL3/SDL_vulkan.h> 44 45/* This is the version of the dynamic API. This doesn't match the SDL version 46 and should not change until there's been a major revamp in API/ABI. 47 So 2.0.5 adds functions over 2.0.4? This number doesn't change; 48 the sizeof(jump_table) changes instead. But 2.1.0 changes how a function 49 works in an incompatible way or removes a function? This number changes, 50 since sizeof(jump_table) isn't sufficient anymore. It's likely 51 we'll forget to bump every time we add a function, so this is the 52 failsafe switch for major API change decisions. Respect it and use it 53 sparingly. */ 54#define SDL_DYNAPI_VERSION 2 55 56#ifdef __cplusplus 57extern "C" { 58#endif 59 60static void SDL_InitDynamicAPI(void); 61 62/* BE CAREFUL CALLING ANY SDL CODE IN HERE, IT WILL BLOW UP. 63 Even self-contained stuff might call SDL_SetError() and break everything. */ 64 65// behold, the macro salsa! 66 67// Can't use the macro for varargs nonsense. This is atrocious. 68#define SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, logname, prio) \ 69 _static void SDLCALL SDL_Log##logname##name(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 70 { \ 71 va_list ap; \ 72 initcall; \ 73 va_start(ap, fmt); \ 74 jump_table.SDL_LogMessageV(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \ 75 va_end(ap); \ 76 } 77 78#define SDL_DYNAPI_VARARGS(_static, name, initcall) \ 79 _static bool SDLCALL SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 80 { \ 81 char buf[128], *str = buf; \ 82 int result; \ 83 va_list ap; \ 84 initcall; \ 85 va_start(ap, fmt); \ 86 result = jump_table.SDL_vsnprintf(buf, sizeof(buf), fmt, ap); \ 87 va_end(ap); \ 88 if (result >= 0 && (size_t)result >= sizeof(buf)) { \ 89 str = NULL; \ 90 va_start(ap, fmt); \ 91 result = jump_table.SDL_vasprintf(&str, fmt, ap); \ 92 va_end(ap); \ 93 } \ 94 if (result >= 0) { \ 95 jump_table.SDL_SetError("%s", str); \ 96 } \ 97 if (str != buf) { \ 98 jump_table.SDL_free(str); \ 99 } \ 100 return false; \ 101 } \ 102 _static int SDLCALL SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) \ 103 { \ 104 int result; \ 105 va_list ap; \ 106 initcall; \ 107 va_start(ap, fmt); \ 108 result = jump_table.SDL_vsscanf(buf, fmt, ap); \ 109 va_end(ap); \ 110 return result; \ 111 } \ 112 _static int SDLCALL SDL_snprintf##name(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 113 { \ 114 int result; \ 115 va_list ap; \ 116 initcall; \ 117 va_start(ap, fmt); \ 118 result = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \ 119 va_end(ap); \ 120 return result; \ 121 } \ 122 _static int SDLCALL SDL_swprintf##name(SDL_OUT_Z_CAP(maxlen) wchar_t *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) \ 123 { \ 124 int result; \ 125 va_list ap; \ 126 initcall; \ 127 va_start(ap, fmt); \ 128 result = jump_table.SDL_vswprintf(buf, maxlen, fmt, ap); \ 129 va_end(ap); \ 130 return result; \ 131 } \ 132 _static int SDLCALL SDL_asprintf##name(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 133 { \ 134 int result; \ 135 va_list ap; \ 136 initcall; \ 137 va_start(ap, fmt); \ 138 result = jump_table.SDL_vasprintf(strp, fmt, ap); \ 139 va_end(ap); \ 140 return result; \ 141 } \ 142 _static size_t SDLCALL SDL_IOprintf##name(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 143 { \ 144 size_t result; \ 145 va_list ap; \ 146 initcall; \ 147 va_start(ap, fmt); \ 148 result = jump_table.SDL_IOvprintf(context, fmt, ap); \ 149 va_end(ap); \ 150 return result; \ 151 } \ 152 _static bool SDLCALL SDL_RenderDebugTextFormat##name(SDL_Renderer *renderer, float x, float y, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 153 { \ 154 char buf[128], *str = buf; \ 155 int result; \ 156 va_list ap; \ 157 initcall; \ 158 va_start(ap, fmt); \ 159 result = jump_table.SDL_vsnprintf(buf, sizeof(buf), fmt, ap); \ 160 va_end(ap); \ 161 if (result >= 0 && (size_t)result >= sizeof(buf)) { \ 162 str = NULL; \ 163 va_start(ap, fmt); \ 164 result = jump_table.SDL_vasprintf(&str, fmt, ap); \ 165 va_end(ap); \ 166 } \ 167 bool retval = false; \ 168 if (result >= 0) { \ 169 retval = jump_table.SDL_RenderDebugTextFormat(renderer, x, y, "%s", str); \ 170 } \ 171 if (str != buf) { \ 172 jump_table.SDL_free(str); \ 173 } \ 174 return retval; \ 175 } \ 176 _static void SDLCALL SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 177 { \ 178 va_list ap; \ 179 initcall; \ 180 va_start(ap, fmt); \ 181 jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \ 182 va_end(ap); \ 183 } \ 184 _static void SDLCALL SDL_LogMessage##name(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 185 { \ 186 va_list ap; \ 187 initcall; \ 188 va_start(ap, fmt); \ 189 jump_table.SDL_LogMessageV(category, priority, fmt, ap); \ 190 va_end(ap); \ 191 } \ 192 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Trace, TRACE) \ 193 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Verbose, VERBOSE) \ 194 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Debug, DEBUG) \ 195 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Info, INFO) \ 196 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Warn, WARN) \ 197 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Error, ERROR) \ 198 SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Critical, CRITICAL) 199 200// Typedefs for function pointers for jump table, and predeclare funcs 201// The DEFAULT funcs will init jump table and then call real function. 202// The REAL funcs are the actual functions, name-mangled to not clash. 203#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) \ 204 typedef rc (SDLCALL *SDL_DYNAPIFN_##fn) params;\ 205 static rc SDLCALL fn##_DEFAULT params; \ 206 extern rc SDLCALL fn##_REAL params; 207#include "SDL_dynapi_procs.h" 208#undef SDL_DYNAPI_PROC 209 210// The jump table! 211typedef struct 212{ 213#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) SDL_DYNAPIFN_##fn fn; 214#include "SDL_dynapi_procs.h" 215#undef SDL_DYNAPI_PROC 216} SDL_DYNAPI_jump_table; 217 218// The actual jump table. 219static SDL_DYNAPI_jump_table jump_table = { 220#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) fn##_DEFAULT, 221#include "SDL_dynapi_procs.h" 222#undef SDL_DYNAPI_PROC 223}; 224 225// Default functions init the function table then call right thing. 226#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) \ 227 static rc SDLCALL fn##_DEFAULT params \ 228 { \ 229 SDL_InitDynamicAPI(); \ 230 ret jump_table.fn args; \ 231 } 232#define SDL_DYNAPI_PROC_NO_VARARGS 1 233#include "SDL_dynapi_procs.h" 234#undef SDL_DYNAPI_PROC 235#undef SDL_DYNAPI_PROC_NO_VARARGS 236SDL_DYNAPI_VARARGS(static, _DEFAULT, SDL_InitDynamicAPI()) 237 238// Public API functions to jump into the jump table. 239#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) \ 240 rc SDLCALL fn params \ 241 { \ 242 ret jump_table.fn args; \ 243 } 244#define SDL_DYNAPI_PROC_NO_VARARGS 1 245#include "SDL_dynapi_procs.h" 246#undef SDL_DYNAPI_PROC 247#undef SDL_DYNAPI_PROC_NO_VARARGS 248SDL_DYNAPI_VARARGS(, , ) 249 250#define ENABLE_SDL_CALL_LOGGING 0 251#if ENABLE_SDL_CALL_LOGGING 252static bool SDLCALL SDL_SetError_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) 253{ 254 char buf[512]; // !!! FIXME: dynamic allocation 255 va_list ap; 256 SDL_Log_REAL("SDL3CALL SDL_SetError"); 257 va_start(ap, fmt); 258 SDL_vsnprintf_REAL(buf, sizeof(buf), fmt, ap); 259 va_end(ap); 260 return SDL_SetError_REAL("%s", buf); 261} 262static int SDLCALL SDL_sscanf_LOGSDLCALLS(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) 263{ 264 int result; 265 va_list ap; 266 SDL_Log_REAL("SDL3CALL SDL_sscanf"); 267 va_start(ap, fmt); 268 result = SDL_vsscanf_REAL(buf, fmt, ap); 269 va_end(ap); 270 return result; 271} 272static int SDLCALL SDL_snprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) 273{ 274 int result; 275 va_list ap; 276 SDL_Log_REAL("SDL3CALL SDL_snprintf"); 277 va_start(ap, fmt); 278 result = SDL_vsnprintf_REAL(buf, maxlen, fmt, ap); 279 va_end(ap); 280 return result; 281} 282static int SDLCALL SDL_asprintf_LOGSDLCALLS(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) 283{ 284 int result; 285 va_list ap; 286 SDL_Log_REAL("SDL3CALL SDL_asprintf"); 287 va_start(ap, fmt); 288 result = SDL_vasprintf_REAL(strp, fmt, ap); 289 va_end(ap); 290 return result; 291} 292static int SDLCALL SDL_swprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) wchar_t *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) 293{ 294 int result; 295 va_list ap; 296 SDL_Log_REAL("SDL3CALL SDL_swprintf"); 297 va_start(ap, fmt); 298 result = SDL_vswprintf_REAL(buf, maxlen, fmt, ap); 299 va_end(ap); 300 return result; 301} 302static size_t SDLCALL SDL_IOprintf_LOGSDLCALLS(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) 303{ 304 size_t result; 305 va_list ap; 306 SDL_Log_REAL("SDL3CALL SDL_IOprintf"); 307 va_start(ap, fmt); 308 result = SDL_IOvprintf_REAL(context, fmt, ap); 309 va_end(ap); 310 return result; 311} 312static void SDLCALL SDL_Log_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) 313{ 314 va_list ap; 315 SDL_Log_REAL("SDL3CALL SDL_Log"); 316 va_start(ap, fmt); 317 SDL_LogMessageV_REAL(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); 318 va_end(ap); 319} 320static void SDLCALL SDL_LogMessage_LOGSDLCALLS(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) 321{ 322 va_list ap; 323 SDL_Log_REAL("SDL3CALL SDL_LogMessage"); 324 va_start(ap, fmt); 325 SDL_LogMessageV_REAL(category, priority, fmt, ap); 326 va_end(ap); 327} 328#define SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(logname, prio) \ 329 static void SDLCALL SDL_Log##logname##_LOGSDLCALLS(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ 330 { \ 331 va_list ap; \ 332 va_start(ap, fmt); \ 333 SDL_Log_REAL("SDL3CALL SDL_Log%s", #logname); \ 334 SDL_LogMessageV_REAL(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \ 335 va_end(ap); \ 336 } 337SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Trace, TRACE) 338SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Verbose, VERBOSE) 339SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Debug, DEBUG) 340SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Info, INFO) 341SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Warn, WARN) 342SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Error, ERROR) 343SDL_DYNAPI_VARARGS_LOGFN_LOGSDLCALLS(Critical, CRITICAL) 344#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) \ 345 rc SDLCALL fn##_LOGSDLCALLS params \ 346 { \ 347 SDL_Log_REAL("SDL3CALL %s", #fn); \ 348 ret fn##_REAL args; \ 349 } 350#define SDL_DYNAPI_PROC_NO_VARARGS 1 351#include "SDL_dynapi_procs.h" 352#undef SDL_DYNAPI_PROC 353#undef SDL_DYNAPI_PROC_NO_VARARGS 354#endif 355 356/* we make this a static function so we can call the correct one without the 357 system's dynamic linker resolving to the wrong version of this. */ 358static Sint32 initialize_jumptable(Uint32 apiver, void *table, Uint32 tablesize) 359{ 360 SDL_DYNAPI_jump_table *output_jump_table = (SDL_DYNAPI_jump_table *)table; 361 362 if (apiver != SDL_DYNAPI_VERSION) { 363 // !!! FIXME: can maybe handle older versions? 364 return -1; // not compatible. 365 } else if (tablesize > sizeof(jump_table)) { 366 return -1; // newer version of SDL with functions we can't provide. 367 } 368 369// Init our jump table first. 370#if ENABLE_SDL_CALL_LOGGING 371 { 372 const char *env = SDL_getenv_unsafe_REAL("SDL_DYNAPI_LOG_CALLS"); 373 const bool log_calls = (env && SDL_atoi_REAL(env)); 374 if (log_calls) { 375#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) jump_table.fn = fn##_LOGSDLCALLS; 376#include "SDL_dynapi_procs.h" 377#undef SDL_DYNAPI_PROC 378 } else { 379#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) jump_table.fn = fn##_REAL; 380#include "SDL_dynapi_procs.h" 381#undef SDL_DYNAPI_PROC 382 } 383 } 384#else 385#define SDL_DYNAPI_PROC(rc, fn, params, args, ret) jump_table.fn = fn##_REAL; 386#include "SDL_dynapi_procs.h" 387#undef SDL_DYNAPI_PROC 388#endif 389 390 // Then the external table... 391 if (output_jump_table != &jump_table) { 392 jump_table.SDL_memcpy(output_jump_table, &jump_table, tablesize); 393 } 394 395 // Safe to call SDL functions now; jump table is initialized! 396 397 return 0; // success! 398} 399 400// Here's the exported entry point that fills in the jump table. 401// Use specific types when an "int" might suffice to keep this sane. 402typedef Sint32 (SDLCALL *SDL_DYNAPI_ENTRYFN)(Uint32 apiver, void *table, Uint32 tablesize); 403extern SDL_DECLSPEC Sint32 SDLCALL SDL_DYNAPI_entry(Uint32, void *, Uint32); 404 405Sint32 SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize) 406{ 407 return initialize_jumptable(apiver, table, tablesize); 408} 409 410#ifdef __cplusplus 411} 412#endif 413 414// Obviously we can't use SDL_LoadObject() to load SDL. :) 415// Also obviously, we never close the loaded library. 416#if defined(WIN32) || defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) 417#ifndef WIN32_LEAN_AND_MEAN 418#define WIN32_LEAN_AND_MEAN 1 419#endif 420#include <windows.h> 421static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym) 422{ 423 HMODULE lib = LoadLibraryA(fname); 424 void *result = NULL; 425 if (lib) { 426 result = (void *) GetProcAddress(lib, sym); 427 if (!result) { 428 FreeLibrary(lib); 429 } 430 } 431 return result; 432} 433 434#elif defined(SDL_PLATFORM_UNIX) || defined(SDL_PLATFORM_APPLE) || defined(SDL_PLATFORM_HAIKU) 435#include <dlfcn.h> 436static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym) 437{ 438 void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL); 439 void *result = NULL; 440 if (lib) { 441 result = dlsym(lib, sym); 442 if (!result) { 443 dlclose(lib); 444 } 445 } 446 return result; 447} 448 449#else 450#error Please define your platform. 451#endif 452 453static void dynapi_warn(const char *msg) 454{ 455 const char *caption = "SDL Dynamic API Failure!"; 456 (void)caption; 457// SDL_ShowSimpleMessageBox() is a too heavy for here. 458#if (defined(WIN32) || defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) 459 MessageBoxA(NULL, msg, caption, MB_OK | MB_ICONERROR); 460#elif defined(HAVE_STDIO_H) 461 fprintf(stderr, "\n\n%s\n%s\n\n", caption, msg); 462 fflush(stderr); 463#endif 464} 465 466/* This is not declared in any header, although it is shared between some 467 parts of SDL, because we don't want anything calling it without an 468 extremely good reason. */ 469#ifdef __cplusplus 470extern "C" { 471#endif 472extern SDL_NORETURN void SDL_ExitProcess(int exitcode); 473#ifdef __WATCOMC__ 474#pragma aux SDL_ExitProcess aborts; 475#endif 476#ifdef __cplusplus 477} 478#endif 479 480static void SDL_InitDynamicAPILocked(void) 481{ 482 const char *libname = SDL_getenv_unsafe_REAL(SDL_DYNAMIC_API_ENVVAR); 483 SDL_DYNAPI_ENTRYFN entry = NULL; // funcs from here by default. 484 bool use_internal = true; 485 486 if (libname) { 487 while (*libname && !entry) { 488 // This is evil, but we're not making any permanent changes... 489 char *ptr = (char *)libname; 490 while (true) { 491 char ch = *ptr; 492 if ((ch == ',') || (ch == '\0')) { 493 *ptr = '\0'; 494 entry = (SDL_DYNAPI_ENTRYFN)get_sdlapi_entry(libname, "SDL_DYNAPI_entry"); 495 *ptr = ch; 496 libname = (ch == '\0') ? ptr : (ptr + 1); 497 break; 498 } else { 499 ptr++; 500 } 501 } 502 } 503 if (!entry) { 504 dynapi_warn("Couldn't load an overriding SDL library. Please fix or remove the " SDL_DYNAMIC_API_ENVVAR " environment variable. Using the default SDL."); 505 // Just fill in the function pointers from this library, later. 506 } 507 } 508 509 if (entry) { 510 if (entry(SDL_DYNAPI_VERSION, &jump_table, sizeof(jump_table)) < 0) { 511 dynapi_warn("Couldn't override SDL library. Using a newer SDL build might help. Please fix or remove the " SDL_DYNAMIC_API_ENVVAR " environment variable. Using the default SDL."); 512 // Just fill in the function pointers from this library, later. 513 } else { 514 use_internal = false; // We overrode SDL! Don't use the internal version! 515 } 516 } 517 518 // Just fill in the function pointers from this library. 519 if (use_internal) { 520 if (initialize_jumptable(SDL_DYNAPI_VERSION, &jump_table, sizeof(jump_table)) < 0) { 521 // Now we're screwed. Should definitely abort now. 522 dynapi_warn("Failed to initialize internal SDL dynapi. As this would otherwise crash, we have to abort now."); 523 SDL_ExitProcess(86); 524 } 525 } 526 527 // we intentionally never close the newly-loaded lib, of course. 528} 529 530static void SDL_InitDynamicAPI(void) 531{ 532 /* So the theory is that every function in the jump table defaults to 533 * calling this function, and then replaces itself with a version that 534 * doesn't call this function anymore. But it's possible that, in an 535 * extreme corner case, you can have a second thread hit this function 536 * while the jump table is being initialized by the first. 537 * In this case, a spinlock is really painful compared to what spinlocks 538 * _should_ be used for, but this would only happen once, and should be 539 * insanely rare, as you would have to spin a thread outside of SDL (as 540 * SDL_CreateThread() would also call this function before building the 541 * new thread). 542 */ 543 static bool already_initialized = false; 544 545 static SDL_SpinLock lock = 0; 546 SDL_LockSpinlock_REAL(&lock); 547 548 if (!already_initialized) { 549 SDL_InitDynamicAPILocked(); 550 already_initialized = true; 551 } 552 553 SDL_UnlockSpinlock_REAL(&lock); 554} 555 556#else // SDL_DYNAMIC_API 557 558#include <SDL3/SDL.h> 559 560Sint32 SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize); 561Sint32 SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize) 562{ 563 (void)apiver; 564 (void)table; 565 (void)tablesize; 566 return -1; // not compatible. 567} 568 569#endif // SDL_DYNAMIC_API