summaryrefslogtreecommitdiffstats
path: root/Modules/_io/clinic/bytesio.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-11 14:01:14 (GMT)
committerGitHub <noreply@github.com>2019-01-11 14:01:14 (GMT)
commit4fa9591025b6a098f3d6402e5413ee6740ede6c5 (patch)
treea81280fdd40c6a5b8c00613b0a8903624499afc5 /Modules/_io/clinic/bytesio.c.h
parent5485085b324a45307c1ff4ec7d85b5998d7d5e0d (diff)
downloadcpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.zip
cpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.tar.gz
cpython-4fa9591025b6a098f3d6402e5413ee6740ede6c5.tar.bz2
bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313)
Diffstat (limited to 'Modules/_io/clinic/bytesio.c.h')
-rw-r--r--Modules/_io/clinic/bytesio.c.h79
1 files changed, 66 insertions, 13 deletions
diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h
index 07c8866..5588416 100644
--- a/Modules/_io/clinic/bytesio.c.h
+++ b/Modules/_io/clinic/bytesio.c.h
@@ -169,10 +169,16 @@ _io_BytesIO_read(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
- if (!_PyArg_ParseStack(args, nargs, "|O&:read",
- _Py_convert_optional_to_ssize_t, &size)) {
+ if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
+ goto exit;
+ }
+skip_optional:
return_value = _io_BytesIO_read_impl(self, size);
exit:
@@ -200,10 +206,16 @@ _io_BytesIO_read1(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
- if (!_PyArg_ParseStack(args, nargs, "|O&:read1",
- _Py_convert_optional_to_ssize_t, &size)) {
+ if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
+ goto exit;
+ }
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
+skip_optional:
return_value = _io_BytesIO_read1_impl(self, size);
exit:
@@ -232,10 +244,16 @@ _io_BytesIO_readline(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
- if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
- _Py_convert_optional_to_ssize_t, &size)) {
+ if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
goto exit;
}
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
+ goto exit;
+ }
+skip_optional:
return_value = _io_BytesIO_readline_impl(self, size);
exit:
@@ -298,11 +316,11 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
- _PyArg_BadArgument("readinto", "read-write bytes-like object", arg);
+ _PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
- _PyArg_BadArgument("readinto", "contiguous buffer", arg);
+ _PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io_BytesIO_readinto_impl(self, &buffer);
@@ -337,10 +355,16 @@ _io_BytesIO_truncate(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = self->pos;
- if (!_PyArg_ParseStack(args, nargs, "|O&:truncate",
- _Py_convert_optional_to_ssize_t, &size)) {
+ if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
+ goto exit;
+ }
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
+skip_optional:
return_value = _io_BytesIO_truncate_impl(self, size);
exit:
@@ -372,10 +396,39 @@ _io_BytesIO_seek(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t pos;
int whence = 0;
- if (!_PyArg_ParseStack(args, nargs, "n|i:seek",
- &pos, &whence)) {
+ if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
+ goto exit;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ pos = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (PyFloat_Check(args[1])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ whence = _PyLong_AsInt(args[1]);
+ if (whence == -1 && PyErr_Occurred()) {
goto exit;
}
+skip_optional:
return_value = _io_BytesIO_seek_impl(self, pos, whence);
exit:
@@ -450,4 +503,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=f6e720f38fc6e3cd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5c68eb481fa960bf input=a9049054013a1b77]*/