Skip to content

py/runtime: make __main__ preallocate to a configurable size #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@
#define MICROPY_LOADED_MODULES_DICT_SIZE (3)
#endif

// Initial size of __main__ dict
#ifndef MICROPY_MAIN_DICT_SIZE
#define MICROPY_MAIN_DICT_SIZE (1)
#endif

// Whether realloc/free should be passed allocated memory region size
// You must enable this if MICROPY_MEM_STATS is enabled
#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
Expand Down
2 changes: 1 addition & 1 deletion py/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void mp_init(void) {
mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), MICROPY_LOADED_MODULES_DICT_SIZE);

// initialise the __main__ module
mp_obj_dict_init(&MP_STATE_VM(dict_main), 1);
mp_obj_dict_init(&MP_STATE_VM(dict_main), MICROPY_MAIN_DICT_SIZE);
mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(dict_main)), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__));

// locals = globals for outer module (see Objects/frameobject.c/PyFrame_New())
Expand Down
Loading