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

@@ -37,7 +37,7 @@ typedef struct _mp_obj_getitem_iter_t {
} mp_obj_getitem_iter_t;
STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
mp_obj_getitem_iter_t *self = self_in;
mp_obj_getitem_iter_t *self = MP_OBJ_TO_PTR(self_in);
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
// try to get next item
@@ -47,13 +47,13 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
return value;
} else {
// an exception was raised
mp_obj_type_t *t = mp_obj_get_type(nlr.ret_val);
mp_obj_type_t *t = (mp_obj_type_t*)((mp_obj_base_t*)nlr.ret_val)->type;
if (t == &mp_type_StopIteration || t == &mp_type_IndexError) {
// return MP_OBJ_STOP_ITERATION instead of raising
return MP_OBJ_STOP_ITERATION;
} else {
// re-raise exception
nlr_raise(nlr.ret_val);
nlr_jump(nlr.ret_val);
}
}
}
@@ -72,5 +72,5 @@ mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args) {
o->args[0] = args[0];
o->args[1] = args[1];
o->args[2] = MP_OBJ_NEW_SMALL_INT(0);
return o;
return MP_OBJ_FROM_PTR(o);
}