Skip to content

Commit 31c394c

Browse files
pythongh-101819: Remove _PyWindowsConsoleIO_Type from the Windows DLL
1 parent e5da9ab commit 31c394c

8 files changed

+24
-13
lines changed

Include/internal/pycore_global_objects_fini_generated.h

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

Include/internal/pycore_global_strings.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct _Py_global_strings {
6363
STRUCT_FOR_ID(True)
6464
STRUCT_FOR_ID(WarningMessage)
6565
STRUCT_FOR_ID(_)
66+
STRUCT_FOR_ID(_WindowsConsoleIO)
6667
STRUCT_FOR_ID(__IOBase_closed)
6768
STRUCT_FOR_ID(__abc_tpflags__)
6869
STRUCT_FOR_ID(__abs__)

Include/internal/pycore_runtime_init_generated.h

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

Include/internal/pycore_unicodeobject_generated.h

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

Modules/_io/_iomodule.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ extern PyTypeObject PyBufferedRandom_Type;
2121
extern PyTypeObject PyTextIOWrapper_Type;
2222
extern PyTypeObject PyIncrementalNewlineDecoder_Type;
2323

24-
#ifndef Py_LIMITED_API
2524
#ifdef MS_WINDOWS
2625
extern PyTypeObject PyWindowsConsoleIO_Type;
27-
PyAPI_DATA(PyObject *) _PyWindowsConsoleIO_Type;
28-
#define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), (PyTypeObject*)_PyWindowsConsoleIO_Type))
29-
#endif /* MS_WINDOWS */
30-
#endif /* Py_LIMITED_API */
26+
#define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), (PyTypeObject*)PyWindowsConsoleIO_Type))
27+
#endif
3128

3229
/* These functions are used as METH_NOARGS methods, are normally called
3330
* with args=NULL, and return a new reference.

Modules/_io/winconsoleio.c

-2
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,4 @@ PyTypeObject PyWindowsConsoleIO_Type = {
11741174
0, /* tp_finalize */
11751175
};
11761176

1177-
PyObject * _PyWindowsConsoleIO_Type = (PyObject*)&PyWindowsConsoleIO_Type;
1178-
11791177
#endif /* MS_WINDOWS */

PC/_testconsole.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
5151
{
5252
INPUT_RECORD *rec = NULL;
5353

54-
if (!PyWindowsConsoleIO_Check(file)) {
54+
PyObject *winconsoleio_type = _PyImport_GetModuleAttr(
55+
"_io", &_Py_ID(_WindowsConsoleIO));
56+
if (winconsoleio_type == NULL) {
57+
return NULL;
58+
}
59+
int is_subclass = PyObject_TypeCheck(raw, winconsoleio_type);
60+
Py_DECREF(winconsoleio_type);
61+
if (!is_subclass) {
5562
PyErr_SetString(PyExc_TypeError, "expected raw console object");
5663
return NULL;
5764
}

Python/pylifecycle.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ extern void _PyIO_Fini(void);
5454

5555
#ifdef MS_WINDOWS
5656
# undef BYTE
57-
58-
extern PyTypeObject PyWindowsConsoleIO_Type;
59-
# define PyWindowsConsoleIO_Check(op) \
60-
(PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
6157
#endif
6258

6359
#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
@@ -2358,8 +2354,16 @@ create_stdio(const PyConfig *config, PyObject* io,
23582354

23592355
#ifdef MS_WINDOWS
23602356
/* Windows console IO is always UTF-8 encoded */
2361-
if (PyWindowsConsoleIO_Check(raw))
2357+
PyObject *winconsoleio_type = _PyImport_GetModuleAttr(
2358+
"_io", &_Py_ID(_WindowsConsoleIO));
2359+
if (winconsoleio_type == NULL) {
2360+
goto error;
2361+
}
2362+
int is_subclass = PyObject_TypeCheck(raw, winconsoleio_type);
2363+
Py_DECREF(winconsoleio_type);
2364+
if (is_subclass) {
23622365
encoding = L"utf-8";
2366+
}
23632367
#endif
23642368

23652369
text = PyUnicode_FromString(name);

0 commit comments

Comments
 (0)