Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Include/intobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_randommodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -3327,15 +3327,15 @@ 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;

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
Expand Down
6 changes: 3 additions & 3 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
20 changes: 10 additions & 10 deletions Modules/datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/dlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Modules/svmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading