py: Fix bug where GC collected native/viper/asm function data.
Because (for Thumb) a function pointer has the LSB set, pointers to
dynamic functions in RAM (eg native, viper or asm functions) were not
being traced by the GC. This patch is a comprehensive fix for this.
Addresses issue #820.
diff --git a/unix/main.c b/unix/main.c
index dd3fa53..898182f 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -221,7 +221,7 @@
return 1;
}
-mp_obj_t mem_info(void) {
+STATIC mp_obj_t mem_info(void) {
printf("mem: total=%d, current=%d, peak=%d\n",
m_get_total_bytes_allocated(), m_get_current_bytes_allocated(), m_get_peak_bytes_allocated());
printf("stack: %u\n", mp_stack_usage());
@@ -230,13 +230,15 @@
#endif
return mp_const_none;
}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(mem_info_obj, mem_info);
-mp_obj_t qstr_info(void) {
+STATIC mp_obj_t qstr_info(void) {
uint n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
printf("qstr pool: n_pool=%u, n_qstr=%u, n_str_data_bytes=%u, n_total_bytes=%u\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
return mp_const_none;
}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(qstr_info_obj, qstr_info);
// Process options which set interpreter init options
void pre_process_options(int argc, char **argv) {
@@ -322,8 +324,8 @@
mp_obj_list_init(mp_sys_argv, 0);
- mp_store_name(qstr_from_str("mem_info"), mp_make_function_n(0, mem_info));
- mp_store_name(qstr_from_str("qstr_info"), mp_make_function_n(0, qstr_info));
+ mp_store_name(qstr_from_str("mem_info"), (mp_obj_t*)&mem_info_obj);
+ mp_store_name(qstr_from_str("qstr_info"), (mp_obj_t*)&qstr_info_obj);
// Here is some example code to create a class and instance of that class.
// First is the Python, then the C code.