Repository navigation
Isolate the _io extension module #101819
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementextension-modulesC modules in the Modules dirC modules in the Modules dir
on Feb 11, 2023 cc. @kumaraditya303
I see that
_PyWindowsConsoleIO_Typeis marked withPyAPI_DATA, but I can't find it inMisc/stable_abi.toml. @zooba or @eryksun, do you know why this is so? I did a quick code search on GitHub, but I only got hits in various clones of the CPython code base.cpython/Modules/_io/_iomodule.h
Lines 24 to 30 in 2db2c4b
#ifndef Py_LIMITED_API #ifdef MS_WINDOWS extern PyTypeObject PyWindowsConsoleIO_Type; PyAPI_DATA(PyObject *) _PyWindowsConsoleIO_Type; #define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), (PyTypeObject*)_PyWindowsConsoleIO_Type)) #endif /* MS_WINDOWS */ #endif /* Py_LIMITED_API */ UPDATE: I see it was added by Steve in 312cef7, probably because of the
PyWindowsConsoleIO_Checkchecks inPC/_testconsole.candPython/pylifecycle.c:Lines 54 to 57 in 2db2c4b
if (!PyWindowsConsoleIO_Check(file)) { PyErr_SetString(PyExc_TypeError, "expected raw console object"); return NULL; } Lines 58 to 61 in 2db2c4b
extern PyTypeObject PyWindowsConsoleIO_Type; # define PyWindowsConsoleIO_Check(op) \ (PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type)) #endif Lines 2359 to 2363 in 2db2c4b
#ifdef MS_WINDOWS /* Windows console IO is always UTF-8 encoded */ if (PyWindowsConsoleIO_Check(raw)) encoding = L"utf-8"; #endif Perhaps exposing
_PyWindowsConsoleIO_Typethrough a CPython internal capsulated C API could be an option?Other issues that must be resolved before continuing:
_PyBytesIOBuffer_Typeis used by_testcapimodule. Since that type is not exposed in_io, we cannot simply usePyImport_Importand look it up. One possibility is to expose it through a CPython internal capsule C API.... or we could simply expose the types mentioned in #101819 (comment) and #101819 (comment) in the
_iomodule.Internal types are allowed to be exported without being stable API. On Windows, only explicitly exported names are available outside the DLL - it's different on other platforms, so please don't bring their assumptions over 😉
Reacted by Erlend E. AaslandThe type is explicitly not part of the limited API/stable ABI, see
#ifndef Py_LIMITED_API.Reacted by Erlend E. AaslandInternal types are allowed to be exported without being stable API. On Windows, only explicitly exported names are available outside the DLL - it's different on other platforms, so please don't bring their assumptions over 😉
IIUC, we can remove this from the DLL and instead export it via
_ioand look it up from the module using the C API (PyImport_Import, etc.).Yeah, if it's got a leading underscore then we can do whatever we need to make our tests work.
Reacted by Erlend E. AaslandReacted by Erlend E. Aasland50 remaining items
- added a commit that references this issue
on May 11, 2023 - added a commit that references this issue
on May 11, 2023 - added a commit that references this issue
on May 12, 2023 - added a commit that references this issue
on May 15, 2023 - added a commit that references this issue
on May 15, 2023 - added 2 commits that reference this issue
on May 15, 2023 @erlend-aasland erlend-aasland closed this as completed
Great achievement!
Reacted by Erlend E. Aasland
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Isolate the
_ioextension module by moving all global variables to module state, porting static types to heap types, and implementing multi-phase init. All global variables in the_iomodule are static types:Converting the static types to heap types involves applying PEP-687 to
_io.Adapting multi-phase init involves applying PEP-489 to
_io.Linked PRs