diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-03-14 08:32:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 08:32:22 (GMT) |
commit | 3191391515824fa7f3c573d807f1034c6a28fab3 (patch) | |
tree | ff8213b07b206de4df88dc352ee957ce68f0f2de /Modules/clinic/gcmodule.c.h | |
parent | 2c0d3f454705bb5ccf5f6189f3cf77bbae4f056b (diff) | |
download | cpython-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 'Modules/clinic/gcmodule.c.h')
-rw-r--r-- | Modules/clinic/gcmodule.c.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/Modules/clinic/gcmodule.c.h b/Modules/clinic/gcmodule.c.h index eece045..22d2aa4 100644 --- a/Modules/clinic/gcmodule.c.h +++ b/Modules/clinic/gcmodule.c.h @@ -89,14 +89,29 @@ gc_collect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * { PyObject *return_value = NULL; static const char * const _keywords[] = {"generation", NULL}; - static _PyArg_Parser _parser = {"|i:collect", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "collect", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int generation = NUM_GENERATIONS - 1; Py_ssize_t _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &generation)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + generation = _PyLong_AsInt(args[0]); + if (generation == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: _return_value = gc_collect_impl(module, generation); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -238,13 +253,22 @@ gc_get_objects(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = {"generation", NULL}; - static _PyArg_Parser _parser = {"|O&:get_objects", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "get_objects", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; Py_ssize_t generation = -1; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - _Py_convert_optional_to_ssize_t, &generation)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (!_Py_convert_optional_to_ssize_t(args[0], &generation)) { goto exit; } +skip_optional_pos: return_value = gc_get_objects_impl(module, generation); exit: @@ -349,4 +373,4 @@ gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored)) exit: return return_value; } -/*[clinic end generated code: output=d692bf475f0bb096 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e40d384b1f0d513c input=a9049054013a1b77]*/ |