[Pyrex] difficulty while importing extension class

Sat Tara Singh smonkey at entropia.com.mx
Sun Nov 18 18:39:41 CET 2007


Greetings,

I've been working on a Python project with a cellular automaton engine 
at its core, and have been busy developing this engine in Pyrex. I ran 
into an unexpected situation yesterday.

I have compiled a .pyd file name "topology" with an extension class 
called Topology.

I then tried to use this extension class in a different Pyrex module 
named "neighborhood".

Here's the code:

############################

cimport topology as T

cdef class Thing:
     cdef T.Topology topo

     def __init__(self):
          self.topo = T.Topology((100,100),2)

############################

When I tried to compile this I got the following error message:

error: lvalue required as left operand of assignment

So, I looked at the line in the .c file which had raised this error and 
it read as follows:

((PyObject *)((struct __pyx_obj_12neighborhood_Thing 
*)__pyx_v_self)->topo) = __pyx_3;

Having no idea what this means, I did a Google search, read a bug report 
by Dmitry Marakasov, and changed the code to this:

__pyx_v_self = (struct __pyx_obj_12neighborhood_Thing *)__pyx_3;

This compiled successfully and ran without problems.

Happy as I was to see it work, I'm totally befuddled as to what I did, 
and decidedly unwilling to dive into C code I'm too dumb to understand 
every time I want to use an extension class in my project. I wonder if 
anybody has any feedback on this.

I'm running Pyrex 0.9.3.1 for Windows on a WindowsXP box, under Python 
2.5, and using MinGW's gcc as a compiler.

Thanks,

Sat Tara S





More information about the Pyrex mailing list