summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-12-27 15:09:36 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2016-12-27 15:09:36 +0200
commit994f04dbf576f4ebafb9de2bc6821e15cb0de0ea (patch)
tree4967ed9c9688f7fe035c646de993c337141051b0 /Modules
parent58c2c6ebb893917e759cc1401b0d862b3f7c1a94 (diff)
downloadcpython-git-994f04dbf576f4ebafb9de2bc6821e15cb0de0ea.tar.gz
Issue #28998: More APIs now support longs as well as ints.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_csv.c17
-rw-r--r--Modules/_cursesmodule.c14
-rw-r--r--Modules/dlmodule.c5
-rw-r--r--Modules/svmodule.c4
-rw-r--r--Modules/termios.c5
5 files changed, 33 insertions, 12 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 4589f06dec..c39c0f10c3 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -220,15 +220,19 @@ _set_bool(const char *name, int *target, PyObject *src, int dflt)
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 @@ static PyObject *
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 e478a57948..9eab741a01 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -194,8 +194,10 @@ PyCursesCheckERR(int code, char *fname)
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 @@ PyCurses_UnCtrl(PyObject *self, PyObject *args)
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 @@ PyCurses_UngetCh(PyObject *self, PyObject *args)
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 dfecf9d33b..7a6686e3a6 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -107,8 +107,11 @@ dl_call(dlobject *xp, PyObject *args)
}
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 1519065666..42c49c853a 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -686,7 +686,7 @@ sv_LoadMap(svobject *self, PyObject *args)
if (!cell)
goto finally;
- if (!PyInt_Check(cell)) {
+ if (!PyInt_Check(cell) && !PyLong_Check(cell)) {
PyErr_BadArgument();
goto finally;
}
@@ -757,7 +757,7 @@ doParams(svobject *self, PyObject *args,
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 57f30dc4cd..9d4d780dca 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -185,8 +185,11 @@ termios_tcsetattr(PyObject *self, PyObject *args)
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");