[Python-3000] PyObject_HEAD_INIT

Adam Olsen rhamph at gmail.com
Fri Nov 21 18:36:25 CET 2008


On Fri, Nov 21, 2008 at 7:14 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> 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.

The definition of PyObject_HEAD_INIT and PyVarObject_HEAD_INIT
changed.  We've gone from a series of common fields to a single struct
containing the fields.  With the series of fields using
PyObject_HEAD_INIT followed by a size was perfectly correct, but with
a struct it's gibberish.


-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list