[Pyrex] Subclassing an extension type from a built-in

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Oct 16 01:19:30 CEST 2005


Michael Hordijk wrote:
> My problem is
> that I'm segfaulting when I raise an exception in __init__.

I think I've found out what's causing this. Pyrex isn't
setting the GC flag in the type object, because your
class doesn't define any Python attributes. Trouble is,
the base class *does* participate in GC, so Python is
getting confused about whether to track it for GC or not.

I had assumed that PyType_Ready would set the GC flag if
it was set in the base type, but it seems that this does
not happen, so I'll have to make Pyrex generate code to
do it.

In the meantime, you can work around it by giving your
class a dummy object-valued attribute to force Pyrex to
set the GC bit:

   cdef class test4(ListType):

     cdef object dummy # Add this line

     def __init__(self):
       raise StandardError

Greg



More information about the Pyrex mailing list