mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[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 375b723d58
)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
6aee5edb84
commit
0a77058b79
4 changed files with 34 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue