summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-24 18:41:19 (GMT)
committerGitHub <noreply@github.com>2024-06-24 18:41:19 (GMT)
commit0a77058b7971ba140c1f9db443e536ea5f1d71aa (patch)
treeb49acc756824d61cbf0ff353ceab54311b24fe2a /Objects
parent6aee5edb84cfa23f430091270a4118e51894c767 (diff)
downloadcpython-0a77058b7971ba140c1f9db443e536ea5f1d71aa.zip
cpython-0a77058b7971ba140c1f9db443e536ea5f1d71aa.tar.gz
cpython-0a77058b7971ba140c1f9db443e536ea5f1d71aa.tar.bz2
[3.13] gh-120858: PyDict_Next should not lock the dict (GH-120859) (#120964)
PyDict_Next no longer locks the dictionary in the free-threaded build. Locking around individual PyDict_Next calls is not sufficient because the function returns borrowed references and because it allows concurrent modifications during the iteraiton loop. The internal locking also interferes with correct external synchronization because it may suspend outer critical sections created by the caller. (cherry picked from commit 375b723d5873f948696c7e85a97f4778d9e00ff0) Co-authored-by: Sam Gross <colesbury@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index fa9d8ab..27da631 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2801,8 +2801,6 @@ _PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey,
if (!PyDict_Check(op))
return 0;
- ASSERT_DICT_LOCKED(op);
-
mp = (PyDictObject *)op;
i = *ppos;
if (_PyDict_HasSplitTable(mp)) {
@@ -2875,11 +2873,7 @@ _PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey,
int
PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
{
- int res;
- Py_BEGIN_CRITICAL_SECTION(op);
- res = _PyDict_Next(op, ppos, pkey, pvalue, NULL);
- Py_END_CRITICAL_SECTION();
- return res;
+ return _PyDict_Next(op, ppos, pkey, pvalue, NULL);
}