Kaydet (Commit) e1a0d11c authored tarafından Georg Brandl's avatar Georg Brandl

#1316: remove redundant PyLong_Check calls when PyInt_Check was already called.

üst 083bea49
...@@ -236,7 +236,7 @@ static PyObject * ...@@ -236,7 +236,7 @@ static PyObject *
CDataType_from_address(PyObject *type, PyObject *value) CDataType_from_address(PyObject *type, PyObject *value)
{ {
void *buf; void *buf;
if (!PyInt_Check(value) && !PyLong_Check(value)) { if (!PyInt_Check(value)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"integer expected"); "integer expected");
return NULL; return NULL;
...@@ -265,7 +265,7 @@ CDataType_in_dll(PyObject *type, PyObject *args) ...@@ -265,7 +265,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
obj = PyObject_GetAttrString(dll, "_handle"); obj = PyObject_GetAttrString(dll, "_handle");
if (!obj) if (!obj)
return NULL; return NULL;
if (!PyInt_Check(obj) && !PyLong_Check(obj)) { if (!PyInt_Check(obj)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"the _handle attribute of the second argument must be an integer"); "the _handle attribute of the second argument must be an integer");
Py_DECREF(obj); Py_DECREF(obj);
...@@ -1233,7 +1233,7 @@ c_void_p_from_param(PyObject *type, PyObject *value) ...@@ -1233,7 +1233,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
} }
/* Should probably allow buffer interface as well */ /* Should probably allow buffer interface as well */
/* int, long */ /* int, long */
if (PyInt_Check(value) || PyLong_Check(value)) { if (PyInt_Check(value)) {
PyCArgObject *parg; PyCArgObject *parg;
struct fielddesc *fd = getentry("P"); struct fielddesc *fd = getentry("P");
...@@ -2697,7 +2697,7 @@ static int ...@@ -2697,7 +2697,7 @@ static int
_get_name(PyObject *obj, char **pname) _get_name(PyObject *obj, char **pname)
{ {
#ifdef MS_WIN32 #ifdef MS_WIN32
if (PyInt_Check(obj) || PyLong_Check(obj)) { if (PyInt_Check(obj)) {
/* We have to use MAKEINTRESOURCEA for Windows CE. /* We have to use MAKEINTRESOURCEA for Windows CE.
Works on Windows as well, of course. Works on Windows as well, of course.
*/ */
...@@ -2734,7 +2734,7 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -2734,7 +2734,7 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
obj = PyObject_GetAttrString(dll, "_handle"); obj = PyObject_GetAttrString(dll, "_handle");
if (!obj) if (!obj)
return NULL; return NULL;
if (!PyInt_Check(obj) && !PyLong_Check(obj)) { if (!PyInt_Check(obj)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"the _handle attribute of the second argument must be an integer"); "the _handle attribute of the second argument must be an integer");
Py_DECREF(obj); Py_DECREF(obj);
...@@ -2859,8 +2859,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -2859,8 +2859,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
#endif #endif
if (1 == PyTuple_GET_SIZE(args) if (1 == PyTuple_GET_SIZE(args)
&& (PyInt_Check(PyTuple_GET_ITEM(args, 0)) && (PyInt_Check(PyTuple_GET_ITEM(args, 0)))) {
|| PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
CDataObject *ob; CDataObject *ob;
void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0)); void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0));
if (ptr == NULL) if (ptr == NULL)
......
...@@ -329,7 +329,7 @@ static int ...@@ -329,7 +329,7 @@ static int
get_long(PyObject *v, long *p) get_long(PyObject *v, long *p)
{ {
long x; long x;
if (!PyInt_Check(v) && !PyLong_Check(v)) { if (!PyInt_Check(v)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"int expected instead of %s instance", "int expected instead of %s instance",
v->ob_type->tp_name); v->ob_type->tp_name);
...@@ -348,7 +348,7 @@ static int ...@@ -348,7 +348,7 @@ static int
get_ulong(PyObject *v, unsigned long *p) get_ulong(PyObject *v, unsigned long *p)
{ {
unsigned long x; unsigned long x;
if (!PyInt_Check(v) && !PyLong_Check(v)) { if (!PyInt_Check(v)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"int expected instead of %s instance", "int expected instead of %s instance",
v->ob_type->tp_name); v->ob_type->tp_name);
...@@ -369,7 +369,7 @@ static int ...@@ -369,7 +369,7 @@ static int
get_longlong(PyObject *v, PY_LONG_LONG *p) get_longlong(PyObject *v, PY_LONG_LONG *p)
{ {
PY_LONG_LONG x; PY_LONG_LONG x;
if (!PyInt_Check(v) && !PyLong_Check(v)) { if (!PyInt_Check(v)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"int expected instead of %s instance", "int expected instead of %s instance",
v->ob_type->tp_name); v->ob_type->tp_name);
...@@ -388,7 +388,7 @@ static int ...@@ -388,7 +388,7 @@ static int
get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p) get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
{ {
unsigned PY_LONG_LONG x; unsigned PY_LONG_LONG x;
if (!PyInt_Check(v) && !PyLong_Check(v)) { if (!PyInt_Check(v)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"int expected instead of %s instance", "int expected instead of %s instance",
v->ob_type->tp_name); v->ob_type->tp_name);
...@@ -1373,7 +1373,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size) ...@@ -1373,7 +1373,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
assert(PyBytes_Check(str)); assert(PyBytes_Check(str));
*(char **)ptr = PyBytes_AS_STRING(str); *(char **)ptr = PyBytes_AS_STRING(str);
return str; return str;
} else if (PyInt_Check(value) || PyLong_Check(value)) { } else if (PyInt_Check(value)) {
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG #if SIZEOF_VOID_P == SIZEOF_LONG_LONG
*(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value); *(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value);
#else #else
......
...@@ -76,12 +76,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) ...@@ -76,12 +76,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
PyObject* item; PyObject* item;
if (PyInt_Check(idx)) { if (PyLong_Check(idx)) {
_idx = PyInt_AsLong(idx);
item = PyTuple_GetItem(self->data, _idx);
Py_XINCREF(item);
return item;
} else if (PyLong_Check(idx)) {
_idx = PyLong_AsLong(idx); _idx = PyLong_AsLong(idx);
item = PyTuple_GetItem(self->data, _idx); item = PyTuple_GetItem(self->data, _idx);
Py_XINCREF(item); Py_XINCREF(item);
......
...@@ -80,9 +80,10 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con ...@@ -80,9 +80,10 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter) int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
{ {
int rc = SQLITE_OK; int rc = SQLITE_OK;
long longval;
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
PY_LONG_LONG longlongval; PY_LONG_LONG longlongval;
#else
long longval;
#endif #endif
const char* buffer; const char* buffer;
char* string; char* string;
...@@ -91,14 +92,16 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec ...@@ -91,14 +92,16 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
if (parameter == Py_None) { if (parameter == Py_None) {
rc = sqlite3_bind_null(self->st, pos); rc = sqlite3_bind_null(self->st, pos);
} else if (PyInt_CheckExact(parameter)) {
longval = PyInt_AsLong(parameter);
rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
} else if (PyLong_Check(parameter)) { } else if (PyLong_Check(parameter)) {
longlongval = PyLong_AsLongLong(parameter); longlongval = PyLong_AsLongLong(parameter);
/* in the overflow error case, longlongval is -1, and an exception is set */ /* in the overflow error case, longlongval is -1, and an exception is set */
rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval); rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval);
#else
} else if (PyLong_Check(parameter)) {
longval = PyLong_AsLong(parameter);
/* in the overflow error case, longval is -1, and an exception is set */
rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
#endif #endif
} else if (PyFloat_Check(parameter)) { } else if (PyFloat_Check(parameter)) {
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
......
...@@ -313,8 +313,7 @@ multibytecodec_encerror(MultibyteCodec *codec, ...@@ -313,8 +313,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 || if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
!PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) || !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) ||
!(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) || !PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"encoding error handler must return " "encoding error handler must return "
"(unicode, int) tuple"); "(unicode, int) tuple");
...@@ -433,8 +432,7 @@ multibytecodec_decerror(MultibyteCodec *codec, ...@@ -433,8 +432,7 @@ multibytecodec_decerror(MultibyteCodec *codec,
if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 || if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 ||
!PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0))) || !PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0))) ||
!(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) || !PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"decoding error handler must return " "decoding error handler must return "
"(unicode, int) tuple"); "(unicode, int) tuple");
......
...@@ -112,14 +112,14 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length, ...@@ -112,14 +112,14 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
if (r->start == Py_None) { if (r->start == Py_None) {
*start = *step < 0 ? length-1 : 0; *start = *step < 0 ? length-1 : 0;
} else { } else {
if (!PyInt_Check(r->start) && !PyLong_Check(r->step)) return -1; if (!PyInt_Check(r->start)) return -1;
*start = PyInt_AsSsize_t(r->start); *start = PyInt_AsSsize_t(r->start);
if (*start < 0) *start += length; if (*start < 0) *start += length;
} }
if (r->stop == Py_None) { if (r->stop == Py_None) {
*stop = *step < 0 ? -1 : length; *stop = *step < 0 ? -1 : length;
} else { } else {
if (!PyInt_Check(r->stop) && !PyLong_Check(r->step)) return -1; if (!PyInt_Check(r->stop)) return -1;
*stop = PyInt_AsSsize_t(r->stop); *stop = PyInt_AsSsize_t(r->stop);
if (*stop < 0) *stop += length; if (*stop < 0) *stop += length;
} }
......
...@@ -696,9 +696,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, ...@@ -696,9 +696,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'k': { /* long sized bitfield */ case 'k': { /* long sized bitfield */
unsigned long *p = va_arg(*p_va, unsigned long *); unsigned long *p = va_arg(*p_va, unsigned long *);
unsigned long ival; unsigned long ival;
if (PyInt_Check(arg)) if (PyLong_Check(arg))
ival = PyInt_AsUnsignedLongMask(arg);
else if (PyLong_Check(arg))
ival = PyLong_AsUnsignedLongMask(arg); ival = PyLong_AsUnsignedLongMask(arg);
else else
return converterr("integer<k>", arg, msgbuf, bufsize); return converterr("integer<k>", arg, msgbuf, bufsize);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment