[Cython] Crash with freelist() and __slots__

Stefan Behnel stefan_ml at behnel.de
Mon Mar 3 17:38:58 CET 2014


Hi,

I was made aware of crashes in the last lxml release, which turned out to
be due to the use of freelists for types that could be subtyped from Python
code. I was able to work around them in lxml, however, the real problem is
in Cython. There was supposed to be a safe guard for that case in the
freelist code based on the object struct size, which increases for subtypes
that have a __dict__. However, if the Python subtype uses an empty
__slots__ declaration, the object struct size will not increase, thus
passing the guard.

The correct fix is to also test if the type being instantiated lives on the
heap and exclude it from the freelist if so.

https://github.com/cython/cython/commit/d2aff824dd0900982a420ebaaa1dac6120a9d72e

This, together with the buffer/memory view related bugs I fixed since the
last release, suggest (at least to me) that we shouldn't wait all too long
with the next bug fix release.

>From my POV, all changes in current master are safe enough to go out.

Stefan


More information about the cython-devel mailing list