mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-116738: Make _abc module thread-safe (#117488)
A collection of small changes aimed at making the `_abc` module safe to use in a free-threaded build.
This commit is contained in:
parent
1b10efad66
commit
f268e328ed
3 changed files with 205 additions and 115 deletions
|
@ -5117,6 +5117,52 @@ _PyType_LookupId(PyTypeObject *type, _Py_Identifier *name)
|
|||
return _PyType_Lookup(type, oname);
|
||||
}
|
||||
|
||||
static void
|
||||
set_flags(PyTypeObject *self, unsigned long mask, unsigned long flags)
|
||||
{
|
||||
ASSERT_TYPE_LOCK_HELD();
|
||||
self->tp_flags = (self->tp_flags & ~mask) | flags;
|
||||
}
|
||||
|
||||
void
|
||||
_PyType_SetFlags(PyTypeObject *self, unsigned long mask, unsigned long flags)
|
||||
{
|
||||
BEGIN_TYPE_LOCK();
|
||||
set_flags(self, mask, flags);
|
||||
END_TYPE_LOCK();
|
||||
}
|
||||
|
||||
static void
|
||||
set_flags_recursive(PyTypeObject *self, unsigned long mask, unsigned long flags)
|
||||
{
|
||||
if (PyType_HasFeature(self, Py_TPFLAGS_IMMUTABLETYPE) ||
|
||||
(self->tp_flags & mask) == flags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
set_flags(self, mask, flags);
|
||||
|
||||
PyObject *children = _PyType_GetSubclasses(self);
|
||||
if (children == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(children); i++) {
|
||||
PyObject *child = PyList_GET_ITEM(children, i);
|
||||
set_flags_recursive((PyTypeObject *)child, mask, flags);
|
||||
}
|
||||
Py_DECREF(children);
|
||||
}
|
||||
|
||||
void
|
||||
_PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask, unsigned long flags)
|
||||
{
|
||||
BEGIN_TYPE_LOCK();
|
||||
set_flags_recursive(self, mask, flags);
|
||||
END_TYPE_LOCK();
|
||||
}
|
||||
|
||||
/* This is similar to PyObject_GenericGetAttr(),
|
||||
but uses _PyType_Lookup() instead of just looking in type->tp_dict.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue