From 872afe6bdae50d1ac4fec8f7717cd041fd064222 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 15 Nov 2023 17:02:36 -0500 Subject: [PATCH 1/6] Use NumPy macros for overflow detection --- pandas/_libs/src/vendored/numpy/datetime/np_datetime.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index 01e11e5138a8e..1b915e04e89a1 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -28,6 +28,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #include #include #include +#include #if defined(_WIN32) #ifndef ENABLE_INTSAFE_SIGNED_FUNCTIONS @@ -40,14 +41,16 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #else #if defined __has_builtin #if __has_builtin(__builtin_add_overflow) -#if _LP64 || __LP64__ || _ILP64 || __ILP64__ +#if NPY_BITSOF_LONG == 64 #define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res) -#else +#elif NPY_BITSOF_LONGLONG == 64 #define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) +#else +_Static_assert(0, "Sizeof long or long long must be 32 bits"); #endif #else _Static_assert(0, From 96c5e1cc327e6d842bb43936211a6dc292d80bcc Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 15 Nov 2023 17:03:40 -0500 Subject: [PATCH 2/6] typo --- pandas/_libs/src/vendored/numpy/datetime/np_datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index 1b915e04e89a1..64623d4074e88 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -50,7 +50,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) #else -_Static_assert(0, "Sizeof long or long long must be 32 bits"); +_Static_assert(0, "Sizeof long or long long must be 64 bits"); #endif #else _Static_assert(0, From 85b7f3f4666b8bbbce03e06f0a78d2a251f57114 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 16 Nov 2023 22:03:20 -0500 Subject: [PATCH 3/6] try more fix --- pandas/_libs/src/vendored/numpy/datetime/np_datetime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index 64623d4074e88..eb0358efcf98e 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -50,7 +50,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) #else -_Static_assert(0, "Sizeof long or long long must be 64 bits"); +_Static_assert(0, "long or long long must be 64 bits"); #endif #else _Static_assert(0, @@ -59,14 +59,16 @@ _Static_assert(0, // __has_builtin was added in gcc 10, but our muslinux_1_1 build environment // only has gcc-9.3, so fall back to __GNUC__ macro as long as we have that #elif __GNUC__ > 7 -#if _LP64 || __LP64__ || _ILP64 || __ILP64__ +#if NPY_BITSOF_LONG == 64 #define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res) -#else +#elif NPY_BITSOF_LONGLONG == 64 #define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) +#else +_Static_assert(0, "long or long long must be 64 bits"); #endif #else _Static_assert(0, "__has_builtin not detected; please try a newer compiler"); From 647719381a95133d8b0ff4dfedf50fb0ae2b5a26 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 17 Nov 2023 00:05:05 -0500 Subject: [PATCH 4/6] try more --- pandas/_libs/src/vendored/numpy/datetime/np_datetime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index eb0358efcf98e..c6d47e1ecfd02 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -41,11 +41,11 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #else #if defined __has_builtin #if __has_builtin(__builtin_add_overflow) -#if NPY_BITSOF_LONG == 64 +#if NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONG #define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res) -#elif NPY_BITSOF_LONGLONG == 64 +#elif NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONGLONG #define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) @@ -59,11 +59,11 @@ _Static_assert(0, // __has_builtin was added in gcc 10, but our muslinux_1_1 build environment // only has gcc-9.3, so fall back to __GNUC__ macro as long as we have that #elif __GNUC__ > 7 -#if NPY_BITSOF_LONG == 64 +#if NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONG #define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res) -#elif NPY_BITSOF_LONGLONG == 64 +#elif NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONGLONG #define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res) #define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) #define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) From 0b2bc61636f22e6946dec1cbb746d41cca9ad8ed Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 17 Nov 2023 00:24:01 -0500 Subject: [PATCH 5/6] use generic macros --- .../src/vendored/numpy/datetime/np_datetime.c | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index c6d47e1ecfd02..2ccae513a889e 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -41,17 +41,9 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #else #if defined __has_builtin #if __has_builtin(__builtin_add_overflow) -#if NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONG -#define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res) -#define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res) -#define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res) -#elif NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONGLONG -#define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res) -#define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) -#define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) -#else -_Static_assert(0, "long or long long must be 64 bits"); -#endif +#define checked_int64_add(a, b, res) __builtin_add_overflow(a, b, res) +#define checked_int64_sub(a, b, res) __builtin_sub_overflow(a, b, res) +#define checked_int64_mul(a, b, res) __builtin_mul_overflow(a, b, res) #else _Static_assert(0, "Overflow checking not detected; please try a newer compiler"); @@ -59,17 +51,9 @@ _Static_assert(0, // __has_builtin was added in gcc 10, but our muslinux_1_1 build environment // only has gcc-9.3, so fall back to __GNUC__ macro as long as we have that #elif __GNUC__ > 7 -#if NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONG -#define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res) -#define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res) -#define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res) -#elif NPY_SIZEOF_DATETIME == NPY_SIZEOF_LONGLONG -#define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res) -#define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res) -#define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res) -#else -_Static_assert(0, "long or long long must be 64 bits"); -#endif +#define checked_int64_add(a, b, res) __builtin_add_overflow(a, b, res) +#define checked_int64_sub(a, b, res) __builtin_sub_overflow(a, b, res) +#define checked_int64_mul(a, b, res) __builtin_mul_overflow(a, b, res) #else _Static_assert(0, "__has_builtin not detected; please try a newer compiler"); #endif From 61ed1ab49395456a86b9d55092eeb88ff4db7d7f Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 17 Nov 2023 00:39:27 -0500 Subject: [PATCH 6/6] IWYU --- pandas/_libs/src/vendored/numpy/datetime/np_datetime.c | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index 2ccae513a889e..f6efae77c5c01 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -28,7 +28,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #include #include #include -#include #if defined(_WIN32) #ifndef ENABLE_INTSAFE_SIGNED_FUNCTIONS