gh-112529: Remove PyGC_Head from object pre-header in free-threaded build (#114564)

* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build

This avoids allocating space for PyGC_Head in the free-threaded build.
The GC implementation for free-threaded CPython does not use the
PyGC_Head structure.

 * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev`
   in the free-threaded build.
 * The GDB libpython.py file now determines the offset of the managed
   dict field based on whether the running process is a free-threaded
   build. Those are identified by the `ob_ref_local` field in PyObject.
 * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the
   size of `PyGC_Head` in the size of static `PyTypeObject`.
This commit is contained in:
Sam Gross 2024-02-01 15:29:19 -05:00 committed by GitHub
parent 500ede0117
commit 587d480203
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 86 additions and 26 deletions

View file

@ -1878,7 +1878,15 @@ _PySys_GetSizeOf(PyObject *o)
return (size_t)-1;
}
return (size_t)size + _PyType_PreHeaderSize(Py_TYPE(o));
size_t presize = 0;
if (!Py_IS_TYPE(o, &PyType_Type) ||
PyType_HasFeature((PyTypeObject *)o, Py_TPFLAGS_HEAPTYPE))
{
/* Add the size of the pre-header if "o" is not a static type */
presize = _PyType_PreHeaderSize(Py_TYPE(o));
}
return (size_t)size + presize;
}
static PyObject *