diff options
author | da-woods <dw-git@d-woods.co.uk> | 2021-10-06 07:16:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-06 08:16:08 +0200 |
commit | 454a49850d7b0328f566d3026788ef08186c30a5 (patch) | |
tree | d66095075880c93f8044396f97e5031cf06ef7ee | |
parent | 97c05e7a936e1a8929ee8c3e2f6629cc061cb66b (diff) | |
download | cython-454a49850d7b0328f566d3026788ef08186c30a5.tar.gz |
Improve "import_array" guard (GH-4397)
Stop using NPY_NDARRAYOBJECT_H since:
a) in principle it's private
b) Numpy has renamed it
and use a public symbol instead.
I think the existing tests are adequate - we just aren't yet testing
against a new enough version of Numpy to have caught it yet.
Closes https://github.com/cython/cython/issues/4396
Closes https://github.com/cython/cython/issues/4394
-rw-r--r-- | Cython/Utility/NumpyImportArray.c | 2 | ||||
-rw-r--r-- | tests/run/numpy_import_array_error.srctree | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/Cython/Utility/NumpyImportArray.c b/Cython/Utility/NumpyImportArray.c index aa8a18fea..a74a38aca 100644 --- a/Cython/Utility/NumpyImportArray.c +++ b/Cython/Utility/NumpyImportArray.c @@ -8,7 +8,7 @@ * add the line * <void>numpy._import_array */ -#ifdef NPY_NDARRAYOBJECT_H /* numpy headers have been included */ +#ifdef NPY_FEATURE_VERSION /* This is a public define that makes us reasonably confident it's "real" Numpy */ // NO_IMPORT_ARRAY is Numpy's mechanism for indicating that import_array is handled elsewhere #if !NO_IMPORT_ARRAY /* https://docs.scipy.org/doc/numpy-1.17.0/reference/c-api.array.html#c.NO_IMPORT_ARRAY */ if (unlikely(_import_array() == -1)) { diff --git a/tests/run/numpy_import_array_error.srctree b/tests/run/numpy_import_array_error.srctree index 9f2c286f1..f4589ed2c 100644 --- a/tests/run/numpy_import_array_error.srctree +++ b/tests/run/numpy_import_array_error.srctree @@ -18,7 +18,7 @@ setup(ext_modules = cythonize('cimport_numpy.pyx')) cdef extern from *: """ - #define NPY_NDARRAYOBJECT_H + #define NPY_FEATURE_VERSION static int _import_array(void) { PyErr_SetString(PyExc_ValueError, "Oh no!"); return -1; |