From 5650a2617cce40682844ae36f9294a1a6c99e548 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Wed, 8 May 2024 21:12:07 +0900 Subject: [PATCH 1/4] ext/bcmath: Fixed an issue where macros may become undefined --- ext/bcmath/libbcmath/src/private.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index f21bef665f95..34547822e48e 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -53,9 +53,14 @@ # if __has_builtin(__builtin_bswap64) # define BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin(__builtin_bswap64) -# elif defined(__GNUC__) -# define BSWAP32(u) __builtin_bswap32(u) -# define BSWAP64(u) __builtin_bswap64(u) +# endif +# ifdef __GNUC__ +# ifndef BSWAP32 +# define BSWAP32(u) __builtin_bswap32(u) +# endif +# ifndef BSWAP64 +# define BSWAP64(u) __builtin_bswap64(u) +# endif # endif // __has_builtin #endif // defined(_MSC_VER) #ifndef BSWAP32 From effa89cabd4062b55f31ff15f8ef93bf51b33536 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 9 May 2024 13:07:44 +0200 Subject: [PATCH 2/4] Test nightly fix --- ext/bcmath/libbcmath/src/private.h | 31 +++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index 34547822e48e..3c7bcb04c9d0 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -43,28 +43,23 @@ /* Bytes swap */ #if defined(_MSC_VER) # include -# define BSWAP32(u) _byteswap_ulong(u) -# define BSWAP64(u) _byteswap_uint64(u) +# define BC_BSWAP32(u) _byteswap_ulong(u) +# define BC_BSWAP64(u) _byteswap_uint64(u) #else # ifdef __has_builtin # if __has_builtin(__builtin_bswap32) -# define BSWAP32(u) __builtin_bswap32(u) +# define BC_BSWAP32(u) __builtin_bswap32(u) # endif // __has_builtin(__builtin_bswap32) # if __has_builtin(__builtin_bswap64) -# define BSWAP64(u) __builtin_bswap64(u) +# define BC_BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin(__builtin_bswap64) -# endif -# ifdef __GNUC__ -# ifndef BSWAP32 -# define BSWAP32(u) __builtin_bswap32(u) -# endif -# ifndef BSWAP64 -# define BSWAP64(u) __builtin_bswap64(u) -# endif +# elif defined(__GNUC__) +# define BC_BSWAP32(u) __builtin_bswap32(u) +# define BC_BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin #endif // defined(_MSC_VER) -#ifndef BSWAP32 -inline uint32_t BSWAP32(uint32_t u) +#ifndef BC_BSWAP32 +static inline uint32_t BC_BSWAP32(uint32_t u) { return (((u & 0xff000000) >> 24) | ((u & 0x00ff0000) >> 8) @@ -72,8 +67,8 @@ inline uint32_t BSWAP32(uint32_t u) | ((u & 0x000000ff) << 24)); } #endif -#ifndef BSWAP64 -inline uint64_t BSWAP64(uint64_t u) +#ifndef BC_BSWAP64 +static inline uint64_t BC_BSWAP64(uint64_t u) { return (((u & 0xff00000000000000ULL) >> 56) | ((u & 0x00ff000000000000ULL) >> 40) @@ -87,10 +82,10 @@ inline uint64_t BSWAP64(uint64_t u) #endif #if SIZEOF_SIZE_T >= 8 -#define BC_BSWAP(u) BSWAP64(u) +#define BC_BSWAP(u) BC_BSWAP64(u) #define BC_UINT_T uint64_t #else -#define BC_BSWAP(u) BSWAP32(u) +#define BC_BSWAP(u) BC_BSWAP32(u) #define BC_UINT_T uint32_t #endif From 4ebe58bb55e364bdd63082a13e313aa7b0c3b2b6 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Thu, 9 May 2024 22:31:50 +0900 Subject: [PATCH 3/4] Swap the checking order of __has_builtin and __GNUC__ --- ext/bcmath/libbcmath/src/private.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index 3c7bcb04c9d0..e67b0f9ae364 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -46,17 +46,17 @@ # define BC_BSWAP32(u) _byteswap_ulong(u) # define BC_BSWAP64(u) _byteswap_uint64(u) #else -# ifdef __has_builtin +# ifdef __GNUC__ +# define BC_BSWAP32(u) __builtin_bswap32(u) +# define BC_BSWAP64(u) __builtin_bswap64(u) +# elif defined(__has_builtin) # if __has_builtin(__builtin_bswap32) # define BC_BSWAP32(u) __builtin_bswap32(u) # endif // __has_builtin(__builtin_bswap32) # if __has_builtin(__builtin_bswap64) # define BC_BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin(__builtin_bswap64) -# elif defined(__GNUC__) -# define BC_BSWAP32(u) __builtin_bswap32(u) -# define BC_BSWAP64(u) __builtin_bswap64(u) -# endif // __has_builtin +# endif // __GNUC__ #endif // defined(_MSC_VER) #ifndef BC_BSWAP32 static inline uint32_t BC_BSWAP32(uint32_t u) From 4129ab02bd6d566c20dc15cfa9f230da98d26a9b Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Thu, 9 May 2024 22:33:12 +0900 Subject: [PATCH 4/4] Unification of notation --- ext/bcmath/libbcmath/src/private.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index e67b0f9ae364..1403baad0c25 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -41,7 +41,7 @@ #define SWAR_REPEAT(x) (SWAR_ONES * (x)) /* Bytes swap */ -#if defined(_MSC_VER) +#ifdef _MSC_VER # include # define BC_BSWAP32(u) _byteswap_ulong(u) # define BC_BSWAP64(u) _byteswap_uint64(u) @@ -57,7 +57,7 @@ # define BC_BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin(__builtin_bswap64) # endif // __GNUC__ -#endif // defined(_MSC_VER) +#endif // _MSC_VER #ifndef BC_BSWAP32 static inline uint32_t BC_BSWAP32(uint32_t u) { @@ -82,17 +82,17 @@ static inline uint64_t BC_BSWAP64(uint64_t u) #endif #if SIZEOF_SIZE_T >= 8 -#define BC_BSWAP(u) BC_BSWAP64(u) -#define BC_UINT_T uint64_t +# define BC_BSWAP(u) BC_BSWAP64(u) +# define BC_UINT_T uint64_t #else -#define BC_BSWAP(u) BC_BSWAP32(u) -#define BC_UINT_T uint32_t +# define BC_BSWAP(u) BC_BSWAP32(u) +# define BC_UINT_T uint32_t #endif #ifdef WORDS_BIGENDIAN -#define BC_LITTLE_ENDIAN 0 +# define BC_LITTLE_ENDIAN 0 #else -#define BC_LITTLE_ENDIAN 1 +# define BC_LITTLE_ENDIAN 1 #endif