Skip to content

Commit a20ca83

Browse files
committed
prevent TYPE_LOCK release during stw
1 parent e40bd38 commit a20ca83

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Objects/typeobject.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,10 +1920,16 @@ type_set_bases_unlocked(PyTypeObject *type, PyObject *new_bases, PyTypeObject *b
19201920
assert(old_bases != NULL);
19211921
PyTypeObject *old_base = type->tp_base;
19221922

1923+
#ifdef Py_GIL_DISABLED
1924+
type_lock_prevent_release();
1925+
#endif
19231926
types_stop_world();
19241927
set_tp_bases(type, Py_NewRef(new_bases), 0);
19251928
type->tp_base = (PyTypeObject *)Py_NewRef(best_base);
19261929
types_start_world();
1930+
#ifdef Py_GIL_DISABLED
1931+
type_lock_allow_release();
1932+
#endif
19271933

19281934
PyObject *temp = PyList_New(0);
19291935
if (temp == NULL) {
@@ -1984,10 +1990,16 @@ type_set_bases_unlocked(PyTypeObject *type, PyObject *new_bases, PyTypeObject *b
19841990
if (lookup_tp_bases(type) == new_bases) {
19851991
assert(type->tp_base == best_base);
19861992

1993+
#ifdef Py_GIL_DISABLED
1994+
type_lock_prevent_release();
1995+
#endif
19871996
types_stop_world();
19881997
set_tp_bases(type, old_bases, 0);
19891998
type->tp_base = old_base;
19901999
types_start_world();
2000+
#ifdef Py_GIL_DISABLED
2001+
type_lock_allow_release();
2002+
#endif
19912003

19922004
Py_DECREF(new_bases);
19932005
Py_DECREF(best_base);

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ race:PyObject_Realloc
4444

4545
# gh-133467. Some of these could be hard to trigger.
4646
race_top:set_tp_bases
47-
race_top:type_set_bases_unlocked

0 commit comments

Comments
 (0)