aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2016-08-15 23:26:34 +1000
committerDamien George2016-08-15 23:26:34 +1000
commit095e43a9a5b3fc7c1220cdbabe6a4fed0973b1e1 (patch)
tree6a66ef9074eb268c006a784e1500f824f68d0f1c
parentf6a8e84a2557c5edf29a6f3afa4d1cce1d42d389 (diff)
py/sequence: Allow to use bignums as indices in slice objects.
See issue #2264.
-rw-r--r--py/sequence.c6
-rw-r--r--tests/basics/slice_bignum.py5
2 files changed, 8 insertions, 3 deletions
diff --git a/py/sequence.c b/py/sequence.c
index 6f715ff79..239f1b2cc 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -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) {
start = 0;
} else {
- start = MP_OBJ_SMALL_INT_VALUE(ostart);
+ start = mp_obj_get_int(ostart);
}
if (ostop == mp_const_none) {
stop = len;
} else {
- stop = MP_OBJ_SMALL_INT_VALUE(ostop);
+ stop = mp_obj_get_int(ostop);
}
// 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;
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;
}
indexes->step = 1;
diff --git a/tests/basics/slice_bignum.py b/tests/basics/slice_bignum.py
new file mode 100644
index 000000000..cc820522b
--- /dev/null
+++ b/tests/basics/slice_bignum.py
@@ -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])