From fd93f817baebdec5fd454402d42244d0c28ecb2e Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sun, 4 Sep 2022 17:50:29 +0100 Subject: [PATCH] Assume that stdint.h is available on Windows with compilers other than MSVC <= 2008 --- CMakeLists.txt | 2 ++ include/SDL_config.h.cmake | 64 +++++++--------------------------- include/SDL_config_minimal.h | 30 +++++++++------- include/SDL_config_windows.h | 30 +++------------- include/SDL_config_wingdk.h | 36 ++----------------- include/SDL_config_winrt.h | 45 +----------------------- include/SDL_config_xbox.h | 36 ++----------------- src/core/windows/SDL_windows.h | 10 ++++++ 8 files changed, 52 insertions(+), 201 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55c521d1b..077999232 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -930,6 +930,7 @@ endif() if(SDL_LIBC) if(WINDOWS AND NOT MINGW) set(HAVE_LIBC TRUE) + check_include_file(stdint.h HAVE_STDINT_H) foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h) string(TOUPPER "HAVE_${_HEADER}" _UPPER) string(REPLACE "." "_" _HAVE_H ${_UPPER}) @@ -1043,6 +1044,7 @@ else() if(WINDOWS) set(HAVE_STDARG_H 1) set(HAVE_STDDEF_H 1) + check_include_file(stdint.h HAVE_STDINT_H) endif() endif() diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 204a12e0c..15c5c9e1d 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -206,14 +206,11 @@ #cmakedefine HAVE_POLL 1 #cmakedefine HAVE__EXIT 1 -#elif defined(__WIN32__) +#else #cmakedefine HAVE_STDARG_H 1 #cmakedefine HAVE_STDDEF_H 1 +#cmakedefine HAVE_STDINT_H 1 #cmakedefine HAVE_FLOAT_H 1 - -#else -/* We may need some replacement for stdarg.h here */ -#include #endif /* HAVE_LIBC */ #cmakedefine HAVE_ALTIVEC_H 1 @@ -533,24 +530,9 @@ #cmakedefine SDL_VIDEO_VITA_PVR @SDL_VIDEO_VITA_PVR@ #cmakedefine SDL_VIDEO_VITA_PVR_OGL @SDL_VIDEO_VITA_PVR_OGL@ -#if !defined(__WIN32__) && !defined(__WINRT__) -# if !defined(_STDINT_H_) && !defined(_STDINT_H) && !defined(HAVE_STDINT_H) && !defined(_HAVE_STDINT_H) -typedef unsigned int size_t; -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -typedef unsigned long uintptr_t; -# endif /* if (stdint.h isn't available) */ -#else /* __WIN32__ */ -# if !defined(_STDINT_H_) && !defined(HAVE_STDINT_H) && !defined(_HAVE_STDINT_H) -# if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__CODEGEARC__) -#define HAVE_STDINT_H 1 -# elif defined(_MSC_VER) +#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) +/* Most everything except Visual Studio 2008 and earlier has stdint.h now */ +#if defined(_MSC_VER) && (_MSC_VER < 1600) typedef signed __int8 int8_t; typedef unsigned __int8 uint8_t; typedef signed __int16 int16_t; @@ -559,37 +541,15 @@ typedef signed __int32 int32_t; typedef unsigned __int32 uint32_t; typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; -# ifndef _UINTPTR_T_DEFINED -# ifdef _WIN64 +#ifndef _UINTPTR_T_DEFINED +#ifdef _WIN64 typedef unsigned __int64 uintptr_t; -# else +#else typedef unsigned int uintptr_t; -# endif +#endif #define _UINTPTR_T_DEFINED -# endif -/* Older Visual C++ headers don't have the Win64-compatible typedefs... */ -# if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) -#define DWORD_PTR DWORD -# endif -# if ((_MSC_VER <= 1200) && (!defined(LONG_PTR))) -#define LONG_PTR LONG -# endif -# else /* !__GNUC__ && !_MSC_VER */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -# ifndef _SIZE_T_DEFINED_ -#define _SIZE_T_DEFINED_ -typedef unsigned int size_t; -# endif -typedef unsigned int uintptr_t; -# endif /* __GNUC__ || _MSC_VER */ -# endif /* !_STDINT_H_ && !HAVE_STDINT_H */ -#endif /* __WIN32__ */ +#endif +#endif /* Visual Studio 2008 */ +#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ #endif /* SDL_config_h_ */ diff --git a/include/SDL_config_minimal.h b/include/SDL_config_minimal.h index c74fcdb14..2f2559eef 100644 --- a/include/SDL_config_minimal.h +++ b/include/SDL_config_minimal.h @@ -34,23 +34,29 @@ #define HAVE_STDARG_H 1 #define HAVE_STDDEF_H 1 +#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) /* Most everything except Visual Studio 2008 and earlier has stdint.h now */ #if defined(_MSC_VER) && (_MSC_VER < 1600) -/* Here are some reasonable defaults */ -typedef unsigned int size_t; -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -typedef unsigned long uintptr_t; +typedef signed __int8 int8_t; +typedef unsigned __int8 uint8_t; +typedef signed __int16 int16_t; +typedef unsigned __int16 uint16_t; +typedef signed __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; +#ifndef _UINTPTR_T_DEFINED +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned int uintptr_t; +#endif +#define _UINTPTR_T_DEFINED +#endif #else #define HAVE_STDINT_H 1 -#define HAVE_INTTYPES_H 1 #endif /* Visual Studio 2008 */ +#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ #ifdef __GNUC__ #define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1 diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index 3ad3e8ff1..58e0b7ecb 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -53,9 +53,8 @@ /* This is a set of defines to configure the SDL features */ #if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) -#if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__clang__) || defined(__BORLANDC__) || defined(__CODEGEARC__) -#define HAVE_STDINT_H 1 -#elif defined(_MSC_VER) +/* Most everything except Visual Studio 2008 and earlier has stdint.h now */ +#if defined(_MSC_VER) && (_MSC_VER < 1600) typedef signed __int8 int8_t; typedef unsigned __int8 uint8_t; typedef signed __int16 int16_t; @@ -72,28 +71,9 @@ typedef unsigned int uintptr_t; #endif #define _UINTPTR_T_DEFINED #endif -/* Older Visual C++ headers don't have the Win64-compatible typedefs... */ -#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) -#define DWORD_PTR DWORD -#endif -#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR))) -#define LONG_PTR LONG -#endif -#else /* !__GNUC__ && !_MSC_VER */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#ifndef _SIZE_T_DEFINED_ -#define _SIZE_T_DEFINED_ -typedef unsigned int size_t; -#endif -typedef unsigned int uintptr_t; -#endif /* __GNUC__ || _MSC_VER */ +#else +#define HAVE_STDINT_H 1 +#endif /* Visual Studio 2008 */ #endif /* !_STDINT_H_ && !HAVE_STDINT_H */ #ifdef _WIN64 diff --git a/include/SDL_config_wingdk.h b/include/SDL_config_wingdk.h index d456024f2..6f793d2aa 100644 --- a/include/SDL_config_wingdk.h +++ b/include/SDL_config_wingdk.h @@ -28,40 +28,6 @@ /* Windows GDK does not need Windows SDK version checks because it requires * a recent version of the Windows 10 SDK. */ -#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) -/* At this time, only recent MSVC or clang are supported by Windows GDK */ -#if defined(__clang__) -#define HAVE_STDINT_H 1 -#elif defined(_MSC_VER) -typedef signed __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef signed __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef signed __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; -#ifndef _UINTPTR_T_DEFINED -typedef unsigned __int64 uintptr_t; -#define _UINTPTR_T_DEFINED -#endif -#else /* !__clang__ && !_MSC_VER */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#ifndef _SIZE_T_DEFINED_ -#define _SIZE_T_DEFINED_ -typedef unsigned int size_t; -#endif -typedef unsigned int uintptr_t; -#endif /* __clang__ || _MSC_VER */ -#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ - /* GDK only supports 64-bit */ # define SIZEOF_VOIDP 8 @@ -101,6 +67,7 @@ typedef unsigned int uintptr_t; #define HAVE_LIMITS_H 1 #define HAVE_MATH_H 1 #define HAVE_SIGNAL_H 1 +#define HAVE_STDINT_H 1 #define HAVE_STDIO_H 1 #define HAVE_STRING_H 1 @@ -197,6 +164,7 @@ typedef unsigned int uintptr_t; #else #define HAVE_STDARG_H 1 #define HAVE_STDDEF_H 1 +#define HAVE_STDINT_H 1 #endif /* Enable various audio drivers */ diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h index 556940369..da894c883 100644 --- a/include/SDL_config_winrt.h +++ b/include/SDL_config_winrt.h @@ -42,50 +42,6 @@ /* This is a set of defines to configure the SDL features */ -#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) -#if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__) -#define HAVE_STDINT_H 1 -#elif defined(_MSC_VER) -typedef signed __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef signed __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef signed __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; -#ifndef _UINTPTR_T_DEFINED -#ifdef _WIN64 -typedef unsigned __int64 uintptr_t; -#else -typedef unsigned int uintptr_t; -#endif -#define _UINTPTR_T_DEFINED -#endif -/* Older Visual C++ headers don't have the Win64-compatible typedefs... */ -#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) -#define DWORD_PTR DWORD -#endif -#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR))) -#define LONG_PTR LONG -#endif -#else /* !__GNUC__ && !_MSC_VER */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#ifndef _SIZE_T_DEFINED_ -#define _SIZE_T_DEFINED_ -typedef unsigned int size_t; -#endif -typedef unsigned int uintptr_t; -#endif /* __GNUC__ || _MSC_VER */ -#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ - #ifdef _WIN64 # define SIZEOF_VOIDP 8 #else @@ -113,6 +69,7 @@ typedef unsigned int uintptr_t; #define HAVE_LIMITS_H 1 #define HAVE_MATH_H 1 #define HAVE_SIGNAL_H 1 +#define HAVE_STDINT_H 1 #define HAVE_STDIO_H 1 #define HAVE_STRING_H 1 diff --git a/include/SDL_config_xbox.h b/include/SDL_config_xbox.h index 4e68e9f98..54fa1a42b 100644 --- a/include/SDL_config_xbox.h +++ b/include/SDL_config_xbox.h @@ -28,40 +28,6 @@ /* Windows GDK does not need Windows SDK version checks because it requires * a recent version of the Windows 10 SDK. */ -#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H) -/* At this time, only recent MSVC or clang are supported by Windows GDK */ -#if defined(__clang__) -#define HAVE_STDINT_H 1 -#elif defined(_MSC_VER) -typedef signed __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef signed __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef signed __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; -#ifndef _UINTPTR_T_DEFINED -typedef unsigned __int64 uintptr_t; -#define _UINTPTR_T_DEFINED -#endif -#else /* !__clang__ && !_MSC_VER */ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#ifndef _SIZE_T_DEFINED_ -#define _SIZE_T_DEFINED_ -typedef unsigned int size_t; -#endif -typedef unsigned int uintptr_t; -#endif /* __clang__ || _MSC_VER */ -#endif /* !_STDINT_H_ && !HAVE_STDINT_H */ - /* GDK only supports 64-bit */ # define SIZEOF_VOIDP 8 @@ -101,6 +67,7 @@ typedef unsigned int uintptr_t; #define HAVE_LIMITS_H 1 #define HAVE_MATH_H 1 #define HAVE_SIGNAL_H 1 +#define HAVE_STDINT_H 1 #define HAVE_STDIO_H 1 #define HAVE_STRING_H 1 @@ -197,6 +164,7 @@ typedef unsigned int uintptr_t; #else #define HAVE_STDARG_H 1 #define HAVE_STDDEF_H 1 +#define HAVE_STDINT_H 1 #endif /* Enable various audio drivers */ diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index e2d62edd5..5c1d63430 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -69,6 +69,16 @@ #include #include /* for REFIID with broken mingw.org headers */ +/* Older Visual C++ headers don't have the Win64-compatible typedefs... */ +#if defined(_MSC_VER) && (_MSC_VER <= 1200) +#ifndef DWORD_PTR +#define DWORD_PTR DWORD +#endif +#ifndef LONG_PTR +#define LONG_PTR LONG +#endif +#endif + #include "SDL_rect.h" /* Routines to convert from UTF8 to native Windows text */