Skip to content

Commit 7e2a488

Browse files
committed
py/modmicropython: Allow to have stack_use() func without mem_info().
The micropython.stack_use() function is useful to query the current C stack usage, and it's inclusion in the micropython module doesn't need to be tied to the inclusion of mem_info()/qstr_info() because it doesn't rely on any of the code from these functions. So this patch introduces the config option MICROPY_PY_MICROPYTHON_STACK_USE which can be used to independently control the inclusion of stack_use(). By default it is enabled if MICROPY_PY_MICROPYTHON_MEM_INFO is enabled (thus not changing any of the existing ports).
1 parent 2099368 commit 7e2a488

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

py/modmicropython.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ STATIC mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) {
103103
}
104104
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info);
105105

106-
#if MICROPY_STACK_CHECK
106+
#endif // MICROPY_PY_MICROPYTHON_MEM_INFO
107+
108+
#if MICROPY_PY_MICROPYTHON_STACK_USE
107109
STATIC mp_obj_t mp_micropython_stack_use(void) {
108110
return MP_OBJ_NEW_SMALL_INT(mp_stack_usage());
109111
}
110112
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_stack_use_obj, mp_micropython_stack_use);
111113
#endif
112114

113-
#endif // MICROPY_PY_MICROPYTHON_MEM_INFO
114-
115115
#if MICROPY_ENABLE_PYSTACK
116116
STATIC mp_obj_t mp_micropython_pystack_use(void) {
117117
return MP_OBJ_NEW_SMALL_INT(mp_pystack_usage());
@@ -167,10 +167,10 @@ STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = {
167167
#endif
168168
{ MP_ROM_QSTR(MP_QSTR_mem_info), MP_ROM_PTR(&mp_micropython_mem_info_obj) },
169169
{ MP_ROM_QSTR(MP_QSTR_qstr_info), MP_ROM_PTR(&mp_micropython_qstr_info_obj) },
170-
#if MICROPY_STACK_CHECK
170+
#endif
171+
#if MICROPY_PY_MICROPYTHON_STACK_USE
171172
{ MP_ROM_QSTR(MP_QSTR_stack_use), MP_ROM_PTR(&mp_micropython_stack_use_obj) },
172173
#endif
173-
#endif
174174
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0)
175175
{ MP_ROM_QSTR(MP_QSTR_alloc_emergency_exception_buf), MP_ROM_PTR(&mp_alloc_emergency_exception_buf_obj) },
176176
#endif

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,11 @@ typedef double mp_float_t;
907907
#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
908908
#endif
909909

910+
// Whether to provide "micropython.stack_use" function
911+
#ifndef MICROPY_PY_MICROPYTHON_STACK_USE
912+
#define MICROPY_PY_MICROPYTHON_STACK_USE (MICROPY_PY_MICROPYTHON_MEM_INFO)
913+
#endif
914+
910915
// Whether to provide "array" module. Note that large chunk of the
911916
// underlying code is shared with "bytearray" builtin type, so to
912917
// get real savings, it should be disabled too.

0 commit comments

Comments
 (0)