[C++-sig] boost/python 1.33.1 breaks aliasing rules

Philipp Thomas pth at suse.de
Mon Dec 5 12:07:23 CET 2005

* Ralf W. Grosse-Kunstleve (rwgk at yahoo.com) [20051201 18:42]:

> Thanks for pointing out the aliasing problems! Could you help us understanding
> how the problem could be fixed? E.g., this is the code in str.cpp:
>     return (detail::new_reference)PyObject_CallFunction(
>         (PyObject*)&PyString_Type, "(O)",
>         arg_.ptr());
> Line 12 is (PyObject*)&PyString_Type. Is this what we have to look at?

Yes, the cast is what triggers the warning. C aliasing rules say, that
basically an object may only be accessed by a pointer of the same type. Only
char or void pointers may point to anything. These rules also apply to C++,
of cause expanded by the needs of C++.

AFAICS, PyObject and PyString_Type aren't related types, i.e. somehow
derived from one another.

> Both types are defined in Python headers. AFAIK the cast above is standard
> practice in Python code...

Yes, that's because up until now no compiler complained.


More information about the Cplusplus-sig mailing list