8000 bpo-46085: Fix iterator cache mechanism of OrderedDict. (GH-30290) · python/cpython@fb44d05 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb44d05

Browse files
authored
bpo-46085: Fix iterator cache mechanism of OrderedDict. (GH-30290)
1 parent d12bec6 commit fb44d05

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix iterator cache mechanism of :class:`OrderedDict`.

Objects/odictobject.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,7 @@ PyDoc_STRVAR(odict_reversed__doc__, "od.__reversed__() <==> reversed(od)");
12491249
#define _odict_ITER_REVERSED 1
12501250
#define _odict_ITER_KEYS 2
12511251
#define _odict_ITER_VALUES 4
1252+
#define _odict_ITER_ITEMS (_odict_ITER_KEYS|_odict_ITER_VALUES)
12521253

12531254
/* forward */
12541255
static PyObject * odictiter_new(PyODictObject *, int);
@@ -1666,7 +1667,7 @@ odictiter_dealloc(odictiterobject *di)
16661667
_PyObject_GC_UNTRACK(di);
16671668
Py_XDECREF(di->di_odict);
16681669
Py_XDECREF(di->di_current);
1669-
if (di->kind & (_odict_ITER_KEYS | _odict_ITER_VALUES)) {
1670+
if ((di->kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) {
16701671
Py_DECREF(di->di_result);
16711672
}
16721673
PyObject_GC_Del(di);
@@ -1872,15 +1873,16 @@ odictiter_new(PyODictObject *od, int kind)
18721873
if (di == NULL)
18731874
return NULL;
18741875

1875-
if (kind & (_odict_ITER_KEYS | _odict_ITER_VALUES)){
1876+
if ((kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) {
18761877
di->di_result = PyTuple_Pack(2, Py_None, Py_None);
18771878
if (di->di_result == NULL) {
18781879
Py_DECREF(di);
18791880
return NULL;
18801881
}
18811882
}
1882-
else
1883+
else {
18831884
di->di_result = NULL;
1885+
}
18841886

18851887
di->kind = kind;
18861888
node = reversed ? _odict_LAST(od) : _odict_FIRST(od);

0 commit comments

Comments
 (0)
0