[Cython] [cython] Fix __Pyx_ImportType if #Py_LIMITED_API is defined. (#171)

Bradley M. Froehle brad.froehle at gmail.com
Thu Dec 20 08:03:39 CET 2012

This was the only issue I ran into while trying to use a Cython compiled
module from a new module compiled with Py_LIMITED_API, and the fix turned
out to be pretty simple.

The real trick, as you allude to, will be to have a Cython generated module
itself be able to be compiled with Py_LIMITED_API.


On Wed, Dec 19, 2012 at 10:24 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Hi Bradley,
> Bradley M. Froehle, 19.12.2012 21:31:
> > I was recently trying to use mpi4py in a hand-written Python 3 extension
> > module with `#define Py_LIMITED_API`.
> Work on getting Cython play nicely with Py_LIMITED_API is certainly
> appreciated. In most cases, it should be as simple as adding another #ifdef
> to utility functions that are already written in plain C anyway. A lot of
> the optimisations will need this.
> > One side effect of the limited
> > API is that `PyTypeObject` becomes an opaque type.
> > This means that our `__Pyx_ImportType` cannot just introspect
> > `tp_basicsize`.
> >
> > I've updated the code to extract the `tp_basicsize` value from the
> > `__basicsize__` attribute which should be available instead.
> >
> > I'd appreciate comments on the code style here... I'm not sure how to
> > write these sorts of calls most efficiently yet.
> I think it's ok. The only issue is that PyObject_GetAttrString() creates an
> intermediate string object from the char* you pass. Py3.3 (or 3.2+?) has a
> mechanism for avoiding this. We could start using that if available, or
> maybe even copy it over into Cython to use it in older versions as well.
> Anyway, this is code that runs at import time - I don't think it's any
> performance critical (and if a whole import works, the memory allocated for
> a tiny string can't be an issue either...).
> Stefan
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20121219/d232bc37/attachment.html>

More information about the cython-devel mailing list