summaryrefslogtreecommitdiffstats
path: root/PC/clinic
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-03-21 16:45:43 (GMT)
committerGitHub <noreply@github.com>2024-03-21 16:45:43 (GMT)
commitabdd1f938f08e536864532b2071f144515ecc88b (patch)
treee17a96a927762c4364996c2fe1ee47a18d08bd10 /PC/clinic
parent8bea6c411d65cd987616b4ecdb86373e4f21f1c6 (diff)
downloadcpython-abdd1f938f08e536864532b2071f144515ecc88b.zip
cpython-abdd1f938f08e536864532b2071f144515ecc88b.tar.gz
cpython-abdd1f938f08e536864532b2071f144515ecc88b.tar.bz2
gh-85283: Build _testconsole extension with limited C API (#117125)
Diffstat (limited to 'PC/clinic')
-rw-r--r--PC/clinic/_testconsole.c.h99
1 files changed, 19 insertions, 80 deletions
diff --git a/PC/clinic/_testconsole.c.h b/PC/clinic/_testconsole.c.h
index 2c71c11..4c11e54 100644
--- a/PC/clinic/_testconsole.c.h
+++ b/PC/clinic/_testconsole.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
-
#if defined(MS_WINDOWS)
PyDoc_STRVAR(_testconsole_write_input__doc__,
@@ -17,58 +11,30 @@ PyDoc_STRVAR(_testconsole_write_input__doc__,
"Writes UTF-16-LE encoded bytes to the console as if typed by a user.");
#define _TESTCONSOLE_WRITE_INPUT_METHODDEF \
- {"write_input", _PyCFunction_CAST(_testconsole_write_input), METH_FASTCALL|METH_KEYWORDS, _testconsole_write_input__doc__},
+ {"write_input", (PyCFunction)(void(*)(void))_testconsole_write_input, METH_VARARGS|METH_KEYWORDS, _testconsole_write_input__doc__},
static PyObject *
-_testconsole_write_input_impl(PyObject *module, PyObject *file,
- PyBytesObject *s);
+_testconsole_write_input_impl(PyObject *module, PyObject *file, Py_buffer *s);
static PyObject *
-_testconsole_write_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_testconsole_write_input(PyObject *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-
- #define NUM_KEYWORDS 2
- 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(file), &_Py_ID(s), },
- };
- #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[] = {"file", "s", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "write_input",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
+ static char *_keywords[] = {"file", "s", NULL};
PyObject *file;
- PyBytesObject *s;
+ Py_buffer s = {NULL, NULL};
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- file = args[0];
- if (!PyBytes_Check(args[1])) {
- _PyArg_BadArgument("write_input", "argument 's'", "bytes", args[1]);
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oy*:write_input", _keywords,
+ &file, &s))
goto exit;
- }
- s = (PyBytesObject *)args[1];
- return_value = _testconsole_write_input_impl(module, file, s);
+ return_value = _testconsole_write_input_impl(module, file, &s);
exit:
+ /* Cleanup for s */
+ if (s.obj) {
+ PyBuffer_Release(&s);
+ }
+
return return_value;
}
@@ -83,48 +49,21 @@ PyDoc_STRVAR(_testconsole_read_output__doc__,
"Reads a str from the console as written to stdout.");
#define _TESTCONSOLE_READ_OUTPUT_METHODDEF \
- {"read_output", _PyCFunction_CAST(_testconsole_read_output), METH_FASTCALL|METH_KEYWORDS, _testconsole_read_output__doc__},
+ {"read_output", (PyCFunction)(void(*)(void))_testconsole_read_output, METH_VARARGS|METH_KEYWORDS, _testconsole_read_output__doc__},
static PyObject *
_testconsole_read_output_impl(PyObject *module, PyObject *file);
static PyObject *
-_testconsole_read_output(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_testconsole_read_output(PyObject *module, PyObject *args, PyObject *kwargs)
{
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(file), },
- };
- #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[] = {"file", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "read_output",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
+ static char *_keywords[] = {"file", NULL};
PyObject *file;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:read_output", _keywords,
+ &file))
goto exit;
- }
- file = args[0];
return_value = _testconsole_read_output_impl(module, file);
exit:
@@ -140,4 +79,4 @@ exit:
#ifndef _TESTCONSOLE_READ_OUTPUT_METHODDEF
#define _TESTCONSOLE_READ_OUTPUT_METHODDEF
#endif /* !defined(_TESTCONSOLE_READ_OUTPUT_METHODDEF) */
-/*[clinic end generated code: output=08a1c844b3657272 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d60ce07157e3741a input=a9049054013a1b77]*/