py/sequence: Allow to use bignums as indices in slice objects.
See issue #2264.
This commit is contained in:
parent
f6a8e84a25
commit
095e43a9a5
@ -56,12 +56,12 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
|
|||||||
if (ostart == mp_const_none) {
|
if (ostart == mp_const_none) {
|
||||||
start = 0;
|
start = 0;
|
||||||
} else {
|
} else {
|
||||||
start = MP_OBJ_SMALL_INT_VALUE(ostart);
|
start = mp_obj_get_int(ostart);
|
||||||
}
|
}
|
||||||
if (ostop == mp_const_none) {
|
if (ostop == mp_const_none) {
|
||||||
stop = len;
|
stop = len;
|
||||||
} else {
|
} else {
|
||||||
stop = MP_OBJ_SMALL_INT_VALUE(ostop);
|
stop = mp_obj_get_int(ostop);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlike subscription, out-of-bounds slice indexes are never error
|
// 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
|
|||||||
indexes->stop = stop;
|
indexes->stop = stop;
|
||||||
|
|
||||||
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
|
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
|
||||||
indexes->step = MP_OBJ_SMALL_INT_VALUE(ostep);
|
indexes->step = mp_obj_get_int(ostep);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
indexes->step = 1;
|
indexes->step = 1;
|
||||||
|
5
tests/basics/slice_bignum.py
Normal file
5
tests/basics/slice_bignum.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# test slicing when arguments are bignums
|
||||||
|
|
||||||
|
print(list(range(10))[(1<<66)>>65:])
|
||||||
|
print(list(range(10))[:(1<<66)>>65])
|
||||||
|
print(list(range(10))[::(1<<66)>>65])
|
Loading…
x
Reference in New Issue
Block a user