gh-129668: Fix thread-safety of MemoryError freelist in free threaded build (gh-129704)

The MemoryError freelist was not thread-safe in the free threaded build.
Use a mutex to protect accesses to the freelist. Unlike other freelists,
the MemoryError freelist is not performance sensitive.
This commit is contained in:
Sam Gross 2025-02-06 12:38:12 -05:00 committed by GitHub
parent 4d56c40440
commit 51b4edb1a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 27 deletions

View file

@ -24,6 +24,9 @@ struct _Py_exc_state {
PyObject *errnomap;
PyBaseExceptionObject *memerrors_freelist;
int memerrors_numfree;
#ifdef Py_GIL_DISABLED
PyMutex memerrors_lock;
#endif
// The ExceptionGroup type
PyObject *PyExc_ExceptionGroup;
};