[Pyrex] cdef'd classes initialization

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 9 05:21:12 UTC 2006


Daniele Varrazzo wrote:
> When the property __get__ is invoked, i
> create from Pyrex a new instance to wrap the component structure. But
> this instance doesn't own the wrapped structure: on __dealloc__ it must
> not free() anything.

I think I would do this by having the viewer reference
the base Python object, and access the C data through
that, rather than pointing to the C data directly.
That way you won't have problems if the base object
gets deallocated while Python code is still holding
a reference to one of the views.

> Can an instance be created by Pyrex without the __init__ call but with
> an init_owner() or init_viewer() call instead?

There's nothing to stop you defining a type with no
__new__ or __init__ method and calling a C method of
your choice on it to initialise it after creating it.
But currently the only supported way to create the
object in the first place is to make a Python call to
its type.

Also, there's nothing to stop interpreted code from
calling the type as well, and ending up with an
instance that's not fully initialised.

I'm thinking about these issues, but I haven't
figured out what to do about them yet. With new-style
types, creating an object is complicated enough that
attempting to bypass the normal mechanisms is fraught
with peril...

--
Greg



More information about the Pyrex mailing list