[Python-3000] PyObject_HEAD_INIT
M.-A. Lemburg
mal at egenix.com
Fri Nov 21 15:14:18 CET 2008
On 2008-11-20 20:34, Roger Binns wrote:
> M.-A. Lemburg wrote:
>> Whether you write:
>
>> {PyObject_HEAD_INIT(0), 0, ...
>
>> or
>
>> {PyVarObject_HEAD_INIT(0, 0), ...
>
>> for your type definition doesn't really make much difference.
>
> Actually in Py 3 it does. If you use the former (which is how Py 2 does
> it) then you get serious compiler warnings due to misaligned fields in
> Py 3 and presumably even worse if run the code.
You might get warnings (esp. from GCC), but I have yet to see a compiler
that doesn't map the above to the same memory.
After all, Python 2 has been using this layout for years without any
compiler warnings or segfaults because of this.
> See PEP 3123 as to why
> things changed. That is why all the code in Python 3 was changed from
> using the former to the latter.
Right. Things are now more standard compliant and you get fewer
warnings.
>> However, the macros exist to be used for both variable size
>> and fixed size objects, so having both available is useful and
>> legitimate.
> ...
>> Except maybe a few thousand extensions already using it which are
>> waiting to be ported to Python 3.
>
> Can you point to any? All the ones I found (via Google) only use
> PyObject_HEAD_INIT for PyTypeObjects and every single one of those will
> have to change to using PyVarObject_HEAD_INIT.
True, because PyTypeObjects *are* in fact PyVarObjects and not
PyObjects, so they should have used PyVarObject_HEAD_INIT all
along.
It's only that compilers never really cared or always
did the right thing - depending on how you see it :-)
BTW: With the "few thousand extensions" I was referring to the current
use of the PyObject_HEAD_INIT() macro which you wanted to remove, not
to a few thousand extensions using it correctly. Note that it's rather
uncommon to create singletons like the type objects in C.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Nov 21 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2008-11-12: Released mxODBC.Connect 0.9.3 http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-3000
mailing list