Skip to content

Commit

Permalink
pythongh-101819: Remove _PyWindowsConsoleIO_Type from the Windows DLL
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Feb 14, 2023
1 parent d919917 commit e9150a1
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(True)
STRUCT_FOR_ID(WarningMessage)
STRUCT_FOR_ID(_)
STRUCT_FOR_ID(_WindowsConsoleIO)
STRUCT_FOR_ID(__IOBase_closed)
STRUCT_FOR_ID(__abc_tpflags__)
STRUCT_FOR_ID(__abs__)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ extern PyTypeObject PyBufferedRandom_Type;
extern PyTypeObject PyTextIOWrapper_Type;
extern PyTypeObject PyIncrementalNewlineDecoder_Type;

#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 */

/* These functions are used as METH_NOARGS methods, are normally called
* with args=NULL, and return a new reference.
* BUT when args=Py_True is passed, they return a borrowed reference.
Expand Down
2 changes: 0 additions & 2 deletions Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,4 @@ PyTypeObject PyWindowsConsoleIO_Type = {
0, /* tp_finalize */
};

PyObject * _PyWindowsConsoleIO_Type = (PyObject*)&PyWindowsConsoleIO_Type;

#endif /* MS_WINDOWS */
1 change: 1 addition & 0 deletions PC/_testconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
{
INPUT_RECORD *rec = NULL;

int is_subclass = PyObject_TypeCheck(raw, winconsoleio_type);
if (!PyWindowsConsoleIO_Check(file)) {
PyErr_SetString(PyExc_TypeError, "expected raw console object");
return NULL;
Expand Down
15 changes: 9 additions & 6 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ extern void _PyIO_Fini(void);
#ifdef MS_WINDOWS
# undef BYTE

extern PyTypeObject PyWindowsConsoleIO_Type;
# define PyWindowsConsoleIO_Check(op) \
(PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
#endif

#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))


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

#ifdef MS_WINDOWS
/* Windows console IO is always UTF-8 encoded */
if (PyWindowsConsoleIO_Check(raw))
PyObject *winconsoleio_type = PyObject_GetAttr(
buf, &_Py_ID(_WindowsConsoleIO));
if (winconsoleio_type == NULL) {
goto error;
}
int is_subclass = PyObject_TypeCheck(raw, winconsoleio_type);
Py_DECREF(winconsoleio_type);
if (is_subclass) {
encoding = L"utf-8";
}
#endif

text = PyUnicode_FromString(name);
Expand Down

0 comments on commit e9150a1

Please sign in to comment.