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/_bz2module.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/_bz2module.c.h')
-rw-r--r-- | Modules/clinic/_bz2module.c.h | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index fb64333..cc16d8b 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -142,14 +142,44 @@ _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py { PyObject *return_value = NULL; static const char * const _keywords[] = {"data", "max_length", NULL}; - static _PyArg_Parser _parser = {"y*|n:decompress", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; Py_buffer data = {NULL, NULL}; Py_ssize_t max_length = -1; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &data, &max_length)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("decompress", 1, "contiguous buffer", args[0]); + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + max_length = ival; + } +skip_optional_pos: return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length); exit: @@ -190,4 +220,4 @@ _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=892c6133e97ff840 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8e123f4eec497655 input=a9049054013a1b77]*/ |