py/objdict: Fix popitem for ordered dicts.

The popitem method wasn't implemented for ordered dicts and would result in
an invalid state.

Fixes issue #5956.
This commit is contained in:
Jim Mussared
2020-04-23 01:10:30 +10:00
committed by Damien George
parent 347c8917dc
commit 57fce3bdb2
4 changed files with 36 additions and 4 deletions

View File

@@ -177,6 +177,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
--map->used;
memmove(elem, elem + 1, (top - elem - 1) * sizeof(*elem));
// put the found element after the end so the caller can access it if needed
// note: caller must NULL the value so the GC can clean up (e.g. see dict_get_helper).
elem = &map->table[map->used];
elem->key = MP_OBJ_NULL;
elem->value = value;