summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-12-25 11:23:47 (GMT)
committerGitHub <noreply@github.com>2018-12-25 11:23:47 (GMT)
commit32d96a2b5bc3136d45a66adbdb45fac351b520ce (patch)
treeacf51c9945f764ab103597c9cba376f154aa600d /Python
parent65ce60aef150776f884715b4315a10a0d6ae769e (diff)
downloadcpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.zip
cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.gz
cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.bz2
bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689)
Diffstat (limited to 'Python')
-rw-r--r--Python/clinic/bltinmodule.c.h10
-rw-r--r--Python/clinic/import.c.h37
-rw-r--r--Python/clinic/marshal.c.h8
-rw-r--r--Python/getargs.c8
4 files changed, 53 insertions, 10 deletions
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h
index 4a79861..7f043da 100644
--- a/Python/clinic/bltinmodule.c.h
+++ b/Python/clinic/bltinmodule.c.h
@@ -122,7 +122,13 @@ builtin_chr(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int i;
- if (!PyArg_Parse(arg, "i:chr", &i)) {
+ if (PyFloat_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ i = _PyLong_AsInt(arg);
+ if (i == -1 && PyErr_Occurred()) {
goto exit;
}
return_value = builtin_chr_impl(module, i);
@@ -711,4 +717,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=fa8d97ac8695363b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ed300ebf3f6db530 input=a9049054013a1b77]*/
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
index 1eae8f2..d34d68f 100644
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -143,9 +143,14 @@ _imp_init_frozen(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
PyObject *name;
- if (!PyArg_Parse(arg, "U:init_frozen", &name)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("init_frozen", "str", arg);
goto exit;
}
+ if (PyUnicode_READY(arg) == -1) {
+ goto exit;
+ }
+ name = arg;
return_value = _imp_init_frozen_impl(module, name);
exit:
@@ -170,9 +175,14 @@ _imp_get_frozen_object(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
PyObject *name;
- if (!PyArg_Parse(arg, "U:get_frozen_object", &name)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("get_frozen_object", "str", arg);
goto exit;
}
+ if (PyUnicode_READY(arg) == -1) {
+ goto exit;
+ }
+ name = arg;
return_value = _imp_get_frozen_object_impl(module, name);
exit:
@@ -197,9 +207,14 @@ _imp_is_frozen_package(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
PyObject *name;
- if (!PyArg_Parse(arg, "U:is_frozen_package", &name)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("is_frozen_package", "str", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg) == -1) {
goto exit;
}
+ name = arg;
return_value = _imp_is_frozen_package_impl(module, name);
exit:
@@ -224,9 +239,14 @@ _imp_is_builtin(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
PyObject *name;
- if (!PyArg_Parse(arg, "U:is_builtin", &name)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("is_builtin", "str", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg) == -1) {
goto exit;
}
+ name = arg;
return_value = _imp_is_builtin_impl(module, name);
exit:
@@ -251,9 +271,14 @@ _imp_is_frozen(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
PyObject *name;
- if (!PyArg_Parse(arg, "U:is_frozen", &name)) {
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("is_frozen", "str", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg) == -1) {
goto exit;
}
+ name = arg;
return_value = _imp_is_frozen_impl(module, name);
exit:
@@ -396,4 +421,4 @@ exit:
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
#define _IMP_EXEC_DYNAMIC_METHODDEF
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
-/*[clinic end generated code: output=ad747b76e105fff2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d8be58c9541122f1 input=a9049054013a1b77]*/
diff --git a/Python/clinic/marshal.c.h b/Python/clinic/marshal.c.h
index 0df4935..516a315 100644
--- a/Python/clinic/marshal.c.h
+++ b/Python/clinic/marshal.c.h
@@ -121,7 +121,11 @@ marshal_loads(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
Py_buffer bytes = {NULL, NULL};
- if (!PyArg_Parse(arg, "y*:loads", &bytes)) {
+ if (PyObject_GetBuffer(arg, &bytes, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&bytes, 'C')) {
+ _PyArg_BadArgument("loads", "contiguous buffer", arg);
goto exit;
}
return_value = marshal_loads_impl(module, &bytes);
@@ -134,4 +138,4 @@ exit:
return return_value;
}
-/*[clinic end generated code: output=cbb6128201bee7e0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8262e7e6c8cbc1ef input=a9049054013a1b77]*/
diff --git a/Python/getargs.c b/Python/getargs.c
index 00e330d..550d0df 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -612,6 +612,14 @@ 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)
+{
+ 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 *
converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
{