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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/iobase.c

Lines changed: 6 additions & 4 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy