[Cython] Upcoming issues with NumPy deprecated APIs and Cython's sizeof checks
Lisandro Dalcin
dalcinl at gmail.com
Mon Jan 30 22:03:03 CET 2012
I'm testing my code with numpy-dev. They are trying to discourage use
of deprecated APIs, this includes direct access to the ndarray struct.
In order to update your code, you have to pass -DNPY_NO_DEPRECATED_API
to the C compiler (or #define it before including NumPy headers).
However, they have implemented this feature by exposing the ndarray
type with just the Python object header:
https://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/ndarraytypes.h#L695
Obviously, this interact bad with Cython's sizeof check, I'm getting
this runtime warning:
build/lib.linux-x86_64-2.7/petsc4py/lib/__init__.py:64:
RuntimeWarning: numpy.ndarray size changed, may indicate binary
incompatibility
I think there is nothing Cython can do about this (other than
special-casing NumPy to disable this VERY useful warning).
I've tried the patch below with success, but I'm not convinced...
Does any of you have a suggestion for NumPy folks about how to improve
this?
diff --git a/numpy/core/include/numpy/ndarraytypes.h
b/numpy/core/include/numpy/ndarraytypes.h
index 0288272..1fcbf52 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -695,6 +695,7 @@ typedef struct tagPyArrayObject_fields {
#ifdef NPY_NO_DEPRECATED_API
typedef struct tagPyArrayObject {
PyObject_HEAD
+ char _npy_array_fields[sizeof(PyArrayObject_fields)-sizeof(PyObject)];
} PyArrayObject;
#else
/*
--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
More information about the cython-devel
mailing list