[Pyrex] Opaque structures and Extension Types

Robert Bradshaw robertwb at math.washington.edu
Thu May 15 03:29:17 CEST 2008


On May 14, 2008, at 4:47 PM, Greg Ewing wrote:

> Roberto Cavada wrote:
>
>> My way of handling allocation and
>> initialization of classes in C would require that __cinit__ of
>> derived class would be not called at all, as for example
>> Worker_create already handles the allocation and initialization of
>> Person and Worker structures.
>
> I think you'll just have to initialise the struct in
> __init__ rather than __cinit__, then you'll get
> control over whether the base class __init__ is
> called or not.
>
> It's not entirely safe, but it's about the best that
> can be done until I do something about providing a
> more Python-like __new__ method.

One can also make a cdef method which the (only) baseclass __cinit__  
calls, and simply override this for the subclass. One would want to  
do the same with deallocation as well.

- Robert




More information about the Pyrex mailing list