mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 20:50:14 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
7be82f8b7c
commit
72867bce1d
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user