summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
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];