Skip to content

Commit 3cf7a20

Browse files
committed
Revert _testconsole change: it uses the limited C API
1 parent a54e98b commit 3cf7a20

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

PC/_testconsole.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ static PyObject *
6666
_testconsole_write_input_impl(PyObject *module, PyObject *file, Py_buffer *s)
6767
/*[clinic end generated code: output=58631a8985426ad3 input=68062f1bb2e52206]*/
6868
{
69-
PyTypeObject *winconsoleio_type;
70-
winconsoleio_type = (PyTypeObject *)PyImport_ImportModuleAttrString(
71-
"_io",
72-
"_WindowsConsoleIO");
69+
INPUT_RECORD *rec = NULL;
70+
71+
PyObject *mod = PyImport_ImportModule("_io");
72+
if (mod == NULL) {
73+
return NULL;
74+
}
75+
76+
PyTypeObject *winconsoleio_type = (PyTypeObject *)PyObject_GetAttrString(mod, "_WindowsConsoleIO");
77+
Py_DECREF(mod);
7378
if (winconsoleio_type == NULL) {
7479
return NULL;
7580
}
@@ -83,7 +88,7 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file, Py_buffer *s)
8388
const wchar_t *p = (const wchar_t *)s->buf;
8489
DWORD size = (DWORD)s->len / sizeof(wchar_t);
8590

86-
INPUT_RECORD *rec = (INPUT_RECORD*)PyMem_Calloc(size, sizeof(INPUT_RECORD));
91+
rec = (INPUT_RECORD*)PyMem_Calloc(size, sizeof(INPUT_RECORD));
8792
if (!rec)
8893
goto error;
8994

0 commit comments

Comments
 (0)