Skip to content

Commit d63f19b

Browse files
committed
gh-145566: Skip stop-the-world when reassigning __class__ on newly created objects
1 parent 7232883 commit d63f19b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In the free threading build, skip the stop-the-world pause when reassigning
2+
``__class__`` on a newly created object.

Objects/typeobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7608,10 +7608,15 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
76087608
return -1;
76097609
}
76107610

7611-
types_stop_world();
7611+
int unique = _PyObject_IsUniquelyReferenced(self);
7612+
if (!unique) {
7613+
types_stop_world();
7614+
}
76127615
PyTypeObject *oldto = Py_TYPE(self);
76137616
int res = object_set_class_world_stopped(self, newto);
7614-
types_start_world();
7617+
if (!unique) {
7618+
types_start_world();
7619+
}
76157620
if (res == 0) {
76167621
if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE) {
76177622
Py_DECREF(oldto);

0 commit comments

Comments
 (0)