Skip to content

Commit bf059cc

Browse files
committed
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>
1 parent 9113beb commit bf059cc

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

py/objrange.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ typedef struct _mp_obj_range_it_t {
4141
static mp_obj_t range_it_iternext(mp_obj_t o_in) {
4242
mp_obj_range_it_t *o = MP_OBJ_TO_PTR(o_in);
4343
if ((o->step > 0 && o->cur < o->stop) || (o->step < 0 && o->cur > o->stop)) {
44-
mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(o->cur);
44+
mp_int_t cur = o->cur;
4545
o->cur += o->step;
46-
return o_out;
46+
return mp_obj_new_int(cur);
4747
} else {
4848
return MP_OBJ_STOP_ITERATION;
4949
}
@@ -132,7 +132,7 @@ static mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
132132
case MP_UNARY_OP_BOOL:
133133
return mp_obj_new_bool(len > 0);
134134
case MP_UNARY_OP_LEN:
135-
return MP_OBJ_NEW_SMALL_INT(len);
135+
return mp_obj_new_int(len);
136136
default:
137137
return MP_OBJ_NULL; // op not supported
138138
}
@@ -173,7 +173,7 @@ static mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
173173
}
174174
#endif
175175
size_t index_val = mp_get_index(self->base.type, len, index, false);
176-
return MP_OBJ_NEW_SMALL_INT(self->start + index_val * self->step);
176+
return mp_obj_new_int(self->start + index_val * self->step);
177177
} else {
178178
return MP_OBJ_NULL; // op not supported
179179
}

0 commit comments

Comments
 (0)