summaryrefslogtreecommitdiffstats
path: root/PC/clinic/_testconsole.c.h
diff options
context:
space:
mode:
authorAN Long <aisk@users.noreply.github.com>2023-09-22 00:19:48 (GMT)
committerGitHub <noreply@github.com>2023-09-22 00:19:48 (GMT)
commit4230d7ce93cc25e9c5fb564a0b37e93f19ca0e4e (patch)
tree2265d9ec87f128bdacef37a34edf4ec2d12ef56f /PC/clinic/_testconsole.c.h
parent3f5c5649cfefe5b03cebe53b3ae766e2739eee23 (diff)
downloadcpython-4230d7ce93cc25e9c5fb564a0b37e93f19ca0e4e.zip
cpython-4230d7ce93cc25e9c5fb564a0b37e93f19ca0e4e.tar.gz
cpython-4230d7ce93cc25e9c5fb564a0b37e93f19ca0e4e.tar.bz2
gh-108996: fix and enable test_msvcrt (#109226)
* Add _testconsole.flush_console_input_buffer() function. * test_kbhit(), test_getwch() and test_getwche() now call flush_console_input_buffer(). * Don't override sys.stdin anymore (not needed).
Diffstat (limited to 'PC/clinic/_testconsole.c.h')
-rw-r--r--PC/clinic/_testconsole.c.h70
1 files changed, 69 insertions, 1 deletions
diff --git a/PC/clinic/_testconsole.c.h b/PC/clinic/_testconsole.c.h
index 99cd302..b765889 100644
--- a/PC/clinic/_testconsole.c.h
+++ b/PC/clinic/_testconsole.c.h
@@ -132,6 +132,70 @@ exit:
#endif /* defined(MS_WINDOWS) */
+#if defined(MS_WINDOWS)
+
+PyDoc_STRVAR(_testconsole_flush_console_input_buffer__doc__,
+"flush_console_input_buffer($module, /, handle)\n"
+"--\n"
+"\n"
+"Flushes the console input buffer.\n"
+"\n"
+"All input records currently in the input buffer are discarded.");
+
+#define _TESTCONSOLE_FLUSH_CONSOLE_INPUT_BUFFER_METHODDEF \
+ {"flush_console_input_buffer", _PyCFunction_CAST(_testconsole_flush_console_input_buffer), METH_FASTCALL|METH_KEYWORDS, _testconsole_flush_console_input_buffer__doc__},
+
+static PyObject *
+_testconsole_flush_console_input_buffer_impl(PyObject *module, void *handle);
+
+static PyObject *
+_testconsole_flush_console_input_buffer(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 1
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(handle), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"handle", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "flush_console_input_buffer",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[1];
+ void *handle;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ handle = PyLong_AsVoidPtr(args[0]);
+ if (!handle && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = _testconsole_flush_console_input_buffer_impl(module, handle);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(MS_WINDOWS) */
+
#ifndef _TESTCONSOLE_WRITE_INPUT_METHODDEF
#define _TESTCONSOLE_WRITE_INPUT_METHODDEF
#endif /* !defined(_TESTCONSOLE_WRITE_INPUT_METHODDEF) */
@@ -139,4 +203,8 @@ exit:
#ifndef _TESTCONSOLE_READ_OUTPUT_METHODDEF
#define _TESTCONSOLE_READ_OUTPUT_METHODDEF
#endif /* !defined(_TESTCONSOLE_READ_OUTPUT_METHODDEF) */
-/*[clinic end generated code: output=f59fe72cd4e73704 input=a9049054013a1b77]*/
+
+#ifndef _TESTCONSOLE_FLUSH_CONSOLE_INPUT_BUFFER_METHODDEF
+ #define _TESTCONSOLE_FLUSH_CONSOLE_INPUT_BUFFER_METHODDEF
+#endif /* !defined(_TESTCONSOLE_FLUSH_CONSOLE_INPUT_BUFFER_METHODDEF) */
+/*[clinic end generated code: output=5d488564f2500dd9 input=a9049054013a1b77]*/