diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-08-11 09:42:39 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-08-11 09:43:07 +0300 |
commit | bfc2092dc55d1faab4a6d7e832005afd61d25c3c (patch) | |
tree | 37b1449bd001755fc37fe3d23232658b0c82eca8 /py/objdict.c | |
parent | 7d4a2f773cc6ce24a91e2d210378188f3371e8a6 (diff) |
py/modsys: Initial implementation of sys.getsizeof().
Implemented as a new MP_UNARY_OP. This patch adds support lists, dicts and
instances.
Diffstat (limited to 'py/objdict.c')
-rw-r--r-- | py/objdict.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objdict.c b/py/objdict.c index a272ebdb6..f6357a905 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -105,6 +105,12 @@ STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) { switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used); + #if MICROPY_PY_SYS_GETSIZEOF + case MP_UNARY_OP_SIZEOF: { + size_t sz = sizeof(*self) + sizeof(*self->map.table) * self->map.alloc; + return MP_OBJ_NEW_SMALL_INT(sz); + } + #endif default: return MP_OBJ_NULL; // op not supported } } |