diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-01-11 14:01:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-11 14:01:14 (GMT) |
commit | 4fa9591025b6a098f3d6402e5413ee6740ede6c5 (patch) | |
tree | a81280fdd40c6a5b8c00613b0a8903624499afc5 /Modules/_io | |
parent | 5485085b324a45307c1ff4ec7d85b5998d7d5e0d (diff) | |
download | cpython-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')
-rw-r--r-- | Modules/_io/clinic/bufferedio.c.h | 131 | ||||
-rw-r--r-- | Modules/_io/clinic/bytesio.c.h | 79 | ||||
-rw-r--r-- | Modules/_io/clinic/fileio.c.h | 35 | ||||
-rw-r--r-- | Modules/_io/clinic/iobase.c.h | 46 | ||||
-rw-r--r-- | Modules/_io/clinic/stringio.c.h | 65 | ||||
-rw-r--r-- | Modules/_io/clinic/textio.c.h | 55 | ||||
-rw-r--r-- | Modules/_io/clinic/winconsoleio.c.h | 18 |
7 files changed, 356 insertions, 73 deletions
diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 6569e02..6345b9e 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -21,11 +21,11 @@ _io__BufferedIOBase_readinto(PyObject *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__BufferedIOBase_readinto_impl(self, &buffer); @@ -58,11 +58,11 @@ _io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg) if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) { PyErr_Clear(); - _PyArg_BadArgument("readinto1", "read-write bytes-like object", arg); + _PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg); goto exit; } if (!PyBuffer_IsContiguous(&buffer, 'C')) { - _PyArg_BadArgument("readinto1", "contiguous buffer", arg); + _PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg); goto exit; } return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer); @@ -114,10 +114,30 @@ _io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t size = 0; - if (!_PyArg_ParseStack(args, nargs, "|n:peek", - &size)) { + if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + 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; + } + size = ival; + } +skip_optional: return_value = _io__Buffered_peek_impl(self, size); exit: @@ -141,10 +161,16 @@ _io__Buffered_read(buffered *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t n = -1; - if (!_PyArg_ParseStack(args, nargs, "|O&:read", - _Py_convert_optional_to_ssize_t, &n)) { + if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!_Py_convert_optional_to_ssize_t(args[0], &n)) { goto exit; } +skip_optional: return_value = _io__Buffered_read_impl(self, n); exit: @@ -168,10 +194,30 @@ _io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t n = -1; - if (!_PyArg_ParseStack(args, nargs, "|n:read1", - &n)) { + if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + 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; + } + n = ival; + } +skip_optional: return_value = _io__Buffered_read1_impl(self, n); exit: @@ -197,11 +243,11 @@ _io__Buffered_readinto(buffered *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__Buffered_readinto_impl(self, &buffer); @@ -234,11 +280,11 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg) if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) { PyErr_Clear(); - _PyArg_BadArgument("readinto1", "read-write bytes-like object", arg); + _PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg); goto exit; } if (!PyBuffer_IsContiguous(&buffer, 'C')) { - _PyArg_BadArgument("readinto1", "contiguous buffer", arg); + _PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg); goto exit; } return_value = _io__Buffered_readinto1_impl(self, &buffer); @@ -269,10 +315,16 @@ _io__Buffered_readline(buffered *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__Buffered_readline_impl(self, size); exit: @@ -297,10 +349,23 @@ _io__Buffered_seek(buffered *self, PyObject *const *args, Py_ssize_t nargs) PyObject *targetobj; int whence = 0; - if (!_PyArg_ParseStack(args, nargs, "O|i:seek", - &targetobj, &whence)) { + if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { + goto exit; + } + targetobj = args[0]; + 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__Buffered_seek_impl(self, targetobj, whence); exit: @@ -418,7 +483,7 @@ _io_BufferedWriter_write(buffered *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&buffer, 'C')) { - _PyArg_BadArgument("write", "contiguous buffer", arg); + _PyArg_BadArgument("write", 0, "contiguous buffer", arg); goto exit; } return_value = _io_BufferedWriter_write_impl(self, &buffer); @@ -462,10 +527,32 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs) !_PyArg_NoKeywords("BufferedRWPair", kwargs)) { goto exit; } - if (!PyArg_ParseTuple(args, "OO|n:BufferedRWPair", - &reader, &writer, &buffer_size)) { + if (!_PyArg_CheckPositional("BufferedRWPair", PyTuple_GET_SIZE(args), 2, 3)) { goto exit; } + reader = PyTuple_GET_ITEM(args, 0); + writer = PyTuple_GET_ITEM(args, 1); + if (PyTuple_GET_SIZE(args) < 3) { + goto skip_optional; + } + if (PyFloat_Check(PyTuple_GET_ITEM(args, 2))) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 2)); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + buffer_size = ival; + } +skip_optional: return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size); exit: @@ -504,4 +591,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=40de95d461a20782 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a85f61f495feff5c input=a9049054013a1b77]*/ 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]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index bf40f7f..280549e 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -158,11 +158,11 @@ _io_FileIO_readinto(fileio *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_FileIO_readinto_impl(self, &buffer); @@ -219,10 +219,16 @@ _io_FileIO_read(fileio *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_FileIO_read_impl(self, size); exit: @@ -255,7 +261,7 @@ _io_FileIO_write(fileio *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&b, 'C')) { - _PyArg_BadArgument("write", "contiguous buffer", arg); + _PyArg_BadArgument("write", 0, "contiguous buffer", arg); goto exit; } return_value = _io_FileIO_write_impl(self, &b); @@ -296,10 +302,23 @@ _io_FileIO_seek(fileio *self, PyObject *const *args, Py_ssize_t nargs) PyObject *pos; int whence = 0; - if (!_PyArg_ParseStack(args, nargs, "O|i:seek", - &pos, &whence)) { + if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { + goto exit; + } + pos = args[0]; + 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_FileIO_seek_impl(self, pos, whence); exit: @@ -383,4 +402,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=8be0ea9a5ac7aa43 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4cf4e5f0cd656b11 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index 68eaadd..a5c8eea 100644 --- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/_io/clinic/iobase.c.h @@ -185,10 +185,16 @@ _io__IOBase_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t limit = -1; - if (!_PyArg_ParseStack(args, nargs, "|O&:readline", - _Py_convert_optional_to_ssize_t, &limit)) { + if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + if (!_Py_convert_optional_to_ssize_t(args[0], &limit)) { + goto exit; + } +skip_optional: return_value = _io__IOBase_readline_impl(self, limit); exit: @@ -217,10 +223,16 @@ _io__IOBase_readlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t hint = -1; - if (!_PyArg_ParseStack(args, nargs, "|O&:readlines", - _Py_convert_optional_to_ssize_t, &hint)) { + if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!_Py_convert_optional_to_ssize_t(args[0], &hint)) { goto exit; } +skip_optional: return_value = _io__IOBase_readlines_impl(self, hint); exit: @@ -252,10 +264,30 @@ _io__RawIOBase_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t n = -1; - if (!_PyArg_ParseStack(args, nargs, "|n:read", - &n)) { + if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + 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; + } + n = ival; + } +skip_optional: return_value = _io__RawIOBase_read_impl(self, n); exit: @@ -279,4 +311,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _io__RawIOBase_readall_impl(self); } -/*[clinic end generated code: output=cde4b0e96a4e69e3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=60e43a7cbd9f314e input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 3181688..1757d83 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -59,10 +59,16 @@ _io_StringIO_read(stringio *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_StringIO_read_impl(self, size); exit: @@ -89,10 +95,16 @@ _io_StringIO_readline(stringio *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_StringIO_readline_impl(self, size); exit: @@ -121,10 +133,16 @@ _io_StringIO_truncate(stringio *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_StringIO_truncate_impl(self, size); exit: @@ -156,10 +174,39 @@ _io_StringIO_seek(stringio *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_StringIO_seek_impl(self, pos, whence); exit: @@ -286,4 +333,4 @@ _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored)) { return _io_StringIO_seekable_impl(self); } -/*[clinic end generated code: output=00c3c7a1c6ea6773 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=db5e51dcc4dae8d5 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index f056416e..0ff0324 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -251,7 +251,7 @@ _io_TextIOWrapper_write(textio *self, PyObject *arg) PyObject *text; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("write", "str", arg); + _PyArg_BadArgument("write", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -281,10 +281,16 @@ _io_TextIOWrapper_read(textio *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t n = -1; - if (!_PyArg_ParseStack(args, nargs, "|O&:read", - _Py_convert_optional_to_ssize_t, &n)) { + if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + if (!_Py_convert_optional_to_ssize_t(args[0], &n)) { + goto exit; + } +skip_optional: return_value = _io_TextIOWrapper_read_impl(self, n); exit: @@ -308,10 +314,30 @@ _io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs PyObject *return_value = NULL; Py_ssize_t size = -1; - if (!_PyArg_ParseStack(args, nargs, "|n:readline", - &size)) { + if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + 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; + } + size = ival; + } +skip_optional: return_value = _io_TextIOWrapper_readline_impl(self, size); exit: @@ -336,10 +362,23 @@ _io_TextIOWrapper_seek(textio *self, PyObject *const *args, Py_ssize_t nargs) PyObject *cookieObj; int whence = 0; - if (!_PyArg_ParseStack(args, nargs, "O|i:seek", - &cookieObj, &whence)) { + if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) { + goto exit; + } + cookieObj = args[0]; + 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_TextIOWrapper_seek_impl(self, cookieObj, whence); exit: @@ -509,4 +548,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) { return _io_TextIOWrapper_close_impl(self); } -/*[clinic end generated code: output=b933f08c2f2d85cd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8bdd1035bf878d6f input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index 65cac66..e7cd854 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -158,11 +158,11 @@ _io__WindowsConsoleIO_readinto(winconsoleio *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__WindowsConsoleIO_readinto_impl(self, &buffer); @@ -226,10 +226,16 @@ _io__WindowsConsoleIO_read(winconsoleio *self, PyObject *const *args, Py_ssize_t 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__WindowsConsoleIO_read_impl(self, size); exit: @@ -265,7 +271,7 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&b, 'C')) { - _PyArg_BadArgument("write", "contiguous buffer", arg); + _PyArg_BadArgument("write", 0, "contiguous buffer", arg); goto exit; } return_value = _io__WindowsConsoleIO_write_impl(self, &b); @@ -338,4 +344,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */ -/*[clinic end generated code: output=4337e8de65915a1e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ab0f0ee8062eecb3 input=a9049054013a1b77]*/ |