Skip to content

Commit e3f58c8

Browse files
committed
map: Add mp_map_dump() (#ifdef'ed) to be handy when debugging maps.
1 parent c393684 commit e3f58c8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

py/map.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,17 @@ void mp_set_clear(mp_set_t *set) {
243243
set->used = 0;
244244
set->table = NULL;
245245
}
246+
247+
#if DEBUG_PRINT
248+
void mp_map_dump(mp_map_t *map) {
249+
for (int i = 0; i < map->alloc; i++) {
250+
if (map->table[i].key != NULL) {
251+
mp_obj_print(map->table[i].key, PRINT_REPR);
252+
} else {
253+
printf("(nil)");
254+
}
255+
printf(": %p\n", map->table[i].value);
256+
}
257+
printf("---\n");
258+
}
259+
#endif

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void mp_map_deinit(mp_map_t *map);
117117
void mp_map_free(mp_map_t *map);
118118
mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
119119
void mp_map_clear(mp_map_t *map);
120+
void mp_map_dump(mp_map_t *map);
120121

121122
// Underlying set implementation (not set object)
122123

0 commit comments

Comments
 (0)