summaryrefslogtreecommitdiffstatshomepage
path: root/py/modsys.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-11-27 17:01:44 +0000
committerDamien George <damien.p.george@gmail.com>2015-11-29 14:25:35 +0000
commit999cedb90ff0827cdb9dfe0e4faa6ebc1739d271 (patch)
tree897eb07b82f1893cfd413b9ef7f625cd996f859d /py/modsys.c
parentcbf7674025814797f5c537d6d1c195efe58ccaaf (diff)
downloadmicropython-999cedb90ff0827cdb9dfe0e4faa6ebc1739d271.tar.gz
micropython-999cedb90ff0827cdb9dfe0e4faa6ebc1739d271.zip
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.
Diffstat (limited to 'py/modsys.c')
-rw-r--r--py/modsys.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/py/modsys.c b/py/modsys.c
index 3aa1109b8d..57ac2bf058 100644
--- a/py/modsys.c
+++ b/py/modsys.c
@@ -45,7 +45,7 @@ extern struct _mp_dummy_t mp_sys_stdout_obj;
extern struct _mp_dummy_t mp_sys_stderr_obj;
#if MICROPY_PY_IO
-const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, (mp_print_strn_t)mp_stream_write};
+const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adaptor};
#endif
/// \constant version - Python language version that this implementation conforms to, as a string
@@ -106,12 +106,12 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
STATIC mp_obj_t mp_sys_print_exception(mp_uint_t n_args, const mp_obj_t *args) {
#if MICROPY_PY_IO
- mp_obj_t stream_obj = &mp_sys_stdout_obj;
+ void *stream_obj = &mp_sys_stdout_obj;
if (n_args > 1) {
- stream_obj = args[1];
+ stream_obj = MP_OBJ_TO_PTR(args[1]); // XXX may fail
}
- mp_print_t print = {stream_obj, (mp_print_strn_t)mp_stream_write};
+ mp_print_t print = {stream_obj, mp_stream_write_adaptor};
mp_obj_print_exception(&print, args[0]);
#else
(void)n_args;
@@ -124,20 +124,20 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_pri
#if MICROPY_PY_SYS_EXC_INFO
STATIC mp_obj_t mp_sys_exc_info(void) {
- mp_obj_t cur_exc = MP_STATE_VM(cur_exception);
- mp_obj_tuple_t *t = mp_obj_new_tuple(3, NULL);
+ mp_obj_t cur_exc = MP_OBJ_FROM_PTR(MP_STATE_VM(cur_exception));
+ mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
if (cur_exc == MP_OBJ_NULL) {
t->items[0] = mp_const_none;
t->items[1] = mp_const_none;
t->items[2] = mp_const_none;
- return t;
+ return MP_OBJ_FROM_PTR(t);
}
- t->items[0] = mp_obj_get_type(cur_exc);
+ t->items[0] = MP_OBJ_FROM_PTR(mp_obj_get_type(cur_exc));
t->items[1] = cur_exc;
t->items[2] = mp_const_none;
- return t;
+ return MP_OBJ_FROM_PTR(t);
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info);
#endif