diff options
author | Thomas Heller <theller@ctypes.org> | 2008-01-24 13:08:54 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-01-24 13:08:54 (GMT) |
commit | fe528ebf6829b9be7cce38c7b15a3815a361faa2 (patch) | |
tree | 7198a0f1be145169f057e5186973ae935e85ba47 /Modules | |
parent | e105f980460131d192d955fca0df474bcf1c642c (diff) | |
download | cpython-fe528ebf6829b9be7cce38c7b15a3815a361faa2.zip cpython-fe528ebf6829b9be7cce38c7b15a3815a361faa2.tar.gz cpython-fe528ebf6829b9be7cce38c7b15a3815a361faa2.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.
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 0fd82bc..d310ac5 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -355,10 +355,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); @@ -374,10 +373,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); @@ -395,11 +393,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()) @@ -414,12 +411,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; |