[Pyrex] hack to make pyrex generated code compile with gcc4

John (J5) Palmieri johnp at redhat.com
Mon Mar 21 21:51:15 CET 2005


Attached is a post processor that greps pyrex generated code and fixes
lvalue casting which is not allowed in gcc4.  This works for the dbus
bindings.  Your mileage may vary with code that uses constructs that the
dbus bindings don't use.  Again this is just a hack and needs to be
fixed in Pyrex proper at some point.  

There are three cases that I could identify in the Pyrex code where
these lvalue casts happen. Two involve casting values when assigning
PyNone.  The lines typically read:

((PyObject*)<some_var>) = PyNone; 
and
((PyObject *)<some_var>) = PyNone;

which are both the same except for the space in between the asterisk and
the cast pointed to two different code segments that generate these. 
For those lines the output is changed to:

<some_var> = (PyObject *)PyNone;

The last place which may actually be generated in more than one code
segment also read like:

(struct __pyx_vtabstruct_13dbus_bindings_PendingCall *)p->__pyx_vtab =
__pyx_vtabptr_13dbus_bindings_PendingCall;

with PendingCall being replaced in other part of the code for other
object created by the dbus bindings.  This line is rewritten as:

p->__pyx_vtab = ((struct __pyx_vtabstruct_13dbus_bindings_PendingCall
*)__pyx_vtabptr_13dbus_bindings_PendingCall);

Hopefully identifying these problematic areas will speed up developing a
more permanent fix.  Other than those areas the dbus bindings seem to be
compiling with gcc4 quite well.

The attached program take the generated c file as input and outputs a
file of the same name, appended with .gcc4fix.  For example:

lvalue_cast_post_process.py dbus_bindings.c

produces

dbus_bindings.c.gcc4fix

--
J5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lvalue_cast_post_process.py
Type: application/x-python
Size: 1640 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20050321/05ff658e/lvalue_cast_post_process.bin


More information about the Pyrex mailing list