summaryrefslogtreecommitdiffstats
path: root/Modules/_io/_iomodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-05-05 23:53:55 (GMT)
committerGitHub <noreply@github.com>2023-05-05 23:53:55 (GMT)
commitc84029179c3287f9c357ccac231fe78469c6f068 (patch)
tree4b30494f97bc9d71bb6381753e96441cbefc9dce /Modules/_io/_iomodule.c
parent8b7f37dd4c297138e9f4a256ff6750cf1402b421 (diff)
downloadcpython-c84029179c3287f9c357ccac231fe78469c6f068.zip
cpython-c84029179c3287f9c357ccac231fe78469c6f068.tar.gz
cpython-c84029179c3287f9c357ccac231fe78469c6f068.tar.bz2
gh-101819: Prepare to modernize the _io extension (#104178)
* Add references to static types to _PyIO_State: * PyBufferedIOBase_Type * PyBytesIOBuffer_Type * PyIncrementalNewlineDecoder_Type * PyRawIOBase_Type * PyTextIOBase_Type * Add the defining class to methods: * _io.BytesIO.getbuffer() * _io.FileIO.close() * Add get_io_state_by_cls() function. * Add state parameter to _textiowrapper_decode() * _io_TextIOWrapper___init__() now sets self->state before calling _textiowrapper_set_decoder(). Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules/_io/_iomodule.c')
-rw-r--r--Modules/_io/_iomodule.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 8ec3a60..403968a 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -583,13 +583,18 @@ iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
Py_VISIT(state->locale_module);
Py_VISIT(state->unsupported_operation);
+ Py_VISIT(state->PyIncrementalNewlineDecoder_Type);
+ Py_VISIT(state->PyRawIOBase_Type);
+ Py_VISIT(state->PyBufferedIOBase_Type);
Py_VISIT(state->PyBufferedRWPair_Type);
Py_VISIT(state->PyBufferedRandom_Type);
Py_VISIT(state->PyBufferedReader_Type);
Py_VISIT(state->PyBufferedWriter_Type);
+ Py_VISIT(state->PyBytesIOBuffer_Type);
Py_VISIT(state->PyBytesIO_Type);
Py_VISIT(state->PyFileIO_Type);
Py_VISIT(state->PyStringIO_Type);
+ Py_VISIT(state->PyTextIOBase_Type);
Py_VISIT(state->PyTextIOWrapper_Type);
return 0;
}
@@ -604,13 +609,18 @@ iomodule_clear(PyObject *mod) {
Py_CLEAR(state->locale_module);
Py_CLEAR(state->unsupported_operation);
+ Py_CLEAR(state->PyIncrementalNewlineDecoder_Type);
+ Py_CLEAR(state->PyRawIOBase_Type);
+ Py_CLEAR(state->PyBufferedIOBase_Type);
Py_CLEAR(state->PyBufferedRWPair_Type);
Py_CLEAR(state->PyBufferedRandom_Type);
Py_CLEAR(state->PyBufferedReader_Type);
Py_CLEAR(state->PyBufferedWriter_Type);
+ Py_CLEAR(state->PyBytesIOBuffer_Type);
Py_CLEAR(state->PyBytesIO_Type);
Py_CLEAR(state->PyFileIO_Type);
Py_CLEAR(state->PyStringIO_Type);
+ Py_CLEAR(state->PyTextIOBase_Type);
Py_CLEAR(state->PyTextIOWrapper_Type);
return 0;
}
@@ -749,24 +759,33 @@ PyInit__io(void)
}
}
+ // Base classes
+ state->PyIncrementalNewlineDecoder_Type = (PyTypeObject *)Py_NewRef(&PyIncrementalNewlineDecoder_Type);
+
+ // PyIOBase_Type subclasses
+ state->PyRawIOBase_Type = (PyTypeObject *)Py_NewRef(&PyRawIOBase_Type);
+ state->PyBufferedIOBase_Type = (PyTypeObject *)Py_NewRef(&PyBufferedIOBase_Type);
+ state->PyTextIOBase_Type = (PyTypeObject *)Py_NewRef(&PyTextIOBase_Type);
+
// PyBufferedIOBase_Type(PyIOBase_Type) subclasses
- ADD_TYPE(m, state->PyBytesIO_Type, &bytesio_spec, &PyBufferedIOBase_Type);
+ ADD_TYPE(m, state->PyBytesIO_Type, &bytesio_spec, state->PyBufferedIOBase_Type);
ADD_TYPE(m, state->PyBufferedWriter_Type, &bufferedwriter_spec,
- &PyBufferedIOBase_Type);
+ state->PyBufferedIOBase_Type);
ADD_TYPE(m, state->PyBufferedReader_Type, &bufferedreader_spec,
- &PyBufferedIOBase_Type);
+ state->PyBufferedIOBase_Type);
ADD_TYPE(m, state->PyBufferedRWPair_Type, &bufferedrwpair_spec,
- &PyBufferedIOBase_Type);
+ state->PyBufferedIOBase_Type);
ADD_TYPE(m, state->PyBufferedRandom_Type, &bufferedrandom_spec,
- &PyBufferedIOBase_Type);
+ state->PyBufferedIOBase_Type);
// PyRawIOBase_Type(PyIOBase_Type) subclasses
- ADD_TYPE(m, state->PyFileIO_Type, &fileio_spec, &PyRawIOBase_Type);
+ state->PyBytesIOBuffer_Type = (PyTypeObject *)Py_NewRef(&_PyBytesIOBuffer_Type);
+ ADD_TYPE(m, state->PyFileIO_Type, &fileio_spec, state->PyRawIOBase_Type);
// PyTextIOBase_Type(PyIOBase_Type) subclasses
- ADD_TYPE(m, state->PyStringIO_Type, &stringio_spec, &PyTextIOBase_Type);
+ ADD_TYPE(m, state->PyStringIO_Type, &stringio_spec, state->PyTextIOBase_Type);
ADD_TYPE(m, state->PyTextIOWrapper_Type, &textiowrapper_spec,
- &PyTextIOBase_Type);
+ state->PyTextIOBase_Type);
state->initialized = 1;