Skip to content

gh-127545: Specify minimum PyGC_Head and PyObject alignment to fix build failure #135016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline void _PyObject_GC_SET_SHARED(PyObject *op) {
*/
#define _PyGC_NEXT_MASK_OLD_SPACE_1 1

#define _PyGC_PREV_SHIFT 2
#define _PyGC_PREV_SHIFT _PyObject_ALIGNMENT_SHIFT
#define _PyGC_PREV_MASK (((uintptr_t) -1) << _PyGC_PREV_SHIFT)

/* set for debugging information */
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ typedef struct {

// Tagged pointer to previous object in the list.
// Lowest two bits are used for flags documented later.
// Those bits are made available by the struct's minimum alignment.
uintptr_t _gc_prev;
} PyGC_Head;
} PyGC_Head Py_ALIGNED(1 << _PyObject_ALIGNMENT_SHIFT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that Py_ALIGNED is only for GCC. I think we want the _Py_ALIGN_AS macro, but that seems to only be on the free-threaded build for some reason. See capi-workgroup/decisions#61.


#define _PyGC_Head_UNUSED PyGC_Head

Expand Down
9 changes: 7 additions & 2 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ whose size is determined when the object is allocated.
#define PyObject_VAR_HEAD PyVarObject ob_base;
#define Py_INVALID_SIZE (Py_ssize_t)-1

/* PyObjects are given a minimum alignment so that the least significant bits
* of an object pointer become available for other purposes.
*/
#define _PyObject_ALIGNMENT_SHIFT 2

/* Nothing is actually declared to be a PyObject, but every pointer to
* a Python object can be cast to a PyObject*. This is inheritance built
* by hand. Similarly every pointer to a variable-size Python object can,
Expand Down Expand Up @@ -142,7 +147,7 @@ struct _object {
#endif

PyTypeObject *ob_type;
};
} Py_ALIGNED(1 << _PyObject_ALIGNMENT_SHIFT);
#else
// Objects that are not owned by any thread use a thread id (tid) of zero.
// This includes both immortal objects and objects whose reference count
Expand All @@ -160,7 +165,7 @@ struct _object {
uint32_t ob_ref_local; // local reference count
Py_ssize_t ob_ref_shared; // shared (atomic) reference count
PyTypeObject *ob_type;
};
} Py_ALIGNED(1 << _PyObject_ALIGNMENT_SHIFT);
#endif

/* Cast argument to PyObject* type. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when building on Linux/m68k.
Loading