[Python-3000-checkins] r58617 - in python/branches/py3k: Modules/_ctypes/_ctypes.c Modules/_ctypes/cfield.c Modules/_sqlite/row.c Modules/_sqlite/statement.c Modules/cjkcodecs/multibytecodec.c Objects/sliceobject.c Python/getargs.c

georg.brandl python-3000-checkins at python.org
Tue Oct 23 21:24:23 CEST 2007


Author: georg.brandl
Date: Tue Oct 23 21:24:22 2007
New Revision: 58617

Modified:
   python/branches/py3k/Modules/_ctypes/_ctypes.c
   python/branches/py3k/Modules/_ctypes/cfield.c
   python/branches/py3k/Modules/_sqlite/row.c
   python/branches/py3k/Modules/_sqlite/statement.c
   python/branches/py3k/Modules/cjkcodecs/multibytecodec.c
   python/branches/py3k/Objects/sliceobject.c
   python/branches/py3k/Python/getargs.c
Log:
#1316: remove redundant PyLong_Check calls when PyInt_Check was already called.


Modified: python/branches/py3k/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/py3k/Modules/_ctypes/_ctypes.c	Tue Oct 23 21:24:22 2007
@@ -236,7 +236,7 @@
 CDataType_from_address(PyObject *type, PyObject *value)
 {
 	void *buf;
-	if (!PyInt_Check(value) && !PyLong_Check(value)) {
+	if (!PyInt_Check(value)) {
 		PyErr_SetString(PyExc_TypeError,
 				"integer expected");
 		return NULL;
@@ -265,7 +265,7 @@
 	obj = PyObject_GetAttrString(dll, "_handle");
 	if (!obj)
 		return NULL;
-	if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+	if (!PyInt_Check(obj)) {
 		PyErr_SetString(PyExc_TypeError,
 				"the _handle attribute of the second argument must be an integer");
 		Py_DECREF(obj);
@@ -1233,7 +1233,7 @@
 	}
 	/* Should probably allow buffer interface as well */
 /* int, long */
-	if (PyInt_Check(value) || PyLong_Check(value)) {
+	if (PyInt_Check(value)) {
 		PyCArgObject *parg;
 		struct fielddesc *fd = getentry("P");
 
@@ -2697,7 +2697,7 @@
 _get_name(PyObject *obj, char **pname)
 {
 #ifdef MS_WIN32
-	if (PyInt_Check(obj) || PyLong_Check(obj)) {
+	if (PyInt_Check(obj)) {
 		/* We have to use MAKEINTRESOURCEA for Windows CE.
 		   Works on Windows as well, of course.
 		*/
@@ -2734,7 +2734,7 @@
 	obj = PyObject_GetAttrString(dll, "_handle");
 	if (!obj)
 		return NULL;
-	if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+	if (!PyInt_Check(obj)) {
 		PyErr_SetString(PyExc_TypeError,
 				"the _handle attribute of the second argument must be an integer");
 		Py_DECREF(obj);
@@ -2859,8 +2859,7 @@
 #endif
 
 	if (1 == PyTuple_GET_SIZE(args)
-	    && (PyInt_Check(PyTuple_GET_ITEM(args, 0))
-		|| PyLong_Check(PyTuple_GET_ITEM(args, 0)))) {
+	    && (PyInt_Check(PyTuple_GET_ITEM(args, 0)))) {
 		CDataObject *ob;
 		void *ptr = PyLong_AsVoidPtr(PyTuple_GET_ITEM(args, 0));
 		if (ptr == NULL)

Modified: python/branches/py3k/Modules/_ctypes/cfield.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/cfield.c	(original)
+++ python/branches/py3k/Modules/_ctypes/cfield.c	Tue Oct 23 21:24:22 2007
@@ -329,7 +329,7 @@
 get_long(PyObject *v, long *p)
 {
 	long x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
+	if (!PyInt_Check(v)) {
 		PyErr_Format(PyExc_TypeError,
 			     "int expected instead of %s instance",
 			     v->ob_type->tp_name);
@@ -348,7 +348,7 @@
 get_ulong(PyObject *v, unsigned long *p)
 {
 	unsigned long x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
+	if (!PyInt_Check(v)) {
 		PyErr_Format(PyExc_TypeError,
 			     "int expected instead of %s instance",
 			     v->ob_type->tp_name);
@@ -369,7 +369,7 @@
 get_longlong(PyObject *v, PY_LONG_LONG *p)
 {
 	PY_LONG_LONG x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
+	if (!PyInt_Check(v)) {
 		PyErr_Format(PyExc_TypeError,
 			     "int expected instead of %s instance",
 			     v->ob_type->tp_name);
@@ -388,7 +388,7 @@
 get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
 {
 	unsigned PY_LONG_LONG x;
-	if (!PyInt_Check(v) && !PyLong_Check(v)) {
+	if (!PyInt_Check(v)) {
 		PyErr_Format(PyExc_TypeError,
 			     "int expected instead of %s instance",
 			     v->ob_type->tp_name);
@@ -1373,7 +1373,7 @@
 		assert(PyBytes_Check(str));
 		*(char **)ptr = PyBytes_AS_STRING(str);
 		return str;
-	} else if (PyInt_Check(value) || PyLong_Check(value)) {
+	} else if (PyInt_Check(value)) {
 #if SIZEOF_VOID_P == SIZEOF_LONG_LONG
 		*(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value);
 #else

Modified: python/branches/py3k/Modules/_sqlite/row.c
==============================================================================
--- python/branches/py3k/Modules/_sqlite/row.c	(original)
+++ python/branches/py3k/Modules/_sqlite/row.c	Tue Oct 23 21:24:22 2007
@@ -76,12 +76,7 @@
 
     PyObject* item;
 
-    if (PyInt_Check(idx)) {
-        _idx = PyInt_AsLong(idx);
-        item = PyTuple_GetItem(self->data, _idx);
-        Py_XINCREF(item);
-        return item;
-    } else if (PyLong_Check(idx)) {
+    if (PyLong_Check(idx)) {
         _idx = PyLong_AsLong(idx);
         item = PyTuple_GetItem(self->data, _idx);
         Py_XINCREF(item);

Modified: python/branches/py3k/Modules/_sqlite/statement.c
==============================================================================
--- python/branches/py3k/Modules/_sqlite/statement.c	(original)
+++ python/branches/py3k/Modules/_sqlite/statement.c	Tue Oct 23 21:24:22 2007
@@ -80,9 +80,10 @@
 int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
 {
     int rc = SQLITE_OK;
-    long longval;
 #ifdef HAVE_LONG_LONG
     PY_LONG_LONG longlongval;
+#else
+    long longval;
 #endif
     const char* buffer;
     char* string;
@@ -91,14 +92,16 @@
 
     if (parameter == Py_None) {
         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
     } else if (PyLong_Check(parameter)) {
         longlongval = PyLong_AsLongLong(parameter);
         /* in the overflow error case, longlongval is -1, and an exception is set */
         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
     } else if (PyFloat_Check(parameter)) {
         rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));

Modified: python/branches/py3k/Modules/cjkcodecs/multibytecodec.c
==============================================================================
--- python/branches/py3k/Modules/cjkcodecs/multibytecodec.c	(original)
+++ python/branches/py3k/Modules/cjkcodecs/multibytecodec.c	Tue Oct 23 21:24:22 2007
@@ -313,8 +313,7 @@
 
 	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)))) {
+	    !PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
 		PyErr_SetString(PyExc_TypeError,
 				"encoding error handler must return "
 				"(unicode, int) tuple");
@@ -433,8 +432,7 @@
 
 	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)))) {
+	    !PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) {
 		PyErr_SetString(PyExc_TypeError,
 				"decoding error handler must return "
 				"(unicode, int) tuple");

Modified: python/branches/py3k/Objects/sliceobject.c
==============================================================================
--- python/branches/py3k/Objects/sliceobject.c	(original)
+++ python/branches/py3k/Objects/sliceobject.c	Tue Oct 23 21:24:22 2007
@@ -112,14 +112,14 @@
 	if (r->start == Py_None) {
 		*start = *step < 0 ? length-1 : 0;
 	} 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);
 		if (*start < 0) *start += length;
 	}
 	if (r->stop == Py_None) {
 		*stop = *step < 0 ? -1 : length;
 	} 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);
 		if (*stop < 0) *stop += length;
 	}

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Tue Oct 23 21:24:22 2007
@@ -696,9 +696,7 @@
 	case 'k': { /* long sized bitfield */
 		unsigned long *p = va_arg(*p_va, unsigned long *);
 		unsigned long ival;
-		if (PyInt_Check(arg))
-			ival = PyInt_AsUnsignedLongMask(arg);
-		else if (PyLong_Check(arg))
+		if (PyLong_Check(arg))
 			ival = PyLong_AsUnsignedLongMask(arg);
 		else
 			return converterr("integer<k>", arg, msgbuf, bufsize);


More information about the Python-3000-checkins mailing list