summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-24 16:28:17 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-24 16:28:17 +0100
commit3c658a4e755a75e495303957208486e583ddb270 (patch)
tree6418fea9bf3dcf4aed2145db94fda4c0de1d0321 /unix
parent25fc41dd316c38df3e2a6cfe4b53322d76dc92fc (diff)
downloadmicropython-3c658a4e755a75e495303957208486e583ddb270.tar.gz
micropython-3c658a4e755a75e495303957208486e583ddb270.zip
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.
Diffstat (limited to 'unix')
-rw-r--r--unix/main.c10
-rw-r--r--unix/mpconfigport.h4
2 files changed, 8 insertions, 6 deletions
diff --git a/unix/main.c b/unix/main.c
index dd3fa533c2..898182fa92 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -221,7 +221,7 @@ int usage(char **argv) {
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 @@ mp_obj_t mem_info(void) {
#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 @@ int main(int argc, char **argv) {
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.
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index c67bdfba41..900bca7a6d 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -114,8 +114,8 @@ typedef unsigned int mp_uint_t; // must be pointer size
typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size
-extern const struct _mp_obj_fun_native_t mp_builtin_input_obj;
-extern const struct _mp_obj_fun_native_t mp_builtin_open_obj;
+extern const struct _mp_obj_fun_builtin_t mp_builtin_input_obj;
+extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
#define MICROPY_PORT_BUILTINS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },