Skip to content

Commit

Permalink
pythongh-101819: Prepare _io._IOBase for module state
Browse files Browse the repository at this point in the history
- Add PyIOBase_Type to _io module state
- Pass defining class to _io._IOBase.fileno
  • Loading branch information
erlend-aasland committed May 11, 2023
1 parent e629ab6 commit 3d782e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
return 0;
Py_VISIT(state->unsupported_operation);

Py_VISIT(state->PyIOBase_Type);
Py_VISIT(state->PyIncrementalNewlineDecoder_Type);
Py_VISIT(state->PyRawIOBase_Type);
Py_VISIT(state->PyBufferedIOBase_Type);
Expand Down Expand Up @@ -609,6 +610,7 @@ iomodule_clear(PyObject *mod) {
return 0;
Py_CLEAR(state->unsupported_operation);

Py_CLEAR(state->PyIOBase_Type);
Py_CLEAR(state->PyIncrementalNewlineDecoder_Type);
Py_CLEAR(state->PyRawIOBase_Type);
Py_CLEAR(state->PyBufferedIOBase_Type);
Expand Down Expand Up @@ -751,6 +753,7 @@ PyInit__io(void)
}

// Base classes
state->PyIOBase_Type = (PyTypeObject *)Py_NewRef(&PyIOBase_Type);
ADD_TYPE(m, state->PyIncrementalNewlineDecoder_Type, &nldecoder_spec, NULL);
ADD_TYPE(m, state->PyBytesIOBuffer_Type, &bytesiobuf_spec, NULL);

Expand Down
1 change: 1 addition & 0 deletions Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct _io_state {
PyObject *unsupported_operation;

/* Types */
PyTypeObject *PyIOBase_Type;
PyTypeObject *PyIncrementalNewlineDecoder_Type;
PyTypeObject *PyRawIOBase_Type;
PyTypeObject *PyBufferedIOBase_Type;
Expand Down
18 changes: 11 additions & 7 deletions Modules/_io/clinic/iobase.c.h

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

10 changes: 6 additions & 4 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,17 @@ iobase_exit(PyObject *self, PyObject *args)

/*[clinic input]
_io._IOBase.fileno
cls: defining_class
/
Returns underlying file descriptor if one exists.
Return underlying file descriptor if one exists.
OSError is raised if the IO object does not use a file descriptor.
Raise OSError if the IO object does not use a file descriptor.
[clinic start generated code]*/

static PyObject *
_io__IOBase_fileno_impl(PyObject *self)
/*[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/
_io__IOBase_fileno_impl(PyObject *self, PyTypeObject *cls)
/*[clinic end generated code: output=7caaa32a6f4ada3d input=1927c8bea5c85099]*/
{
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "fileno");
Expand Down

0 comments on commit 3d782e9

Please sign in to comment.