Skip to content

Commit 8a562ce

Browse files
Address review
1 parent d2a7095 commit 8a562ce

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

Include/internal/pycore_dict.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ _PyInlineValuesSize(PyTypeObject *tp)
323323
int
324324
_PyDict_DetachFromObject(PyDictObject *dict, PyObject *obj);
325325

326+
PyDictObject *_PyObject_materialize_managed_dict_lock_held(PyObject *);
327+
326328
#ifdef __cplusplus
327329
}
328330
#endif

Objects/dictobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6708,10 +6708,10 @@ make_dict_from_instance_attributes(PyInterpreterState *interp,
67086708
return res;
67096709
}
67106710

6711-
static PyDictObject *
6712-
materialize_managed_dict_lock_held(PyObject *obj)
6711+
PyDictObject *
6712+
_PyObject_materialize_managed_dict_lock_held(PyObject *obj)
67136713
{
6714-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(obj);
6714+
ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(obj);
67156715

67166716
PyDictValues *values = _PyObject_InlineValues(obj);
67176717
PyInterpreterState *interp = _PyInterpreterState_GET();
@@ -6740,7 +6740,7 @@ _PyObject_MaterializeManagedDict(PyObject *obj)
67406740
goto exit;
67416741
}
67426742
#endif
6743-
dict = materialize_managed_dict_lock_held(obj);
6743+
dict = _PyObject_materialize_managed_dict_lock_held(obj);
67446744

67456745
#ifdef Py_GIL_DISABLED
67466746
exit:

Objects/typeobject.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6598,13 +6598,13 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
65986598
return -1;
65996599
}
66006600

6601-
PyTypeObject *oldto = Py_TYPE(self);
66026601
#ifdef Py_GIL_DISABLED
66036602
PyInterpreterState *interp = _PyInterpreterState_GET();
66046603
// The real Py_TYPE(self) (`oldto`) may have changed from
6605-
// underneath us in another thread, so we re-fetch it here.
6604+
// underneath us in another thread, so we stop the world.
66066605
_PyEval_StopTheWorld(interp);
66076606
#endif
6607+
PyTypeObject *oldto = Py_TYPE(self);
66086608

66096609
/* In versions of CPython prior to 3.5, the code in
66106610
compatible_for_assignment was not set up to correctly check for memory
@@ -6669,9 +6669,12 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
66696669
/* Changing the class will change the implicit dict keys,
66706670
* so we must materialize the dictionary first. */
66716671
if (oldto->tp_flags & Py_TPFLAGS_INLINE_VALUES) {
6672-
PyDictObject *dict = _PyObject_MaterializeManagedDict(self);
6672+
PyDictObject *dict = _PyObject_GetManagedDict(self);
66736673
if (dict == NULL) {
6674-
goto err;
6674+
dict = _PyObject_materialize_managed_dict_lock_held(self);
6675+
if (dict == NULL) {
6676+
goto err;
6677+
}
66756678
}
66766679

66776680
// If we raced after materialization and replaced the dict
@@ -6691,7 +6694,9 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
66916694
Py_INCREF(newto);
66926695
}
66936696

6694-
oldto = Py_TYPE(self);
6697+
#ifdef Py_GIL_DISABLED
6698+
_PyEval_StartTheWorld(interp);
6699+
#endif
66956700
Py_SET_TYPE(self, newto);
66966701

66976702
if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE) {
@@ -6700,9 +6705,6 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
67006705

67016706
RARE_EVENT_INC(set_class);
67026707

6703-
#ifdef Py_GIL_DISABLED
6704-
_PyEval_StartTheWorld(interp);
6705-
#endif
67066708
return 0;
67076709
}
67086710
else {

0 commit comments

Comments
 (0)