Index: Modules/_struct.c =================================================================== --- Modules/_struct.c (Revision 70277) +++ Modules/_struct.c (Arbeitskopie) @@ -172,29 +172,6 @@ return 0; } - -/* Same, but handling unsigned long */ - -static int -get_ulong(PyObject *v, unsigned long *p) -{ - if (PyLong_Check(v)) { - unsigned long x = PyLong_AsUnsignedLong(v); - if (x == (unsigned long)(-1) && PyErr_Occurred()) - return -1; - *p = x; - return 0; - } - if (get_long(v, (long *)p) < 0) - return -1; - if (((long)*p) < 0) { - PyErr_SetString(StructError, - "unsigned argument is < 0"); - return -1; - } - return 0; -} - #ifdef HAVE_LONG_LONG /* Same, but handling native long long. */ @@ -333,6 +310,28 @@ #else +/* Same, but handling unsigned long */ + +static int +get_ulong(PyObject *v, unsigned long *p) +{ + if (PyLong_Check(v)) { + unsigned long x = PyLong_AsUnsignedLong(v); + if (x == (unsigned long)(-1) && PyErr_Occurred()) + return -1; + *p = x; + return 0; + } + if (get_long(v, (long *)p) < 0) + return -1; + if (((long)*p) < 0) { + PyErr_SetString(StructError, + "unsigned argument is < 0"); + return -1; + } + return 0; +} + #define get_wrapped_long get_long #define get_wrapped_ulong get_ulong #define RANGE_ERROR(x, f, flag, mask) return _range_error(f, flag) @@ -731,7 +730,7 @@ static int np_bool(char *p, PyObject *v, const formatdef *f) { - BOOL_TYPE y; + BOOL_TYPE y; y = PyObject_IsTrue(v); memcpy(p, (char *)&y, sizeof y); return 0; @@ -1007,7 +1006,7 @@ static int bp_bool(char *p, PyObject *v, const formatdef *f) { - char y; + char y; y = PyObject_IsTrue(v); memcpy(p, (char *)&y, sizeof y); return 0; @@ -2060,7 +2059,7 @@ {"pack", pack, METH_VARARGS, pack_doc}, {"pack_into", pack_into, METH_VARARGS, pack_into_doc}, {"unpack", unpack, METH_VARARGS, unpack_doc}, - {"unpack_from", (PyCFunction)unpack_from, + {"unpack_from", (PyCFunction)unpack_from, METH_VARARGS|METH_KEYWORDS, unpack_from_doc}, {NULL, NULL} /* sentinel */ };