summaryrefslogtreecommitdiffstats
path: root/Objects/clinic/funcobject.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-03-14 08:32:22 (GMT)
committerGitHub <noreply@github.com>2019-03-14 08:32:22 (GMT)
commit3191391515824fa7f3c573d807f1034c6a28fab3 (patch)
treeff8213b07b206de4df88dc352ee957ce68f0f2de /Objects/clinic/funcobject.c.h
parent2c0d3f454705bb5ccf5f6189f3cf77bbae4f056b (diff)
downloadcpython-3191391515824fa7f3c573d807f1034c6a28fab3.zip
cpython-3191391515824fa7f3c573d807f1034c6a28fab3.tar.gz
cpython-3191391515824fa7f3c573d807f1034c6a28fab3.tar.bz2
bpo-36127: Argument Clinic: inline parsing code for keyword parameters. (GH-12058)
Diffstat (limited to 'Objects/clinic/funcobject.c.h')
-rw-r--r--Objects/clinic/funcobject.c.h39
1 files changed, 35 insertions, 4 deletions
diff --git a/Objects/clinic/funcobject.c.h b/Objects/clinic/funcobject.c.h
index 4c54483..929797b 100644
--- a/Objects/clinic/funcobject.c.h
+++ b/Objects/clinic/funcobject.c.h
@@ -28,20 +28,51 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"code", "globals", "name", "argdefs", "closure", NULL};
- static _PyArg_Parser _parser = {"O!O!|OOO:function", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "function", 0};
+ PyObject *argsbuf[5];
+ PyObject * const *fastargs;
+ Py_ssize_t nargs = PyTuple_GET_SIZE(args);
+ Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
PyCodeObject *code;
PyObject *globals;
PyObject *name = Py_None;
PyObject *defaults = Py_None;
PyObject *closure = Py_None;
- if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
- &PyCode_Type, &code, &PyDict_Type, &globals, &name, &defaults, &closure)) {
+ fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 5, 0, argsbuf);
+ if (!fastargs) {
goto exit;
}
+ if (!PyObject_TypeCheck(fastargs[0], &PyCode_Type)) {
+ _PyArg_BadArgument("function", 1, (&PyCode_Type)->tp_name, fastargs[0]);
+ goto exit;
+ }
+ code = (PyCodeObject *)fastargs[0];
+ if (!PyDict_Check(fastargs[1])) {
+ _PyArg_BadArgument("function", 2, "dict", fastargs[1]);
+ goto exit;
+ }
+ globals = fastargs[1];
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (fastargs[2]) {
+ name = fastargs[2];
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ if (fastargs[3]) {
+ defaults = fastargs[3];
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ closure = fastargs[4];
+skip_optional_pos:
return_value = func_new_impl(type, code, globals, name, defaults, closure);
exit:
return return_value;
}
-/*[clinic end generated code: output=a6ab29e4dd33010a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1d01072cd5620d7e input=a9049054013a1b77]*/