[Pyrex] A problem in generating Python extension types.
Lenard Lindstrom
len-l at telus.net
Mon Jan 15 19:13:37 UTC 2007
Daehyok Shin wrote:
> I am trying to replace complex C structures with Python extension
> types generated from PyRex code. My purpose is to create Python
> extension types which allows other C programs to access structure
> variables inside the extension types.
>
> A problem I met during the development may be best explained with the
> following simple example.
>
> --------- C Code --------------------------------
> struct child_object {
> int ID;
> }
>
> struct parent_object {
> struct child_object *child;
> }
>
> ---------- PyRex Code ------------------------
> public Child[object child_object, type child_type]:
> cdef public int ID
>
> public Parent[object parent_object, type parent_type]:
> cdef Child child
>
> def __new__(self)
> self.child = Child() # I got an error message here when compiling
> generated C code.
>
> def __dealloc_(self):
> del self.child
>
>
I can't comment on this code because it isn't value Pyrex.
"1:7: Syntax error in simple statement list"
> I succeeded in creating the same C structures from the above PyRex
> code, but when I compiled the generated C code, I got an error message
> because self.child expects a pointer to child_object but Child()
> returns a pointer to PyObject.
> Is there any way I can solve this problem so that the extension types
> act as a commond data models for both Python programs and C programs.
> Thanks in advance.
>
>
After converting everything into extension class declarations and
removing the "del self.child" I got it to compile in Pyrex 0.9.4.1. My
gcc 3.4.5 compiler only generated a warning when compiling the resulting
C code. So this is likely a Pyrex bug since early versions expected a
forgiving C compiler.
--
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list