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

Serhiy Storchaka webhook-mailer at python.org
Tue Jul 31 02:09:39 EDT 2018


https://github.com/python/cpython/commit/48c8bf21f97aeb124dbd48bf2bdec1ab4ebc5202
commit: 48c8bf21f97aeb124dbd48bf2bdec1ab4ebc5202
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-07-31T09:09:36+03:00
summary:

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

files:
M Include/intobject.h
M Modules/_csv.c
M Modules/_ctypes/_ctypes.c
M Modules/_ctypes/cfield.c
M Modules/_cursesmodule.c
M Modules/_elementtree.c
M Modules/_json.c
M Modules/_randommodule.c
M Modules/_sqlite/statement.c
M Modules/_sre.c
M Modules/_struct.c
M Modules/_tkinter.c
M Modules/cjkcodecs/multibytecodec.c
M Modules/datetimemodule.c
M Modules/dlmodule.c
M Modules/mathmodule.c
M Modules/posixmodule.c
M Modules/socketmodule.c
M Modules/svmodule.c
M Modules/termios.c
M Objects/abstract.c
M Objects/bytearrayobject.c
M Objects/classobject.c
M Objects/codeobject.c
M Objects/complexobject.c
M Objects/enumobject.c
M Objects/floatobject.c
M Objects/sliceobject.c
M Objects/stringobject.c
M Objects/unicodeobject.c
M PC/_winreg.c
M Parser/asdl_c.py
M Python/Python-ast.c
M Python/bltinmodule.c
M Python/ceval.c
M Python/pythonrun.c

diff --git a/Include/intobject.h b/Include/intobject.h
index 59d061629e25..d1985748b3e3 100644
--- a/Include/intobject.h
+++ b/Include/intobject.h
@@ -31,6 +31,9 @@ PyAPI_DATA(PyTypeObject) PyInt_Type;
 		 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS)
 #define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)
 
+#define _PyAnyInt_Check(op) (PyInt_Check(op) || PyLong_Check(op))
+#define _PyAnyInt_CheckExact(op) (PyInt_CheckExact(op) || PyLong_CheckExact(op))
+
 PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
 #ifdef Py_USING_UNICODE
 PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
diff --git a/Modules/_csv.c b/Modules/_csv.c
index c39c0f10c3cc..ea7d08931c45 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 25740ed77121..fabbdf13e940 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 6f632d0a0728..46f041b00e39 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 935712a0bed7..0ec4ee1244f6 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 1d316a1c91d2..f7f992dd3a95 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 39ec467b093e..28c0b3f4570e 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 2e49db6ef737..2c0daef71f79 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 5d6263c8e66c..ec60095ab8c4 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 efef8f508f3d..081a1aa0053f 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 d83d57f2e8fa..8b97672070ac 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 444c268c0b47..c71ffd016ad8 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 8901b42e41e8..4b482bf9e251 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 e818c5cfdc4d..c0b7102de234 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 7a6686e3a6df..3f150487007c 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 01ed36b2137d..67354a759498 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 2baf9202c303..7a1a6945c102 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 8d3670529e85..634c1b90778b 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 42c49c853a00..14f236cb1620 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 9d4d780dca27..e26e714e0ec1 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;
diff --git a/Objects/abstract.c b/Objects/abstract.c
index aa92ea9156d3..75c1a1047357 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1492,14 +1492,13 @@ PyNumber_Index(PyObject *item)
     PyObject *result = NULL;
     if (item == NULL)
         return null_error();
