Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e38497

Browse filesBrowse files
committed
Use apply_slot_updates() for type_setattro().
1 parent d511ca6 commit 5e38497
Copy full SHA for 5e38497

File tree

Expand file treeCollapse file tree

1 file changed

+27
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-4
lines changed

‎Objects/typeobject.c

Copy file name to clipboardExpand all lines: Objects/typeobject.c
+27-4Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6314,6 +6314,32 @@ type_update_dict(PyTypeObject *type, PyDictObject *dict, PyObject *name,
63146314
return 0;
63156315
}
63166316

6317+
static int
6318+
update_slot_after_setattr(PyTypeObject *type, PyObject *name)
6319+
{
6320+
#ifdef Py_GIL_DISABLED
6321+
// stack allocate one chunk since that's all we need
6322+
assert(SLOT_UPDATE_CHUNK_SIZE >= MAX_EQUIV);
6323+
slot_update_chunk_t chunk = {0};
6324+
slot_update_t queued_updates = {&chunk};
6325+
6326+
if (update_slot(type, name, &queued_updates) < 0) {
6327+
return -1;
6328+
}
6329+
if (queued_updates.head != NULL) {
6330+
types_stop_world();
6331+
apply_slot_updates(&queued_updates);
6332+
types_start_world();
6333+
ASSERT_TYPE_LOCK_HELD();
6334+
// should never allocate another chunk
6335+
assert(chunk.prev == NULL);
6336+
}
6337+
#else
6338+
update_slot(type, name, NULL);
6339+
#endif
6340+
return 0;
6341+
}
6342+
63176343
static int
63186344
type_setattro(PyObject *self, PyObject *name, PyObject *value)
63196345
{
@@ -6389,10 +6415,7 @@ type_setattro(PyObject *self, PyObject *name, PyObject *value)
63896415
if (res == 0) {
63906416
if (is_dunder_name(name) && has_slotdef(name)) {
63916417
// The name corresponds to a type slot.
6392-
types_stop_world();
6393-
res = update_slot(type, name, NULL);
6394-
types_start_world();
6395-
ASSERT_TYPE_LOCK_HELD();
6418+
res = update_slot_after_setattr(type, name);
63966419
}
63976420
}
63986421
END_TYPE_DICT_LOCK();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.