Skip to content

Commit 15795b5

Browse files
gh-101819: Prepare _io._IOBase for module state (#104386)
- Add PyIOBase_Type to _io module state - Pass defining class to _io._IOBase.fileno
1 parent 718b132 commit 15795b5

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

Modules/_io/_iomodule.c

+3
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
582582
return 0;
583583
Py_VISIT(state->unsupported_operation);
584584

585+
Py_VISIT(state->PyIOBase_Type);
585586
Py_VISIT(state->PyIncrementalNewlineDecoder_Type);
586587
Py_VISIT(state->PyRawIOBase_Type);
587588
Py_VISIT(state->PyBufferedIOBase_Type);
@@ -609,6 +610,7 @@ iomodule_clear(PyObject *mod) {
609610
return 0;
610611
Py_CLEAR(state->unsupported_operation);
611612

613+
Py_CLEAR(state->PyIOBase_Type);
612614
Py_CLEAR(state->PyIncrementalNewlineDecoder_Type);
613615
Py_CLEAR(state->PyRawIOBase_Type);
614616
Py_CLEAR(state->PyBufferedIOBase_Type);
@@ -751,6 +753,7 @@ PyInit__io(void)
751753
}
752754

753755
// Base classes
756+
state->PyIOBase_Type = (PyTypeObject *)Py_NewRef(&PyIOBase_Type);
754757
ADD_TYPE(m, state->PyIncrementalNewlineDecoder_Type, &nldecoder_spec, NULL);
755758
ADD_TYPE(m, state->PyBytesIOBuffer_Type, &bytesiobuf_spec, NULL);
756759

Modules/_io/_iomodule.h

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct _io_state {
149149
PyObject *unsupported_operation;
150150

151151
/* Types */
152+
PyTypeObject *PyIOBase_Type;
152153
PyTypeObject *PyIncrementalNewlineDecoder_Type;
153154
PyTypeObject *PyRawIOBase_Type;
154155
PyTypeObject *PyBufferedIOBase_Type;

Modules/_io/clinic/iobase.c.h

+11-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/iobase.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,17 @@ iobase_exit(PyObject *self, PyObject *args)
511511

512512
/*[clinic input]
513513
_io._IOBase.fileno
514+
cls: defining_class
515+
/
514516
515-
Returns underlying file descriptor if one exists.
517+
Return underlying file descriptor if one exists.
516518
517-
OSError is raised if the IO object does not use a file descriptor.
519+
Raise OSError if the IO object does not use a file descriptor.
518520
[clinic start generated code]*/
519521

520522
static PyObject *
521-
_io__IOBase_fileno_impl(PyObject *self)
522-
/*[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/
523+
_io__IOBase_fileno_impl(PyObject *self, PyTypeObject *cls)
524+
/*[clinic end generated code: output=7caaa32a6f4ada3d input=1927c8bea5c85099]*/
523525
{
524526
_PyIO_State *state = IO_STATE();
525527
return iobase_unsupported(state, "fileno");

0 commit comments

Comments
 (0)