Stefan Behnel wrote:
>> On Fri, Feb 27, 2009 at 11:23 AM, Stefan Behnel wrote:
>>> -------------------------------
>>>  __pyx_vtable_4lxml_5etree__XSLTContext.__pyx_base =
>>> *__pyx_vtabptr_4lxml_5etree__BaseContext;
>>>
>>>  *(void(**)(void))&__pyx_vtable_4lxml_5etree__XSLTContext.__pyx_base._copy
>>> = (void(*)(void))__pyx_f_4lxml_5etree_12_XSLTContext__copy;
>>> -------------------------------
>>>
>> OK, I'm guessing that's actually not technically a bug.  Since
>> __pyx_base has no components of type (void(*)(void)), an assignment to
>> a storage location with that type "can't possibly" interfere with an
>> assignment to __pyx_base (according to the ANSI C aliasing rules), and
>> gcc is perfectly within its rights to reorder the two.
>>
>> The fix is to get rid of the casts in the vtable initializations.
> 
> This is now ticket #226.
> http://trac.cython.org/cython_trac/ticket/226

The following patch works for me. At least, it makes lxml compile and run
with -fstrict-aliasing and without aliasing warnings. Note that it's a
Py3-only change, so you will need Py3.0 to give it a try. Any feedback is
greatly appreciated.

Stefan


diff -r cb0f315bb4f5 Cython/Compiler/ModuleNode.py
--- a/Cython/Compiler/ModuleNode.py     Fri Feb 27 00:22:20 2009 -0800
+++ b/Cython/Compiler/ModuleNode.py     Fri Feb 27 22:11:13 2009 +0100
@@ -1969,11 +1969,22 @@
                         type.base_type.vtabptr_cname))
             for meth_entry in type.scope.cfunc_entries:
                 if meth_entry.func_cname:
+                    code.putln('#if PY_MAJOR_VERSION >= 3')
+                    cast = '(%s)' % (
+                        meth_entry.type.declaration_code('(*)'))
+                    code.putln(
+                        "%s.%s = %s%s;" % (
+                            type.vtable_cname,
+                            meth_entry.cname,
+                            cast,
+                            meth_entry.func_cname))
+                    code.putln('#else')
                     code.putln(
                         "*(void(**)(void))&%s.%s = (void(*)(void))%s;" % (
                             type.vtable_cname,
                             meth_entry.cname,
                             meth_entry.func_cname))
+                    code.putln('#endif')

     def generate_typeptr_assignment_code(self, entry, code):
         # Generate code to initialise the typeptr of an extension

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

Reply via email to