Skip to content

Commit 0379b55

Browse files
committed
py: Fix casting and printing of small int.
1 parent b25ef4d commit 0379b55

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

py/objint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ STATIC mp_obj_t int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
4747

4848
void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
4949
if (MP_OBJ_IS_SMALL_INT(self_in)) {
50-
print(env, "%d", (int)MP_OBJ_SMALL_INT_VALUE(self_in));
50+
print(env, INT_FMT, MP_OBJ_SMALL_INT_VALUE(self_in));
5151
}
5252
}
5353

py/objint_longlong.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
2525
if (MP_OBJ_IS_SMALL_INT(self_in)) {
26-
print(env, "%d", (int)MP_OBJ_SMALL_INT_VALUE(self_in));
26+
print(env, INT_FMT, MP_OBJ_SMALL_INT_VALUE(self_in));
2727
} else {
2828
mp_obj_int_t *self = self_in;
2929
print(env, "%lld" SUFFIX, self->val);

py/showbc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ void mp_byte_code_print(const byte *ip, int len) {
6868
break;
6969

7070
case MP_BC_LOAD_CONST_SMALL_INT: {
71-
int num = 0;
71+
machine_int_t num = 0;
7272
if ((ip[0] & 0x40) != 0) {
7373
// Number is negative
7474
num--;
7575
}
7676
do {
7777
num = (num << 7) | (*ip & 0x7f);
7878
} while ((*ip++ & 0x80) != 0);
79-
printf("LOAD_CONST_SMALL_INT %d", num);
79+
printf("LOAD_CONST_SMALL_INT " INT_FMT, num);
8080
break;
8181
}
8282

0 commit comments

Comments
 (0)