[Python-modules-team] Bug#515207: pyusb: diff for NMU version 0.4.1-4.1

Thomas Viehmann tv at beamnet.de
Sat Feb 14 19:17:47 UTC 2009


Package: pyusb
Version: 0.4.1-4
Severity: grave
Tags: patch

Hi Petter, Bernd,

build log:

pyusb.c: In function 'getBuffer':
pyusb.c:145: warning: passing argument 3 of 'PyString_AsStringAndSize'
from incompatible pointer type

Might not be too good.
In fact, on the current package, the python 2.5 value will overwrite
the value of index parameter passed to controlMsg. python 2.4 worked.

Mind you, I believe #476796 should be closed as invalid / reassigned
to libusb because the string comes from there and it does the right
thing. I'm saying this here because I could imagine that Tollef was
seeing his problem after a controlMsg failed for the same reason as it
did for me. Note that this bug was very hard to find (I actually added
a lot of debug statements in libusb before I found what happened
because I thought it was a problem with the USB protocol).

Unfortunately, the workaround needs a compatibility #defines (see
below).

Apologies for not auditing all python extensions for this bug when
seeing a previous instance in a different package.

Kind regards

T.

diff -u pyusb-0.4.1/debian/changelog pyusb-0.4.1/debian/changelog
--- pyusb-0.4.1/debian/changelog
+++ pyusb-0.4.1/debian/changelog
@@ -1,3 +1,12 @@
+pyusb (0.4.1-4.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Don't pass int* where we need Py_ssize_t*.
+    Breaks (overwriting parameters) for python 2.5 on 64 bit arch.
+    Needs the usual PEP353 compatibility bruhaha plus printf.
+
+ -- Thomas Viehmann <tv at beamnet.de>  Sat, 14 Feb 2009 20:13:04 +0100
+
 pyusb (0.4.1-4) unstable; urgency=low
 
   [ Piotr Ożarowski ]
only in patch2:
unchanged:
--- pyusb-0.4.1.orig/pyusb.c
+++ pyusb-0.4.1/pyusb.c
@@ -13,6 +13,14 @@
 #include <stdio.h>
 #define DEFAULT_TIMEOUT 100
 
+/* see PEP353 */
+#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
+typedef int Py_ssize_t;
+# define PY_SSIZE_T_MAX INT_MAX
+# define PY_SSIZE_T_MIN INT_MIN
+# define PY_FORMAT_SIZE_T ""
+#endif
+
 /*
  * Necessary to compile successfully in python 2.3
  * Thanks to Mark Rages for the patch
@@ -126,7 +134,7 @@
  */
 PYUSB_STATIC char *getBuffer(
 	PyObject *obj,
-	int *size
+	Py_ssize_t *size
 	)
 {
 	char *p = NULL;
@@ -1104,7 +1112,7 @@
 	int index = 0;
 	char *bytes;
 	PyObject *data;
-	int size;
+	Py_ssize_t size;
 	int timeout = DEFAULT_TIMEOUT;
 	int ret;
 	int as_read = 0;
@@ -1162,7 +1170,7 @@
 		   timeout);
 
 	if (as_read) {
-		fprintf(stderr, "\tbuffer: %d\n", size);
+		fprintf(stderr, "\tbuffer: %" PY_FORMAT_SIZE_T "d\n", size);
 	} else {
 		fprintf(stderr, "controlMsg buffer param:\n");
 		printBuffer(bytes, size);
@@ -1386,7 +1394,7 @@
 	int endpoint;
 	int timeout = DEFAULT_TIMEOUT;
 	char *data;
-	int size;
+	Py_ssize_t size;
 	PyObject *bytes;
 	int ret;
 	PyObject *retObj;
@@ -1493,7 +1501,7 @@
 	int endpoint;
 	int timeout = DEFAULT_TIMEOUT;
 	char *data;
-	int size;
+	Py_ssize_t size;
 	PyObject *bytes;
 	int ret;
 	PyObject *retObj;





More information about the Python-modules-team mailing list