summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-11 14:01:14 (GMT)
committerGitHub <noreply@github.com>2019-01-11 14:01:14 (GMT)
commit4fa9591025b6a098f3d6402e5413ee6740ede6c5 (patch)
treea81280fdd40c6a5b8c00613b0a8903624499afc5 /Python/getargs.c
parent5485085b324a45307c1ff4ec7d85b5998d7d5e0d (diff)
downloadcpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.zip
cpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.tar.gz
cpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.tar.bz2
bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313)
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 550d0df..c491169 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -613,11 +613,21 @@ convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
/* Format an error message generated by convertsimple(). */
void
-_PyArg_BadArgument(const char *fname, const char *expected, PyObject *arg)
+_PyArg_BadArgument(const char *fname, int iarg,
+ const char *expected, PyObject *arg)
{
- PyErr_Format(PyExc_TypeError, "%.200s() argument must be %.50s, not %.50s",
- fname, expected,
- arg == Py_None ? "None" : arg->ob_type->tp_name);
+ if (iarg) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() argument %d must be %.50s, not %.50s",
+ fname, iarg, expected,
+ arg == Py_None ? "None" : arg->ob_type->tp_name);
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() argument must be %.50s, not %.50s",
+ fname, expected,
+ arg == Py_None ? "None" : arg->ob_type->tp_name);
+ }
}
static const char *
@@ -2416,13 +2426,12 @@ err:
}
-static int
-unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
- Py_ssize_t min, Py_ssize_t max, va_list vargs)
-{
- Py_ssize_t i;
- PyObject **o;
+#undef _PyArg_CheckPositional
+int
+_PyArg_CheckPositional(const char *name, Py_ssize_t nargs,
+ Py_ssize_t min, Py_ssize_t max)
+{
assert(min >= 0);
assert(min <= max);
@@ -2460,6 +2469,20 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
return 0;
}
+ return 1;
+}
+
+static int
+unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
+ Py_ssize_t min, Py_ssize_t max, va_list vargs)
+{
+ Py_ssize_t i;
+ PyObject **o;
+
+ if (!_PyArg_CheckPositional(name, nargs, min, max)) {
+ return 0;
+ }
+
for (i = 0; i < nargs; i++) {
o = va_arg(vargs, PyObject **);
*o = args[i];