Index: Modules/_struct.c =================================================================== --- Modules/_struct.c (Revision 65996) +++ Modules/_struct.c (Arbeitskopie) @@ -35,7 +35,7 @@ arguments for integer formats with a warning for backwards compatibility. */ -#define PY_STRUCT_FLOAT_COERCE 1 +//#define PY_STRUCT_FLOAT_COERCE 0 #ifdef PY_STRUCT_FLOAT_COERCE #define FLOAT_COERCE "integer argument expected, got float" @@ -153,23 +153,28 @@ static int get_long(PyObject *v, long *p) { - long x = PyInt_AsLong(v); - if (x == -1 && PyErr_Occurred()) { + long x; + /* must check explicitly for float here */ + if (PyFloat_Check(v)) { #ifdef PY_STRUCT_FLOAT_COERCE - if (PyFloat_Check(v)) { - PyObject *o; - int res; - PyErr_Clear(); - if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0) - return -1; - o = PyNumber_Int(v); - if (o == NULL) - return -1; - res = get_long(o, p); - Py_DECREF(o); - return res; - } + PyObject *o; + int res; + if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0) + return -1; + o = PyNumber_Int(v); + if (o == NULL) + return -1; + res = get_long(o, p); + Py_DECREF(o); + return res; +#else + PyErr_SetString(StructError, + "required argument is not an integer"); + return -1; #endif + } + x = PyInt_AsLong(v); + if (x == -1 && PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_TypeError)) PyErr_SetString(StructError, "required argument is not an integer"); @@ -260,21 +265,6 @@ PyObject *wrapped; long x; PyErr_Clear(); -#ifdef PY_STRUCT_FLOAT_COERCE - if (PyFloat_Check(v)) { - PyObject *o; - int res; - PyErr_Clear(); - if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0) - return -1; - o = PyNumber_Int(v); - if (o == NULL) - return -1; - res = get_wrapped_long(o, p); - Py_DECREF(o); - return res; - } -#endif if (PyErr_WarnEx(PyExc_DeprecationWarning, INT_OVERFLOW, 2) < 0) return -1; wrapped = PyNumber_And(v, pylong_ulong_mask); @@ -1748,13 +1738,16 @@ /* Extract a writable memory buffer from the first argument */ if ( PyObject_AsWriteBuffer(PyTuple_GET_ITEM(args, 0), - (void**)&buffer, &buffer_len) == -1 ) { + (void**)&buffer, &buffer_len) == -1 ) { return NULL; } assert( buffer_len >= 0 ); /* Extract the offset from the first argument */ offset = PyInt_AsSsize_t(PyTuple_GET_ITEM(args, 1)); + if (offset == -1 && PyErr_Occurred()) { + return NULL; + } /* Support negative offsets. */ if (offset < 0)