gh-108494: AC supports pos-only args in limited C API (#108498)

AC now checks for "#define Py_LIMITED_API" pattern to use the limited
C API.
This commit is contained in:
Victor Stinner 2023-08-26 00:39:24 +02:00 • committed by GitHub
parent 73d33c1a30
commit 86bc9e35c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 5 deletions

View file

@ -45,9 +45,27 @@ my_int_func_impl(PyObject *module, int arg)
}
/*[clinic input]
my_int_sum -> int
x: int
y: int
/
[clinic start generated code]*/
static int
my_int_sum_impl(PyObject *module, int x, int y)
/*[clinic end generated code: output=3e52db9ab5f37e2f input=0edb6796813bf2d3]*/
{
return x + y;
}
static PyMethodDef tester_methods[] = {
TEST_EMPTY_FUNCTION_METHODDEF
MY_INT_FUNC_METHODDEF
MY_INT_SUM_METHODDEF
{NULL, NULL}
};

View file

@ -50,4 +50,36 @@ my_int_func(PyObject *module, PyObject *arg_)
exit:
return return_value;
}
/*[clinic end generated code: output=07e2e8ed6923cd16 input=a9049054013a1b77]*/
PyDoc_STRVAR(my_int_sum__doc__,
"my_int_sum($module, x, y, /)\n"
"--\n"
"\n");
#define MY_INT_SUM_METHODDEF \
{"my_int_sum", (PyCFunction)my_int_sum, METH_VARARGS, my_int_sum__doc__},
static int
my_int_sum_impl(PyObject *module, int x, int y);
static PyObject *
my_int_sum(PyObject *module, PyObject *args)
{
PyObject *return_value = NULL;
int x;
int y;
int _return_value;
if (!PyArg_ParseTuple(args, "ii:my_int_sum",
&x, &y))
goto exit;
_return_value = my_int_sum_impl(module, x, y);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
/*[clinic end generated code: output=f9f7209255bb969e input=a9049054013a1b77]*/