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

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Dec 1 18:40:02 CET 2005

--- Philipp Thomas <pth at suse.de> wrote:

> We use a patch for gcc 4.1 that also makes it warn about violations of the
> C/C++ aliasing
> rules in C++ code (stock gcc only warns for C code). For the code in boost
> 1.33.1 I get
> warning: dereferencing type-punned pointer will break strict-aliasing rules
> for the following files:
>  /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/long.cpp:
> 12,19, 26
>  /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/dict.cpp: 32
>  /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/tuple.cpp:12
>  /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/str.cpp: 12

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)",

Line 12 is (PyObject*)&PyString_Type. Is this what we have to look at?

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

Thank you in advance!


Yahoo! Mail - PC Magazine Editors' Choice 2005 

More information about the Cplusplus-sig mailing list