diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-30 05:29:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-30 05:29:03 (GMT) |
commit | 1b37268ef10bd20c30d349b8401c88215c8a6be8 (patch) | |
tree | a93517fdd4a738e144a2e42dcc8b95183c59fd9c /Objects | |
parent | 9f0e40fae5191c3e3ed6109bd2e2f97aa0ac8d64 (diff) | |
download | cpython-1b37268ef10bd20c30d349b8401c88215c8a6be8.zip cpython-1b37268ef10bd20c30d349b8401c88215c8a6be8.tar.gz cpython-1b37268ef10bd20c30d349b8401c88215c8a6be8.tar.bz2 |
bpo-46085: Fix iterator cache mechanism of OrderedDict. (GH-30290)
(cherry picked from commit fb44d0589615590b1e7895ba78a038e96b15a219)
Co-authored-by: Dong-hee Na <donghee.na@python.org>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/odictobject.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 6c7f117..c0ccb16 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1288,6 +1288,7 @@ PyDoc_STRVAR(odict_reversed__doc__, "od.__reversed__() <==> reversed(od)"); #define _odict_ITER_REVERSED 1 #define _odict_ITER_KEYS 2 #define _odict_ITER_VALUES 4 +#define _odict_ITER_ITEMS (_odict_ITER_KEYS|_odict_ITER_VALUES) /* forward */ static PyObject * odictiter_new(PyODictObject *, int); @@ -1705,7 +1706,7 @@ odictiter_dealloc(odictiterobject *di) _PyObject_GC_UNTRACK(di); Py_XDECREF(di->di_odict); Py_XDECREF(di->di_current); - if (di->kind & (_odict_ITER_KEYS | _odict_ITER_VALUES)) { + if ((di->kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) { Py_DECREF(di->di_result); } PyObject_GC_Del(di); @@ -1911,15 +1912,16 @@ odictiter_new(PyODictObject *od, int kind) if (di == NULL) return NULL; - if (kind & (_odict_ITER_KEYS | _odict_ITER_VALUES)){ + if ((kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) { di->di_result = PyTuple_Pack(2, Py_None, Py_None); if (di->di_result == NULL) { Py_DECREF(di); return NULL; } } - else + else { di->di_result = NULL; + } di->kind = kind; node = reversed ? _odict_LAST(od) : _odict_FIRST(od); |