<div class="gmail_quote">2011/9/28 Alex Pyattaev <span dir="ltr">&lt;<a href="mailto:alex.pyattaev@gmail.com">alex.pyattaev@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi!<br>
I have a quite sophisticated program that can be summarized as follows:<br>
1. Save a pypy object pointer inside C program. Here I call Py_XINCREF so that<br>
it does not get deleted.<br>
2. Do some logic, move this reference around C code.<br>
3. Return a python tuple via typemap, here I am probably supposed to return a<br>
borrowed reference. And in Python2 it works just fine. BUT. In pypy, for some<br>
reason, it causes segfault with following message:<br>
&quot;&quot;&quot;<br>
Fatal error in cpyext, CPython compatibility layer, calling PyTuple_SetItem<br>
Either report a bug or consider not using this particular extension<br>
&lt;InvalidPointerException object at 0x14a87a8&gt;<br>
RPython traceback:<br>
  File &quot;module_cpyext_api_1.c&quot;, line 28965, in PyTuple_SetItem<br>
  File &quot;module_cpyext_pyobject.c&quot;, line 1018, in CpyTypedescr_realize<br>
Segmentation fault<br>
&quot;&quot;&quot;<br>
If I call Py_XINCREF before returning the object, the crash does not happen<br>
and the memory does not seem to be leaking (at least not noticeably massive<br>
amounts of it). So it seems that PyPy is somewhat incompatible with Python2 in<br>
that matter.<br>
If you want I could send the code example that triggers the bug (it IS quite<br>
large app, which might have many more bugs apart from this, but still).<br></blockquote><div><br></div><div>Isn&#39;t PyTuple_SetItem supposed to &quot;steal&quot; the reference?</div><div>In this case you&#39;d better INCREF the object if it is globally shared.</div>
<div><br></div></div>-- <br>Amaury Forgeot d&#39;Arc<br>