Skip to content

Commit 095e43a

Browse files
committed
py/sequence: Allow to use bignums as indices in slice objects.
See issue adafruit#2264.
1 parent f6a8e84 commit 095e43a

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

py/sequence.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
5656
if (ostart == mp_const_none) {
5757
start = 0;
5858
} else {
59-
start = MP_OBJ_SMALL_INT_VALUE(ostart);
59+
start = mp_obj_get_int(ostart);
6060
}
6161
if (ostop == mp_const_none) {
6262
stop = len;
6363
} else {
64-
stop = MP_OBJ_SMALL_INT_VALUE(ostop);
64+
stop = mp_obj_get_int(ostop);
6565
}
6666

6767
// Unlike subscription, out-of-bounds slice indexes are never error
@@ -88,7 +88,7 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
8888
indexes->stop = stop;
8989

9090
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
91-
indexes->step = MP_OBJ_SMALL_INT_VALUE(ostep);
91+
indexes->step = mp_obj_get_int(ostep);
9292
return false;
9393
}
9494
indexes->step = 1;

tests/basics/slice_bignum.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test slicing when arguments are bignums
2+
3+
print(list(range(10))[(1<<66)>>65:])
4+
print(list(range(10))[:(1<<66)>>65])
5+
print(list(range(10))[::(1<<66)>>65])

0 commit comments

Comments
 (0)