-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
gc.c: Ensure a gap of one byte before the finaliser table. #7722
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
Conversation
When you wish to use the valgrind memory analysis tool on micropython, you can arrange to define MICROPY_DEBUG_VALGRIND to enable use of special valgrind macros. For now, this only fixes `gc_get_ptr` so that it never emits the diagnostic "Conditional jump or move depends on uninitialised value(s)". Signed-off-by: Jeff Epler <jepler@gmail.com>
.. or, for !MICROPY_ENABLE_FINALISER, before the first block of the pool. Closes: adafruit#5021 Closes: micropython#7116 Signed-off-by: Jeff Epler <jepler@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #7722 +/- ##
==========================================
- Coverage 98.27% 98.24% -0.03%
==========================================
Files 154 154
Lines 20077 20042 -35
==========================================
- Hits 19730 19690 -40
- Misses 347 352 +5
Continue to review full report at Codecov.
|
Can someone let me know what's going on with this CI failure? I didn't immediately make sense of it.
|
This is a PPA to get a backported version of |
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.
Is it at all possible to make a test for this?
I've updated this PR:
|
CI is encountering difficulties:
|
This test must be separate from the "regular" coverage test, as it destroys the gc heap, and must exit via exit() rather than returning to python code. This test fails due to adafruit#7716. Signed-off-by: Jeff Epler <jepler@gmail.com>
078f6fb
to
b776383
Compare
.. and the Windows (appveyor) build is failing with almost every test saying "FATAL: uncaught NLR", which could be some new problem I've introduced even though no effect on nlr was intended. |
794c4ed
to
347046d
Compare
Signed-off-by: Jeff Epler <jepler@gmail.com>
347046d
to
1ea027e
Compare
I have rebased this here: https://github.com/dpgeorge/micropython/tree/py-gc-ensure-one-byte-after-atb |
@@ -118,7 +128,8 @@ void gc_init(void *start, void *end) { | |||
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK) | |||
size_t total_byte_len = (byte *)end - (byte *)start; | |||
#if MICROPY_ENABLE_FINALISER | |||
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len * MP_BITS_PER_BYTE / (MP_BITS_PER_BYTE + MP_BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + MP_BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK); | |||
size_t gc_alloc_table_byte_len = (total_byte_len - ALLOC_TABLE_GAP_BYTE) * MP_BITS_PER_BYTE / (MP_BITS_PER_BYTE + MP_BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + MP_BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK); | |||
MP_STATE_MEM(gc_alloc_table_byte_len) = gc_alloc_table_byte_len; | |||
#else | |||
MP_STATE_MEM(gc_alloc_table_byte_len) = total_byte_len / (1 + MP_BITS_PER_BYTE / 2 * BYTES_PER_BLOCK); |
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 think this should be (total_byte_len - ALLOCA_TABLE_GAP_BYTE) ...
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 fixed this during merge.
heap_size++; | ||
} | ||
mp_printf(&mp_plat_print, "# end coverage.c gc test\n"); | ||
exit(0); |
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 quite brutal, to exit so abruptly! I wonder if there's a better way to do it...
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 think this is a good way to do it because it prevents coverage/testing of the tear down and exiting of the executable.
Two options I can think of:
- save and then restore the
mp_state_mem_t
struct inmp_state_ctx_t
at the start/end of this function, which should restore the original heap on exit of this function - run this code at the start or end of main() (probably at the start, just before
gc_init()
).
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 did option (1) during merge.
Thanks @jepler , this is an important fix. |
Thanks! And thank you for fixing the test to be more appropriate |
.. or, for !MICROPY_ENABLE_FINALISER, before the first block of the pool.
Closes: adafruit#5021
Closes: #7716
I tested this with a version of #7716 (comment) and there were no problems detected.
I haven't tested it on our real HW yet.it also fixes the original problem on our real hw