Skip to content

Commit 140c2c9

Browse files
committed
extmod/moductypes: Convert pointers as unsigned integers.
This fixes a test failure that only occurred on the qemu VIRT_RV32 board, where RAM address range has the high bit set. Pointer addresses were being return as negative small ints, which meant tobytes() now fails to convert them. Such a pointer needs to be represented as a long integer, instead. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 6cc1bea commit 140c2c9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

extmod/moductypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
602602
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
603603
if (agg_type == PTR) {
604604
byte *p = *(void **)self->addr;
605-
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
605+
return mp_obj_new_int_from_uint((uintptr_t)p);
606606
}
607607
}
608608
MP_FALLTHROUGH
@@ -629,7 +629,7 @@ static mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
629629
static mp_obj_t uctypes_struct_addressof(mp_obj_t buf) {
630630
mp_buffer_info_t bufinfo;
631631
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
632-
return mp_obj_new_int((mp_int_t)(uintptr_t)bufinfo.buf);
632+
return mp_obj_new_int_from_uint((uintptr_t)bufinfo.buf);
633633
}
634634
MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof);
635635

0 commit comments

Comments
 (0)