[Python-Dev] mingw32 and gc-header weirdness

Christian Tismer tismer at stackless.com
Thu Jul 23 23:14:35 CEST 2009


On 7/23/09 2:04 AM, Antoine Pitrou wrote:
> Christian Tismer<tismer<at>  stackless.com>  writes:
>> Despite the fact that Python probably has to be changed:
>> If it is true then all the 32-bit Linux Pythons have a 12
>> byte GC head, IOW they are *all* badly aligned.
>
> Why are they badly aligned?
> The fact that long double is 12 bytes long doesn't mean it will force a 12-byte
> alignment - just whatever alignment is enough for a long double on the target
> machine. This could be 4, 8 or 16 bytes.

Things are a bit different:

Alignment is not the primary concern of the gc header structure.
Note that all the objects are created by malloc (system or python's
arena allocator), and therefore all objects are correctly aligned
by construction.

The point is: The GC header is a structure invisible to the "real"
gc allocated objects. It is opaquely prepended to every gc aware
object. Therefore, it *needs* to have the correct size, in order
to propagate its (already correct) alignment to the real object.

It appears that python, compiled with gcc for all x64 32bit Linuxen
(and mingw32) produces a 12 byte GC header. Not relevant for the
header itself, but all GC objects are misaligned.

This may not be recognized so far, because there is no builtin
GC-enabled type that embeds a double.
But if you create such a type, then the double will be correctly
aligned in your object's structure, but then, when the object
gets allocated, it is misaligned, because the header size is not a
multiple of 8.

To Martin: So I disagree. The gc header is not responsible for
alignment in the first place, but to propagate it, correctly.
And this fails miserably (in principle) since years.

Proposal: We should use a simple construct that makes the
gc header size simply a multiple of 8 or 16, whatever needed.
Even a byte array would be ok.

But please no long double :-)

cheers - chris
-- 
Christian Tismer             :^)   <mailto:tismer at stackless.com>
tismerysoft GmbH             :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
       whom do you want to sponsor today?   http://www.stackless.com/


More information about the Python-Dev mailing list