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

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);