_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__));
_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));
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__)
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)
INIT_ID(True), \
INIT_ID(WarningMessage), \
INIT_ID(_), \
+ INIT_ID(_WindowsConsoleIO), \
INIT_ID(__IOBase_closed), \
INIT_ID(__abc_tpflags__), \
INIT_ID(__abs__), \
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), \
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__);
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_);
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.
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. */
0, /* tp_finalize */
};
-PyObject * _PyWindowsConsoleIO_Type = (PyObject*)&PyWindowsConsoleIO_Type;
-
#endif /* MS_WINDOWS */
#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>
{
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;
}
#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))
#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);