-    if (PyInt_Check(item) || PyLong_Check(item)) {
+    if (_PyAnyInt_Check(item)) {
         Py_INCREF(item);
         return item;
     }
     if (PyIndex_Check(item)) {
         result = item->ob_type->tp_as_number->nb_index(item);
-        if (result &&
-            !PyInt_Check(result) && !PyLong_Check(result)) {
+        if (result && !_PyAnyInt_Check(result)) {
             PyErr_Format(PyExc_TypeError,
                          "__index__ returned non-(int,long) " \
                          "(type %.200s)",
@@ -1574,8 +1573,7 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
             return NULL;
     }
 
-    if (integral && (!PyInt_Check(integral) &&
-                     !PyLong_Check(integral))) {
+    if (integral && !_PyAnyInt_Check(integral)) {
         /* Don't go through tp_as_number->nb_int to avoid
            hitting the classic class fallback to __trunc__. */
         PyObject *int_func = PyObject_GetAttr(integral, int_name);
@@ -1586,8 +1584,7 @@ _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
         Py_DECREF(integral);
         integral = PyEval_CallObject(int_func, NULL);
         Py_DECREF(int_func);
-        if (integral && (!PyInt_Check(integral) &&
-                          !PyLong_Check(integral))) {
+        if (integral && !_PyAnyInt_Check(integral)) {
             goto non_integral_error;
         }
     }
@@ -1632,7 +1629,7 @@ PyNumber_Int(PyObject *o)
     if (m && m->nb_int) { /* This should include subclasses of int */
         /* Classic classes always take this branch. */
         PyObject *res = m->nb_int(o);
-        if (res && (!PyInt_Check(res) && !PyLong_Check(res))) {
+        if (res && !_PyAnyInt_Check(res)) {
             PyErr_Format(PyExc_TypeError,
                          "__int__ returned non-int (type %.200s)",
                          res->ob_type->tp_name);
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 04c25061ef52..c178d9ef65d4 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -35,7 +35,7 @@ _getbytevalue(PyObject* arg, int *value)
         *value = Py_CHARMASK(((PyBytesObject*)arg)->ob_sval[0]);
         return 1;
     }
-    else if (PyInt_Check(arg) || PyLong_Check(arg)) {
+    else if (_PyAnyInt_Check(arg)) {
         face_value = PyLong_AsLong(arg);
     }
     else {
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 5b645787cbf6..02d7cfd019b9 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1009,7 +1009,7 @@ instance_hash(PyInstanceObject *inst)
     Py_DECREF(func);
     if (res == NULL)
         return -1;
-    if (PyInt_Check(res) || PyLong_Check(res))
+    if (_PyAnyInt_Check(res))
         /* This already converts a -1 result to -2. */
         outcome = Py_TYPE(res)->tp_hash(res);
     else {
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index a66aa6905a92..d50e4c61f088 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -423,10 +423,9 @@ _PyCode_ConstantKey(PyObject *op)
 
     /* Py_None is a singleton */
     if (op == Py_None
-       || PyInt_CheckExact(op)
-       || PyLong_CheckExact(op)
-       || PyBool_Check(op)
-       || PyBytes_CheckExact(op)
+        || _PyAnyInt_CheckExact(op)
+        || PyBool_Check(op)
+        || PyBytes_CheckExact(op)
 #ifdef Py_USING_UNICODE
        || PyUnicode_CheckExact(op)
 #endif
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index aaefa2dcda8a..871eea319f4c 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -796,7 +796,7 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
          * NotImplemented.  Only comparisons with core numeric types raise
          * TypeError.
          */
-        if (PyInt_Check(w) || PyLong_Check(w) ||
+        if (_PyAnyInt_Check(w) ||
             PyFloat_Check(w) || PyComplex_Check(w)) {
             PyErr_SetString(PyExc_TypeError,
                             "no ordering relation is defined "
@@ -809,7 +809,7 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
     assert(PyComplex_Check(v));
     TO_COMPLEX(v, i);
 
-    if (PyInt_Check(w) || PyLong_Check(w)) {
+    if (_PyAnyInt_Check(w)) {
         /* Check for 0.0 imaginary part first to avoid the rich
          * comparison when possible.
          */
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 8f86a5b8de39..73b656b8e08b 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -31,7 +31,7 @@ enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
             Py_DECREF(en);
             return NULL;
         }
-        assert(PyInt_Check(start) || PyLong_Check(start));
+        assert(_PyAnyInt_Check(start));
         en->en_index = PyInt_AsSsize_t(start);
         if (en->en_index == -1 && PyErr_Occurred()) {
             PyErr_Clear();
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 37dd67e66938..5954d39cdb33 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -428,7 +428,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
         j = PyFloat_AS_DOUBLE(w);
 
     else if (!Py_IS_FINITE(i)) {
-        if (PyInt_Check(w) || PyLong_Check(w))
+        if (_PyAnyInt_Check(w))
             /* If i is an infinity, its magnitude exceeds any
              * finite integer, so it doesn't matter which int we
              * compare i with.  If i is a NaN, similarly.
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 9daeafcc4a18..dc1821157375 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -107,20 +107,20 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
     if (r->step == Py_None) {
         *step = 1;
     } else {
-        if (!PyInt_Check(r->step) && !PyLong_Check(r->step)) return -1;
+        if (!_PyAnyInt_Check(r->step)) return -1;
         *step = PyInt_AsSsize_t(r->step);
     }
     if (r->start == Py_None) {
         *start = *step < 0 ? length-1 : 0;
     } else {
-        if (!PyInt_Check(r->start) && !PyLong_Check(r->start)) return -1;
+        if (!_PyAnyInt_Check(r->start)) return -1;
         *start = PyInt_AsSsize_t(r->start);
         if (*start < 0) *start += length;
     }
     if (r->stop == Py_None) {
         *stop = *step < 0 ? -1 : length;
     } else {
-        if (!PyInt_Check(r->stop) && !PyLong_Check(r->stop)) return -1;
+        if (!_PyAnyInt_Check(r->stop)) return -1;
         *stop = PyInt_AsSsize_t(r->stop);
         if (*stop < 0) *stop += length;
     }
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 59d22e76946b..b21afb4424d1 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -4504,7 +4504,7 @@ PyString_Format(PyObject *format, PyObject *args)
                 if (PyNumber_Check(v)) {
                     PyObject *iobj=NULL;
 
-                    if (PyInt_Check(v) || (PyLong_Check(v))) {
+                    if (_PyAnyInt_Check(v)) {
                         iobj = v;
                         Py_INCREF(iobj);
                     }
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index d011f7d50c2b..8bf04df2c86c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8628,7 +8628,7 @@ PyObject *PyUnicode_Format(PyObject *format,
                 if (PyNumber_Check(v)) {
                     PyObject *iobj=NULL;
 
-                    if (PyInt_Check(v) || (PyLong_Check(v))) {
+                    if (_PyAnyInt_Check(v)) {
                         iobj = v;
                         Py_INCREF(iobj);
                     }
diff --git a/PC/_winreg.c b/PC/_winreg.c
index e139cce85f82..f0f8df33107b 100644
--- a/PC/_winreg.c
+++ b/PC/_winreg.c
@@ -641,7 +641,7 @@ PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
         PyHKEYObject *pH = (PyHKEYObject *)ob;
         *pHANDLE = pH->hkey;
     }
-    else if (PyInt_Check(ob) || PyLong_Check(ob)) {
+    else if (_PyAnyInt_Check(ob)) {
         /* We also support integers */
         PyErr_Clear();
         *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
@@ -753,8 +753,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
     Py_ssize_t i,j;
     switch (typ) {
         case REG_DWORD:
-            if (value != Py_None &&
-                !(PyInt_Check(value) || PyLong_Check(value)))
+            if (value != Py_None && !_PyAnyInt_Check(value))
                 return FALSE;
             *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
             if (*retDataBuf==NULL){
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 08353a9e7f5d..ac61c78afc4a 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -830,7 +830,7 @@ def visitModule(self, mod):
 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
 {
     int i;
-    if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+    if (!_PyAnyInt_Check(obj)) {
         PyObject *s = PyObject_Repr(obj);
         if (s == NULL) return 1;
         PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 4ac5cf578fb7..2e7a1afbbc27 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -617,7 +617,7 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
 {
     int i;
-    if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+    if (!_PyAnyInt_Check(obj)) {
         PyObject *s = PyObject_Repr(obj);
         if (s == NULL) return 1;
         PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 9ce3b275eab2..f19115d2cb3f 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1780,7 +1780,7 @@ get_range_long_argument(PyObject *arg, const char *name)
 {
     PyObject *v;
     PyNumberMethods *nb;
-    if (PyInt_Check(arg) || PyLong_Check(arg)) {
+    if (_PyAnyInt_Check(arg)) {
         Py_INCREF(arg);
         return arg;
     }
@@ -1795,7 +1795,7 @@ get_range_long_argument(PyObject *arg, const char *name)
     v = nb->nb_int(arg);
     if (v == NULL)
         return NULL;
-    if (PyInt_Check(v) || PyLong_Check(v))
+    if (_PyAnyInt_Check(v))
         return v;
     Py_DECREF(v);
     PyErr_SetString(PyExc_TypeError,
diff --git a/Python/ceval.c b/Python/ceval.c
index b55b4d66880c..2088a271d86e 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4750,8 +4750,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi)
 
 
 #undef ISINDEX
-#define ISINDEX(x) ((x) == NULL || \
-                    PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x))
+#define ISINDEX(x) ((x) == NULL || _PyAnyInt_Check(x) || PyIndex_Check(x))
 
 static PyObject *
 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index c33b6c00efbb..5707c9f52452 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1136,7 +1136,7 @@ handle_system_exit(void)
         /* If we failed to dig out the 'code' attribute,
            just let the else clause below print the error. */
     }
-    if (PyInt_Check(value) || PyLong_Check(value))
+    if (_PyAnyInt_Check(value))
         exitcode = (int)PyInt_AsLong(value);
     else {
         PyObject *sys_stderr = PySys_GetObject("stderr");



More information about the Python-checkins mailing list