diff options
author | Thomas Heller <theller@ctypes.org> | 2008-01-24 19:15:02 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-01-24 19:15:02 (GMT) |
commit | 5ca924038dd196217cedd4b02480ea16acd634f3 (patch) | |
tree | e1a954d47e19d4006c157858e1d6618004b3f0fe /Modules | |
parent | 5a05364049a7b0c3eeee94fb7b77e6b41036b3ae (diff) | |
download | cpython-5ca924038dd196217cedd4b02480ea16acd634f3.zip cpython-5ca924038dd196217cedd4b02480ea16acd634f3.tar.gz cpython-5ca924038dd196217cedd4b02480ea16acd634f3.tar.bz2 |
Invert the checks in get_[u]long and get_[u]longlong. The intent was
to not accept float types; the result was that integer-like objects
were not accepted.
Ported from release25-maint.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/cfield.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 03aacbd..155e75e 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -346,10 +346,9 @@ static int get_long(PyObject *v, long *p) { long x; - if (!PyInt_Check(v) && !PyLong_Check(v)) { - PyErr_Format(PyExc_TypeError, - "int expected instead of %s instance", - v->ob_type->tp_name); + if (PyFloat_Check(v)) { + PyErr_SetString(PyExc_TypeError, + "int expected instead of float"); return -1; } x = PyInt_AsUnsignedLongMask(v); @@ -365,10 +364,9 @@ static int get_ulong(PyObject *v, unsigned long *p) { unsigned long x; - if (!PyInt_Check(v) && !PyLong_Check(v)) { - PyErr_Format(PyExc_TypeError, - "int expected instead of %s instance", - v->ob_type->tp_name); + if (PyFloat_Check(v)) { + PyErr_SetString(PyExc_TypeError, + "int expected instead of float"); return -1; } x = PyInt_AsUnsignedLongMask(v); @@ -386,11 +384,10 @@ static int get_longlong(PyObject *v, PY_LONG_LONG *p) { PY_LONG_LONG x; - if (!PyInt_Check(v) && !PyLong_Check(v)) { - PyErr_Format(PyExc_TypeError, - "int expected instead of %s instance", - v->ob_type->tp_name); - return -1; + if (PyFloat_Check(v)) { + PyErr_SetString(PyExc_TypeError, + "int expected instead of float"); + return -1; } x = PyInt_AsUnsignedLongLongMask(v); if (x == -1 && PyErr_Occurred()) @@ -405,12 +402,11 @@ static int get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p) { unsigned PY_LONG_LONG x; - if (!PyInt_Check(v) && !PyLong_Check(v)) { - PyErr_Format(PyExc_TypeError, - "int expected instead of %s instance", - v->ob_type->tp_name); - return -1; - } + if (PyFloat_Check(v)) { + PyErr_SetString(PyExc_TypeError, + "int expected instead of float"); + return -1; + } x = PyInt_AsUnsignedLongLongMask(v); if (x == -1 && PyErr_Occurred()) return -1; |