[Pyrex] Pyrex and C++

Greg Ewing greg at cosc.canterbury.ac.nz
Mon Nov 17 04:37:08 CET 2003


"David J. C. Beach" <beach at verinet.com>:

> it seems that there are three categories of error that cause the C++
> compiler to complain about the pyrexc produced code:
> 
> 1) Assignment to "non l-values"
> 2) Redeclaration of variables
> 3) Assigning to non-void pointers from void* values
> 
> I don't yet fully understand the details of #1, but I believe that #2
> and #3 are easily fixed.

You're right, I think. The only instance of #2 that I'm aware of is
caused by the way it initialises the filename table, and that can be
fixed by initialising it dynamically in the module init function.

Pyrex itself never needs to do #3; it only happens if the user writes
code which does it. I think the best solution would be to change
Pyrex's pointer type checking rules to make it illegal (again -- it
was like that originally, but I changed it when I found that C will
allow assignments both to and from void *. I should have left it the
way it was!)

#1 will be the hardest to fix cleanly. The code generator currently
inserts casts in some places without knowing whether the result will
be used as an lvalue or an rvalue. Fixing this properly will require
a fairly extensive re-design of the code generator.

A quick and dirty way to fix it would be to replace things like

   (foo *)x

with

   *(foo **)&x

which should be usable as an lvalue as well as an rvalue. Good
luck on tracking down all the places that need changing, though...

> Is there any way I can help by working on these difficulties?  Should
> I just start digging my way through the Pyrex codebase?

That's about the only way, really.

> Is there a development version I should be working from (instead of
> the 0.9 release source code?)

No, that would be the one to use. 

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list