Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-101819: Remove _PyWindowsConsoleIO_Type from the Windows DLL #101904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 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.

2 changes: 2 additions & 0 deletions 2 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 Expand Up @@ -238,6 +239,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(_get_sourcefile)
STRUCT_FOR_ID(_handle_fromlist)
STRUCT_FOR_ID(_initializing)
STRUCT_FOR_ID(_io)
STRUCT_FOR_ID(_is_text_encoding)
STRUCT_FOR_ID(_length_)
STRUCT_FOR_ID(_limbo)
Expand Down
2 changes: 2 additions & 0 deletions 2 Include/internal/pycore_runtime_init_generated.h

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

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

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

4 changes: 0 additions & 4 deletions 4 Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ 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.
Expand Down
4 changes: 1 addition & 3 deletions 4 Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
int fd_is_own = 0;
HANDLE handle = NULL;

assert(PyWindowsConsoleIO_Check(self));
assert(PyObject_TypeCheck(self, (PyTypeObject *)&PyWindowsConsoleIO_Type));
if (self->fd >= 0) {
if (self->closefd) {
/* Have to close the existing file first. */
Expand Down Expand Up @@ -1174,6 +1174,4 @@ PyTypeObject PyWindowsConsoleIO_Type = {
0, /* tp_finalize */
};

PyObject * _PyWindowsConsoleIO_Type = (PyObject*)&PyWindowsConsoleIO_Type;

#endif /* MS_WINDOWS */
11 changes: 9 additions & 2 deletions 11 PC/_testconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifdef MS_WINDOWS

#include "pycore_fileutils.h" // _Py_get_osfhandle()
#include "..\modules\_io\_iomodule.h"
#include "pycore_runtime.h" // _Py_ID()

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Expand Down Expand Up @@ -51,7 +51,14 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
{
INPUT_RECORD *rec = NULL;

if (!PyWindowsConsoleIO_Check(file)) {
PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr(
&_Py_ID(_io), &_Py_ID(_WindowsConsoleIO));
if (winconsoleio_type == NULL) {
return NULL;
}
int is_subclass = PyObject_TypeCheck(file, winconsoleio_type);
Py_DECREF(winconsoleio_type);
if (!is_subclass) {
PyErr_SetString(PyExc_TypeError, "expected raw console object");
return NULL;
}
Expand Down
14 changes: 9 additions & 5 deletions 14 Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,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 +2354,16 @@ create_stdio(const PyConfig *config, PyObject* io,

#ifdef MS_WINDOWS
/* Windows console IO is always UTF-8 encoded */
if (PyWindowsConsoleIO_Check(raw))
PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr(
&_Py_ID(_io), &_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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.