[Python-Dev] mingw32 and gc-header weirdness
Antoine Pitrou
solipsis at pitrou.net
Thu Jul 23 23:27:15 CEST 2009
Christian Tismer <tismer <at> stackless.com> writes:
>
> 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.
Indeed.
> 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.
I'm not sure a double aligned on a 4-byte boundary is "misaligned" on a x86 CPU.
Alignment is primarily important to avoid access violations on CPUs and
datatypes which don't support arbitrary alignment, although it can also be
useful for performance reasons.
In any case, you seem to be right on this particular point: the PyGC_Head union
should probably contain a "double" alternative in addition to the "long double"
(and perhaps even a "long long" one).
Of course, it will also make memory consumption a tad bigger for GC-enabled
objects (but GC-enabled objects are generally not that small anyway).
(I disagree, however, that we should remove the "long double". After all, we
also want alignment of PyObjects to allow inclusion of a "long double" in them)
Feel free to propose a patch on bugs.python.org, by the way.
Regards
Antoine.
More information about the Python-Dev
mailing list