diff options
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/bufferedio.c | 15 | ||||
-rw-r--r-- | Modules/_io/bytesio.c | 6 | ||||
-rw-r--r-- | Modules/_io/clinic/bufferedio.c.h | 13 | ||||
-rw-r--r-- | Modules/_io/clinic/bytesio.c.h | 26 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 4 | ||||
-rw-r--r-- | Modules/_io/iobase.c | 3 | ||||
-rw-r--r-- | Modules/_io/stringio.c | 2 | ||||
-rw-r--r-- | Modules/_io/textio.c | 12 | ||||
-rw-r--r-- | Modules/_io/winconsoleio.c | 6 |
9 files changed, 55 insertions, 32 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index cbe7425..cb4173e 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -305,7 +305,7 @@ _enter_buffered_busy(buffered *self) "could not acquire lock for %A at interpreter " "shutdown, possibly due to daemon threads", (PyObject *) self); - char *msg = PyUnicode_AsUTF8(msgobj); + const char *msg = PyUnicode_AsUTF8(msgobj); Py_FatalError(msg); } return 1; @@ -454,7 +454,8 @@ buffered_dealloc_warn(buffered *self, PyObject *source) { if (self->ok && self->raw) { PyObject *r; - r = _PyObject_CallMethodId(self->raw, &PyId__dealloc_warn, "O", source); + r = _PyObject_CallMethodIdObjArgs(self->raw, &PyId__dealloc_warn, + source, NULL); if (r) Py_DECREF(r); else @@ -904,7 +905,7 @@ _io__Buffered_read_impl(buffered *self, Py_ssize_t n) CHECK_INITIALIZED(self) if (n < -1) { PyErr_SetString(PyExc_ValueError, - "read length must be positive or -1"); + "read length must be non-negative or -1"); return NULL; } @@ -932,22 +933,20 @@ _io__Buffered_read_impl(buffered *self, Py_ssize_t n) /*[clinic input] _io._Buffered.read1 - size as n: Py_ssize_t + size as n: Py_ssize_t = -1 / [clinic start generated code]*/ static PyObject * _io__Buffered_read1_impl(buffered *self, Py_ssize_t n) -/*[clinic end generated code: output=bcc4fb4e54d103a3 input=8d2869c18b983184]*/ +/*[clinic end generated code: output=bcc4fb4e54d103a3 input=7d22de9630b61774]*/ { Py_ssize_t have, r; PyObject *res = NULL; CHECK_INITIALIZED(self) if (n < 0) { - PyErr_SetString(PyExc_ValueError, - "read length must be positive"); - return NULL; + n = self->buffer_size; } CHECK_CLOSED(self, "read of closed file") diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index a1ba121..96be0f4 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -420,7 +420,7 @@ _io_BytesIO_read_impl(bytesio *self, PyObject *arg) /*[clinic input] _io.BytesIO.read1 - size: object + size: object(c_default="Py_None") = -1 / Read at most size bytes, returned as a bytes object. @@ -430,8 +430,8 @@ Return an empty bytes object at EOF. [clinic start generated code]*/ static PyObject * -_io_BytesIO_read1(bytesio *self, PyObject *size) -/*[clinic end generated code: output=16021f5d0ac3d4e2 input=d4f40bb8f2f99418]*/ +_io_BytesIO_read1_impl(bytesio *self, PyObject *size) +/*[clinic end generated code: output=a60d80c84c81a6b8 input=0951874bafee8e80]*/ { return _io_BytesIO_read_impl(self, size); } diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 58144a4..dc69c48 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -140,23 +140,24 @@ exit: } PyDoc_STRVAR(_io__Buffered_read1__doc__, -"read1($self, size, /)\n" +"read1($self, size=-1, /)\n" "--\n" "\n"); #define _IO__BUFFERED_READ1_METHODDEF \ - {"read1", (PyCFunction)_io__Buffered_read1, METH_O, _io__Buffered_read1__doc__}, + {"read1", (PyCFunction)_io__Buffered_read1, METH_VARARGS, _io__Buffered_read1__doc__}, static PyObject * _io__Buffered_read1_impl(buffered *self, Py_ssize_t n); static PyObject * -_io__Buffered_read1(buffered *self, PyObject *arg) +_io__Buffered_read1(buffered *self, PyObject *args) { PyObject *return_value = NULL; - Py_ssize_t n; + Py_ssize_t n = -1; - if (!PyArg_Parse(arg, "n:read1", &n)) { + if (!PyArg_ParseTuple(args, "|n:read1", + &n)) { goto exit; } return_value = _io__Buffered_read1_impl(self, n); @@ -475,4 +476,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=a956f394ecde4cf9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=490c97bfcfd92c51 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index c64ce5c..1434782 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -181,7 +181,7 @@ exit: } PyDoc_STRVAR(_io_BytesIO_read1__doc__, -"read1($self, size, /)\n" +"read1($self, size=-1, /)\n" "--\n" "\n" "Read at most size bytes, returned as a bytes object.\n" @@ -190,7 +190,27 @@ PyDoc_STRVAR(_io_BytesIO_read1__doc__, "Return an empty bytes object at EOF."); #define _IO_BYTESIO_READ1_METHODDEF \ - {"read1", (PyCFunction)_io_BytesIO_read1, METH_O, _io_BytesIO_read1__doc__}, + {"read1", (PyCFunction)_io_BytesIO_read1, METH_VARARGS, _io_BytesIO_read1__doc__}, + +static PyObject * +_io_BytesIO_read1_impl(bytesio *self, PyObject *size); + +static PyObject * +_io_BytesIO_read1(bytesio *self, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *size = Py_None; + + if (!PyArg_UnpackTuple(args, "read1", + 0, 1, + &size)) { + goto exit; + } + return_value = _io_BytesIO_read1_impl(self, size); + +exit: + return return_value; +} PyDoc_STRVAR(_io_BytesIO_readline__doc__, "readline($self, size=None, /)\n" @@ -428,4 +448,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=6382e8eb578eea64 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8f469431da1b3857 input=a9049054013a1b77]*/ diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 6854a44..f454d3c 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -153,8 +153,8 @@ _io_FileIO_close_impl(fileio *self) PyObject *exc, *val, *tb; int rc; _Py_IDENTIFIER(close); - res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type, - &PyId_close, "O", self); + res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type, + &PyId_close, self, NULL); if (!self->closefd) { self->fd = -1; return res; diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 472ef3b..ee6ad47 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -661,7 +661,8 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) to remove the bytecode interpretation overhead, but it could probably be removed here. */ _Py_IDENTIFIER(extend); - PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self); + PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend, + self, NULL); if (ret == NULL) { Py_DECREF(result); diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index 8542efd..93c8b47 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -693,7 +693,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value, PyObject *newline_obj) /*[clinic end generated code: output=a421ea023b22ef4e input=cee2d9181b2577a3]*/ { - char *newline = "\n"; + const char *newline = "\n"; Py_ssize_t value_len; /* Parse the newline argument. We only want to allow unicode objects or diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 1c7200b..0a6dfe1 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -899,8 +899,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, PyObject *locale_module = _PyIO_get_locale_module(state); if (locale_module == NULL) goto catch_ImportError; - self->encoding = _PyObject_CallMethodId( - locale_module, &PyId_getpreferredencoding, "O", Py_False); + self->encoding = _PyObject_CallMethodIdObjArgs( + locale_module, &PyId_getpreferredencoding, Py_False, NULL); Py_DECREF(locale_module); if (self->encoding == NULL) { catch_ImportError: @@ -2435,7 +2435,7 @@ _io_TextIOWrapper_tell_impl(textio *self) } finally: - res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state); + res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL); Py_DECREF(saved_state); if (res == NULL) return NULL; @@ -2449,7 +2449,7 @@ fail: if (saved_state) { PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state); + res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL); _PyErr_ChainExceptions(type, value, traceback); Py_DECREF(saved_state); Py_XDECREF(res); @@ -2644,7 +2644,9 @@ _io_TextIOWrapper_close_impl(textio *self) else { PyObject *exc = NULL, *val, *tb; if (self->finalizing) { - res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self); + res = _PyObject_CallMethodIdObjArgs(self->buffer, + &PyId__dealloc_warn, + self, NULL); if (res) Py_DECREF(res); else diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 7b00a9e..d8e4339 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -85,7 +85,7 @@ char _PyIO_get_console_type(PyObject *path_or_fd) { Py_CLEAR(decoded); return '\0'; } - decoded_upper = PyObject_CallMethod(decoded, "upper", ""); + decoded_upper = PyObject_CallMethod(decoded, "upper", NULL); Py_CLEAR(decoded); if (!decoded_upper) { PyErr_Clear(); @@ -181,8 +181,8 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self) PyObject *exc, *val, *tb; int rc; _Py_IDENTIFIER(close); - res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type, - &PyId_close, "O", self); + res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type, + &PyId_close, self, NULL); if (!self->closehandle) { self->handle = INVALID_HANDLE_VALUE; return res; |