[Python-Dev] GC head alignment issue

Tim Peters tim.one@home.com
Thu, 11 Oct 2001 13:04:46 -0400


[Guido]
> ...
> So far this only affects HP hardware, but we can't trust that!

Doubt it, and the status quo may be inefficient even on HW where "it works"
(it's actually common for HW to *allow* for some suboptimal alignments, but
at reduced speed).

My head hurts, so I'm not sure this is strictly legit C (drop-in replacement
for the current PyGC_Head declaration):

/* GC information is stored BEFORE the object structure */
typedef union _gc_head {
	struct {
		union _gc_head *gc_next; /* not NULL if object is tracked */
		union _gc_head *gc_prev;
		int gc_refs;
	};
	double dummy;  /* force worst-case alignment */
} PyGC_Head;

Works fine under MSVC-for-Intel, and indeed MSVC-for-Intel prefers (but does
not insist upon) 8-byte alignment for doubles.

About "strictly legit":  I'm not positive it's OK to (A) have an anonymous
struct, and then (B) directly reference members of the anonymous struct
within a union, e.g.

    PyGC_Head *p;
    p->gc_refs = 1; /* guaranteed legit? */

If that's not legit, we could make it legit by naming the struct member and
interpolating the name into all existing references.