Issue #28998: More APIs now support longs as well as ints.
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 4589f06..c39c0f1 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -220,15 +220,19 @@
static int
_set_int(const char *name, int *target, PyObject *src, int dflt)
{
+ int value;
if (src == NULL)
*target = dflt;
else {
- if (!PyInt_Check(src)) {
+ if (!PyInt_Check(src) && !PyLong_Check(src)) {
PyErr_Format(PyExc_TypeError,
"\"%s\" must be an integer", name);
return -1;
}
- *target = PyInt_AsLong(src);
+ value = PyInt_AsLong(src);
+ if (value == -1 && PyErr_Occurred())
+ return -1;
+ *target = value;
}
return 0;
}
@@ -1443,17 +1447,20 @@
csv_field_size_limit(PyObject *module, PyObject *args)
{
PyObject *new_limit = NULL;
- long old_limit = field_limit;
+ long old_limit = field_limit, limit;
if (!PyArg_UnpackTuple(args, "field_size_limit", 0, 1, &new_limit))
return NULL;
if (new_limit != NULL) {
- if (!PyInt_Check(new_limit)) {
+ if (!PyInt_Check(new_limit) && !PyLong_Check(new_limit)) {
PyErr_Format(PyExc_TypeError,
"limit must be an integer");
return NULL;
}
- field_limit = PyInt_AsLong(new_limit);
+ limit = PyInt_AsLong(new_limit);
+ if (limit == -1 && PyErr_Occurred())
+ return NULL;
+ field_limit = limit;
}
return PyInt_FromLong(old_limit);
}
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index e478a57..9eab741 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -194,8 +194,10 @@
static int
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{
- if (PyInt_Check(obj)) {
+ if (PyInt_Check(obj) || PyLong_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
+ if (*ch == (chtype) -1 && PyErr_Occurred())
+ return 0;
} else if(PyString_Check(obj)
&& (PyString_Size(obj) == 1)) {
*ch = (chtype) *PyString_AsString(obj);
@@ -2576,8 +2578,11 @@
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
- if (PyInt_Check(temp))
+ if (PyInt_Check(temp) || PyLong_Check(temp)) {
ch = (chtype) PyInt_AsLong(temp);
+ if (ch == (chtype) -1 && PyErr_Occurred())
+ return NULL;
+ }
else if (PyString_Check(temp))
ch = (chtype) *PyString_AsString(temp);
else {
@@ -2598,8 +2603,11 @@
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
- if (PyInt_Check(temp))
+ if (PyInt_Check(temp) || PyLong_Check(temp)) {
ch = (int) PyInt_AsLong(temp);
+ if (ch == -1 && PyErr_Occurred())
+ return NULL;
+ }
else if (PyString_Check(temp))
ch = (int) *PyString_AsString(temp);
else {
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
index dfecf9d..7a6686e 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -107,8 +107,11 @@
}
for (i = 1; i < n; i++) {
PyObject *v = PyTuple_GetItem(args, i);
- if (PyInt_Check(v))
+ if (PyInt_Check(v) || PyLong_Check(v)) {
alist[i-1] = PyInt_AsLong(v);
+ if (alist[i-1] == -1 && PyErr_Occurred())
+ return NULL;
+ }
else if (PyString_Check(v))
alist[i-1] = (long)PyString_AsString(v);
else if (v == Py_None)
diff --git a/Modules/svmodule.c b/Modules/svmodule.c
index 1519065..42c49c8 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -686,7 +686,7 @@
if (!cell)
goto finally;
- if (!PyInt_Check(cell)) {
+ if (!PyInt_Check(cell) && !PyLong_Check(cell)) {
PyErr_BadArgument();
goto finally;
}
@@ -757,7 +757,7 @@
if (!v)
goto finally;
- if (!PyInt_Check(v)) {
+ if (!PyInt_Check(v) && !PyLong_Check(v)) {
PyErr_BadArgument();
goto finally;
}
diff --git a/Modules/termios.c b/Modules/termios.c
index 57f30dc..9d4d780 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -185,8 +185,11 @@
if (PyString_Check(v) && PyString_Size(v) == 1)
mode.c_cc[i] = (cc_t) * PyString_AsString(v);
- else if (PyInt_Check(v))
+ else if (PyInt_Check(v) || PyLong_Check(v)) {
mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
+ if (mode.c_cc[i] == (cc_t) -1 && PyErr_Occurred())
+ return NULL;
+ }
else {
PyErr_SetString(PyExc_TypeError,
"tcsetattr: elements of attributes must be characters or integers");