Skip to content

Commit

Permalink
pythongh-101819: Adapt _io.IOBase.seek and _io.IOBase.truncate to Arg…
Browse files Browse the repository at this point in the history
…ument Clinic

Pass defining class, so we can easily fetch module state in the future.
  • Loading branch information
erlend-aasland committed May 11, 2023
1 parent 7470321 commit d5a2b6e
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 22 deletions.
102 changes: 101 additions & 1 deletion Modules/_io/clinic/iobase.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 34 additions & 21 deletions Modules/_io/iobase.c
Expand Up @@ -79,21 +79,27 @@ iobase_unsupported(_PyIO_State *state, const char *message)

/* Positioning */

PyDoc_STRVAR(iobase_seek_doc,
"Change stream position.\n"
"\n"
"Change the stream position to the given byte offset. The offset is\n"
"interpreted relative to the position indicated by whence. Values\n"
"for whence are:\n"
"\n"
"* 0 -- start of stream (the default); offset should be zero or positive\n"
"* 1 -- current stream position; offset may be negative\n"
"* 2 -- end of stream; offset is usually negative\n"
"\n"
"Return the new absolute position.");
/*[clinic input]
_io._IOBase.seek
cls: defining_class
/
*args: object
Change the stream position to the given byte offset.
The offset is interpreted relative to the position indicated by whence.
Values for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offset is usually negative
Return the new absolute position.
[clinic start generated code]*/

static PyObject *
iobase_seek(PyObject *self, PyObject *args)
_io__IOBase_seek_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
/*[clinic end generated code: output=1dd694ac9de260fa input=ebb5476eb22fc5d4]*/
{
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "seek");
Expand All @@ -112,14 +118,21 @@ _io__IOBase_tell_impl(PyObject *self)
return _PyObject_CallMethod(self, &_Py_ID(seek), "ii", 0, 1);
}

PyDoc_STRVAR(iobase_truncate_doc,
"Truncate file to size bytes.\n"
"\n"
"File pointer is left unchanged. Size defaults to the current IO\n"
"position as reported by tell(). Returns the new size.");
/*[clinic input]
_io._IOBase.truncate
cls: defining_class
/
*args: object
Truncate file to size bytes.
File pointer is left unchanged. Size defaults to the current IO position
as reported by tell(). Return the new size.
[clinic start generated code]*/

static PyObject *
iobase_truncate(PyObject *self, PyObject *args)
_io__IOBase_truncate_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
/*[clinic end generated code: output=b7eed4649cbe22c1 input=ad90582a1d8b5cc9]*/
{
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "truncate");
Expand Down Expand Up @@ -809,9 +822,9 @@ _io__IOBase_writelines(PyObject *self, PyObject *lines)
#include "clinic/iobase.c.h"

static PyMethodDef iobase_methods[] = {
{"seek", iobase_seek, METH_VARARGS, iobase_seek_doc},
_IO__IOBASE_SEEK_METHODDEF
_IO__IOBASE_TELL_METHODDEF
{"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc},
_IO__IOBASE_TRUNCATE_METHODDEF
_IO__IOBASE_FLUSH_METHODDEF
_IO__IOBASE_CLOSE_METHODDEF

Expand Down

0 comments on commit d5a2b6e

Please sign in to comment.