From 509671c53e31d2fc9af6f89d1ac158cce8160d62 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 17:59:33 -0500 Subject: [PATCH 1/8] fix INT64 def and add warning if not set --- src/libImaging/ImPlatform.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index af9996ca98c..f183c3aa407 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -61,7 +61,9 @@ #if SIZEOF_LONG == 8 #define INT64 long #elif SIZEOF_LONG_LONG == 8 -#define INT64 long +#define INT64 long long +#else +#warning Cannot find required 64-bit integer type #endif #define INT8 signed char From 6de5e999bd7ee571877c975c9cb2a3038ee90f27 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 18:00:45 -0500 Subject: [PATCH 2/8] add UINT64 def if INT64 is defined --- src/libImaging/ImPlatform.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index f183c3aa407..522776b58cf 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -71,6 +71,9 @@ #define UINT16 unsigned INT16 #define UINT32 unsigned INT32 +#ifdef INT64 +#define UINT64 unsigned INT64 +#endif #endif From e9cfe4b6a2139923e3cab44bdd55cbf45ac16333 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 18:02:41 -0500 Subject: [PATCH 3/8] label preprocessor if..else..endif for clarity --- src/libImaging/ImPlatform.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index 522776b58cf..6db251bf155 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -25,7 +25,7 @@ #endif #endif -#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ #define WIN32_LEAN_AND_MEAN #include @@ -37,7 +37,7 @@ #undef WIN32 #endif -#else +#else /* WIN */ /* For System that are not Windows, we'll need to define these. */ #if SIZEOF_SHORT == 2 @@ -75,7 +75,7 @@ #define UINT64 unsigned INT64 #endif -#endif +#endif /* WIN */ /* assume IEEE; tweak if necessary (patches are welcome) */ #define FLOAT16 UINT16 From c2527348ecf4487be76fa55eefa440be1a96e9f5 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 18:04:10 -0500 Subject: [PATCH 4/8] add comment explaining why #define and not typedef --- src/libImaging/ImPlatform.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index 6db251bf155..e2d2d597b2e 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -39,6 +39,9 @@ #else /* WIN */ /* For System that are not Windows, we'll need to define these. */ +/* We have to define them instead of using typedef because the JPEG lib also + defines their own types with the same names, so we need to be able to undef + ours before including the JPEG code. */ #if SIZEOF_SHORT == 2 #define INT16 short From fbec8f19dd1ec77e3cf741c11038f0229967830c Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 18:11:02 -0500 Subject: [PATCH 5/8] add check for C99+ to use their defs if possible --- src/libImaging/ImPlatform.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index e2d2d597b2e..9f736ed75a7 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -43,6 +43,23 @@ defines their own types with the same names, so we need to be able to undef ours before including the JPEG code. */ +#if __STDC_VERSION__ >= 199901L /* C99+ */ + +#include + +#define INT8 int8_t +#define UINT8 uint8_t +#define INT16 int16_t +#define UINT16 uint16_t +#define INT32 int32_t +#define UINT32 uint32_t +#ifdef INT64_MAX +#define INT64 int64_t +#define UINT64 uint64_t +#endif + +#else /* C99+ */ + #if SIZEOF_SHORT == 2 #define INT16 short #elif SIZEOF_INT == 2 @@ -78,6 +95,8 @@ #define UINT64 unsigned INT64 #endif +#endif /* C99+ */ + #endif /* WIN */ /* assume IEEE; tweak if necessary (patches are welcome) */ From 9da0b58eea9d59d725106a76702b592e302c9665 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 18:13:50 -0500 Subject: [PATCH 6/8] move INT8 def to top --- src/libImaging/ImPlatform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index 9f736ed75a7..303ebf9871e 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -60,6 +60,8 @@ #else /* C99+ */ +#define INT8 signed char + #if SIZEOF_SHORT == 2 #define INT16 short #elif SIZEOF_INT == 2 @@ -86,9 +88,7 @@ #warning Cannot find required 64-bit integer type #endif -#define INT8 signed char #define UINT8 unsigned char - #define UINT16 unsigned INT16 #define UINT32 unsigned INT32 #ifdef INT64 From 724f2664601708dd1355c8a03b3815d56d788609 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 6 Oct 2022 18:14:55 -0500 Subject: [PATCH 7/8] change INT16 def failure to an error --- src/libImaging/ImPlatform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index 303ebf9871e..912b1785548 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -67,7 +67,7 @@ #elif SIZEOF_INT == 2 #define INT16 int #else -#define INT16 short /* most things works just fine anyway... */ +#error Cannot find required 16-bit integer type #endif #if SIZEOF_SHORT == 4 From f6b516bb068f28134c781b42f4188931f9e11b6b Mon Sep 17 00:00:00 2001 From: Yay295 Date: Fri, 19 May 2023 08:01:02 -0500 Subject: [PATCH 8/8] Adjust C preprocessor block labels Co-authored-by: Hugo van Kemenade --- src/libImaging/ImPlatform.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImPlatform.h index 912b1785548..10d6905b9d9 100644 --- a/src/libImaging/ImPlatform.h +++ b/src/libImaging/ImPlatform.h @@ -37,7 +37,7 @@ #undef WIN32 #endif -#else /* WIN */ +#else /* not WIN */ /* For System that are not Windows, we'll need to define these. */ /* We have to define them instead of using typedef because the JPEG lib also defines their own types with the same names, so we need to be able to undef @@ -58,7 +58,7 @@ #define UINT64 uint64_t #endif -#else /* C99+ */ +#else /* < C99 */ #define INT8 signed char @@ -95,9 +95,9 @@ #define UINT64 unsigned INT64 #endif -#endif /* C99+ */ +#endif /* < C99 */ -#endif /* WIN */ +#endif /* not WIN */ /* assume IEEE; tweak if necessary (patches are welcome) */ #define FLOAT16 UINT16