[2.7] bpo-34234: Use _PyAnyInt_Check() and _PyAnyInt_CheckExact(). (GH-8479)

diff --git a/Modules/_csv.c b/Modules/_csv.c
index c39c0f1..ea7d089 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -224,7 +224,7 @@
     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 @@
     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 25740ed..fabbdf1 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -547,7 +547,7 @@
 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 @@
     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 @@
     }
     /* 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 @@
 _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 @@
         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 @@
 #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 6f632d0..46f041b 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1361,7 +1361,7 @@
             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 @@
                                             _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 @@
         _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 935712a..0ec4ee1 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -194,7 +194,7 @@
 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 @@
 
     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 @@
 
     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 1d316a1..f7f992d 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1347,7 +1347,7 @@
     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 @@
     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 39ec467..28c0b3f 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1981,7 +1981,7 @@
             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 @@
             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 2e49db6..2c0daef 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -415,7 +415,7 @@
     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 5d6263c..ec60095 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -205,7 +205,7 @@
         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 efef8f5..081a1aa 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -3327,7 +3327,7 @@
 {
     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 @@
     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 d83d57f..8b97672 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -110,7 +110,7 @@
     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 @@
             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 @@
         /* 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 444c268..c71ffd0 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -2107,7 +2107,7 @@
 
     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 8901b42..4b482bf 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -310,8 +310,7 @@
 
     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 @@
 
     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 e818c5c..c0b7102 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1537,7 +1537,7 @@
     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 @@
     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 @@
 
     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 @@
 
     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 @@
 
     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 @@
          * 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 @@
         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 7a6686e..3f15048 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -107,7 +107,7 @@
     }
     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 01ed36b..67354a7 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1188,7 +1188,7 @@
     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 2baf920..7a1a694 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6121,7 +6121,7 @@
         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 8d36705..634c1b9 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -4194,7 +4194,7 @@
                         "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 42c49c8..14f236c 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -686,7 +686,7 @@
             if (!cell)
                 goto finally;
 
-            if (!PyInt_Check(cell) && !PyLong_Check(cell)) {
+            if (!_PyAnyInt_Check(cell)) {
                 PyErr_BadArgument();
                 goto finally;
             }
@@ -757,7 +757,7 @@
         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 9d4d780..e26e714 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -185,7 +185,7 @@
 
         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;