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:
@@ -50,17 +50,17 @@ void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields,
|
||||
|
||||
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 @@ mp_obj_t mp_obj_new_attrtuple(const qstr *fields, mp_uint_t n, const mp_obj_t *i
|
||||
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 = {
|
||||
|
||||
Reference in New Issue
Block a user