[Pyrex] gcc's -fstrict-aliasing optimization can break vtable construction in PyMODINIT_FUNC

Dan Gindikin dg at pnylab.com
Fri Nov 23 16:55:05 CET 2007


I have a module that works with "-O6 -fno-strict-aliasing", but breaks with just
"-O6". I chased this down to the bitter end, here is what I think happens, I 
have the following code:

	cdef class Base:
		cdef void F(self):
			...

	cdef class Derived(Base):
		cdef void F(self):
			...

	cdef Derived d=Derived()

	d.F() # <--- This in fact calls Base.F(), not Derived.F()

I believe what happens, is that because of the strict aliasing assumption, gcc 
re-orders the writes to the vtables in PyMODINIT_FUNC(), and the function 
pointer of Derived.F gets assigned to the vtable before the assignment of 
Base.F, even though in the code it comes later.

Has anyone seen something like this before?

-- 
Dan



More information about the Pyrex mailing list