On Tue, Apr 3, 2012 at 10:49 PM, Amaury Forgeot d'Arc <span dir="ltr"><<a href="mailto:amauryfa@gmail.com">amauryfa@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2012/4/3 Stefan Behnel <<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>>:<br>
<div class="im">> The basic C code that gets executed in the test_append() function is simply<br>
><br>
> PyObject* m = PyObject_GetAttrString(L, "append");<br>
> r = PyObject_CallFunctionObjArgs(m, x, NULL);<br>
><br>
> And that's where the error gets raised (returning r==NULL). Specifically,<br>
> it does not enter into the actual append() method but fails before that,<br>
> right at the call.<br>
<br>
</div>The issue is with CyFunctionType, which looks like a subclass of<br>
PyCFunction_Type.<br>
(it's a hack: normally this type is not subclassable, booo)<br>
<br>
L.append is such a CyFunctionType.<br>
Its tp_call slot is called, but this is defined to __Pyx_PyCFunction_Call<br>
which is #defined to PyObject_Call, which itself invokes the tp_call slot...<br>
<br>
A solution would be to access the "base" tp_call, the one that CPython<br>
exposes as PyCFunction_Call.<br>
Unfortunately cpyext only defines one tp_call shared by all types, one<br>
which simply delegates to self.__call__.<br>
<br>
This means that "calling the base slot" does not work very well with cpyext.<br>
There is a solution though, which I implemented a long time ago for<br>
the tp_setattro slot.<br>
It can be easily expanded to it's a hack: normally this type is not<br>
subclassable, booo)<br>
all slots but I'm a bit scared of the explosion of code this could generate.<br>
<font color="#888888"><br>
--<br>
Amaury Forgeot d'Arc<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
pypy-dev mailing list<br>
<a href="mailto:pypy-dev@python.org">pypy-dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/pypy-dev" target="_blank">http://mail.python.org/mailman/listinfo/pypy-dev</a></div></div></blockquote><div> </div></div>Hey<div><br></div><div>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</div>
<div><br></div><div>Cheers,</div><div>fijal</div>