Bug report
PyDict_Next currently wraps _PyDict_Next in a critical section. We shouldn't do this -- the locking needs to be external to the call.
- It's not sufficient to lock the dict just for each
_PyDict_Next call because we return borrowed references and because pos becomes meaningless if the dictionary gets resized or rehashed.
- It interferes with externally locking the dict because the inner critical sections can suspend the outer ones. In other words, if the caller use a critical section to lock the dict for multiple iterations, this will break that.
|
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; |
|
} |
cc @DinoV
Linked PRs
Bug report
PyDict_Nextcurrently wraps_PyDict_Nextin a critical section. We shouldn't do this -- the locking needs to be external to the call._PyDict_Nextcall because we return borrowed references and becauseposbecomes meaningless if the dictionary gets resized or rehashed.cpython/Objects/dictobject.c
Lines 2883 to 2890 in 8f17d69
cc @DinoV
Linked PRs