[pypy-dev] swig + pypy - object reference counting

Alex Pyattaev alex.pyattaev at gmail.com
Wed Sep 28 11:06:02 CEST 2011


Hi!
I have a quite sophisticated program that can be summarized as follows:
1. Save a pypy object pointer inside C program. Here I call Py_XINCREF so that 
it does not get deleted.
2. Do some logic, move this reference around C code.
3. Return a python tuple via typemap, here I am probably supposed to return a 
borrowed reference. And in Python2 it works just fine. BUT. In pypy, for some 
reason, it causes segfault with following message:
"""
Fatal error in cpyext, CPython compatibility layer, calling PyTuple_SetItem
Either report a bug or consider not using this particular extension
<InvalidPointerException object at 0x14a87a8>
RPython traceback:
  File "module_cpyext_api_1.c", line 28965, in PyTuple_SetItem
  File "module_cpyext_pyobject.c", line 1018, in CpyTypedescr_realize
Segmentation fault
"""
If I call Py_XINCREF before returning the object, the crash does not happen 
and the memory does not seem to be leaking (at least not noticeably massive 
amounts of it). So it seems that PyPy is somewhat incompatible with Python2 in 
that matter. 
If you want I could send the code example that triggers the bug (it IS quite 
large app, which might have many more bugs apart from this, but still).

Thank you,
Alex.


More information about the pypy-dev mailing list