Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address reviews
  • Loading branch information
Fidget-Spinner committed Jul 10, 2024
commit a409ab27ca0a2deab743d76fb7a7074e2fb791c1
2 changes: 1 addition & 1 deletion Lib/test/test_free_threading/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Bar:
thing = Foo()
def work():
foo = thing
for _ in range(10000):
for _ in range(5000):
foo.__class__ = Bar
type(foo)
foo.__class__ = Foo
Expand Down
18 changes: 4 additions & 14 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6607,7 +6607,7 @@ compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, const char*


static int
object_set_class_world_stopped(PyObject *self, PyTypeObject *newto, PyTypeObject **oldto_p)
object_set_class_world_stopped(PyObject *self, PyTypeObject *newto)
{
PyTypeObject *oldto = Py_TYPE(self);

Expand Down Expand Up @@ -6682,13 +6682,7 @@ object_set_class_world_stopped(PyObject *self, PyTypeObject *newto, PyTypeObject
}
}

// If we raced after materialization and replaced the dict
// then the materialized dict should no longer have the
// inline values in which case detach is a nop.
// Note: we don't need to lock here because the world should be stopped.

assert(_PyObject_GetManagedDict(self) == dict ||
dict->ma_values != _PyObject_InlineValues(self));
assert(_PyObject_GetManagedDict(self) == dict);

if (_PyDict_DetachFromObject(dict, self) < 0) {
return -1;
Expand All @@ -6701,8 +6695,6 @@ object_set_class_world_stopped(PyObject *self, PyTypeObject *newto, PyTypeObject

Py_SET_TYPE(self, newto);

*oldto_p = oldto;

return 0;
}
else {
Expand Down Expand Up @@ -6734,12 +6726,10 @@ object_set_class(PyObject *self, PyObject *value, void *closure)

#ifdef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
// The real Py_TYPE(self) (`oldto`) may have changed from
// underneath us in another thread, so we stop the world.
_PyEval_StopTheWorld(interp);
#endif
PyTypeObject *oldto;
int res = object_set_class_world_stopped(self, newto, &oldto);
PyTypeObject *oldto = Py_TYPE(self);
int res = object_set_class_world_stopped(self, newto);
#ifdef Py_GIL_DISABLED
_PyEval_StartTheWorld(interp);
#endif
Expand Down