diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2020-08-04 14:28:06 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-10-10 00:16:32 +1100 |
commit | b137d064e9e0bfebd2a59a9b312935031252e742 (patch) | |
tree | db213232f48e771c19270bc387919668d120f60c /py | |
parent | 880875bea1d825b8fa0d1c4a779ff767377f7655 (diff) | |
download | micropython-b137d064e9e0bfebd2a59a9b312935031252e742.tar.gz micropython-b137d064e9e0bfebd2a59a9b312935031252e742.zip |
py/objtype: Handle __dict__ attribute when type has no locals.
Diffstat (limited to 'py')
-rw-r--r-- | py/objtype.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/py/objtype.c b/py/objtype.c index 40900dc050..7f75232941 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -1014,13 +1014,16 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (attr == MP_QSTR___dict__) { // Returns a read-only dict of the class attributes. // If the internal locals is not fixed, a copy will be created. - mp_obj_dict_t *dict = self->locals_dict; + const mp_obj_dict_t *dict = self->locals_dict; + if (!dict) { + dict = &mp_const_empty_dict_obj; + } if (dict->map.is_fixed) { dest[0] = MP_OBJ_FROM_PTR(dict); } else { dest[0] = mp_obj_dict_copy(MP_OBJ_FROM_PTR(dict)); - dict = MP_OBJ_TO_PTR(dest[0]); - dict->map.is_fixed = 1; + mp_obj_dict_t *dict_copy = MP_OBJ_TO_PTR(dest[0]); + dict_copy->map.is_fixed = 1; } return; } |