[pypy-dev] Findings in the Cython test suite

Maciej Fijalkowski fijall at gmail.com
Tue Apr 3 23:07:38 CEST 2012


On Tue, Apr 3, 2012 at 10:49 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com>wrote:

> 2012/4/3 Stefan Behnel <stefan_ml at behnel.de>:
> > The basic C code that gets executed in the test_append() function is
> simply
> >
> >    PyObject* m = PyObject_GetAttrString(L, "append");
> >    r = PyObject_CallFunctionObjArgs(m, x, NULL);
> >
> > And that's where the error gets raised (returning r==NULL). Specifically,
> > it does not enter into the actual append() method but fails before that,
> > right at the call.
>
> The issue is with CyFunctionType, which looks like a subclass of
> PyCFunction_Type.
> (it's a hack: normally this type is not subclassable, booo)
>
> L.append is such a CyFunctionType.
> Its tp_call slot is called, but this is defined to __Pyx_PyCFunction_Call
> which is #defined to PyObject_Call, which itself invokes the tp_call
> slot...
>
> A solution would be to access the "base" tp_call, the one that CPython
> exposes as PyCFunction_Call.
> Unfortunately cpyext only defines one tp_call shared by all types, one
> which simply delegates to self.__call__.
>
> This means that "calling the base slot" does not work very well with
> cpyext.
> There is a solution though, which I implemented a long time ago for
> the tp_setattro slot.
> It can be easily expanded to it's a hack: normally this type is not
> subclassable, booo)
> all slots but I'm a bit scared of the explosion of code this could
> generate.
>
> --
> Amaury Forgeot d'Arc
> _______________________________________________
> pypy-dev mailing list
> pypy-dev at python.org
> http://mail.python.org/mailman/listinfo/pypy-dev
>

Hey

I would like to point out that all the assumptions like "this type is not
subclassable" or "this field is read only" might work on cpython, but the
JIT will make assumptions based on that and it'll stop working or produce
very occasional segfaults

Cheers,
fijal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120403/92c8b630/attachment.html>


More information about the pypy-dev mailing list