Hello all,

as a happy Pyrex user for more than six years I recently got interested 
in Cython as well. So far adopting codes to Cython has in most cases 
been quite straightforward. In fact it even resulted in improvements due 
to some errors, which Pyrex had not complained about and which were 
detected by Cython.

However, for the following minimalistic example the resulting C code 
doesn't compile:

#### _stypes.pxd ####
ctypedef public class Time [type MyTime_Type, object MyTimeObject]:
     cdef public double seconds

ctypedef public class Event [type MyEvent_Type, object MyEventObject]:
     cdef public Time time

#### _stypes.pyx ####
ctypedef public class Time [type MyTime_Type, object MyTimeObject]:
     def __init__(self, seconds):
         self.seconds = seconds

ctypedef public class Event [type MyEvent_Type, object MyEventObject]:
     def __init__(self, Time time):
         self.time = time

####

Compilation to C works without complaint, but the compilation of the 
resulting C code gives errors like

_stypes.c:319: error: expected specifier-qualifier-list before 
'MyTimeObject'
_stypes.c: In function '__pyx_pf_7_stypes_5Event___init__':
_stypes.c:463: error: 'MyEventObject' has no member named 'time'
[The last error repeated several times]

It turns out that in _stypes.c, the declaration of MyEventObject 
precedes that of MyTimeObject. Here's the relevant code snippet:

/* Type declarations */

/* "/home/saul/Cython-Test/_stypes.pxd":5
  *     cdef public double seconds
  *
  * ctypedef public class Event [type MyEvent_Type, object 
MyEventObject]:             # <<<<<<<<<<<<<<
  *     cdef public Time time
  */

typedef struct {
   PyObject_HEAD
   MyTimeObject *time;
} MyEventObject;

/* "/home/saul/Cython-Test/_stypes.pxd":1
  * ctypedef public class Time [type MyTime_Type, object MyTimeObject]: 
             # <<<<<<<<<<<<<<
  *     cdef public double seconds
  */

 
                                                      typedef struct {
   PyObject_HEAD
   double seconds;
} MyTimeObject;
/* Module declarations from _stypes */


I.e. MyTimeObject is declared *after* MyEventObject, which I wouldn't 
have expected. Is there any reason for that?

At this point I am stuck, although I suspect that I overlooked something 
very simple. Any hints would be appreciated.

By the way, the C code Pyrex produces from the above pyx/pxd compiles 
and works properly.

Cython 0.11.2 and Python 2.6 under Ubuntu 9.04.

Cheers,
Joachim
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to