]> granicus.if.org Git - python/commitdiff
Patch #1011240: SystemError generated by struct.pack('P', 'foo').
authorArmin Rigo <arigo@tunes.org>
Mon, 27 Sep 2004 19:27:51 +0000 (19:27 +0000)
committerArmin Rigo <arigo@tunes.org>
Mon, 27 Sep 2004 19:27:51 +0000 (19:27 +0000)
Lib/test/test_struct.py
Modules/structmodule.c

index 0641d9ba45ed4b79126de366a196bf5a2219ccaf..933246639c9dbb287cdbf762626289e0a82902b6 100644 (file)
@@ -54,6 +54,7 @@ if sz * 3 != sz3:
 simple_err(struct.pack, 'iii', 3)
 simple_err(struct.pack, 'i', 3, 3, 3)
 simple_err(struct.pack, 'i', 'foo')
+simple_err(struct.pack, 'P', 'foo')
 simple_err(struct.unpack, 'd', 'flap')
 s = struct.pack('ii', 1, 2)
 simple_err(struct.unpack, 'iii', s)
index b78231f4d3cfcb85d3e3bcd19f03160ad8d775d6..33134e920b7e33eb17317848389da0db4c1a12c1 100644 (file)
@@ -518,14 +518,16 @@ np_double(char *p, PyObject *v, const formatdef *f)
 static int
 np_void_p(char *p, PyObject *v, const formatdef *f)
 {
-       void *x = PyLong_AsVoidPtr(v);
-       if (x == NULL && PyErr_Occurred()) {
-               /* ### hrm. PyLong_AsVoidPtr raises SystemError */
-               if (PyErr_ExceptionMatches(PyExc_TypeError))
-                       PyErr_SetString(StructError,
-                                       "required argument is not an integer");
+       void *x;
+
+       v = get_pylong(v);
+       if (v == NULL)
+               return -1;
+       assert(PyLong_Check(v));
+       x = PyLong_AsVoidPtr(v);
+       Py_DECREF(v);
+       if (x == NULL && PyErr_Occurred())
                return -1;
-       }
        memcpy(p, (char *)&x, sizeof x);
        return 0;
 }