]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101819: Remove _PyWindowsConsoleIO_Type from the Windows DLL (GH-101904)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Wed, 15 Feb 2023 13:07:59 +0000 (14:07 +0100)
committerGitHub <noreply@github.com>
Wed, 15 Feb 2023 13:07:59 +0000 (05:07 -0800)
Automerge-Triggered-By: GH:erlend-aasland
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_unicodeobject_generated.h
Modules/_io/_iomodule.h
Modules/_io/winconsoleio.c
PC/_testconsole.c
Python/pylifecycle.c

index 8c210111b5899fac86c7b7c92d44bd2a7424e272..dc5cd58d853534bb9edc327861f6edb02a722b74 100644 (file)
@@ -577,6 +577,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(True));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(WarningMessage));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_));
+    _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_WindowsConsoleIO));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__IOBase_closed));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__abc_tpflags__));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__abs__));
@@ -752,6 +753,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_get_sourcefile));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_handle_fromlist));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_initializing));
+    _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_io));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_is_text_encoding));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_length_));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_limbo));
index 6b1c8424424d969033430efa70204d9dfcd7a6d6..8b23aa1547930180fee4c76a632fe8076adeed79 100644 (file)
@@ -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__)
@@ -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)
index fcb613083ffe9998e1d0ee64f5213ca04913af22..471efadb13bb4f4f761e4caabe65e1cbe25da25f 100644 (file)
@@ -569,6 +569,7 @@ extern "C" {
     INIT_ID(True), \
     INIT_ID(WarningMessage), \
     INIT_ID(_), \
+    INIT_ID(_WindowsConsoleIO), \
     INIT_ID(__IOBase_closed), \
     INIT_ID(__abc_tpflags__), \
     INIT_ID(__abs__), \
@@ -744,6 +745,7 @@ extern "C" {
     INIT_ID(_get_sourcefile), \
     INIT_ID(_handle_fromlist), \
     INIT_ID(_initializing), \
+    INIT_ID(_io), \
     INIT_ID(_is_text_encoding), \
     INIT_ID(_length_), \
     INIT_ID(_limbo), \
index 301aee5210e799e38d7bdaa76b944d221262bc9d..b47d240e492ff9760142e78cf520d6d6955ca779 100644 (file)
@@ -32,6 +32,8 @@ _PyUnicode_InitStaticStrings(void) {
     PyUnicode_InternInPlace(&string);
     string = &_Py_ID(_);
     PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_WindowsConsoleIO);
+    PyUnicode_InternInPlace(&string);
     string = &_Py_ID(__IOBase_closed);
     PyUnicode_InternInPlace(&string);
     string = &_Py_ID(__abc_tpflags__);
@@ -382,6 +384,8 @@ _PyUnicode_InitStaticStrings(void) {
     PyUnicode_InternInPlace(&string);
     string = &_Py_ID(_initializing);
     PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_io);
+    PyUnicode_InternInPlace(&string);
     string = &_Py_ID(_is_text_encoding);
     PyUnicode_InternInPlace(&string);
     string = &_Py_ID(_length_);
index c260080f0e348b9f59287e1bfcf351cb959d172a..7617cb8fb70e43adebd1e1746e1f84cc55749a1d 100644 (file)
@@ -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.
index 4f41ab965e2e676c87641d3c1f5ccae7b827eb5a..e913d83187461742b1bc21b2c7f7b2e1c0af7808 100644 (file)
@@ -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. */
@@ -1174,6 +1174,4 @@ PyTypeObject PyWindowsConsoleIO_Type = {
     0,                                          /* tp_finalize */
 };
 
-PyObject * _PyWindowsConsoleIO_Type = (PyObject*)&PyWindowsConsoleIO_Type;
-
 #endif /* MS_WINDOWS */
index a8308835d8f85dc061c5d4c89b23f5f4ac745fe1..f14a2d45b1be26ee6291580a39a852afcef84296 100644 (file)
@@ -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>
@@ -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;
     }
index a8a8e7f3d84f2116dce6754c9fd0a28e20c80d1f..045a2996e8988b6cd8fcce887fdf18a342713097 100644 (file)
@@ -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))
@@ -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);