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

gh-120198: Stop the world when setting __class__ on free-threaded build by Fidget-Spinner · Pull Request #120672 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (2) .h  (1) All 2 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
Prev Previous commit
Next Next commit
Address review
  • Loading branch information
Fidget-Spinner committed Jun 19, 2024
commit 8a562ceafdff061e3e5caeef53324f26f8fd75e5
2 changes: 2 additions & 0 deletions Include/internal/pycore_dict.h
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 @@ -323,6 +323,8 @@ _PyInlineValuesSize(PyTypeObject *tp)
int
_PyDict_DetachFromObject(PyDictObject *dict, PyObject *obj);

PyDictObject *_PyObject_materialize_managed_dict_lock_held(PyObject *);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's name this like the other functions: _PyObject_MaterializeManagedDict_LockHeld and move the definition up next to _PyObject_MaterializeManagedDict.


#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions Objects/dictobject.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 @@ -6708,10 +6708,10 @@ make_dict_from_instance_attributes(PyInterpreterState *interp,
return res;
}

static PyDictObject *
materialize_managed_dict_lock_held(PyObject *obj)
PyDictObject *
_PyObject_materialize_managed_dict_lock_held(PyObject *obj)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(obj);
ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(obj);

PyDictValues *values = _PyObject_InlineValues(obj);
PyInterpreterState *interp = _PyInterpreterState_GET();
Expand Down Expand Up @@ -6740,7 +6740,7 @@ _PyObject_MaterializeManagedDict(PyObject *obj)
goto exit;
}
#endif
dict = materialize_managed_dict_lock_held(obj);
dict = _PyObject_materialize_managed_dict_lock_held(obj);

#ifdef Py_GIL_DISABLED
exit:
Expand Down
18 changes: 10 additions & 8 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 @@ -6598,13 +6598,13 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
return -1;
}

PyTypeObject *oldto = Py_TYPE(self);
#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 re-fetch it here.
// underneath us in another thread, so we stop the world.
_PyEval_StopTheWorld(interp);
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
#endif
PyTypeObject *oldto = Py_TYPE(self);

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

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

oldto = Py_TYPE(self);
#ifdef Py_GIL_DISABLED
_PyEval_StartTheWorld(interp);
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
#endif
Py_SET_TYPE(self, newto);

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

RARE_EVENT_INC(set_class);

#ifdef Py_GIL_DISABLED
_PyEval_StartTheWorld(interp);
#endif
return 0;
}
else {
Expand Down

Back | FazBrowse Home | New Git URL