py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.

This allows the mp_obj_t type to be configured to something other than a
pointer-sized primitive type.

This patch also includes additional changes to allow the code to compile
when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of
mp_uint_t, and various casts.
This commit is contained in:
Damien George
2015-11-27 17:01:44 +00:00
parent cbf7674025
commit 999cedb90f
76 changed files with 856 additions and 816 deletions

View File

@@ -263,7 +263,7 @@ STATIC qstr load_qstr(mp_reader_t *reader) {
STATIC mp_obj_t load_obj(mp_reader_t *reader) {
byte obj_type = read_byte(reader);
if (obj_type == 'e') {
return (mp_obj_t)&mp_const_ellipsis_obj;
return MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj);
} else {
size_t len = read_uint(reader);
vstr_t vstr;
@@ -324,7 +324,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) {
*ct++ = (mp_uint_t)load_obj(reader);
}
for (mp_uint_t i = 0; i < n_raw_code; ++i) {
*ct++ = (mp_uint_t)load_raw_code(reader);
*ct++ = (mp_uint_t)(uintptr_t)load_raw_code(reader);
}
// create raw_code and return it
@@ -511,7 +511,7 @@ STATIC void save_obj(mp_print_t *print, mp_obj_t o) {
mp_print_bytes(print, &obj_type, 1);
mp_print_uint(print, len);
mp_print_bytes(print, (const byte*)str, len);
} else if (o == &mp_const_ellipsis_obj) {
} else if (MP_OBJ_TO_PTR(o) == &mp_const_ellipsis_obj) {
byte obj_type = 'e';
mp_print_bytes(print, &obj_type, 1);
} else {
@@ -582,7 +582,7 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc) {
save_obj(print, (mp_obj_t)*const_table++);
}
for (uint i = 0; i < rc->data.u_byte.n_raw_code; ++i) {
save_raw_code(print, (mp_raw_code_t*)*const_table++);
save_raw_code(print, (mp_raw_code_t*)(uintptr_t)*const_table++);
}
}
@@ -614,7 +614,7 @@ STATIC void fd_print_strn(void *env, const char *str, size_t len) {
void mp_raw_code_save_file(mp_raw_code_t *rc, const char *filename) {
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
mp_print_t fd_print = {(void*)(mp_int_t)fd, fd_print_strn};
mp_print_t fd_print = {(void*)(intptr_t)fd, fd_print_strn};
mp_raw_code_save(rc, &fd_print);
close(fd);
}