diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index c7ae60281c2f58..00e228bca4375b 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -419,8 +419,13 @@ buffered_dealloc(buffered *self) Py_DECREF(tp); } +/*[clinic input] +_io._Buffered.__sizeof__ +[clinic start generated code]*/ + static PyObject * -buffered_sizeof(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered___sizeof___impl(buffered *self) +/*[clinic end generated code: output=0231ef7f5053134e input=753c782d808d34df]*/ { size_t res = _PyObject_SIZE(Py_TYPE(self)); if (self->buffer) { @@ -450,8 +455,17 @@ buffered_clear(buffered *self) /* Because this can call arbitrary code, it shouldn't be called when the refcount is 0 (that is, not directly from tp_dealloc unless the refcount has been temporarily re-incremented). */ +/*[clinic input] +_io._Buffered._dealloc_warn + + source: object + / + +[clinic start generated code]*/ + static PyObject * -buffered_dealloc_warn(buffered *self, PyObject *source) +_io__Buffered__dealloc_warn(buffered *self, PyObject *source) +/*[clinic end generated code: output=690dcc3df8967162 input=8f845f2a4786391c]*/ { if (self->ok && self->raw) { PyObject *r; @@ -471,9 +485,13 @@ buffered_dealloc_warn(buffered *self, PyObject *source) */ /* Flush and close */ +/*[clinic input] +_io._Buffered.flush as _io__Buffered_simple_flush +[clinic start generated code]*/ static PyObject * -buffered_simple_flush(buffered *self, PyObject *args) +_io__Buffered_simple_flush_impl(buffered *self) +/*[clinic end generated code: output=29ebb3820db1bdfd input=f33ef045e7250767]*/ { CHECK_INITIALIZED(self) return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(flush)); @@ -500,8 +518,13 @@ buffered_closed_get(buffered *self, void *context) return PyObject_GetAttr(self->raw, &_Py_ID(closed)); } +/*[clinic input] +_io._Buffered.close +[clinic start generated code]*/ + static PyObject * -buffered_close(buffered *self, PyObject *args) +_io__Buffered_close_impl(buffered *self) +/*[clinic end generated code: output=7280b7b42033be0c input=d20b83d1ddd7d805]*/ { PyObject *res = NULL; int r; @@ -520,7 +543,7 @@ buffered_close(buffered *self, PyObject *args) } if (self->finalizing) { - PyObject *r = buffered_dealloc_warn(self, (PyObject *) self); + PyObject *r = _io__Buffered__dealloc_warn(self, (PyObject *) self); if (r) Py_DECREF(r); else @@ -560,10 +583,13 @@ buffered_close(buffered *self, PyObject *args) return res; } -/* detach */ +/*[clinic input] +_io._Buffered.detach +[clinic start generated code]*/ static PyObject * -buffered_detach(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_detach_impl(buffered *self) +/*[clinic end generated code: output=dd0fc057b8b779f7 input=482762a345cc9f44]*/ { PyObject *raw, *res; CHECK_INITIALIZED(self) @@ -580,22 +606,37 @@ buffered_detach(buffered *self, PyObject *Py_UNUSED(ignored)) /* Inquiries */ +/*[clinic input] +_io._Buffered.seekable +[clinic start generated code]*/ + static PyObject * -buffered_seekable(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_seekable_impl(buffered *self) +/*[clinic end generated code: output=90172abb5ceb6e8f input=7d35764f5fb5262b]*/ { CHECK_INITIALIZED(self) return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(seekable)); } +/*[clinic input] +_io._Buffered.readable +[clinic start generated code]*/ + static PyObject * -buffered_readable(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_readable_impl(buffered *self) +/*[clinic end generated code: output=92afa07661ecb698 input=640619addb513b8b]*/ { CHECK_INITIALIZED(self) return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(readable)); } +/*[clinic input] +_io._Buffered.writable +[clinic start generated code]*/ + static PyObject * -buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_writable_impl(buffered *self) +/*[clinic end generated code: output=4e3eee8d6f9d8552 input=b35ea396b2201554]*/ { CHECK_INITIALIZED(self) return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(writable)); @@ -617,15 +658,25 @@ buffered_mode_get(buffered *self, void *context) /* Lower-level APIs */ +/*[clinic input] +_io._Buffered.fileno +[clinic start generated code]*/ + static PyObject * -buffered_fileno(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_fileno_impl(buffered *self) +/*[clinic end generated code: output=b717648d58a95ee3 input=768ea30b3f6314a7]*/ { CHECK_INITIALIZED(self) return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(fileno)); } +/*[clinic input] +_io._Buffered.isatty +[clinic start generated code]*/ + static PyObject * -buffered_isatty(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_isatty_impl(buffered *self) +/*[clinic end generated code: output=c20e55caae67baea input=9ea007b11559bee4]*/ { CHECK_INITIALIZED(self) return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(isatty)); @@ -830,8 +881,13 @@ buffered_flush_and_rewind_unlocked(buffered *self) Py_RETURN_NONE; } +/*[clinic input] +_io._Buffered.flush +[clinic start generated code]*/ + static PyObject * -buffered_flush(buffered *self, PyObject *args) +_io__Buffered_flush_impl(buffered *self) +/*[clinic end generated code: output=da2674ef1ce71f3a input=fda63444697c6bf4]*/ { PyObject *res; @@ -1205,8 +1261,13 @@ _io__Buffered_readline_impl(buffered *self, Py_ssize_t size) } +/*[clinic input] +_io._Buffered.tell +[clinic start generated code]*/ + static PyObject * -buffered_tell(buffered *self, PyObject *Py_UNUSED(ignored)) +_io__Buffered_tell_impl(buffered *self) +/*[clinic end generated code: output=386972ae84716c1e input=ad61e04a6b349573]*/ { Py_off_t pos; @@ -1318,20 +1379,21 @@ _io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence) /*[clinic input] _io._Buffered.truncate + cls: defining_class pos: object = None / [clinic start generated code]*/ static PyObject * -_io__Buffered_truncate_impl(buffered *self, PyObject *pos) -/*[clinic end generated code: output=667ca03c60c270de input=8a1be34d57cca2d3]*/ +_io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos) +/*[clinic end generated code: output=fe3882fbffe79f1a input=f5b737d97d76303f]*/ { PyObject *res = NULL; CHECK_INITIALIZED(self) CHECK_CLOSED(self, "truncate of closed file") if (!self->writable) { - _PyIO_State *state = IO_STATE(); + _PyIO_State *state = get_io_state_by_cls(cls); return bufferediobase_unsupported(state, "truncate"); } if (!ENTER_BUFFERED(self)) @@ -2427,14 +2489,14 @@ PyTypeObject PyBufferedIOBase_Type = { static PyMethodDef bufferedreader_methods[] = { /* BufferedIOMixin methods */ - {"detach", (PyCFunction)buffered_detach, METH_NOARGS}, - {"flush", (PyCFunction)buffered_simple_flush, METH_NOARGS}, - {"close", (PyCFunction)buffered_close, METH_NOARGS}, - {"seekable", (PyCFunction)buffered_seekable, METH_NOARGS}, - {"readable", (PyCFunction)buffered_readable, METH_NOARGS}, - {"fileno", (PyCFunction)buffered_fileno, METH_NOARGS}, - {"isatty", (PyCFunction)buffered_isatty, METH_NOARGS}, - {"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O}, + _IO__BUFFERED_DETACH_METHODDEF + _IO__BUFFERED_SIMPLE_FLUSH_METHODDEF + _IO__BUFFERED_CLOSE_METHODDEF + _IO__BUFFERED_SEEKABLE_METHODDEF + _IO__BUFFERED_READABLE_METHODDEF + _IO__BUFFERED_FILENO_METHODDEF + _IO__BUFFERED_ISATTY_METHODDEF + _IO__BUFFERED__DEALLOC_WARN_METHODDEF _IO__BUFFERED_READ_METHODDEF _IO__BUFFERED_PEEK_METHODDEF @@ -2443,9 +2505,9 @@ static PyMethodDef bufferedreader_methods[] = { _IO__BUFFERED_READINTO1_METHODDEF _IO__BUFFERED_READLINE_METHODDEF _IO__BUFFERED_SEEK_METHODDEF - {"tell", (PyCFunction)buffered_tell, METH_NOARGS}, + _IO__BUFFERED_TELL_METHODDEF _IO__BUFFERED_TRUNCATE_METHODDEF - {"__sizeof__", (PyCFunction)buffered_sizeof, METH_NOARGS}, + _IO__BUFFERED___SIZEOF___METHODDEF {NULL, NULL} }; @@ -2489,20 +2551,20 @@ PyType_Spec bufferedreader_spec = { static PyMethodDef bufferedwriter_methods[] = { /* BufferedIOMixin methods */ - {"close", (PyCFunction)buffered_close, METH_NOARGS}, - {"detach", (PyCFunction)buffered_detach, METH_NOARGS}, - {"seekable", (PyCFunction)buffered_seekable, METH_NOARGS}, - {"writable", (PyCFunction)buffered_writable, METH_NOARGS}, - {"fileno", (PyCFunction)buffered_fileno, METH_NOARGS}, - {"isatty", (PyCFunction)buffered_isatty, METH_NOARGS}, - {"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O}, + _IO__BUFFERED_CLOSE_METHODDEF + _IO__BUFFERED_DETACH_METHODDEF + _IO__BUFFERED_SEEKABLE_METHODDEF + _IO__BUFFERED_WRITABLE_METHODDEF + _IO__BUFFERED_FILENO_METHODDEF + _IO__BUFFERED_ISATTY_METHODDEF + _IO__BUFFERED__DEALLOC_WARN_METHODDEF _IO_BUFFEREDWRITER_WRITE_METHODDEF _IO__BUFFERED_TRUNCATE_METHODDEF - {"flush", (PyCFunction)buffered_flush, METH_NOARGS}, + _IO__BUFFERED_FLUSH_METHODDEF _IO__BUFFERED_SEEK_METHODDEF - {"tell", (PyCFunction)buffered_tell, METH_NOARGS}, - {"__sizeof__", (PyCFunction)buffered_sizeof, METH_NOARGS}, + _IO__BUFFERED_TELL_METHODDEF + _IO__BUFFERED___SIZEOF___METHODDEF {NULL, NULL} }; @@ -2596,19 +2658,19 @@ PyType_Spec bufferedrwpair_spec = { static PyMethodDef bufferedrandom_methods[] = { /* BufferedIOMixin methods */ - {"close", (PyCFunction)buffered_close, METH_NOARGS}, - {"detach", (PyCFunction)buffered_detach, METH_NOARGS}, - {"seekable", (PyCFunction)buffered_seekable, METH_NOARGS}, - {"readable", (PyCFunction)buffered_readable, METH_NOARGS}, - {"writable", (PyCFunction)buffered_writable, METH_NOARGS}, - {"fileno", (PyCFunction)buffered_fileno, METH_NOARGS}, - {"isatty", (PyCFunction)buffered_isatty, METH_NOARGS}, - {"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O}, + _IO__BUFFERED_CLOSE_METHODDEF + _IO__BUFFERED_DETACH_METHODDEF + _IO__BUFFERED_SEEKABLE_METHODDEF + _IO__BUFFERED_READABLE_METHODDEF + _IO__BUFFERED_WRITABLE_METHODDEF + _IO__BUFFERED_FILENO_METHODDEF + _IO__BUFFERED_ISATTY_METHODDEF + _IO__BUFFERED__DEALLOC_WARN_METHODDEF - {"flush", (PyCFunction)buffered_flush, METH_NOARGS}, + _IO__BUFFERED_FLUSH_METHODDEF _IO__BUFFERED_SEEK_METHODDEF - {"tell", (PyCFunction)buffered_tell, METH_NOARGS}, + _IO__BUFFERED_TELL_METHODDEF _IO__BUFFERED_TRUNCATE_METHODDEF _IO__BUFFERED_READ_METHODDEF _IO__BUFFERED_READ1_METHODDEF @@ -2617,7 +2679,7 @@ static PyMethodDef bufferedrandom_methods[] = { _IO__BUFFERED_READLINE_METHODDEF _IO__BUFFERED_PEEK_METHODDEF _IO_BUFFEREDWRITER_WRITE_METHODDEF - {"__sizeof__", (PyCFunction)buffered_sizeof, METH_NOARGS}, + _IO__BUFFERED___SIZEOF___METHODDEF {NULL, NULL} }; diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index a898b01899babe..e2ac90c54a10f0 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -266,6 +266,184 @@ _io__BufferedIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *ar return return_value; } +PyDoc_STRVAR(_io__Buffered___sizeof____doc__, +"__sizeof__($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED___SIZEOF___METHODDEF \ + {"__sizeof__", (PyCFunction)_io__Buffered___sizeof__, METH_NOARGS, _io__Buffered___sizeof____doc__}, + +static PyObject * +_io__Buffered___sizeof___impl(buffered *self); + +static PyObject * +_io__Buffered___sizeof__(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered___sizeof___impl(self); +} + +PyDoc_STRVAR(_io__Buffered__dealloc_warn__doc__, +"_dealloc_warn($self, source, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED__DEALLOC_WARN_METHODDEF \ + {"_dealloc_warn", (PyCFunction)_io__Buffered__dealloc_warn, METH_O, _io__Buffered__dealloc_warn__doc__}, + +PyDoc_STRVAR(_io__Buffered_simple_flush__doc__, +"flush($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_SIMPLE_FLUSH_METHODDEF \ + {"flush", (PyCFunction)_io__Buffered_simple_flush, METH_NOARGS, _io__Buffered_simple_flush__doc__}, + +static PyObject * +_io__Buffered_simple_flush_impl(buffered *self); + +static PyObject * +_io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_simple_flush_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_close__doc__, +"close($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_CLOSE_METHODDEF \ + {"close", (PyCFunction)_io__Buffered_close, METH_NOARGS, _io__Buffered_close__doc__}, + +static PyObject * +_io__Buffered_close_impl(buffered *self); + +static PyObject * +_io__Buffered_close(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_close_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_detach__doc__, +"detach($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_DETACH_METHODDEF \ + {"detach", (PyCFunction)_io__Buffered_detach, METH_NOARGS, _io__Buffered_detach__doc__}, + +static PyObject * +_io__Buffered_detach_impl(buffered *self); + +static PyObject * +_io__Buffered_detach(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_detach_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_seekable__doc__, +"seekable($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_SEEKABLE_METHODDEF \ + {"seekable", (PyCFunction)_io__Buffered_seekable, METH_NOARGS, _io__Buffered_seekable__doc__}, + +static PyObject * +_io__Buffered_seekable_impl(buffered *self); + +static PyObject * +_io__Buffered_seekable(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_seekable_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_readable__doc__, +"readable($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_READABLE_METHODDEF \ + {"readable", (PyCFunction)_io__Buffered_readable, METH_NOARGS, _io__Buffered_readable__doc__}, + +static PyObject * +_io__Buffered_readable_impl(buffered *self); + +static PyObject * +_io__Buffered_readable(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_readable_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_writable__doc__, +"writable($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_WRITABLE_METHODDEF \ + {"writable", (PyCFunction)_io__Buffered_writable, METH_NOARGS, _io__Buffered_writable__doc__}, + +static PyObject * +_io__Buffered_writable_impl(buffered *self); + +static PyObject * +_io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_writable_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_fileno__doc__, +"fileno($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_FILENO_METHODDEF \ + {"fileno", (PyCFunction)_io__Buffered_fileno, METH_NOARGS, _io__Buffered_fileno__doc__}, + +static PyObject * +_io__Buffered_fileno_impl(buffered *self); + +static PyObject * +_io__Buffered_fileno(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_fileno_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_isatty__doc__, +"isatty($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_ISATTY_METHODDEF \ + {"isatty", (PyCFunction)_io__Buffered_isatty, METH_NOARGS, _io__Buffered_isatty__doc__}, + +static PyObject * +_io__Buffered_isatty_impl(buffered *self); + +static PyObject * +_io__Buffered_isatty(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_isatty_impl(self); +} + +PyDoc_STRVAR(_io__Buffered_flush__doc__, +"flush($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_FLUSH_METHODDEF \ + {"flush", (PyCFunction)_io__Buffered_flush, METH_NOARGS, _io__Buffered_flush__doc__}, + +static PyObject * +_io__Buffered_flush_impl(buffered *self); + +static PyObject * +_io__Buffered_flush(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_flush_impl(self); +} + PyDoc_STRVAR(_io__Buffered_peek__doc__, "peek($self, size=0, /)\n" "--\n" @@ -490,6 +668,23 @@ _io__Buffered_readline(buffered *self, PyObject *const *args, Py_ssize_t nargs) return return_value; } +PyDoc_STRVAR(_io__Buffered_tell__doc__, +"tell($self, /)\n" +"--\n" +"\n"); + +#define _IO__BUFFERED_TELL_METHODDEF \ + {"tell", (PyCFunction)_io__Buffered_tell, METH_NOARGS, _io__Buffered_tell__doc__}, + +static PyObject * +_io__Buffered_tell_impl(buffered *self); + +static PyObject * +_io__Buffered_tell(buffered *self, PyObject *Py_UNUSED(ignored)) +{ + return _io__Buffered_tell_impl(self); +} + PyDoc_STRVAR(_io__Buffered_seek__doc__, "seek($self, target, whence=0, /)\n" "--\n" @@ -532,26 +727,41 @@ PyDoc_STRVAR(_io__Buffered_truncate__doc__, "\n"); #define _IO__BUFFERED_TRUNCATE_METHODDEF \ - {"truncate", _PyCFunction_CAST(_io__Buffered_truncate), METH_FASTCALL, _io__Buffered_truncate__doc__}, + {"truncate", _PyCFunction_CAST(_io__Buffered_truncate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__Buffered_truncate__doc__}, static PyObject * -_io__Buffered_truncate_impl(buffered *self, PyObject *pos); +_io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos); static PyObject * -_io__Buffered_truncate(buffered *self, PyObject *const *args, Py_ssize_t nargs) +_io__Buffered_truncate(buffered *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "truncate", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *pos = Py_None; - if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } if (nargs < 1) { - goto skip_optional; + goto skip_optional_posonly; } pos = args[0]; -skip_optional: - return_value = _io__Buffered_truncate_impl(self, pos); +skip_optional_posonly: + return_value = _io__Buffered_truncate_impl(self, cls, pos); exit: return return_value; @@ -877,4 +1087,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=c4ea041ccc91b5d2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d770e392e8702e12 input=a9049054013a1b77]*/