forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
py/persistentcode: Explicitly track native BSS/rodata when needed.
Signed-off-by: Damien George <[email protected]>
- Loading branch information
Showing
7 changed files
with
144 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
3628800 | ||
123456 | ||
13 | ||
123456 | ||
13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
MPY_DIR = ../../.. | ||
|
||
MOD = test_$(ARCH) | ||
SRC = test.c | ||
ARCH = x64 | ||
|
||
.PHONY: main | ||
main: all | ||
$(Q)cat $(MOD).mpy | python -c 'import sys; print(sys.stdin.buffer.read())' | ||
|
||
include $(MPY_DIR)/py/dynruntime.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This test native module is used by import_mpy_native_gc.py. | ||
// It has: | ||
// - A variable in the BSS, to check that the BSS is not reclaimed by the GC. | ||
// - An unused native function at the start so that subsequent native functions | ||
// don't start at the beginning of the native function data. This tests that the | ||
// GC doesn't reclaim the native function data even when the only pointer to that | ||
// data is pointing inside the allocated memory. | ||
|
||
#include "py/dynruntime.h" | ||
|
||
uint32_t bss_variable; | ||
|
||
static mp_obj_t unused(mp_obj_t x_obj) { | ||
return mp_const_none; | ||
} | ||
static MP_DEFINE_CONST_FUN_OBJ_1(unused_obj, unused); | ||
|
||
static mp_obj_t get(void) { | ||
return mp_obj_new_int(bss_variable); | ||
} | ||
static MP_DEFINE_CONST_FUN_OBJ_0(get_obj, get); | ||
|
||
static mp_obj_t add1(mp_obj_t x_obj) { | ||
return mp_obj_new_int(mp_obj_get_int(x_obj) + 1); | ||
} | ||
static MP_DEFINE_CONST_FUN_OBJ_1(add1_obj, add1); | ||
|
||
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { | ||
MP_DYNRUNTIME_INIT_ENTRY | ||
|
||
bss_variable = 123456; | ||
|
||
mp_store_global(MP_QSTR_unused, MP_OBJ_FROM_PTR(&unused_obj)); | ||
mp_store_global(MP_QSTR_get, MP_OBJ_FROM_PTR(&get_obj)); | ||
mp_store_global(MP_QSTR_add1, MP_OBJ_FROM_PTR(&add1_obj)); | ||
|
||
MP_DYNRUNTIME_INIT_EXIT | ||
} |