extmod/moductypes: Fix large return values of addressof and INT_MAYBE.

So they don't return a negative number for an address (prior to this fix
they would return negative addresses for values that were larger than the
maximum small-int value).

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-11-24 15:06:30 +11:00
parent 23bfa95d34
commit 8970ede7cc

View File

@@ -602,7 +602,7 @@ static mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
if (agg_type == PTR) {
byte *p = *(void **)self->addr;
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
return mp_obj_new_int_from_uint((uintptr_t)p);
}
}
MP_FALLTHROUGH
@@ -629,7 +629,7 @@ static mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
static mp_obj_t uctypes_struct_addressof(mp_obj_t buf) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
return mp_obj_new_int((mp_int_t)(uintptr_t)bufinfo.buf);
return mp_obj_new_int_from_uint((uintptr_t)bufinfo.buf);
}
MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof);