From 72867bce1d2cf39abe164bebf4d239c6974c9122 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 15 Jul 2025 16:09:19 +0100 Subject: py/objrange: Allow return of non-small ints. The magnitude of `range()` arguments is not restricted to "small" ints, but includes "machine ints" which fit inside a register but can only be represented as "long integer" objects in Python. Signed-off-by: Jeff Epler --- py/objrange.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'py/objrange.c') diff --git a/py/objrange.c b/py/objrange.c index 1cc575f33..e19d6c4df 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -41,9 +41,9 @@ typedef struct _mp_obj_range_it_t { static mp_obj_t range_it_iternext(mp_obj_t o_in) { mp_obj_range_it_t *o = MP_OBJ_TO_PTR(o_in); if ((o->step > 0 && o->cur < o->stop) || (o->step < 0 && o->cur > o->stop)) { - mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(o->cur); + mp_int_t cur = o->cur; o->cur += o->step; - return o_out; + return mp_obj_new_int(cur); } else { return MP_OBJ_STOP_ITERATION; } @@ -132,7 +132,7 @@ static mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len > 0); case MP_UNARY_OP_LEN: - return MP_OBJ_NEW_SMALL_INT(len); + return mp_obj_new_int(len); default: return MP_OBJ_NULL; // op not supported } @@ -173,7 +173,7 @@ static mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } #endif size_t index_val = mp_get_index(self->base.type, len, index, false); - return MP_OBJ_NEW_SMALL_INT(self->start + index_val * self->step); + return mp_obj_new_int(self->start + index_val * self->step); } else { return MP_OBJ_NULL; // op not supported } -- cgit v1.2.3