mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-108494: Argument Clinic partial supports of Limited C API (#108495)
Argument Clinic now has a partial support of the Limited API: * Add --limited option to clinic.c. * Add '_testclinic_limited' extension which is built with the limited C API version 3.13. * For now, hardcode in clinic.py that "_testclinic_limited.c" targets the limited C API.
This commit is contained in:
parent
4eae1e5342
commit
1dd9510977
7 changed files with 208 additions and 13 deletions
|
|
@ -161,6 +161,7 @@
|
|||
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c
|
||||
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyos.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c
|
||||
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
|
||||
@MODULE__TESTCLINIC_TRUE@_testclinic_limited _testclinic_limited.c
|
||||
|
||||
# Some testing modules MUST be built as shared libraries.
|
||||
*shared*
|
||||
|
|
|
|||
69
Modules/_testclinic_limited.c
Normal file
69
Modules/_testclinic_limited.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// For now, only limited C API 3.13 is supported
|
||||
#define Py_LIMITED_API 0x030d0000
|
||||
|
||||
/* Always enable assertions */
|
||||
#undef NDEBUG
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
|
||||
#include "clinic/_testclinic_limited.c.h"
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
module _testclinic_limited
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=dd408149a4fc0dbb]*/
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
test_empty_function
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
test_empty_function_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=0f8aeb3ddced55cb input=0dd7048651ad4ae4]*/
|
||||
{
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
my_int_func -> int
|
||||
|
||||
arg: int
|
||||
/
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
my_int_func_impl(PyObject *module, int arg)
|
||||
/*[clinic end generated code: output=761cd54582f10e4f input=16eb8bba71d82740]*/
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef tester_methods[] = {
|
||||
TEST_EMPTY_FUNCTION_METHODDEF
|
||||
MY_INT_FUNC_METHODDEF
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef _testclinic_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
.m_name = "_testclinic_limited",
|
||||
.m_size = 0,
|
||||
.m_methods = tester_methods,
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
PyInit__testclinic_limited(void)
|
||||
{
|
||||
PyObject *m = PyModule_Create(&_testclinic_module);
|
||||
if (m == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
53
Modules/clinic/_testclinic_limited.c.h
generated
Normal file
53
Modules/clinic/_testclinic_limited.c.h
generated
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*[clinic input]
|
||||
preserve
|
||||
[clinic start generated code]*/
|
||||
|
||||
PyDoc_STRVAR(test_empty_function__doc__,
|
||||
"test_empty_function($module, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define TEST_EMPTY_FUNCTION_METHODDEF \
|
||||
{"test_empty_function", (PyCFunction)test_empty_function, METH_NOARGS, test_empty_function__doc__},
|
||||
|
||||
static PyObject *
|
||||
test_empty_function_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
test_empty_function(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return test_empty_function_impl(module);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(my_int_func__doc__,
|
||||
"my_int_func($module, arg, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define MY_INT_FUNC_METHODDEF \
|
||||
{"my_int_func", (PyCFunction)my_int_func, METH_O, my_int_func__doc__},
|
||||
|
||||
static int
|
||||
my_int_func_impl(PyObject *module, int arg);
|
||||
|
||||
static PyObject *
|
||||
my_int_func(PyObject *module, PyObject *arg_)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int arg;
|
||||
int _return_value;
|
||||
|
||||
arg = PyLong_AsInt(arg_);
|
||||
if (arg == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
_return_value = my_int_func_impl(module, arg);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyLong_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=07e2e8ed6923cd16 input=a9049054013a1b77]*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue