summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
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 /Modules/cjkcodecs
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 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/clinic/multibytecodec.c.h120
1 files changed, 107 insertions, 13 deletions
diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h
index c62a641..84774f0 100644
--- a/Modules/cjkcodecs/clinic/multibytecodec.c.h
+++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h
@@ -26,14 +26,39 @@ _multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *cons
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"input", "errors", NULL};
- static _PyArg_Parser _parser = {"O|z:encode", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
PyObject *input;
const char *errors = NULL;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &input, &errors)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
goto exit;
}
+ input = args[0];
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[1] == Py_None) {
+ errors = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ Py_ssize_t errors_length;
+ errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
+ if (errors == NULL) {
+ goto exit;
+ }
+ if (strlen(errors) != (size_t)errors_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("encode", 2, "str or None", args[1]);
+ goto exit;
+ }
+skip_optional_pos:
return_value = _multibytecodec_MultibyteCodec_encode_impl(self, input, errors);
exit:
@@ -64,14 +89,45 @@ _multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *cons
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"input", "errors", NULL};
- static _PyArg_Parser _parser = {"y*|z:decode", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer input = {NULL, NULL};
const char *errors = NULL;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &input, &errors)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &input, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&input, 'C')) {
+ _PyArg_BadArgument("decode", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[1] == Py_None) {
+ errors = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ Py_ssize_t errors_length;
+ errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
+ if (errors == NULL) {
+ goto exit;
+ }
+ if (strlen(errors) != (size_t)errors_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("decode", 2, "str or None", args[1]);
goto exit;
}
+skip_optional_pos:
return_value = _multibytecodec_MultibyteCodec_decode_impl(self, &input, errors);
exit:
@@ -101,14 +157,30 @@ _multibytecodec_MultibyteIncrementalEncoder_encode(MultibyteIncrementalEncoderOb
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"input", "final", NULL};
- static _PyArg_Parser _parser = {"O|i:encode", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
PyObject *input;
int final = 0;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &input, &final)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
goto exit;
}
+ input = args[0];
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (PyFloat_Check(args[1])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ final = _PyLong_AsInt(args[1]);
+ if (final == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_pos:
return_value = _multibytecodec_MultibyteIncrementalEncoder_encode_impl(self, input, final);
exit:
@@ -196,14 +268,36 @@ _multibytecodec_MultibyteIncrementalDecoder_decode(MultibyteIncrementalDecoderOb
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"input", "final", NULL};
- static _PyArg_Parser _parser = {"y*|i:decode", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer input = {NULL, NULL};
int final = 0;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &input, &final)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &input, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&input, 'C')) {
+ _PyArg_BadArgument("decode", 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;
+ }
+ final = _PyLong_AsInt(args[1]);
+ if (final == -1 && PyErr_Occurred()) {
goto exit;
}
+skip_optional_pos:
return_value = _multibytecodec_MultibyteIncrementalDecoder_decode_impl(self, &input, final);
exit:
@@ -431,4 +525,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
#define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \
{"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__},
-/*[clinic end generated code: output=bcd6311010557faf input=a9049054013a1b77]*/
+/*[clinic end generated code: output=eb95a408c4ddbfff input=a9049054013a1b77]*/