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

@ -6160,7 +6160,7 @@ type_dealloc(PyObject *self)
Py_XDECREF(et->ht_module);
PyMem_Free(et->_ht_tpname);
#ifdef Py_GIL_DISABLED
assert(et->unique_id == -1);
assert(et->unique_id == _Py_INVALID_UNIQUE_ID);
#endif
et->ht_token = NULL;
Py_TYPE(type)->tp_free((PyObject *)type);