From 6742db7bdbcf026a98a360418af42fa21a0a85a5 Mon Sep 17 00:00:00 2001 From: Edward E Date: Fri, 21 Apr 2023 16:04:38 -0500 Subject: [PATCH] MAINT: Overhaul and refactor NPY_OS_WIN* An addendum to #20884 that fixes and deobfuscates Windows OS defines. NPY_OS_WIN64 was never defined, as _WIN32 is defined whenever _WIN64 is. Rename NPY_OS_WIN* constants to be less ambiguous, to avoid future confusion about their meanings. Also remove NPY_OS_MINGW, since it too never got defined. Note that MINGW is not an OS anyway, but a build environment like MSVC. All changes either preserve functionality or restore original intent. --- numpy/core/include/numpy/npy_common.h | 4 ++-- numpy/core/include/numpy/npy_os.h | 12 +++++++----- numpy/core/src/multiarray/convert.c | 2 +- .../src/umath/loops_trigonometric.dispatch.c.src | 2 +- numpy/f2py/cfuncs.py | 6 +++--- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h index fb976aa6ae09..fb6fbec9f9d2 100644 --- a/numpy/core/include/numpy/npy_common.h +++ b/numpy/core/include/numpy/npy_common.h @@ -138,8 +138,8 @@ #endif /* 64 bit file position support, also on win-amd64. Issue gh-2256 */ -#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400) || \ - defined(__MINGW32__) || defined(__MINGW64__) +#if (defined(_MSC_VER) && (_MSC_VER > 1400) && defined(NPY_OS_WIN_64BIT)) || \ + defined(__MINGW32__) #include #define npy_fseek _fseeki64 diff --git a/numpy/core/include/numpy/npy_os.h b/numpy/core/include/numpy/npy_os.h index 6d8317d0667c..aa69f7450f05 100644 --- a/numpy/core/include/numpy/npy_os.h +++ b/numpy/core/include/numpy/npy_os.h @@ -20,11 +20,13 @@ #elif defined(__CYGWIN__) #define NPY_OS_CYGWIN #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) - #define NPY_OS_WIN32 -#elif defined(_WIN64) || defined(__WIN64__) || defined(WIN64) - #define NPY_OS_WIN64 -#elif defined(__MINGW32__) || defined(__MINGW64__) - #define NPY_OS_MINGW +/* _WIN32 is defined on 64-bit as well as 32-bit */ + #define NPY_OS_WINDOWS + #if defined(_WIN64) || defined(__WIN64__) || defined(WIN64) + #define NPY_OS_WIN_64BIT + #else + #define NPY_OS_WIN_32BIT + #endif #elif defined(__APPLE__) #define NPY_OS_DARWIN #elif defined(__HAIKU__) diff --git a/numpy/core/src/multiarray/convert.c b/numpy/core/src/multiarray/convert.c index aef78ff5ef23..04e5e7175051 100644 --- a/numpy/core/src/multiarray/convert.c +++ b/numpy/core/src/multiarray/convert.c @@ -157,7 +157,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) size = PyArray_SIZE(self); NPY_BEGIN_ALLOW_THREADS; -#if defined(NPY_OS_WIN64) +#if defined(NPY_OS_WIN_64BIT) /* * Workaround Win64 fwrite() bug. Issue gh-2256 * The native 64 windows runtime has this issue, the above will diff --git a/numpy/core/src/umath/loops_trigonometric.dispatch.c.src b/numpy/core/src/umath/loops_trigonometric.dispatch.c.src index 1b77592c818b..0f0e62eedd7f 100644 --- a/numpy/core/src/umath/loops_trigonometric.dispatch.c.src +++ b/numpy/core/src/umath/loops_trigonometric.dispatch.c.src @@ -44,7 +44,7 @@ simd_range_reduction_@sfx@(npyv_@sfx@ x, npyv_@sfx@ y, npyv_@sfx@ c1, npyv_@sfx@ /**begin repeat * #op = cos, sin# */ -#if defined(NPY_OS_WIN32) || defined(NPY_OS_CYGWIN) +#if defined(NPY_OS_WINDOWS) || defined(NPY_OS_CYGWIN) NPY_FINLINE npyv_f64 #else NPY_NOINLINE npyv_f64 diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index 2d27b652432b..b557d1461022 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -64,7 +64,7 @@ typedefs['unsigned_long'] = 'typedef unsigned long unsigned_long;' typedefs['signed_char'] = 'typedef signed char signed_char;' typedefs['long_long'] = """\ -#if defined(NPY_OS_WIN32) +#if defined(NPY_OS_WINDOWS) typedef __int64 long_long; #else typedef long long long_long; @@ -72,7 +72,7 @@ #endif """ typedefs['unsigned_long_long'] = """\ -#if defined(NPY_OS_WIN32) +#if defined(NPY_OS_WINDOWS) typedef __uint64 long_long; #else typedef unsigned long long unsigned_long_long; @@ -542,7 +542,7 @@ #ifndef F2PY_THREAD_LOCAL_DECL #if defined(_MSC_VER) #define F2PY_THREAD_LOCAL_DECL __declspec(thread) -#elif defined(NPY_OS_MINGW) +#elif defined(__MINGW32__) #define F2PY_THREAD_LOCAL_DECL __thread #elif defined(__STDC_VERSION__) \\ && (__STDC_VERSION__ >= 201112L) \\