Just an odd question. What happens if one allocates the emergency exception buffer (via alloc_emergency_exception_buf) more than once?
Is the memory used for the first allocation lost, reallocated or anything else?
I ask this since, as a sloppy programmer, I sometimes use alloc_emergency_exception_buf more than once in various modules, rather than once in, say, boot.py
Allocate the emergency exception buffer more than once
Re: Allocate the emergency exception buffer more than once
alloc_emergency_exception_buf allocated the emergency exception buffer in the GC heap. So yeah it just grabs a new buffer, then for good measure it also frees the old one (which means it's available for reuse immediately without a collection taking place).
https://github.com/micropython/micropyt ... cept.c#L89
Re: Allocate the emergency exception buffer more than once
Thanks.The source code is rather clear. The only thing is that I would not have found it alone: sometimes one can be overwhelmed by the amount of files to search into.
Re: Allocate the emergency exception buffer more than once
If it helps, two approaches to do this quickly:
- Almost all modules "foo" are modfoo.c. My editor has fast goto-file, so modmicropython.c
- From there search for "alloc_em" which tells me the name of the method.
- In this case it's in a different file (objexcept.c) but a global search founs that quickly.
Or:
- Anything that ends up being a string "foo" in the firmware (i.e. the name of the method) must be MP_QSTR_foo.
- Global search for MP_QSTR_alloc_em (this gets you to modmicropython.c).
I use my editors jump-to-file, and either "git grep" or "ag" (silver searcher) for global search.