From 8eed17500e5f821f0943cc267eaad05b82d32b55 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 9 Jan 2025 02:46:19 +0100 Subject: [PATCH 1/3] Disable long long support in the headers with SDL_NOLONGLONG Some older toolchains don't support 'long long'. --- include/SDL3/SDL_stdinc.h | 8 ++++++++ src/SDL_internal.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h index cd172c4250dcb..923ed2986642c 100644 --- a/include/SDL3/SDL_stdinc.h +++ b/include/SDL3/SDL_stdinc.h @@ -753,7 +753,9 @@ typedef Sint64 SDL_Time; #endif /* Specifically for the `long long` -- SDL-specific. */ #ifdef SDL_PLATFORM_WINDOWS +#ifndef SDL_NOLONGLONG SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */ +#endif #define SDL_PRILL_PREFIX "I64" #else #define SDL_PRILL_PREFIX "ll" @@ -1126,8 +1128,10 @@ SDL_COMPILE_TIME_ASSERT(uint32_size, sizeof(Uint32) == 4); SDL_COMPILE_TIME_ASSERT(sint32_size, sizeof(Sint32) == 4); SDL_COMPILE_TIME_ASSERT(uint64_size, sizeof(Uint64) == 8); SDL_COMPILE_TIME_ASSERT(sint64_size, sizeof(Sint64) == 8); +#ifndef SDL_NOLONGLONG SDL_COMPILE_TIME_ASSERT(uint64_longlong, sizeof(Uint64) <= sizeof(unsigned long long)); SDL_COMPILE_TIME_ASSERT(size_t_longlong, sizeof(size_t) <= sizeof(unsigned long long)); +#endif typedef struct SDL_alignment_test { Uint8 a; @@ -3492,6 +3496,7 @@ extern SDL_DECLSPEC char * SDLCALL SDL_ltoa(long value, char *str, int radix); */ extern SDL_DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *str, int radix); +#ifndef SDL_NOLONGLONG /** * Convert a long long integer into a string. * @@ -3547,6 +3552,7 @@ extern SDL_DECLSPEC char * SDLCALL SDL_lltoa(long long value, char *str, int rad * \sa SDL_ultoa */ extern SDL_DECLSPEC char * SDLCALL SDL_ulltoa(unsigned long long value, char *str, int radix); +#endif /** * Parse an `int` from a string. @@ -3660,6 +3666,7 @@ extern SDL_DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int ba */ extern SDL_DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base); +#ifndef SDL_NOLONGLONG /** * Parse a `long long` from a string. * @@ -3726,6 +3733,7 @@ extern SDL_DECLSPEC long long SDLCALL SDL_strtoll(const char *str, char **endp, * \sa SDL_ulltoa */ extern SDL_DECLSPEC unsigned long long SDLCALL SDL_strtoull(const char *str, char **endp, int base); +#endif /** * Parse a `double` from a string. diff --git a/src/SDL_internal.h b/src/SDL_internal.h index f776f5071b9a7..e3910cf500000 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -217,6 +217,10 @@ #define SDL_EndThreadFunction NULL #endif +#ifdef SDL_NOLONGLONG +#error We cannot build a valid SDL3 library without long long support +#endif + /* Enable internal definitions in SDL API headers */ #define SDL_INTERNAL From 56100d90676c8debdba80ba7ce8dadb9230ae7bd Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 9 Jan 2025 02:46:48 +0100 Subject: [PATCH 2/3] _BitScanReverse was introduced in Microsoft Visual Studio 2005 --- include/SDL3/SDL_bits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL3/SDL_bits.h b/include/SDL3/SDL_bits.h index 0837f14bbac98..6657e6b256a59 100644 --- a/include/SDL3/SDL_bits.h +++ b/include/SDL3/SDL_bits.h @@ -78,7 +78,7 @@ SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x) return -1; } return _SDL_bsr_watcom(x); -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && _MSC_VER >= 1400 unsigned long index; if (_BitScanReverse(&index, x)) { return (int)index; From cc4fd706c78473cce5ec35e07047bd5b458b45e3 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 9 Jan 2025 03:26:36 +0100 Subject: [PATCH 3/3] __debugbreak was introduced in Microsoft Visual Studio 2003 --- include/SDL3/SDL_assert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL3/SDL_assert.h b/include/SDL3/SDL_assert.h index eb374699432be..0cb455984b363 100644 --- a/include/SDL3/SDL_assert.h +++ b/include/SDL3/SDL_assert.h @@ -127,7 +127,7 @@ extern "C" { */ #define SDL_TriggerBreakpoint() TriggerABreakpointInAPlatformSpecificManner -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && _MSC_VER >= 1310 /* Don't include intrin.h here because it contains C++ code */ extern void __cdecl __debugbreak(void); #define SDL_TriggerBreakpoint() __debugbreak()