[Pyrex] some questions about extension types

Robby Dermody robbyd at u20.org
Tue Feb 22 03:33:26 CET 2005


Hey guys,

I have a dilemma. I have a grouping of variables that both:
   -has some members that are python objects (normally necessitating the
use of an extension type as opposed to a C structure (cdef struct))
   -has some members that are C structures, which it would be great if I
could take the address of (which afaik does not work with extension
types...but would work with a plain C structure )

Apparently, I can't take the address of an extension type's members. For
instance, say I have
cdef class Bla:
	cdef char myCString[50]
	cdef otherStruct* someData

bla = Bla()
strncpy(bla.myCString, otherString, 50) #not allowed
memcpy(bla.someData, foo, sizeof(otherStruct)) #also not allowed

Will I just have to pass every (integer-type) member of someData, for
example, or the extension type itself, if I wanted to pass it to some
function?


Also, there is the issue of extension type initialization. I noticed
that I could "make" an extension type like:
cdef myType foo1
(as opposed to "foo1 = myType()")

However, all it looks like I'm doing in the first case is instanciating
that type's internal C struct. The first time I try to set one of its
python object members, I get a segfault, as the pythonic side to it has
not been initialized yet I'm guessing.




More information about the Pyrex mailing list