diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-07-25 22:34:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-25 22:34:58 -0400 |
| commit | fbfc9c39957b389fd359ed8107d1e244e9749930 (patch) | |
| tree | eac648d26df8052ce7ae55cca57d3785d77df4e5 /py | |
| parent | f6d09d060552dd3a9033eb0f091a58b161ce30ee (diff) | |
| parent | 1ffb0a714f056eaffdebaa411c3fcadb79a2b6d1 (diff) | |
Merge pull request #1062 from tannewt/import_merge
Merge in the rest of 3.x
Diffstat (limited to 'py')
| -rwxr-xr-x | py/gc_long_lived.c | 12 | ||||
| -rw-r--r-- | py/obj.h | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/py/gc_long_lived.c b/py/gc_long_lived.c index e30b389fa..3c54de7ed 100755 --- a/py/gc_long_lived.c +++ b/py/gc_long_lived.c @@ -91,6 +91,13 @@ mp_obj_dict_t *make_dict_long_lived(mp_obj_dict_t *dict, uint8_t max_depth) { if (dict == NULL || max_depth == 0) { return dict; } + // Don't recurse unnecessarily. Return immediately if we've already seen this dict. + if (dict->map.scanning) { + return dict; + } + // Mark that we're processing this dict. + dict->map.scanning = 1; + // Update all of the references first so that we reduce the chance of references to the old // copies. dict->map.table = gc_make_long_lived(dict->map.table); @@ -100,7 +107,10 @@ mp_obj_dict_t *make_dict_long_lived(mp_obj_dict_t *dict, uint8_t max_depth) { dict->map.table[i].value = make_obj_long_lived(value, max_depth - 1); } } - return gc_make_long_lived(dict); + dict = gc_make_long_lived(dict); + // Done recursing through this dict. + dict->map.scanning = 0; + return dict; } mp_obj_str_t *make_str_long_lived(mp_obj_str_t *str) { @@ -359,7 +359,9 @@ typedef struct _mp_map_t { size_t all_keys_are_qstrs : 1; size_t is_fixed : 1; // a fixed array that can't be modified; must also be ordered size_t is_ordered : 1; // an ordered array - size_t used : (8 * sizeof(size_t) - 3); + size_t scanning : 1; // true if we're in the middle of scanning linked dictionaries, + // e.g., make_dict_long_lived() + size_t used : (8 * sizeof(size_t) - 4); size_t alloc; mp_map_elem_t *table; } mp_map_t; |
