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 /PC/clinic | |
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 'PC/clinic')
-rw-r--r-- | PC/clinic/_testconsole.c.h | 23 | ||||
-rw-r--r-- | PC/clinic/winreg.c.h | 12 | ||||
-rw-r--r-- | PC/clinic/winsound.c.h | 65 |
3 files changed, 79 insertions, 21 deletions
diff --git a/PC/clinic/_testconsole.c.h b/PC/clinic/_testconsole.c.h index 2809f2a..a37d123 100644 --- a/PC/clinic/_testconsole.c.h +++ b/PC/clinic/_testconsole.c.h @@ -22,14 +22,21 @@ _testconsole_write_input(PyObject *module, PyObject *const *args, Py_ssize_t nar { PyObject *return_value = NULL; static const char * const _keywords[] = {"file", "s", NULL}; - static _PyArg_Parser _parser = {"OS:write_input", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "write_input", 0}; + PyObject *argsbuf[2]; PyObject *file; PyBytesObject *s; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &file, &s)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { goto exit; } + file = args[0]; + if (!PyBytes_Check(args[1])) { + _PyArg_BadArgument("write_input", 2, "bytes", args[1]); + goto exit; + } + s = (PyBytesObject *)args[1]; return_value = _testconsole_write_input_impl(module, file, s); exit: @@ -57,13 +64,15 @@ _testconsole_read_output(PyObject *module, PyObject *const *args, Py_ssize_t nar { PyObject *return_value = NULL; static const char * const _keywords[] = {"file", NULL}; - static _PyArg_Parser _parser = {"O:read_output", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "read_output", 0}; + PyObject *argsbuf[1]; PyObject *file; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &file)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { goto exit; } + file = args[0]; return_value = _testconsole_read_output_impl(module, file); exit: @@ -79,4 +88,4 @@ exit: #ifndef _TESTCONSOLE_READ_OUTPUT_METHODDEF #define _TESTCONSOLE_READ_OUTPUT_METHODDEF #endif /* !defined(_TESTCONSOLE_READ_OUTPUT_METHODDEF) */ -/*[clinic end generated code: output=ab9ea8e78d26288e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ef452d5fb9287fc2 input=a9049054013a1b77]*/ diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index 21a9302..5021025 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -88,15 +88,19 @@ winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t n { PyObject *return_value = NULL; static const char * const _keywords[] = {"exc_type", "exc_value", "traceback", NULL}; - static _PyArg_Parser _parser = {"OOO:__exit__", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "__exit__", 0}; + PyObject *argsbuf[3]; PyObject *exc_type; PyObject *exc_value; PyObject *traceback; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &exc_type, &exc_value, &traceback)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); + if (!args) { goto exit; } + exc_type = args[0]; + exc_value = args[1]; + traceback = args[2]; return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback); exit: @@ -1117,4 +1121,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=bd491131d343ae7a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1204d20c543b5b4a input=a9049054013a1b77]*/ diff --git a/PC/clinic/winsound.c.h b/PC/clinic/winsound.c.h index 86514f5..b37db4c 100644 --- a/PC/clinic/winsound.c.h +++ b/PC/clinic/winsound.c.h @@ -24,12 +24,23 @@ winsound_PlaySound(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py { PyObject *return_value = NULL; static const char * const _keywords[] = {"sound", "flags", NULL}; - static _PyArg_Parser _parser = {"Oi:PlaySound", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "PlaySound", 0}; + PyObject *argsbuf[2]; PyObject *sound; int flags; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &sound, &flags)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + sound = args[0]; + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[1]); + if (flags == -1 && PyErr_Occurred()) { goto exit; } return_value = winsound_PlaySound_impl(module, sound, flags); @@ -61,12 +72,31 @@ winsound_Beep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec { PyObject *return_value = NULL; static const char * const _keywords[] = {"frequency", "duration", NULL}; - static _PyArg_Parser _parser = {"ii:Beep", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "Beep", 0}; + PyObject *argsbuf[2]; int frequency; int duration; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &frequency, &duration)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + frequency = _PyLong_AsInt(args[0]); + if (frequency == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + duration = _PyLong_AsInt(args[1]); + if (duration == -1 && PyErr_Occurred()) { goto exit; } return_value = winsound_Beep_impl(module, frequency, duration); @@ -94,16 +124,31 @@ winsound_MessageBeep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, { PyObject *return_value = NULL; static const char * const _keywords[] = {"type", NULL}; - static _PyArg_Parser _parser = {"|i:MessageBeep", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "MessageBeep", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int type = MB_OK; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &type)) { + 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; + } + type = _PyLong_AsInt(args[0]); + if (type == -1 && PyErr_Occurred()) { goto exit; } +skip_optional_pos: return_value = winsound_MessageBeep_impl(module, type); exit: return return_value; } -/*[clinic end generated code: output=19e5f0fb15bcd5bc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=28d1cd033282723d input=a9049054013a1b77]*/ |