mirror of
https://github.com/python/cpython.git
synced 2025-11-08 17:41:42 +00:00
[3.11] gh-101765: Fix SystemError / segmentation fault in iter __reduce__ when internal access of builtins.__dict__ exhausts the iterator (GH-101769) (#102228)
(cherry picked from commit 54dfa14c5a)
This commit is contained in:
parent
9da3e7f389
commit
5d461225a5
9 changed files with 148 additions and 23 deletions
|
|
@ -15757,14 +15757,19 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(
|
|||
static PyObject *
|
||||
unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
|
||||
|
||||
/* _PyEval_GetBuiltin can invoke arbitrary code,
|
||||
* call must be before access of iterator pointers.
|
||||
* see issue #101765 */
|
||||
|
||||
if (it->it_seq != NULL) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
|
||||
} else {
|
||||
PyObject *u = (PyObject *)_PyUnicode_New(0);
|
||||
if (u == NULL)
|
||||
return NULL;
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), u);
|
||||
return Py_BuildValue("N(N)", iter, u);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue