Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1a0d11

Browse files
committed
#1316: remove redundant PyLong_Check calls when PyInt_Check was already called.
1 parent 083bea4 commit e1a0d11

7 files changed

Lines changed: 24 additions & 31 deletions

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static PyObject *
236236
CDataType_from_address(PyObject *type, PyObject *value)
237237
{
238238
void *buf;
239-
if (!PyInt_Check(value) && !PyLong_Check(value)) {
239+
if (!PyInt_Check(value)) {
240240
PyErr_SetString(PyExc_TypeError,
241241
"integer expected");
242242
return NULL;
@@ -265,7 +265,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
265265
obj = PyObject_GetAttrString(dll, "_handle");
266266
if (!obj)
267267
return NULL;
268-
if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
268+
if (!PyInt_Check(obj)) {
269269
PyErr_SetString(PyExc_TypeError,
270270
"the _handle attribute of the second argument must be an integer");
271271
Py_DECREF(obj);
@@ -1233,7 +1233,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
12331233
}
12341234
/* Should probably allow buffer interface as well */
12351235
/* int, long */
1236-
if (PyInt_Check(value) || PyLong_Check(value)) {
1236+
if (PyInt_Check(value)) {
12371237
PyCArgObject *parg;
12381238
struct fielddesc *fd = getentry("P");
12391239

@@ -2697,7 +2697,7 @@ static int
26972697
_get_name(PyObject *obj, char **pname)
26982698
{
26992699
#ifdef MS_WIN32
2700-
if (PyInt_Check(obj) || PyLong_Check(obj)) {
2700+
if (PyInt_Check(obj)) {
27012701
/* We have to use MAKEINTRESOURCEA for Windows CE.
27022702
Works on Windows as well, of course.
27032703
*/
@@ -2734,7 +2734,7 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
27342734
obj = PyObject_GetAttrString(dll, "_handle");
27352735
if (!obj)
27362736
return NULL;
2737-
if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
2737+
if (!PyInt_Check(obj)) {
27382738
PyErr_SetString(PyExc_TypeError,
27392739
"the _handle attribute of the second argument must be an integer");
27402740
Py_DECREF(obj);
@@ -2859,8 +2859,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
28592859
#endif
28602860

28612861
if (1 == PyTuple_GET_SIZE(args)
2862-
&& (PyInt_Check(PyTuple_GET_ITEM(args, 0))
2863-
|| PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
2862+
&& (PyInt_Check(PyTuple_GET_ITEM(args, 0)))) {
28642863
CDataObject *ob;
28652864
void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0));
28662865
if (ptr == NULL)

Modules/_ctypes/cfield.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static int
329329
get_long(PyObject *v, long *p)
330330
{
331331
long x;
332-
if (!PyInt_Check(v) && !PyLong_Check(v)) {
332+
if (!PyInt_Check(v)) {
333333
PyErr_Format(PyExc_TypeError,
334334
"int expected instead of %s instance",
335335
v->ob_type->tp_name);
@@ -348,7 +348,7 @@ static int
348348
get_ulong(PyObject *v, unsigned long *p)
349349
{
350350
unsigned long x;
351-
if (!PyInt_Check(v) && !PyLong_Check(v)) {
351+
if (!PyInt_Check(v)) {
352352
PyErr_Format(PyExc_TypeError,
353353
"int expected instead of %s instance",
354354
v->ob_type->tp_name);
@@ -369,7 +369,7 @@ static int
369369
get_longlong(PyObject *v, PY_LONG_LONG *p)
370370
{
371371
PY_LONG_LONG x;
372-
if (!PyInt_Check(v) && !PyLong_Check(v)) {
372+
if (!PyInt_Check(v)) {
373373
PyErr_Format(PyExc_TypeError,
374374
"int expected instead of %s instance",
375375
v->ob_type->tp_name);
@@ -388,7 +388,7 @@ static int
388388
get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
389389
{
390390
unsigned PY_LONG_LONG x;
391-
if (!PyInt_Check(v) && !PyLong_Check(v)) {
391+
if (!PyInt_Check(v)) {
392392
PyErr_Format(PyExc_TypeError,
393393
"int expected instead of %s instance",
394394
v->ob_type->tp_name);
@@ -1373,7 +1373,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
13731373
assert(PyBytes_Check(str));
13741374
*(char **)ptr = PyBytes_AS_STRING(str);
13751375
return str;
1376-
} else if (PyInt_Check(value) || PyLong_Check(value)) {
1376+
} else if (PyInt_Check(value)) {
13771377
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
13781378
*(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value);
13791379
#else

Modules/_sqlite/row.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
7676

7777
PyObject* item;
7878

79-
if (PyInt_Check(idx)) {
80-
_idx = PyInt_AsLong(idx);
81-
item = PyTuple_GetItem(self->data, _idx);
82-
Py_XINCREF(item);
83-
return item;
84-
} else if (PyLong_Check(idx)) {
79+
if (PyLong_Check(idx)) {
8580
_idx = PyLong_AsLong(idx);
8681
item = PyTuple_GetItem(self->data, _idx);
8782
Py_XINCREF(item);

Modules/_sqlite/statement.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
8080
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
8181
{
8282
int rc = SQLITE_OK;
83-
long longval;
8483
#ifdef HAVE_LONG_LONG
8584
PY_LONG_LONG longlongval;
85+
#else
86+
long longval;
8687
#endif
8788
const char* buffer;
8889
char* string;
@@ -91,14 +92,16 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
9192

9293
if (parameter == Py_None) {
9394
rc = sqlite3_bind_null(self->st, pos);
94-
} else if (PyInt_CheckExact(parameter)) {
95-
longval = PyInt_AsLong(parameter);
96-
rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
9795
#ifdef HAVE_LONG_LONG
9896
} else if (PyLong_Check(parameter)) {
9997
longlongval = PyLong_AsLongLong(parameter);
10098
/* in the overflow error case, longlongval is -1, and an exception is set */
10199
rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval);
100+
#else
101+
} else if (PyLong_Check(parameter)) {
102+
longval = PyLong_AsLong(parameter);
103+
/* in the overflow error case, longval is -1, and an exception is set */
104+
rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
102105
#endif
103106
} else if (PyFloat_Check(parameter)) {
104107
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));

Modules/cjkcodecs/multibytecodec.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
313313

314314
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
315315
!PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) ||
316-
!(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) ||
317-
PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
316+
!PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
318317
PyErr_SetString(PyExc_TypeError,
319318
"encoding error handler must return "
320319
"(unicode, int) tuple");
@@ -433,8 +432,7 @@ multibytecodec_decerror(MultibyteCodec *codec,
433432

434433
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
435434
!PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0))) ||
436-
!(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) ||
437-
PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
435+
!PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
438436
PyErr_SetString(PyExc_TypeError,
439437
"decoding error handler must return "
440438
"(unicode, int) tuple");

Objects/sliceobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
112112
if (r->start == Py_None) {
113113
*start = *step < 0 ? length-1 : 0;
114114
} else {
115-
if (!PyInt_Check(r->start) && !PyLong_Check(r->step)) return -1;
115+
if (!PyInt_Check(r->start)) return -1;
116116
*start = PyInt_AsSsize_t(r->start);
117117
if (*start < 0) *start += length;
118118
}
119119
if (r->stop == Py_None) {
120120
*stop = *step < 0 ? -1 : length;
121121
} else {
122-
if (!PyInt_Check(r->stop) && !PyLong_Check(r->step)) return -1;
122+
if (!PyInt_Check(r->stop)) return -1;
123123
*stop = PyInt_AsSsize_t(r->stop);
124124
if (*stop < 0) *stop += length;
125125
}

Python/getargs.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
696696
case 'k': { /* long sized bitfield */
697697
unsigned long *p = va_arg(*p_va, unsigned long *);
698698
unsigned long ival;
699-
if (PyInt_Check(arg))
700-
ival = PyInt_AsUnsignedLongMask(arg);
701-
else if (PyLong_Check(arg))
699+
if (PyLong_Check(arg))
702700
ival = PyLong_AsUnsignedLongMask(arg);
703701
else
704702
return converterr("integer<k>", arg, msgbuf, bufsize);

0 commit comments

Comments
 (0)