diff options
author | Damien George <damien.p.george@gmail.com> | 2015-11-27 17:01:44 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-11-29 14:25:35 +0000 |
commit | 999cedb90ff0827cdb9dfe0e4faa6ebc1739d271 (patch) | |
tree | 897eb07b82f1893cfd413b9ef7f625cd996f859d /py/objfun.c | |
parent | cbf7674025814797f5c537d6d1c195efe58ccaaf (diff) | |
download | micropython-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/objfun.c')
-rw-r--r-- | py/objfun.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/py/objfun.c b/py/objfun.c index 86dbe32e7f..88e84ce9fc 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -54,7 +54,7 @@ STATIC mp_obj_t fun_builtin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_fun_builtin)); - mp_obj_fun_builtin_t *self = self_in; + mp_obj_fun_builtin_t *self = MP_OBJ_TO_PTR(self_in); // check number of arguments mp_arg_check_num(n_args, n_kw, self->n_args_min, self->n_args_max, self->is_kw); @@ -118,7 +118,7 @@ STATIC const mp_obj_type_t mp_type_fun_native; #endif qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { - const mp_obj_fun_bc_t *fun = fun_in; + const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); #if MICROPY_EMIT_NATIVE if (fun->base.type == &mp_type_fun_native) { // TODO native functions don't have name stored @@ -139,8 +139,8 @@ qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { #if MICROPY_CPYTHON_COMPAT STATIC void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; - mp_obj_fun_bc_t *o = o_in; - mp_printf(print, "<function %q at 0x%x>", mp_obj_fun_get_name(o), o); + mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(o_in); + mp_printf(print, "<function %q at 0x%p>", mp_obj_fun_get_name(o_in), o); } #endif @@ -204,7 +204,7 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, dump_args(args, n_args); DEBUG_printf("Input kw args: "); dump_args(args + n_args, n_kw * 2); - mp_obj_fun_bc_t *self = self_in; + mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); DEBUG_printf("Func n_def_args: %d\n", self->n_def_args); // get start of bytecode @@ -325,9 +325,9 @@ const mp_obj_type_t mp_type_fun_bc = { mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table) { mp_uint_t n_def_args = 0; mp_uint_t n_extra_args = 0; - mp_obj_tuple_t *def_args = def_args_in; - if (def_args != MP_OBJ_NULL) { - assert(MP_OBJ_IS_TYPE(def_args, &mp_type_tuple)); + mp_obj_tuple_t *def_args = MP_OBJ_TO_PTR(def_args_in); + if (def_args_in != MP_OBJ_NULL) { + assert(MP_OBJ_IS_TYPE(def_args_in, &mp_type_tuple)); n_def_args = def_args->len; n_extra_args = def_args->len; } @@ -339,13 +339,13 @@ mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byt o->globals = mp_globals_get(); o->bytecode = code; o->const_table = const_table; - if (def_args != MP_OBJ_NULL) { + if (def_args != NULL) { memcpy(o->extra_args, def_args->items, n_def_args * sizeof(mp_obj_t)); } if (def_kw_args != MP_OBJ_NULL) { o->extra_args[n_def_args] = def_kw_args; } - return o; + return MP_OBJ_FROM_PTR(o); } /******************************************************************************/ |