Skip to content

Commit 4856992

Browse files
authored
[3.14] gh-145446: Add critical section in functools module for PyDict_Next (GH-145487) (GH-145879)
(cherry picked from commit 17eb035)
1 parent b5e5013 commit 4856992

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Now :mod:`functools` is safer in free-threaded build when using keywords in :func:`functools.partial`

Modules/_functoolsmodule.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,16 +646,23 @@ partial_repr(PyObject *self)
646646
}
647647
}
648648
/* Pack keyword arguments */
649+
int error = 0;
650+
Py_BEGIN_CRITICAL_SECTION(kw);
649651
for (i = 0; PyDict_Next(kw, &i, &key, &value);) {
650652
/* Prevent key.__str__ from deleting the value. */
651653
Py_INCREF(value);
652654
Py_SETREF(arglist, PyUnicode_FromFormat("%U, %S=%R", arglist,
653655
key, value));
654656
Py_DECREF(value);
655657
if (arglist == NULL) {
656-
goto done;
658+
error = 1;
659+
break;
657660
}
658661
}
662+
Py_END_CRITICAL_SECTION();
663+
if (error) {
664+
goto done;
665+
}
659666

660667
mod = PyType_GetModuleName(Py_TYPE(pto));
661668
if (mod == NULL) {

0 commit comments

Comments
 (0)