[Pyrex] public extension type to replace a complex structure variable

Gavin Baker gavinb at gmail.com
Tue Feb 22 02:27:38 CET 2005


On Mon, 21 Feb 2005 15:06:00 +1300, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:

> The idea is that you have an extension type corresponding
> to each C type that you want to expose, with methods that
> make calls to the underlying C code for performing
> operations on it.

This is very similar to what I am working on, which I imagine is a
fairly common shape.

> Note that the SmallObject's __new__ method allows it to
> be called without arguments, in which case it leaves the
> C pointer uninitialised so it can be filled in with a
> pointer to an existing smallobject. This is obviously
> not entirely safe, since there's nothing stopping Python
> code from calling it that way and ending up with an
> invalid SmallObject that will lead to a crash. There
> are ways of fixing that, but this message is long
> enough -- ask me if you want more details.

I have come across this initialisation problem also, whereby you often
want to create a Python object to encapsulate an existing struct so
you need to create it empty and use a cdef method to give it a
pointer.  Apart from asserting the pointer is not NULL in every
method, I'm not sure how best to handle this.

Any further light you can shed on this would be very useful, so I'd
certainly appreciate some more details when you get a chance.

Thanks -

  :: Gavin



More information about the Pyrex mailing list