[Python-Dev] PyRange_New() alternative?
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Sat Jun 24 07:28:46 CEST 2006
--- Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
> Ralf W. Grosse-Kunstleve wrote:
> > Thanks! This does the trick for me:
> >
> > #if PY_VERSION_HEX >= 0x02030000
> > PyObject_CallFunction(
> > (PyObject*) &PyRange_Type, "lll", start, start+len*step, step)
> > #else
> > PyRange_New(start, len, step, 1)
> > #endif
> >
> > I am compiling the code above with a C++ compiler (in the context of
> > Boost.Python). Newer g++ versions unfortunatly produce a warning if -Wall
> is
> > specified:
> >
> > warning: dereferencing type-punned pointer will break strict-aliasing rules
>
> I am not sure about your compiler, but if I remember the standard
> correctly, the following code shouldn't complain:
>
> PyObject_CallFunction((PyObject*) (void *) &PyRange_Type,
> "lll", start, start+len*step, step)
Thanks for the suggestion!
I just tried:
g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
g++ (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
g++ (GCC) 4.0.0 20050519 (Red Hat 4.0.0-8)
with -Wall -Wno-sign-compare. These compilers don't issue the "will break
strict-aliasing rules" warning with or without the intermediate (void *).
However, I also tried:
g++ (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3)
which issues the warning without the (void *), but not with the (void *).
I am not an expert of the C/C++ language details, but the intermediate cast
seems to be a great local alternative to the global -fno-strict-aliasing flag.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Python-Dev
mailing list