Skip to content

Commit f00bb03

Browse files
committed
Support functional test for Argument Clinic
1 parent 18b1782 commit f00bb03

File tree

6 files changed

+406
-0
lines changed

6 files changed

+406
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .test_clinic_functionality import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import unittest
2+
3+
unittest.main('test.test_clinic_functionality')

Lib/test/test_clinic_functionality/clinic/test_clinic_functionality.c.h

+165
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from setuptools import setup, Extension
2+
from test import support
3+
4+
5+
def main():
6+
SOURCE = support.findfile('test_clinic_functionality.c', subdir='test_clinic_functionality')
7+
module = Extension('test_clinic_functionality', sources=[SOURCE])
8+
setup(name='test_clinic_functionality', version='0.0', ext_modules=[module])
9+
10+
11+
if __name__ == '__main__':
12+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
#include "clinic/test_clinic_functionality.c.h"
4+
5+
6+
/*[clinic input]
7+
module clinic_functional_tester
8+
[clinic start generated code]*/
9+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2ee8b0b242501b11]*/
10+
11+
/*[clinic input]
12+
gh_32092_oob
13+
14+
pos1: object
15+
pos2: object
16+
*varargs: object
17+
kw1: object = None
18+
kw2: object = None
19+
20+
Proof-of-concept of GH-32092 OOB bug.
21+
22+
Array index out-of-bound bug in function
23+
`_PyArg_UnpackKeywordsWithVararg` .
24+
25+
Calling this function by gh_32092_oob(1, 2, 3, 4, kw1=5, kw2=6)
26+
to trigger this bug (crash).
27+
Expected return: (1, 2, (3, 4), 5, 6)
28+
29+
[clinic start generated code]*/
30+
31+
static PyObject *
32+
gh_32092_oob_impl(PyObject *module, PyObject *pos1, PyObject *pos2,
33+
PyObject *varargs, PyObject *kw1, PyObject *kw2)
34+
/*[clinic end generated code: output=ee259c130054653f input=91d8e227acf93b02]*/
35+
{
36+
PyObject *tuple = PyTuple_New(5);;
37+
PyTuple_SET_ITEM(tuple, 0, Py_NewRef(pos1));
38+
PyTuple_SET_ITEM(tuple, 1, Py_NewRef(pos2));
39+
PyTuple_SET_ITEM(tuple, 2, Py_NewRef(varargs));
40+
PyTuple_SET_ITEM(tuple, 3, Py_NewRef(kw1));
41+
PyTuple_SET_ITEM(tuple, 4, Py_NewRef(kw2));
42+
return tuple;
43+
}
44+
45+
/*[clinic input]
46+
gh_32092_kw_pass
47+
48+
pos: object
49+
*args: object
50+
kw: object = None
51+
52+
Proof-of-concept of GH-32092 keyword args passing bug.
53+
54+
The calculation of `noptargs` in AC-generated function
55+
`builtin_kw_pass_poc` is incorrect.
56+
57+
Calling this function by gh_32092_kw_pass(1, 2, 3)
58+
to trigger this bug (crash).
59+
Expected return: (1, (2, 3))
60+
61+
[clinic start generated code]*/
62+
63+
static PyObject *
64+
gh_32092_kw_pass_impl(PyObject *module, PyObject *pos, PyObject *args,
65+
PyObject *kw)
66+
/*[clinic end generated code: output=4a2bbe4f7c8604e9 input=c51b7572ac09f193]*/
67+
{
68+
PyObject *tuple = PyTuple_New(3);;
69+
PyTuple_SET_ITEM(tuple, 0, Py_NewRef(pos));
70+
PyTuple_SET_ITEM(tuple, 1, Py_NewRef(args));
71+
PyTuple_SET_ITEM(tuple, 2, Py_NewRef(kw));
72+
return tuple;
73+
}
74+
75+
static PyMethodDef tester_methods[] = {
76+
GH_32092_OOB_METHODDEF
77+
GH_32092_KW_PASS_METHODDEF
78+
{NULL, NULL}
79+
};
80+
81+
static struct PyModuleDef clinic_functional_tester_module = {
82+
PyModuleDef_HEAD_INIT,
83+
"clinic_functional_tester",
84+
NULL,
85+
0,
86+
tester_methods,
87+
NULL,
88+
NULL,
89+
NULL,
90+
NULL
91+
};
92+
93+
PyMODINIT_FUNC
94+
PyInit_test_clinic_functionality(void)
95+
{
96+
return PyModule_Create(&clinic_functional_tester_module);
97+
}

0 commit comments

Comments
 (0)