Skip to content

py/map: allow disabling reallocation for specific dicts #17

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

Closed
wants to merge 1 commit into from

Conversation

romanz
Copy link

@romanz romanz commented Mar 28, 2025

Also, enable this feature for __main__ and sys.modules.

@romanz romanz self-assigned this Mar 28, 2025
@romanz
Copy link
Author

romanz commented Mar 28, 2025

Following trezor/trezor-firmware#4823 (comment).

@romanz romanz marked this pull request as draft March 30, 2025 17:16
Also, enable this feature for `__main__` and `sys.modules`.
@romanz romanz force-pushed the romanz/dict-no-alloc branch from 498bdb6 to f78dfb8 Compare March 31, 2025 07:35
@romanz
Copy link
Author

romanz commented Mar 31, 2025

If no_realloc is set in runtime.c, it causes CI failures (e.g. in core unittests) -> force-pushed a fix:

diff --git a/py/runtime.c b/py/runtime.c
index af360970b..696b99825 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -103,11 +103,9 @@ void mp_init(void) {
 
     // init global module dict
     mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), MICROPY_LOADED_MODULES_DICT_SIZE);
-    MP_STATE_VM(mp_loaded_modules_dict).map.no_realloc = 1;
 
     // initialise the __main__ module
     mp_obj_dict_init(&MP_STATE_VM(dict_main), MICROPY_MAIN_DICT_SIZE);
-    MP_STATE_VM(dict_main).map.no_realloc = 1;
     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())

@romanz romanz closed this Apr 2, 2025
@romanz romanz deleted the romanz/dict-no-alloc branch April 2, 2025 12:16
@romanz romanz restored the romanz/dict-no-alloc branch April 2, 2025 12:16
@romanz
Copy link
Author

romanz commented Apr 2, 2025

Another approach is used in trezor/trezor-firmware#4842.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants