Project:Python/Strict aliasing

The Python 2 API had a design bug that caused some of the extensions to not comply with strict aliasing rules. For this reason, many extensions need to be explicitly built with -fno-strict-aliasing when built for Python 2.

When to use it?
To determine whether an extension needs -fno-strict-aliasing, build it with optimization and warnings enabled (-O2 -Wstrict-aliasing or just -O2 -Wall). If you get warnings similar to the following:

then you should add -fno-strict-aliasing to the build. However, usually this applies to Python 2 only (unless the extension code itself is broken).

How to add it?
The following snippet can be used to force -fno-strict-aliasing for Python 2-based implementations.