summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-01-01 19:27:32 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-01-01 19:27:32 (GMT)
commitde60401909fb6232159f8c3b14c50d108556caad (patch)
tree08594ee22b17a110aaef0c589abd813c0923d0b1 /Python/getargs.c
parentd78735d8e32411a20fc31a78e705f4c067b4344f (diff)
downloadcpython-de60401909fb6232159f8c3b14c50d108556caad.zip
cpython-de60401909fb6232159f8c3b14c50d108556caad.tar.gz
cpython-de60401909fb6232159f8c3b14c50d108556caad.tar.bz2
Merged revisions 77218 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77218 | mark.dickinson | 2010-01-01 17:27:30 +0000 (Fri, 01 Jan 2010) | 5 lines Issue #5080: turn the DeprecationWarning from float arguments passed to integer PyArg_Parse* format codes into a TypeError. Add a DeprecationWarning for floats passed with the 'L' format code, which didn't previously have a warning. ........
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index b69aaed..39be98c 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -582,6 +582,19 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
#define CONV_UNICODE "(unicode conversion error)"
+/* explicitly check for float arguments when integers are expected. For now
+ * signal a warning. Returns true if an exception was raised. */
+static int
+float_argument_warning(PyObject *arg)
+{
+ if (PyFloat_Check(arg) &&
+ PyErr_Warn(PyExc_DeprecationWarning,
+ "integer argument expected, got float" ))
+ return 1;
+ else
+ return 0;
+}
+
/* Explicitly check for float arguments when integers are expected.
Return 1 for error, 0 if ok. */
static int
@@ -777,7 +790,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
#ifdef HAVE_LONG_LONG
case 'L': {/* PY_LONG_LONG */
PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );
- PY_LONG_LONG ival = PyLong_AsLongLong( arg );
+ PY_LONG_LONG ival;
+ if (float_argument_warning(arg))
+ return converterr("long<L>", arg, msgbuf, bufsize);
+ ival = PyLong_AsLongLong(arg);
if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {
return converterr("long<L>", arg, msgbuf, bufsize);
} else {