mirror of
https://github.com/python/cpython.git
synced 2025-09-09 02:11:51 +00:00
gh-113743: Make the MRO cache thread-safe in free-threaded builds (#113930)
Makes _PyType_Lookup thread safe, including: Thread safety of the underlying cache. Make mutation of mro and type members thread safe Also _PyType_GetMRO and _PyType_GetBases are currently returning borrowed references which aren't safe.
This commit is contained in:
parent
e74fa294c9
commit
ae460d450a
11 changed files with 500 additions and 80 deletions
|
@ -8,7 +8,6 @@
|
|||
#include "pycore_object.h" // _PyType_GetSubclasses()
|
||||
#include "pycore_runtime.h" // _Py_ID()
|
||||
#include "pycore_setobject.h" // _PySet_NextEntry()
|
||||
#include "pycore_typeobject.h" // _PyType_GetMRO()
|
||||
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
|
||||
#include "clinic/_abc.c.h"
|
||||
|
||||
|
@ -744,18 +743,12 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
|
|||
Py_DECREF(ok);
|
||||
|
||||
/* 4. Check if it's a direct subclass. */
|
||||
PyObject *mro = _PyType_GetMRO((PyTypeObject *)subclass);
|
||||
assert(PyTuple_Check(mro));
|
||||
for (pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) {
|
||||
PyObject *mro_item = PyTuple_GET_ITEM(mro, pos);
|
||||
assert(mro_item != NULL);
|
||||
if ((PyObject *)self == mro_item) {
|
||||
if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
|
||||
goto end;
|
||||
}
|
||||
result = Py_True;
|
||||
if (PyType_IsSubtype((PyTypeObject *)subclass, (PyTypeObject *)self)) {
|
||||
if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
|
||||
goto end;
|
||||
}
|
||||
result = Py_True;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* 5. Check if it's a subclass of a registered class (recursive). */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue