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.
diff --git a/py/objattrtuple.c b/py/objattrtuple.c
index 04c17a2..c6dd3ae 100644
--- a/py/objattrtuple.c
+++ b/py/objattrtuple.c
@@ -50,17 +50,17 @@
STATIC void mp_obj_attrtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
- mp_obj_tuple_t *o = o_in;
- const qstr *fields = (const qstr*)o->items[o->len];
+ mp_obj_tuple_t *o = MP_OBJ_TO_PTR(o_in);
+ const qstr *fields = (const qstr*)MP_OBJ_TO_PTR(o->items[o->len]);
mp_obj_attrtuple_print_helper(print, fields, o);
}
STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if (dest[0] == MP_OBJ_NULL) {
// load attribute
- mp_obj_tuple_t *self = self_in;
+ mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t len = self->len;
- const qstr *fields = (const qstr*)self->items[len];
+ const qstr *fields = (const qstr*)MP_OBJ_TO_PTR(self->items[len]);
for (mp_uint_t i = 0; i < len; i++) {
if (fields[i] == attr) {
dest[0] = self->items[i];
@@ -77,8 +77,8 @@
for (mp_uint_t i = 0; i < n; i++) {
o->items[i] = items[i];
}
- o->items[n] = (void*)fields;
- return o;
+ o->items[n] = MP_OBJ_FROM_PTR(fields);
+ return MP_OBJ_FROM_PTR(o);
}
const mp_obj_type_t mp_type_attrtuple = {