summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-04-02 14:45:00 (GMT)
committerGitHub <noreply@github.com>2024-04-02 14:45:00 (GMT)
commit027fa2eccf39ddccdf7b416d16601277a7112054 (patch)
treea116ac1f4e6a1fcd4ef327e742850a92cb146a0f /Objects/listobject.c
parent954d616b4c8cd091214aa3b8ea886bcf9067243a (diff)
downloadcpython-027fa2eccf39ddccdf7b416d16601277a7112054.zip
cpython-027fa2eccf39ddccdf7b416d16601277a7112054.tar.gz
cpython-027fa2eccf39ddccdf7b416d16601277a7112054.tar.bz2
gh-112087: Make `list.extend(dict)` behave atomically (#117438)
Add a special case for `list.extend(dict)` and `list(dict)` so that those patterns behave atomically with respect to modifications to the list or dictionary. This is required by multiprocessing, which assumes that `list(_finalizer_registry)` is atomic.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 470ad8e..472c471 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1374,6 +1374,11 @@ _list_extend(PyListObject *self, PyObject *iterable)
res = list_extend_set(self, (PySetObject *)iterable);
Py_END_CRITICAL_SECTION2();
}
+ else if (PyDict_CheckExact(iterable)) {
+ Py_BEGIN_CRITICAL_SECTION2(self, iterable);
+ res = list_extend_dict(self, (PyDictObject *)iterable, 0 /*keys*/);
+ Py_END_CRITICAL_SECTION2();
+ }
else if (Py_IS_TYPE(iterable, &PyDictKeys_Type)) {
PyDictObject *dict = ((_PyDictViewObject *)iterable)->dv_dict;
Py_BEGIN_CRITICAL_SECTION2(self, dict);