[Pyrex] Segmentation Fault with -O0

Samuele Kaplun Samuele.Kaplun at cern.ch
Thu Aug 9 14:32:39 CEST 2007


Dear Pyrex & Cython lists,
I've found a strange behaviour of my code developed with Pyrex (and Cython) 
which I can't solve.
I wrote and integer bit set extension to Python with Pyrex. It has the 
possibility to be searialized into a string and deserialized from that 
string.
I pass a correctly serialized representation to the constructor of my code (in 
the rhs variable):
[...]
cdef class intbitset:
[...]
    cdef IntBitSet *bitset
[...]
    def __new__(intbitset self, rhs=0, int minsize=-1):
[...]
        cdef size_t size
        cdef void *buf
[...]
                tmp = zlib.decompress(rhs)
                PyObject_AsReadBuffer(tmp, &buf, &size)
                self.bitset = intBitSetCreateFromBuffer(buf, size)
[...]
as you can see, I decompress the rhs string into the tmp Python object, I then 
retrieve a pointer to tmp and then I retrieve a pointer and the size of the 
pointed area, in order to pass it to my C constructor.

When I compile everything without optimization (-O0) it always crashes after 
exiting from __new__.
I tried to selectively commenting-out the code and I found that the 
incriminated row is:
		PyObject_AsReadBuffer(tmp, &buf, &size)
But I really don't know why.
The most interesting thing, is that it never segfaults when compiled with -02 
or -03.
If checked this with latest Cython & Pyrex and I obtain the same behaviour.

Do you maybe see anything obviously wrong in my code?
Best regards,
	Samuele
-- 
.O.
..O
OOO



More information about the Pyrex mailing list