Skip to content

Commit e9150a1

Browse files
pythongh-101819: Remove _PyWindowsConsoleIO_Type from the Windows DLL
1 parent d919917 commit e9150a1

8 files changed

+15
-16
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

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ extern PyTypeObject PyBufferedRandom_Type;
2121
extern PyTypeObject PyTextIOWrapper_Type;
2222
extern PyTypeObject PyIncrementalNewlineDecoder_Type;
2323

24-
#ifndef Py_LIMITED_API
25-
#ifdef MS_WINDOWS
26-
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 */
31-
3224
/* These functions are used as METH_NOARGS methods, are normally called
3325
* with args=NULL, and return a new reference.
3426
* BUT when args=Py_True is passed, they return a borrowed 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

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

54+
int is_subclass = PyObject_TypeCheck(raw, winconsoleio_type);
5455
if (!PyWindowsConsoleIO_Check(file)) {
5556
PyErr_SetString(PyExc_TypeError, "expected raw console object");
5657
return NULL;

Python/pylifecycle.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ extern void _PyIO_Fini(void);
5555
#ifdef MS_WINDOWS
5656
# undef BYTE
5757

58-
extern PyTypeObject PyWindowsConsoleIO_Type;
59-
# define PyWindowsConsoleIO_Check(op) \
60-
(PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
61-
#endif
62-
6358
#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
6459

6560

@@ -2358,8 +2353,16 @@ create_stdio(const PyConfig *config, PyObject* io,
23582353

23592354
#ifdef MS_WINDOWS
23602355
/* Windows console IO is always UTF-8 encoded */
2361-
if (PyWindowsConsoleIO_Check(raw))
2356+
PyObject *winconsoleio_type = PyObject_GetAttr(
2357+
buf, &_Py_ID(_WindowsConsoleIO));
2358+
if (winconsoleio_type == NULL) {
2359+
goto error;
2360+
}
2361+
int is_subclass = PyObject_TypeCheck(raw, winconsoleio_type);
2362+
Py_DECREF(winconsoleio_type);
2363+
if (is_subclass) {
23622364
encoding = L"utf-8";
2365+
}
23632366
#endif
23642367

23652368
text = PyUnicode_FromString(name);

0 commit comments

Comments
 (0)