gh-128923: Use zero to indicate unassigned unique id (#128925)

In the free threading build, the per thread reference counting uses a
unique id for some objects to index into the local reference count
table. Use 0 instead of -1 to indicate that the id is not assigned. This
avoids bugs where zero-initialized heap type objects look like they have
a unique id assigned.
This commit is contained in:
Sam Gross 2025-01-17 10:42:27 -05:00 committed by GitHub
parent 767c89ba7c
commit d66c08aa75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 110 additions and 33 deletions

View file

@ -1911,7 +1911,7 @@ code_dealloc(PyObject *self)
Py_XDECREF(co->co_linetable);
Py_XDECREF(co->co_exceptiontable);
#ifdef Py_GIL_DISABLED
assert(co->_co_unique_id == -1);
assert(co->_co_unique_id == _Py_INVALID_UNIQUE_ID);
#endif
if (co->_co_cached != NULL) {
Py_XDECREF(co->_co_cached->_co_code);