mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/modsys: Initial implementation of sys.getsizeof().
Implemented as a new MP_UNARY_OP. This patch adds support lists, dicts and instances.
This commit is contained in:
@@ -104,6 +104,12 @@ STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) {
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
|
||||
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
|
||||
#if MICROPY_PY_SYS_GETSIZEOF
|
||||
case MP_UNARY_OP_SIZEOF: {
|
||||
size_t sz = sizeof(*self) + sizeof(mp_obj_t) * self->alloc;
|
||||
return MP_OBJ_NEW_SMALL_INT(sz);
|
||||
}
|
||||
#endif
|
||||
default: return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user