-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix m_realloc/m_free when MICROPY_MALLOC_USES_ALLOCATED_SIZE is set #10094
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
Fix m_realloc/m_free when MICROPY_MALLOC_USES_ALLOCATED_SIZE is set #10094
Conversation
…s set When 'MICROPY_MALLOC_USES_ALLOCATED_SIZE' is set, we need to pass the previously allocated size to 'm_realloc', 'm_realloc_maybe' and 'm_free'. For the atmel-samd and raspberrypi ports, the variable keeping track of the allocated buffer size was already present, but not properly used. For the nordic and stm ports, there was no such veriable. It is now added only if necessary to save on resources. Signed-off-by: Samantaz Fox <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine with me. Please ensure pre-commit passes though.
I think I also found a bug in pre-commit: pre-commit hook(s) made changes.
If you are seeing this message in CI, reproduce locally with: `pre-commit run --all-files`.
To run `pre-commit` as part of git workflow, use `pre-commit install`.
All changes made by hooks:
diff --git a/shared-module/atexit/__init__.c b/shared-module/atexit/__init__.c
index 6cc13e9..3960732 100644
--- a/shared-module/atexit/__init__.c
+++ b/shared-module/atexit/__init__.c
@@ -47,7 +47,7 @@ void shared_module_atexit_register(mp_obj_t *func, size_t n_args, const mp_obj_t
callback = (atexit_callback_t *)m_realloc(callback,
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
- callback_len * sizeof(cb), // Old size
+ callback_len *sizeof(cb), // Old size
#endif
(callback_len + 1) * sizeof(cb));
|
…D_SIZE is set When 'MICROPY_MALLOC_USES_ALLOCATED_SIZE' is set, we need to pass the previously allocated size to 'm_realloc', 'm_realloc_maybe' and 'm_free'. Signed-off-by: Samantaz Fox <[email protected]>
954cd8f
to
fb0aea8
Compare
Hi! thanks for the PR. We don't mind seeing changes for alternate configuration options like MICROPY_MEM_STATS if the impact of the required changes can easily be managed. we kinda get to live with whatever uncrustufy does; and the CI runs the canonically correct version. Even if it looks wrong to your eyes and mine :-/ Unlike the ideal for pre-commit, we depend on an externally installed uncrustify program; I think
If there's a newer version of uncrustify that formats this differently we may need to add a check for a too-new uncrustify version. What does
The other thing I wonder about here is whether these sites should (mostly) change to use |
Well,
Oh, that's a great question. I assumed that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any problem with taking these changes, if they're useful to someone. A CI-time build that enables USES_ALLOCATED_SIZE would be helpful to try to prevent these sites breaking, but can be done as a separate PR if it someone wants to put in the work.
Thanks @SamantazFox ! |
I wanted to build CircuitPython with
MICROPY_MEM_STATS
enabled to debug some out of memory issues I had, but encountered a few compilation errors.MICROPY_MEM_STATS
requiresMICROPY_MALLOC_USES_ALLOCATED_SIZE
to be set, which in turn causesm_realloc
,m_realloc_maybe
andm_free
to take an extra argument: the previously allocated size.I fixed what I could with my limited knowledge of that code. Some places of the code still lack a proper support for
MICROPY_MALLOC_USES_ALLOCATED_SIZE
.