diff options
| author | Jeff Epler <jepler@gmail.com> | 2025-07-15 16:09:19 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-09-26 13:34:57 +1000 |
| commit | 72867bce1d2cf39abe164bebf4d239c6974c9122 (patch) | |
| tree | 98ff05005b20da33550d9f11ad684c5126a608e5 /py | |
| parent | 7be82f8b7c9ee83696cb08f8f2936f0ed93cd52c (diff) | |
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 <jepler@gmail.com>
Diffstat (limited to 'py')
| -rw-r--r-- | py/objrange.c | 8 |
1 files changed, 4 insertions, 4 deletions
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 } |
