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

Commit eb0c485

Browse filesBrowse files
gh-101819: Remove _PyWindowsConsoleIO_Type from the Windows DLL (GH-101904)
Automerge-Triggered-By: GH:erlend-aasland
1 parent c776624 commit eb0c485
Copy full SHA for eb0c485

File tree

Expand file treeCollapse file tree

8 files changed

+29
-14
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+29
-14
lines changed

‎Include/internal/pycore_global_objects_fini_generated.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_global_objects_fini_generated.h
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/internal/pycore_global_strings.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_global_strings.h
+2Lines changed: 2 additions & 0 deletions
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__)
@@ -238,6 +239,7 @@ struct _Py_global_strings {
238239
STRUCT_FOR_ID(_get_sourcefile)
239240
STRUCT_FOR_ID(_handle_fromlist)
240241
STRUCT_FOR_ID(_initializing)
242+
STRUCT_FOR_ID(_io)
241243
STRUCT_FOR_ID(_is_text_encoding)
242244
STRUCT_FOR_ID(_length_)
243245
STRUCT_FOR_ID(_limbo)

‎Include/internal/pycore_runtime_init_generated.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_runtime_init_generated.h
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/internal/pycore_unicodeobject_generated.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_unicodeobject_generated.h
+4Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/_iomodule.h

Copy file name to clipboardExpand all lines: Modules/_io/_iomodule.h
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ 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))
2926
#endif /* MS_WINDOWS */
30-
#endif /* Py_LIMITED_API */
3127

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

‎Modules/_io/winconsoleio.c

Copy file name to clipboardExpand all lines: Modules/_io/winconsoleio.c
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
260260
int fd_is_own = 0;
261261
HANDLE handle = NULL;
262262

263-
assert(PyWindowsConsoleIO_Check(self));
263+
assert(PyObject_TypeCheck(self, (PyTypeObject *)&PyWindowsConsoleIO_Type));
264264
if (self->fd >= 0) {
265265
if (self->closefd) {
266266
/* Have to close the existing file first. */
@@ -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

Copy file name to clipboardExpand all lines: PC/_testconsole.c
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifdef MS_WINDOWS
1111

1212
#include "pycore_fileutils.h" // _Py_get_osfhandle()
13-
#include "..\modules\_io\_iomodule.h"
13+
#include "pycore_runtime.h" // _Py_ID()
1414

1515
#define WIN32_LEAN_AND_MEAN
1616
#include <windows.h>
@@ -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+
PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr(
55+
&_Py_ID(_io), &_Py_ID(_WindowsConsoleIO));
56+
if (winconsoleio_type == NULL) {
57+
return NULL;
58+
}
59+
int is_subclass = PyObject_TypeCheck(file, 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

Copy file name to clipboardExpand all lines: Python/pylifecycle.c
+9-5Lines changed: 9 additions & 5 deletions
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+
PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr(
2358+
&_Py_ID(_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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.