[Pyrex] sizeof operator problem

Daniele Pianu muogoro at gmail.com
Mon Dec 29 12:36:25 CET 2008


I'm using the sizeof C operator to obtain the size of this spam structure:

cdef struct spam:
  int foo
  int bar

The spam structure is declared in the spam.pxd source. The egg
extention type, defined in the egg.pyx source, imports the spam's
definition and trys to print the spam structure size:

cimport spam
cdef class egg:
  def __init__( self ):
    print sizeof(spam.spam)

The compilation of the egg.pyx source raises this error:

[daniele at tharros 0.0.9]$ pyrexc tmp/PyArrayF32.pyx
/home/daniele/Projects/Python/PyBBDMMaker/0.0.9/tmp/PyArrayF32.pyx:9:64:
'ArrayF32' is not a constant, variable or function identifier

I've read here http://thread.gmane.org/gmane.comp.python.pyrex/2340/focus=2341
that a from-cimport statment solves the problem, but I'm using the
sizeof operator in the way described above in my sources, where the C
structure and the extension type which wraps the structure have the
same name (that is, for a Foo structure, a C_Foo.pxd source contains
the structure-extern definition and a PyFoo.pxd defines the wrapper. I
refer to the structure in the Foo extension type as C_Foo.Foo and I
pass the same name to the sizeof operator). Now the question: is there
a solution different from the from-cimport statement suggested in the
linked post?

Thanks for your help,
Daniele



More information about the Pyrex mailing list