Skip to content

Commit 4c73e4d

Browse files
author
Will Roberts
committed
bpo-30537: use PyNumber in itertools instead of PyLong
1 parent aead53b commit 4c73e4d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Modules/itertoolsmodule.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14171417
numargs = PyTuple_Size(args);
14181418
if (numargs == 2) {
14191419
if (a1 != Py_None) {
1420-
stop = PyLong_AsSsize_t(a1);
1420+
stop = PyNumber_AsSsize_t(a1, PyExc_OverflowError);
14211421
if (stop == -1) {
14221422
if (PyErr_Occurred())
14231423
PyErr_Clear();
@@ -1429,11 +1429,11 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14291429
}
14301430
} else {
14311431
if (a1 != Py_None)
1432-
start = PyLong_AsSsize_t(a1);
1432+
start = PyNumber_AsSsize_t(a1, PyExc_OverflowError);
14331433
if (start == -1 && PyErr_Occurred())
14341434
PyErr_Clear();
14351435
if (a2 != Py_None) {
1436-
stop = PyLong_AsSsize_t(a2);
1436+
stop = PyNumber_AsSsize_t(a2, PyExc_OverflowError);
14371437
if (stop == -1) {
14381438
if (PyErr_Occurred())
14391439
PyErr_Clear();
@@ -1453,7 +1453,7 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14531453

14541454
if (a3 != NULL) {
14551455
if (a3 != Py_None)
1456-
step = PyLong_AsSsize_t(a3);
1456+
step = PyNumber_AsSsize_t(a3, PyExc_OverflowError);
14571457
if (step == -1 && PyErr_Occurred())
14581458
PyErr_Clear();
14591459
}
@@ -1573,7 +1573,7 @@ islice_reduce(isliceobject *lz)
15731573
static PyObject *
15741574
islice_setstate(isliceobject *lz, PyObject *state)
15751575
{
1576-
Py_ssize_t cnt = PyLong_AsSsize_t(state);
1576+
Py_ssize_t cnt = PyNumber_AsSsize_t(state, PyExc_OverflowError);
15771577

15781578
if (cnt == -1 && PyErr_Occurred())
15791579
return NULL;
@@ -2265,7 +2265,7 @@ product_setstate(productobject *lz, PyObject *state)
22652265
for (i=0; i<n; i++)
22662266
{
22672267
PyObject* indexObject = PyTuple_GET_ITEM(state, i);
2268-
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
2268+
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);
22692269
PyObject* pool;
22702270
Py_ssize_t poolsize;
22712271
if (index < 0 && PyErr_Occurred())
@@ -2592,7 +2592,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state)
25922592
for (i=0; i<lz->r; i++) {
25932593
Py_ssize_t max;
25942594
PyObject* indexObject = PyTuple_GET_ITEM(state, i);
2595-
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
2595+
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);
25962596

25972597
if (index == -1 && PyErr_Occurred())
25982598
return NULL; /* not an integer */
@@ -2925,7 +2925,7 @@ cwr_setstate(cwrobject *lz, PyObject *state)
29252925
n = PyTuple_GET_SIZE(lz->pool);
29262926
for (i=0; i<lz->r; i++) {
29272927
PyObject* indexObject = PyTuple_GET_ITEM(state, i);
2928-
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
2928+
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);
29292929

29302930
if (index < 0 && PyErr_Occurred())
29312931
return NULL; /* not an integer */
@@ -3072,11 +3072,11 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
30723072

30733073
r = n;
30743074
if (robj != Py_None) {
3075-
if (!PyLong_Check(robj)) {
3076-
PyErr_SetString(PyExc_TypeError, "Expected int as r");
3075+
if (!PyNumber_Check(robj)) {
3076+
PyErr_SetString(PyExc_TypeError, "Expected number as r");
30773077
goto error;
30783078
}
3079-
r = PyLong_AsSsize_t(robj);
3079+
r = PyNumber_AsSsize_t(robj, PyExc_OverflowError);
30803080
if (r == -1 && PyErr_Occurred())
30813081
goto error;
30823082
}
@@ -3307,7 +3307,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)
33073307

33083308
for (i=0; i<n; i++) {
33093309
PyObject* indexObject = PyTuple_GET_ITEM(indices, i);
3310-
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
3310+
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);
33113311
if (index < 0 && PyErr_Occurred())
33123312
return NULL; /* not an integer */
33133313
/* clamp the index */
@@ -3320,7 +3320,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)
33203320

33213321
for (i=0; i<po->r; i++) {
33223322
PyObject* indexObject = PyTuple_GET_ITEM(cycles, i);
3323-
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
3323+
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);
33243324
if (index < 0 && PyErr_Occurred())
33253325
return NULL; /* not an integer */
33263326
if (index < 1)

0 commit comments

Comments
 (0)