Skip to content

Commit 9a24a04

Browse files
committed
Add mp_map_deinit() & mp_map_free() to finalize maps.
mp_map_deinit() finalizes static map, mp_map_free() - dynamic.
1 parent fcd4ae8 commit 9a24a04

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

py/map.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ mp_map_t *mp_map_new(int n) {
4040
return map;
4141
}
4242

43+
// Differentiate from mp_map_clear() - semantics is different
44+
void mp_map_deinit(mp_map_t *map) {
45+
m_del(mp_map_elem_t, map->table, map->alloc);
46+
map->used = map->alloc = 0;
47+
}
48+
49+
void mp_map_free(mp_map_t *map) {
50+
mp_map_deinit(map);
51+
m_del_obj(mp_map_t, map);
52+
}
53+
4354
void mp_map_clear(mp_map_t *map) {
4455
map->used = 0;
4556
map->all_keys_are_qstrs = 1;

py/map.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ typedef enum _mp_map_lookup_kind_t {
2828
int get_doubling_prime_greater_or_equal_to(int x);
2929
void mp_map_init(mp_map_t *map, int n);
3030
mp_map_t *mp_map_new(int n);
31+
void mp_map_deinit(mp_map_t *map);
32+
void mp_map_free(mp_map_t *map);
3133
mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
3234
void mp_map_clear(mp_map_t *map);
3335

0 commit comments

Comments
 (0)