[Numpy-discussion] c api deprecations with NPY_NO_DEPRECATED_API

Charles R Harris charlesr.harris at gmail.com
Sat Mar 8 17:25:09 EST 2014


On Sat, Mar 8, 2014 at 2:54 PM, Paul Brossier <piem at piem.org> wrote:

> hi all,
>
> I'm trying to understand how to use the deprecation mechanism.
>
> 1. When not defining NPY_NO_DEPRECATED_API, I get warnings (as expected):
>
>         #warning "Using deprecated NumPy API, disable it by #defining
> NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
>
> 2. When defining NPY_NO_DEPRECATED_API, as mentioned in the above
> warning and in the documentation, I get this error:
>
>         #error Should never include npy_deprecated_api directly.
>
> 3. If instead I include <numpy/npy_no_deprecated_api.h>, I get no
> warning at all, and the extension builds as expected.
>
> Now, why does the second error occur, whereas I do not include
> npy_deprecated_api.h, and most important, what is the correct way to use
> the deprecation mechanism?
>
> There seems to be a few issues related to this on github, most of them
> closed, but reading them did not help me understanding.
>
> The extension i'm trying to improve is aubio and can be found at
> http://aubio.org. A copy of the relevant code is at:
>
> https://github.com/piem/aubio/blob/develop/python/ext/aubio-types.h
>
>
You should include the same files whether or not NPY_NO_DEPRECATED_API is
defined. Usually  numpy/arrayobject.h is the only needed include file. For
instance, fftpack_litemodule.c has at the top

#define NPY_NO_DEPRECATED_API NPY_API_VERSION

#include "fftpack.h"
#include "Python.h"
#include "numpy/arrayobject.h"

Where in this case  NPY_API_VERSION is the current version,
NPY_1_7_API_VERSION would be the numpy1.7.x API, etc. You use the version
you intend to support and things deprecated after that version will still
be available to you.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140308/285f5b0f/attachment.html>


More information about the NumPy-Discussion mailing list