Skip to content

Commit 48c8bf2

Browse files
[2.7] bpo-34234: Use _PyAnyInt_Check() and _PyAnyInt_CheckExact(). (GH-8479)
1 parent dc9039d commit 48c8bf2

36 files changed

Lines changed: 75 additions & 81 deletions

Include/intobject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ PyAPI_DATA(PyTypeObject) PyInt_Type;
3131
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS)
3232
#define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)
3333

34+
#define _PyAnyInt_Check(op) (PyInt_Check(op) || PyLong_Check(op))
35+
#define _PyAnyInt_CheckExact(op) (PyInt_CheckExact(op) || PyLong_CheckExact(op))
36+
3437
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
3538
#ifdef Py_USING_UNICODE
3639
PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);

Modules/_csv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ _set_int(const char *name, int *target, PyObject *src, int dflt)
224224
if (src == NULL)
225225
*target = dflt;
226226
else {
227-
if (!PyInt_Check(src) && !PyLong_Check(src)) {
227+
if (!_PyAnyInt_Check(src)) {
228228
PyErr_Format(PyExc_TypeError,
229229
"\"%s\" must be an integer", name);
230230
return -1;
@@ -1452,7 +1452,7 @@ csv_field_size_limit(PyObject *module, PyObject *args)
14521452
if (!PyArg_UnpackTuple(args, "field_size_limit", 0, 1, &new_limit))
14531453
return NULL;
14541454
if (new_limit != NULL) {
1455-
if (!PyInt_Check(new_limit) && !PyLong_Check(new_limit)) {
1455+
if (!_PyAnyInt_Check(new_limit)) {
14561456
PyErr_Format(PyExc_TypeError,
14571457
"limit must be an integer");
14581458
return NULL;

Modules/_ctypes/_ctypes.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static PyObject *
547547
CDataType_from_address(PyObject *type, PyObject *value)
548548
{
549549
void *buf;
550-
if (!PyInt_Check(value) && !PyLong_Check(value)) {
550+
if (!_PyAnyInt_Check(value)) {
551551
PyErr_SetString(PyExc_TypeError,
552552
"integer expected");
553553
return NULL;
@@ -691,7 +691,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
691691
obj = PyObject_GetAttrString(dll, "_handle");
692692
if (!obj)
693693
return NULL;
694-
if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
694+
if (!_PyAnyInt_Check(obj)) {
695695
PyErr_SetString(PyExc_TypeError,
696696
"the _handle attribute of the second argument must be an integer");
697697
Py_DECREF(obj);
@@ -1779,7 +1779,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
17791779
}
17801780
/* Should probably allow buffer interface as well */
17811781
/* int, long */
1782-
if (PyInt_Check(value) || PyLong_Check(value)) {
1782+
if (_PyAnyInt_Check(value)) {
17831783
PyCArgObject *parg;
17841784
struct fielddesc *fd = _ctypes_get_fielddesc("P");
17851785

@@ -3419,7 +3419,7 @@ static int
34193419
_get_name(PyObject *obj, char **pname)
34203420
{
34213421
#ifdef MS_WIN32
3422-
if (PyInt_Check(obj) || PyLong_Check(obj)) {
3422+
if (_PyAnyInt_Check(obj)) {
34233423
/* We have to use MAKEINTRESOURCEA for Windows CE.
34243424
Works on Windows as well, of course.
34253425
*/
@@ -3469,7 +3469,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
34693469
Py_DECREF(ftuple);
34703470
return NULL;
34713471
}
3472-
if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
3472+
if (!_PyAnyInt_Check(obj)) {
34733473
PyErr_SetString(PyExc_TypeError,
34743474
"the _handle attribute of the second argument must be an integer");
34753475
Py_DECREF(ftuple);
@@ -3600,8 +3600,7 @@ PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
36003600
#endif
36013601

36023602
if (1 == PyTuple_GET_SIZE(args)
3603-
&& (PyInt_Check(PyTuple_GET_ITEM(args, 0))
3604-
|| PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
3603+
&& _PyAnyInt_Check(PyTuple_GET_ITEM(args, 0))) {
36053604
CDataObject *ob;
36063605
void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0));
36073606
if (ptr == NULL && PyErr_Occurred())

Modules/_ctypes/cfield.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
13611361
return NULL;
13621362
*(char **)ptr = PyString_AS_STRING(str);
13631363
return str;
1364-
} else if (PyInt_Check(value) || PyLong_Check(value)) {
1364+
} else if (_PyAnyInt_Check(value)) {
13651365
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
13661366
*(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value);
13671367
#else
@@ -1410,7 +1410,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
14101410
_ctypes_conversion_errors);
14111411
if (!value)
14121412
return NULL;
1413-
} else if (PyInt_Check(value) || PyLong_Check(value)) {
1413+
} else if (_PyAnyInt_Check(value)) {
14141414
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
14151415
*(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongLongMask(value);
14161416
#else
@@ -1565,7 +1565,7 @@ P_set(void *ptr, PyObject *value, Py_ssize_t size)
15651565
_RET(value);
15661566
}
15671567

1568-
if (!PyInt_Check(value) && !PyLong_Check(value)) {
1568+
if (!_PyAnyInt_Check(value)) {
15691569
PyErr_SetString(PyExc_TypeError,
15701570
"cannot be converted to pointer");
15711571
return NULL;

Modules/_cursesmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ PyCursesCheckERR(int code, char *fname)
194194
static int
195195
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
196196
{
197-
if (PyInt_Check(obj) || PyLong_Check(obj)) {
197+
if (_PyAnyInt_Check(obj)) {
198198
*ch = (chtype) PyInt_AsLong(obj);
199199
if (*ch == (chtype) -1 && PyErr_Occurred())
200200
return 0;
@@ -2603,7 +2603,7 @@ PyCurses_UnCtrl(PyObject *self, PyObject *args)
26032603

26042604
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
26052605

2606-
if (PyInt_Check(temp) || PyLong_Check(temp)) {
2606+
if (_PyAnyInt_Check(temp)) {
26072607
ch = (chtype) PyInt_AsLong(temp);
26082608
if (ch == (chtype) -1 && PyErr_Occurred())
26092609
return NULL;
@@ -2628,7 +2628,7 @@ PyCurses_UngetCh(PyObject *self, PyObject *args)
26282628

26292629
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
26302630

2631-
if (PyInt_Check(temp) || PyLong_Check(temp)) {
2631+
if (_PyAnyInt_Check(temp)) {
26322632
ch = (int) PyInt_AsLong(temp);
26332633
if (ch == -1 && PyErr_Occurred())
26342634
return NULL;

Modules/_elementtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ element_subscr(PyObject* self_, PyObject* item)
13471347
ElementObject* self = (ElementObject*) self_;
13481348

13491349
#if (PY_VERSION_HEX < 0x02050000)
1350-
if (PyInt_Check(item) || PyLong_Check(item)) {
1350+
if (_PyAnyInt_Check(item)) {
13511351
long i = PyInt_AsLong(item);
13521352
#else
13531353
if (PyIndex_Check(item)) {
@@ -1404,7 +1404,7 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
14041404
ElementObject* self = (ElementObject*) self_;
14051405

14061406
#if (PY_VERSION_HEX < 0x02050000)
1407-
if (PyInt_Check(item) || PyLong_Check(item)) {
1407+
if (_PyAnyInt_Check(item)) {
14081408
long i = PyInt_AsLong(item);
14091409
#else
14101410
if (PyIndex_Check(item)) {

Modules/_json.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssi
19811981
return -1;
19821982
return _steal_list_append(rval, encoded);
19831983
}
1984-
else if (PyInt_Check(obj) || PyLong_Check(obj)) {
1984+
else if (_PyAnyInt_Check(obj)) {
19851985
PyObject *encoded = PyObject_Str(obj);
19861986
if (encoded == NULL)
19871987
return -1;
@@ -2131,7 +2131,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
21312131
if (kstr == NULL)
21322132
goto bail;
21332133
}
2134-
else if (PyInt_Check(key) || PyLong_Check(key)) {
2134+
else if (_PyAnyInt_Check(key)) {
21352135
kstr = PyObject_Str(key);
21362136
if (kstr == NULL)
21372137
goto bail;

Modules/_randommodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ random_jumpahead(RandomObject *self, PyObject *n)
415415
PyObject *remobj;
416416
unsigned long *mt, tmp, nonzero;
417417

418-
if (!PyInt_Check(n) && !PyLong_Check(n)) {
418+
if (!_PyAnyInt_Check(n)) {
419419
PyErr_Format(PyExc_TypeError, "jumpahead requires an "
420420
"integer, not '%s'",
421421
Py_TYPE(n)->tp_name);

Modules/_sqlite/statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int _need_adapt(PyObject* obj)
205205
return 1;
206206
}
207207

208-
if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
208+
if (_PyAnyInt_CheckExact(obj)
209209
|| PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
210210
|| PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
211211
return 0;

Modules/_sre.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,15 +3327,15 @@ match_getindex(MatchObject* self, PyObject* index)
33273327
{
33283328
Py_ssize_t i;
33293329

3330-
if (PyInt_Check(index) || PyLong_Check(index))
3330+
if (_PyAnyInt_Check(index))
33313331
return PyInt_AsSsize_t(index);
33323332

33333333
i = -1;
33343334

33353335
if (self->pattern->groupindex) {
33363336
index = PyObject_GetItem(self->pattern->groupindex, index);
33373337
if (index) {
3338-
if (PyInt_Check(index) || PyLong_Check(index))
3338+
if (_PyAnyInt_Check(index))
33393339
i = PyInt_AsSsize_t(index);
33403340
Py_DECREF(index);
33413341
} else

0 commit comments

Comments
 (0)