forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support functional test for Argument Clinic
- Loading branch information
1 parent
18b1782
commit f00bb03
Showing
6 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .test_clinic_functionality import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import unittest | ||
|
||
unittest.main('test.test_clinic_functionality') |
165 changes: 165 additions & 0 deletions
165
Lib/test/test_clinic_functionality/clinic/test_clinic_functionality.c.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from setuptools import setup, Extension | ||
from test import support | ||
|
||
|
||
def main(): | ||
SOURCE = support.findfile('test_clinic_functionality.c', subdir='test_clinic_functionality') | ||
module = Extension('test_clinic_functionality', sources=[SOURCE]) | ||
setup(name='test_clinic_functionality', version='0.0', ext_modules=[module]) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
97 changes: 97 additions & 0 deletions
97
Lib/test/test_clinic_functionality/test_clinic_functionality.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#define PY_SSIZE_T_CLEAN | ||
#include <Python.h> | ||
#include "clinic/test_clinic_functionality.c.h" | ||
|
||
|
||
/*[clinic input] | ||
module clinic_functional_tester | ||
[clinic start generated code]*/ | ||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2ee8b0b242501b11]*/ | ||
|
||
/*[clinic input] | ||
gh_32092_oob | ||
pos1: object | ||
pos2: object | ||
*varargs: object | ||
kw1: object = None | ||
kw2: object = None | ||
Proof-of-concept of GH-32092 OOB bug. | ||
Array index out-of-bound bug in function | ||
`_PyArg_UnpackKeywordsWithVararg` . | ||
Calling this function by gh_32092_oob(1, 2, 3, 4, kw1=5, kw2=6) | ||
to trigger this bug (crash). | ||
Expected return: (1, 2, (3, 4), 5, 6) | ||
[clinic start generated code]*/ | ||
|
||
static PyObject * | ||
gh_32092_oob_impl(PyObject *module, PyObject *pos1, PyObject *pos2, | ||
PyObject *varargs, PyObject *kw1, PyObject *kw2) | ||
/*[clinic end generated code: output=ee259c130054653f input=91d8e227acf93b02]*/ | ||
{ | ||
PyObject *tuple = PyTuple_New(5);; | ||
PyTuple_SET_ITEM(tuple, 0, Py_NewRef(pos1)); | ||
PyTuple_SET_ITEM(tuple, 1, Py_NewRef(pos2)); | ||
PyTuple_SET_ITEM(tuple, 2, Py_NewRef(varargs)); | ||
PyTuple_SET_ITEM(tuple, 3, Py_NewRef(kw1)); | ||
PyTuple_SET_ITEM(tuple, 4, Py_NewRef(kw2)); | ||
return tuple; | ||
} | ||
|
||
/*[clinic input] | ||
gh_32092_kw_pass | ||
pos: object | ||
*args: object | ||
kw: object = None | ||
Proof-of-concept of GH-32092 keyword args passing bug. | ||
The calculation of `noptargs` in AC-generated function | ||
`builtin_kw_pass_poc` is incorrect. | ||
Calling this function by gh_32092_kw_pass(1, 2, 3) | ||
to trigger this bug (crash). | ||
Expected return: (1, (2, 3)) | ||
[clinic start generated code]*/ | ||
|
||
static PyObject * | ||
gh_32092_kw_pass_impl(PyObject *module, PyObject *pos, PyObject *args, | ||
PyObject *kw) | ||
/*[clinic end generated code: output=4a2bbe4f7c8604e9 input=c51b7572ac09f193]*/ | ||
{ | ||
PyObject *tuple = PyTuple_New(3);; | ||
PyTuple_SET_ITEM(tuple, 0, Py_NewRef(pos)); | ||
PyTuple_SET_ITEM(tuple, 1, Py_NewRef(args)); | ||
PyTuple_SET_ITEM(tuple, 2, Py_NewRef(kw)); | ||
return tuple; | ||
} | ||
|
||
static PyMethodDef tester_methods[] = { | ||
GH_32092_OOB_METHODDEF | ||
GH_32092_KW_PASS_METHODDEF | ||
{NULL, NULL} | ||
}; | ||
|
||
static struct PyModuleDef clinic_functional_tester_module = { | ||
PyModuleDef_HEAD_INIT, | ||
"clinic_functional_tester", | ||
NULL, | ||
0, | ||
tester_methods, | ||
NULL, | ||
NULL, | ||
NULL, | ||
NULL | ||
}; | ||
|
||
PyMODINIT_FUNC | ||
PyInit_test_clinic_functionality(void) | ||
{ | ||
return PyModule_Create(&clinic_functional_tester_module); | ||
} |
Oops, something went wrong.