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/modsys.c | |
parent | 7d4a2f773cc6ce24a91e2d210378188f3371e8a6 (diff) | |
download | micropython-bfc2092dc55d1faab4a6d7e832005afd61d25c3c.tar.gz micropython-bfc2092dc55d1faab4a6d7e832005afd61d25c3c.zip |
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/modsys.c')
-rw-r--r-- | py/modsys.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/py/modsys.c b/py/modsys.c index ee6f8686e0..b7d55fdcc6 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2014-2017 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,8 +32,11 @@ #include "py/objtuple.h" #include "py/objstr.h" #include "py/objint.h" +#include "py/objtype.h" #include "py/stream.h" #include "py/smallint.h" +#include "py/runtime0.h" +#include "py/runtime.h" #if MICROPY_PY_SYS @@ -143,6 +147,11 @@ STATIC mp_obj_t mp_sys_exc_info(void) { MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); #endif +STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { + return mp_unary_op(MP_UNARY_OP_SIZEOF, obj); +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); + STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) }, @@ -192,6 +201,9 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #if MICROPY_PY_SYS_EXC_INFO { MP_ROM_QSTR(MP_QSTR_exc_info), MP_ROM_PTR(&mp_sys_exc_info_obj) }, #endif + #if MICROPY_PY_SYS_GETSIZEOF + { MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) }, + #endif /* * Extensions to CPython |