[Pyrex] sizeof cimport struct

Eric Huss e-huss at netmeridian.com
Fri Dec 16 07:32:29 CET 2005


I noticed an odd behavior when using cimport to pull in a struct
definition and the sizeof function.

An example, in something.pxd:

cdef extern from "someheader.h":

    ctypedef struct SOMESTRUCT:
        unsigned long value

And in mything.pyx:

cimport something
from something cimport SOMESTRUCT

def foo():
    print sizeof(something.SOMESTRUCT)
    print sizeof(SOMESTRUCT)

The first call to sizeof produces an error:

mything.pyx:5:26: 'SOMESTRUCT' is not a constant, variable or function identifier

The second one seems to work fine (in fact, the c code that is produced is
correct for both cases).

Am I misusing/abusing the cimport feature, or is this just a quirk?

-Eric




More information about the Pyrex mailing list