Re: sizeof operator problem
Robert Bradshaw <[email protected]> Tue, 30 Dec 2008 00:41:06 -0800
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
This is because Pyrex resolves sizeof(type) vs. sizeof(var) at parsing, rather than at a later stage of the algorithm when spam.spam can actually be analyzed. Cython resolves this by revisiting this decision at the analyse_types phase, so dotted names as variables and types can both be handled correctly. - Robert On Dec 30, 2008, at 12:36 AM, Daniele Pianu wrote: > Excuse me for the wrong error message specified in the mail sent. > Compile the egg.pyx source of the previous mail with the pyrexc > compiler raises this error: > > [daniele@tharros sizeofTest]$ pyrexc egg.pyx > /home/daniele/Projects/Pyrex/sizeofTest/egg.pyx:4:21: 'spam' is not a > constant, variable or function identifier > > Any idea? > Daniele. > > 2008/12/29 Daniele Pianu <[email protected]>: >> 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@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 >> > > _______________________________________________ > Pyrex mailing list > [email protected] > http://lists.copyleft.no/mailman/listinfo/pyrex