[Pyrex] [Cython-dev] Segmentation Fault with -O0

Samuele Kaplun Samuele.Kaplun at cern.ch
Thu Aug 9 17:47:35 CEST 2007


To the lists:

In data giovedì 09 agosto 2007, Samuele Kaplun scribacchiaste dette parole:
> 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

Some additional information: I run the tests with gcc-3.4.6, 4.1.2 and 4.2.0, 
with the same behaviour (crash with -O0, -O, no crash with -O2, -O3), on an 
amd64 machine and Python 2.5. It never crash on gcc-3.x on 32bits.
Best regards,
	Samuele

Ps. In the previous email I was CCing a wrong email address. Please refer to 
the new one, when you'll replay.

-- 
.O.
..O
OOO



More information about the Pyrex mailing list