summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-07-31 09:09:36 +0300
committerGitHub <noreply@github.com>2018-07-31 09:09:36 +0300
commit48c8bf21f97aeb124dbd48bf2bdec1ab4ebc5202 (patch)
tree6678ae7f56e368ef192b8e0f5988f7c317dbb246 /Modules
parentdc9039da239ee572eaaf56e4a026be1fc4d74e24 (diff)
downloadcpython-git-48c8bf21f97aeb124dbd48bf2bdec1ab4ebc5202.tar.gz
[2.7] bpo-34234: Use _PyAnyInt_Check() and _PyAnyInt_CheckExact(). (GH-8479)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_csv.c4
-rw-r--r--Modules/_ctypes/_ctypes.c13
-rw-r--r--Modules/_ctypes/cfield.c6
-rw-r--r--Modules/_cursesmodule.c6
-rw-r--r--Modules/_elementtree.c4
-rw-r--r--Modules/_json.c4
-rw-r--r--Modules/_randommodule.c2
-rw-r--r--Modules/_sqlite/statement.c2
-rw-r--r--Modules/_sre.c4
-rw-r--r--Modules/_struct.c6
-rw-r--r--Modules/_tkinter.c2
-rw-r--r--Modules/cjkcodecs/multibytecodec.c6
-rw-r--r--Modules/datetimemodule.c20
-rw-r--r--Modules/dlmodule.c2
-rw-r--r--Modules/mathmodule.c2
-rw-r--r--Modules/posixmodule.c2
-rw-r--r--Modules/socketmodule.c2
-rw-r--r--Modules/svmodule.c4
-rw-r--r--Modules/termios.c2
19 files changed, 45 insertions, 48 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index c39c0f10c3..ea7d08931c 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -224,7 +224,7 @@ _set_int(const char *name, int *target, PyObject *src, int dflt)
if (src == NULL)
*target = dflt;
else {
- if (!PyInt_Check(src) && !PyLong_Check(src)) {
+ if (!_PyAnyInt_Check(src)) {
PyErr_Format(PyExc_TypeError,
"\"%s\" must be an integer", name);
return -1;
@@ -1452,7 +1452,7 @@ csv_field_size_limit(PyObject *module, PyObject *args)
if (!PyArg_UnpackTuple(args, "field_size_limit", 0, 1, &new_limit))
return NULL;
if (new_limit != NULL) {
- if (!PyInt_Check(new_limit) && !PyLong_Check(new_limit)) {
+ if (!_PyAnyInt_Check(new_limit)) {
PyErr_Format(PyExc_TypeError,
"limit must be an integer");
return NULL;
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 25740ed771..fabbdf13e9 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -547,7 +547,7 @@ static PyObject *
CDataType_from_address(PyObject *type, PyObject *value)
{
void *buf;
- if (!PyInt_Check(value) && !PyLong_Check(value)) {
+ if (!_PyAnyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"integer expected");
return NULL;
@@ -691,7 +691,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
obj = PyObject_GetAttrString(dll, "_handle");
if (!obj)
return NULL;
- if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+ if (!_PyAnyInt_Check(obj)) {
PyErr_SetString(PyExc_TypeError,
"the _handle attribute of the second argument must be an integer");
Py_DECREF(obj);
@@ -1779,7 +1779,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
}
/* Should probably allow buffer interface as well */
/* int, long */
- if (PyInt_Check(value) || PyLong_Check(value)) {
+ if (_PyAnyInt_Check(value)) {
PyCArgObject *parg;
struct fielddesc *fd = _ctypes_get_fielddesc("P");
@@ -3419,7 +3419,7 @@ static int
_get_name(PyObject *obj, char **pname)
{
#ifdef MS_WIN32
- if (PyInt_Check(obj) || PyLong_Check(obj)) {
+ if (_PyAnyInt_Check(obj)) {
/* We have to use MAKEINTRESOURCEA for Windows CE.
Works on Windows as well, of course.
*/
@@ -3469,7 +3469,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(ftuple);
return NULL;
}
- if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+ if (!_PyAnyInt_Check(obj)) {
PyErr_SetString(PyExc_TypeError,
"the _handle attribute of the second argument must be an integer");
Py_DECREF(ftuple);
@@ -3600,8 +3600,7 @@ PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
#endif
if (1 == PyTuple_GET_SIZE(args)
- && (PyInt_Check(PyTuple_GET_ITEM(args, 0))
- || PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
+ && _PyAnyInt_Check(PyTuple_GET_ITEM(args, 0))) {
CDataObject *ob;
void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0));
if (ptr == NULL && PyErr_Occurred())
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index 6f632d0a07..46f041b00e 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1361,7 +1361,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
return NULL;
*(char **)ptr = PyString_AS_STRING(str);
return str;
- } else if (PyInt_Check(value) || PyLong_Check(value)) {
+ } else if (_PyAnyInt_Check(value)) {
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
*(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value);
#else
@@ -1410,7 +1410,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
_ctypes_conversion_errors);
if (!value)
return NULL;
- } else if (PyInt_Check(value) || PyLong_Check(value)) {
+ } else if (_PyAnyInt_Check(value)) {
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
*(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongLongMask(value);
#else
@@ -1565,7 +1565,7 @@ P_set(void *ptr, PyObject *value, Py_ssize_t size)
_RET(value);
}
- if (!PyInt_Check(value) && !PyLong_Check(value)) {
+ if (!_PyAnyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"cannot be converted to pointer");
return NULL;
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 935712a0be..0ec4ee1244 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -194,7 +194,7 @@ PyCursesCheckERR(int code, char *fname)
static int
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{
- if (PyInt_Check(obj) || PyLong_Check(obj)) {
+ if (_PyAnyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
if (*ch == (chtype) -1 && PyErr_Occurred())
return 0;
@@ -2603,7 +2603,7 @@ PyCurses_UnCtrl(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
- if (PyInt_Check(temp) || PyLong_Check(temp)) {
+ if (_PyAnyInt_Check(temp)) {
ch = (chtype) PyInt_AsLong(temp);
if (ch == (chtype) -1 && PyErr_Occurred())
return NULL;
@@ -2628,7 +2628,7 @@ PyCurses_UngetCh(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
- if (PyInt_Check(temp) || PyLong_Check(temp)) {
+ if (_PyAnyInt_Check(temp)) {
ch = (int) PyInt_AsLong(temp);
if (ch == -1 && PyErr_Occurred())
return NULL;
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 1d316a1c91..f7f992dd3a 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1347,7 +1347,7 @@ element_subscr(PyObject* self_, PyObject* item)
ElementObject* self = (ElementObject*) self_;
#if (PY_VERSION_HEX < 0x02050000)
- if (PyInt_Check(item) || PyLong_Check(item)) {
+ if (_PyAnyInt_Check(item)) {
long i = PyInt_AsLong(item);
#else
if (PyIndex_Check(item)) {
@@ -1404,7 +1404,7 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
ElementObject* self = (ElementObject*) self_;
#if (PY_VERSION_HEX < 0x02050000)
- if (PyInt_Check(item) || PyLong_Check(item)) {
+ if (_PyAnyInt_Check(item)) {
long i = PyInt_AsLong(item);
#else
if (PyIndex_Check(item)) {
diff --git a/Modules/_json.c b/Modules/_json.c
index 39ec467b09..28c0b3f457 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1981,7 +1981,7 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi
return -1;
return _steal_list_append(rval, encoded);
}
- else if (PyInt_Check(obj) || PyLong_Check(obj)) {
+ else if (_PyAnyInt_Check(obj)) {
PyObject *encoded = PyObject_Str(obj);
if (encoded == NULL)
return -1;
@@ -2131,7 +2131,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
if (kstr == NULL)
goto bail;
}
- else if (PyInt_Check(key) || PyLong_Check(key)) {
+ else if (_PyAnyInt_Check(key)) {
kstr = PyObject_Str(key);
if (kstr == NULL)
goto bail;
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 2e49db6ef7..2c0daef71f 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -415,7 +415,7 @@ random_jumpahead(RandomObject *self, PyObject *n)
PyObject *remobj;
unsigned long *mt, tmp, nonzero;
- if (!PyInt_Check(n) && !PyLong_Check(n)) {
+ if (!_PyAnyInt_Check(n)) {
PyErr_Format(PyExc_TypeError, "jumpahead requires an "
"integer, not '%s'",
Py_TYPE(n)->tp_name);
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 5d6263c8e6..ec60095ab8 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -205,7 +205,7 @@ static int _need_adapt(PyObject* obj)
return 1;
}
- if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
+ if (_PyAnyInt_CheckExact(obj)
|| PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
|| PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
return 0;
diff --git a/Modules/_sre.c b/Modules/_sre.c
index efef8f508f..081a1aa005 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -3327,7 +3327,7 @@ match_getindex(MatchObject* self, PyObject* index)
{
Py_ssize_t i;
- if (PyInt_Check(index) || PyLong_Check(index))
+ if (_PyAnyInt_Check(index))
return PyInt_AsSsize_t(index);
i = -1;
@@ -3335,7 +3335,7 @@ match_getindex(MatchObject* self, PyObject* index)
if (self->pattern->groupindex) {
index = PyObject_GetItem(self->pattern->groupindex, index);
if (index) {
- if (PyInt_Check(index) || PyLong_Check(index))
+ if (_PyAnyInt_Check(index))
i = PyInt_AsSsize_t(index);
Py_DECREF(index);
} else
diff --git a/Modules/_struct.c b/Modules/_struct.c
index d83d57f2e8..8b97672070 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -110,7 +110,7 @@ get_pylong(PyObject *v)
PyObject *r, *w;
int converted = 0;
assert(v != NULL);
- if (!PyInt_Check(v) && !PyLong_Check(v)) {
+ if (!_PyAnyInt_Check(v)) {
PyNumberMethods *m;
/* Not an integer; first try to use __index__ to
convert to an integer. If the __index__ method
@@ -150,7 +150,7 @@ get_pylong(PyObject *v)
v = m->nb_int(v);
if (v == NULL)
return NULL;
- if (!PyInt_Check(v) && !PyLong_Check(v)) {
+ if (!_PyAnyInt_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"__int__ method returned "
"non-integer");
@@ -169,7 +169,7 @@ get_pylong(PyObject *v)
/* Ensure we own a reference to v. */
Py_INCREF(v);
- assert(PyInt_Check(v) || PyLong_Check(v));
+ assert(_PyAnyInt_Check(v));
if (PyInt_Check(v)) {
r = PyLong_FromLong(PyInt_AS_LONG(v));
Py_DECREF(v);
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 444c268c0b..c71ffd016a 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -2107,7 +2107,7 @@ Tkapp_GetInt(PyObject *self, PyObject *args)
if (PyTuple_Size(args) == 1) {
PyObject* o = PyTuple_GetItem(args, 0);
- if (PyInt_Check(o) || PyLong_Check(o)) {
+ if (_PyAnyInt_Check(o)) {
Py_INCREF(o);
return o;
}
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 8901b42e41..4b482bf9e2 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -310,8 +310,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
!PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) ||
- !(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) ||
- PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
+ !_PyAnyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
PyErr_SetString(PyExc_TypeError,
"encoding error handler must return "
"(unicode, int) tuple");
@@ -430,8 +429,7 @@ multibytecodec_decerror(MultibyteCodec *codec,
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
!PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0))) ||
- !(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) ||
- PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
+ !_PyAnyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
PyErr_SetString(PyExc_TypeError,
"decoding error handler must return "
"(unicode, int) tuple");
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index e818c5cfdc..c0b7102de2 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1537,7 +1537,7 @@ delta_to_microseconds(PyDateTime_Delta *self)
if (x2 == NULL)
goto Done;
result = PyNumber_Add(x1, x2);
- assert(result == NULL || PyInt_CheckExact(result) || PyLong_CheckExact(result));
+ assert(result == NULL || _PyAnyInt_CheckExact(result));
Done:
Py_XDECREF(x1);
@@ -1560,7 +1560,7 @@ microseconds_to_delta_ex(PyObject *pyus, PyTypeObject *type)
PyObject *num = NULL;
PyObject *result = NULL;
- assert(PyInt_CheckExact(pyus) || PyLong_CheckExact(pyus));
+ assert(_PyAnyInt_CheckExact(pyus));
tuple = PyNumber_Divmod(pyus, us_per_second);
if (tuple == NULL)
goto Done;
@@ -1803,11 +1803,11 @@ delta_multiply(PyObject *left, PyObject *right)
if (PyDelta_Check(left)) {
/* delta * ??? */
- if (PyInt_Check(right) || PyLong_Check(right))
+ if (_PyAnyInt_Check(right))
result = multiply_int_timedelta(right,
(PyDateTime_Delta *) left);
}
- else if (PyInt_Check(left) || PyLong_Check(left))
+ else if (_PyAnyInt_Check(left))
result = multiply_int_timedelta(left,
(PyDateTime_Delta *) right);
@@ -1823,7 +1823,7 @@ delta_divide(PyObject *left, PyObject *right)
if (PyDelta_Check(left)) {
/* delta * ??? */
- if (PyInt_Check(right) || PyLong_Check(right))
+ if (_PyAnyInt_Check(right))
result = divide_timedelta_int(
(PyDateTime_Delta *)left,
right);
@@ -1852,14 +1852,14 @@ accum(const char* tag, PyObject *sofar, PyObject *num, PyObject *factor,
assert(num != NULL);
- if (PyInt_Check(num) || PyLong_Check(num)) {
+ if (_PyAnyInt_Check(num)) {
prod = PyNumber_Multiply(factor, num);
if (prod == NULL)
return NULL;
- assert(PyInt_CheckExact(prod) || PyLong_CheckExact(prod));
+ assert(_PyAnyInt_CheckExact(prod));
sum = PyNumber_Add(sofar, prod);
Py_DECREF(prod);
- assert(sum == NULL || PyInt_CheckExact(sum) || PyLong_CheckExact(sum));
+ assert(sum == NULL || _PyAnyInt_CheckExact(sum));
return sum;
}
@@ -1902,7 +1902,7 @@ accum(const char* tag, PyObject *sofar, PyObject *num, PyObject *factor,
* fractional part requires float arithmetic, and may
* lose a little info.
*/
- assert(PyInt_CheckExact(factor) || PyLong_CheckExact(factor));
+ assert(_PyAnyInt_CheckExact(factor));
if (PyInt_Check(factor))
dnum = (double)PyInt_AsLong(factor);
else
@@ -1920,7 +1920,7 @@ accum(const char* tag, PyObject *sofar, PyObject *num, PyObject *factor,
Py_DECREF(sum);
Py_DECREF(x);
*leftover += fracpart;
- assert(y == NULL || PyInt_CheckExact(y) || PyLong_CheckExact(y));
+ assert(y == NULL || _PyAnyInt_CheckExact(y));
return y;
}
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
index 7a6686e3a6..3f15048700 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -107,7 +107,7 @@ dl_call(dlobject *xp, PyObject *args)
}
for (i = 1; i < n; i++) {
PyObject *v = PyTuple_GetItem(args, i);
- if (PyInt_Check(v) || PyLong_Check(v)) {
+ if (_PyAnyInt_Check(v)) {
alist[i-1] = PyInt_AsLong(v);
if (alist[i-1] == -1 && PyErr_Occurred())
return NULL;
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 01ed36b213..67354a7594 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1188,7 +1188,7 @@ math_ldexp(PyObject *self, PyObject *args)
if (! PyArg_ParseTuple(args, "dO:ldexp", &x, &oexp))
return NULL;
- if (PyLong_Check(oexp) || PyInt_Check(oexp)) {
+ if (_PyAnyInt_Check(oexp)) {
/* on overflow, replace exponent with either LONG_MAX
or LONG_MIN, depending on the sign. */
exp = PyLong_AsLongAndOverflow(oexp, &overflow);
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 2baf9202c3..7a1a6945c1 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6121,7 +6121,7 @@ posix_setgroups(PyObject *self, PyObject *groups)
elem = PySequence_GetItem(groups, i);
if (!elem)
return NULL;
- if (!PyInt_Check(elem) && !PyLong_Check(elem)) {
+ if (!_PyAnyInt_Check(elem)) {
PyErr_SetString(PyExc_TypeError,
"groups must be integers");
Py_DECREF(elem);
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 8d3670529e..634c1b9077 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -4194,7 +4194,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
"getaddrinfo() argument 1 must be string or None");
return NULL;
}
- if (PyInt_Check(pobj) || PyLong_Check(pobj)) {
+ if (_PyAnyInt_Check(pobj)) {
long value = PyLong_AsLong(pobj);
if (value == -1 && PyErr_Occurred())
return NULL;
diff --git a/Modules/svmodule.c b/Modules/svmodule.c
index 42c49c853a..14f236cb16 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) && !PyLong_Check(cell)) {
+ if (!_PyAnyInt_Check(cell)) {
PyErr_BadArgument();
goto finally;
}
@@ -757,7 +757,7 @@ doParams(svobject *self, PyObject *args,
if (!v)
goto finally;
- if (!PyInt_Check(v) && !PyLong_Check(v)) {
+ if (!_PyAnyInt_Check(v)) {
PyErr_BadArgument();
goto finally;
}
diff --git a/Modules/termios.c b/Modules/termios.c
index 9d4d780dca..e26e714e0e 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -185,7 +185,7 @@ 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) || PyLong_Check(v)) {
+ else if (_PyAnyInt_Check(v)) {
mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
if (mode.c_cc[i] == (cc_t) -1 && PyErr_Occurred())
return NULL;