FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-133467: fix data race in `type_set_name` (GH-137302) by miss-islington · Pull Request #137303 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .txt  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 14 additions & 0 deletions Lib/test/test_free_threading/test_type.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ class ClassB(Base):
obj.__class__ = ClassB


def test_name_change(self):
class Foo:
pass

def writer():
for _ in range(1000):
Foo.__name__ = 'Bar'

def reader():
for _ in range(1000):
Foo.__name__

self.run_one(writer, reader)

def run_one(self, writer_func, reader_func):
barrier = threading.Barrier(NTHREADS)

Expand Down
10 changes: 8 additions & 2 deletions Objects/typeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1434,9 +1434,13 @@ type_set_name(PyObject *tp, PyObject *value, void *Py_UNUSED(closure))
return -1;
}

PyInterpreterState *interp = _PyInterpreterState_GET();
_PyEval_StopTheWorld(interp);
type->tp_name = tp_name;
Py_SETREF(((PyHeapTypeObject*)type)->ht_name, Py_NewRef(value));

PyObject *old_name = ((PyHeapTypeObject*)type)->ht_name;
((PyHeapTypeObject*)type)->ht_name = Py_NewRef(value);
_PyEval_StartTheWorld(interp);
Py_DECREF(old_name);
return 0;
}

Expand Down Expand Up @@ -10406,9 +10410,11 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)

get = _PyType_LookupRef(tp, &_Py_ID(__get__));
if (get == NULL) {
#ifndef Py_GIL_DISABLED
/* Avoid further slowdowns */
if (tp->tp_descr_get == slot_tp_descr_get)
tp->tp_descr_get = NULL;
#endif
return Py_NewRef(self);
}
if (obj == NULL)
Expand Down
2 changes: 0 additions & 2 deletions Tools/tsan/suppressions_free_threading.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ race:PyObject_Realloc

# gh-133467. Some of these could be hard to trigger.
race_top:update_one_slot
race_top:slot_tp_descr_get
race_top:type_set_name
race_top:set_tp_bases
race_top:type_set_bases_unlocked
Loading

Back | FazBrowse Home | New Git URL