[Cython] Upcoming issues with NumPy deprecated APIs and Cython's sizeof checks

Lisandro Dalcin dalcinl at gmail.com
Tue Jan 31 16:36:00 CET 2012

On 31 January 2012 11:29, mark florisson <markflorisson88 at gmail.com> wrote:
> On 30 January 2012 21:03, Lisandro Dalcin <dalcinl at gmail.com> wrote:
>> I think there is nothing Cython can do about this (other than
>> special-casing NumPy to disable this VERY useful warning).
> Weird, shouldn't you be getting an error? Because the size of the
> PyArrayObject should be less than what Cython expects.

Well, as long as your code does not access the structure fiels,
everything is OK.

> I'm not sure this should be fixed in NumPy. Their entire point is that
> people shouldn't use those attributes directly.

This makes me think about the all those arguments about the beauties
of "private:" in C++ (and others OOP langs). IMHO, if they way to
discourage access to these slots, they should declare them with some
weird names.

> I think numpy.pxd
> should be fixed, but the problem is that some attributes might be used
> in user code (especially shape), and we still want that to work in
> nogil mode.

You can still use PyArray_DATA(), PyArray_DIMS(), etc...

> As such, I'm not sure what the best way of fixing it is,
> without special casing these attributes in the compiler directly.
> Maybe Dag will have some thoughts about this.

I'v just noticed now NumPy #defines NPY_SIZEOF_PYARRAYOBJECT, that
could serve as a workaround for the sizeof check:

Lisandro Dalcin
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