8000 bpo-30537: use PyNumber in itertools.islice instead of PyLong by wroberts · Pull Request #1918 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-30537: use PyNumber in itertools.islice instead of PyLong #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-30537: use PyNumber in itertools instead of PyLong
  • Loading branch information
Will Roberts committed Jun 2, 2017
commit 4c73e4da47d8cca55fa3982a23e79f78b5bf1341
26 changes: 13 additions & 13 deletions Modules/itertoolsmodule.c
C77D
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
numargs = PyTuple_Size(args);
if (numargs == 2) {
if (a1 != Py_None) {
stop = PyLong_AsSsize_t(a1);
stop = PyNumber_AsSsize_t(a1, PyExc_OverflowError);
if (stop == -1) {
if (PyErr_Occurred())
PyErr_Clear();
Expand All @@ -1429,11 +1429,11 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
} else {
if (a1 != Py_None)
start = PyLong_AsSsize_t(a1);
start = PyNumber_AsSsize_t(a1, PyExc_OverflowError);
if (start == -1 && PyErr_Occurred())
PyErr_Clear();
if (a2 != Py_None) {
stop = PyLong_AsSsize_t(a2);
stop = PyNumber_AsSsize_t(a2, PyExc_OverflowError);
if (stop == -1) {
if (PyErr_Occurred())
PyErr_Clear();
Expand All @@ -1453,7 +1453,7 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

if (a3 != NULL) {
if (a3 != Py_None)
step = PyLong_AsSsize_t(a3);
step = PyNumber_AsSsize_t(a3, PyExc_OverflowError);
if (step == -1 && PyErr_Occurred())
PyErr_Clear();
}
Expand Down Expand Up @@ -1573,7 +1573,7 @@ islice_reduce(isliceobject *lz)
static PyObject *
islice_setstate(isliceobject *lz, PyObject *state)
{
Py_ssize_t cnt = PyLong_AsSsize_t(state);
Py_ssize_t cnt = PyNumber_AsSsize_t(state, PyExc_OverflowError);

if (cnt == -1 && PyErr_Occurred())
return NULL;
Expand Down Expand Up @@ -2265,7 +2265,7 @@ product_setstate(productobject *lz, PyObject *state)
for (i=0; i<n; i++)
{
PyObject* indexObject = PyTuple_GET_ITEM(state, i);
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);
PyObject* pool;
Py_ssize_t poolsize;
if (index < 0 && PyErr_Occurred())
Expand Down Expand Up @@ -2592,7 +2592,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state)
for (i=0; i<lz->r; i++) {
Py_ssize_t max;
PyObject* indexObject = PyTuple_GET_ITEM(state, i);
Py_ssize_t index = PyLong_AsSsize_t(indexObject);
Py_ssize_t index = PyNumber_AsSsize_t(indexObject, PyExc_OverflowError);

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

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

r = n;
if (robj != Py_None) {
if (!PyLong_Check(robj)) {
PyErr_SetString(PyExc_TypeError, "Expected int as r");
if (!PyNumber_Check(robj)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use PyIndex_Check.

PyErr_SetString(PyExc_TypeError, "Expected number as r");
goto error;
}
r = PyLong_AsSsize_t(robj);
r = PyNumber_AsSsize_t(robj, PyExc_OverflowError);
if (r == -1 && PyErr_Occurred())
goto error;
}
Expand Down Expand Up @@ -3307,7 +3307,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)

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

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