8000 gh-96002: Add functional test for Argument Clinic by colorfulappl · Pull Request #96178 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-96002: Add functional test for Argument Clinic #96178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Nov 21, 2022
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f00bb03
Support functional test for Argument Clinic
colorfulappl Aug 22, 2022
a59e304
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 22, 2022
2bd331e
Revert "Support functional test for Argument Clinic"
colorfulappl Aug 23, 2022
fac5b77
Add functional test for Argument Clinic
colorfulappl Aug 23, 2022
962434c
Add testcases written in C
colorfulappl Aug 23, 2022
b93b2ae
Rename _testclinicfunctionality.c to _testclinic.c
colorfulappl Oct 25, 2022
35c5f13
Add _testclinic to stdlib IGNORE list
colorfulappl Oct 25, 2022
86703de
Merge TestClinicFunctionalityC class into TestClinicFunctionality
colorfulappl Oct 25, 2022
e66d60b
Format code in _testclinic.c
colorfulappl Oct 25, 2022
f1fb377
Merge test_clinic_functionality.py into test_clinic.py
colorfulappl Oct 26, 2022
449c8fe
Simplify testcases
colorfulappl Oct 26, 2022
1553574
Merge branch 'main' into test_clinic_functionality
colorfulappl Oct 26, 2022
81fe77b
Add more testcases
colorfulappl Oct 28, 2022
7c269d0
Rename class TestClinicFunctionality to ClinicFunctionalTest
colorfulappl Nov 1, 2022
a3a3455
Fix UB problem
colorfulappl Nov 2, 2022
80ba71a
Fix refleaks
colorfulappl Nov 4, 2022
cf77785
Clean code
colorfulappl Nov 4, 2022
10ce3c7
Add PoC of GH-99233
colorfulappl Nov 8, 2022
2cc6c0a
Add PoC of GH-99240
colorfulappl Nov 8, 2022
6a2d334
Delete test cases which fail this test
colorfulappl Nov 10, 2022
d82ef72
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 10, 2022
b27b43d
Rerun `make regen-all`
colorfulappl Nov 10, 2022
1cae160
Fix leaking
colorfulappl Nov 13, 2022
fb6d3be
Fix code style
colorfulappl Nov 13, 2022
fd1ed14
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 13, 2022
e82c88a
Rerun `make regen-all`
colorfulappl Nov 13, 2022
598568c
Fix object leaking and code style
colorfulappl Nov 14, 2022
dd43f24
Change argument release order
colorfulappl Nov 14, 2022
325e35b
Rename macro
colorfulappl Nov 14, 2022
967dda6
Update news
colorfulappl Nov 14, 2022
d568683
Fix object leaking
colorfulappl Nov 14, 2022
ce337e8
Remove unnecessary logic
colorfulappl Nov 15, 2022
3314465
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 15, 2022
68277c5
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 15, 2022
da0789f
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix refleaks
  • Loading branch information
colorfulappl committed Nov 4, 2022
commit 80ba71a4614b7ff4d315f2f2865e36bda7e4cc21
93 changes: 57 additions & 36 deletions Modules/_testclinic.c
< A93C td id="diff-b0fa0e79fca88f55305bd9931e4a149957d282c96447d0df0adf9c132bd04aa1L777" data-line-number="777" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@

#include "clinic/_testclinic.c.h"

PyObject *
pack_arguments(int arg_num, ...) {
static PyObject *
pack_arguments_newref(int argc, ...) {
va_list vargs;
va_start(vargs, arg_num);
PyObject *tuple = PyTuple_New(arg_num);
for (int i = 0; i < arg_num; i++) {
va_start(vargs, argc);
PyObject *tuple = PyTuple_New(argc);
if (!tuple) {
return NULL;
}
for (int i = 0; i < argc; i++) {
PyObject *arg = va_arg(vargs, PyObject *);
if (arg) {
if (_PyObject_IsFreed(arg)) {
PyErr_Format(PyExc_AssertionError,
"argument %d at %p is freed or corrupted!",
i, arg);
va_end(vargs);
Py_DECREF(tuple);
return NULL;
}
} else {
Expand All @@ -35,6 +39,23 @@ pack_arguments(int arg_num, ...) {
return tuple;
}

static PyObject *
pack_arguments(int argc, ...) {
va_list vargs;
va_start(vargs, argc);
PyObject *tuple = PyTuple_New(argc);
if (!tuple) {
return NULL;
}
for (int i = 0; i < argc; i++) {
PyObject *arg = va_arg(vargs, PyObject *);
assert(arg && !_PyObject_IsFreed(arg));
PyTuple_SET_ITEM(tuple, i, arg);
}
va_end(vargs);
return tuple;
}


/*[clinic input]
module _testclinic
Expand Down Expand Up @@ -68,7 +89,7 @@ static PyObject *
objects_converter_impl(PyObject *module, PyObject *a, PyObject *b)
/*[clinic end generated code: output=3f9c9415ec86c695 input=1533b1bd94187de4]*/
{
return pack_arguments(2, a, b);
return pack_arguments_newref(2, a, b);
}


Expand All @@ -87,7 +108,7 @@ bytes_object_converter_impl(PyObject *module, PyBytesObject *a)
if (!PyBytes_Check(a)) {
PyErr_SetString(PyExc_AssertionError, "argument a is not a PyBytesObject");
}
return pack_arguments(1, a);
return pack_arguments_newref(1, a);
}


Expand All @@ -106,7 +127,7 @@ byte_array_object_converter_impl(PyObject *module, PyByteArrayObject *a)
if (!PyByteArray_Check(a)) {
PyErr_SetString(PyExc_AssertionError, "argument a is not a PyByteArrayObject");
}
return pack_arguments(1, a);
return pack_arguments_newref(1, a);
}


Expand All @@ -125,7 +146,7 @@ unicode_converter_impl(PyObject *module, PyObject *a)
if (!PyUnicode_Check(a)) {
PyErr_SetString(PyExc_AssertionError, "argument a is not a unicode object");
}
return pack_arguments(1, a);
return pack_arguments_newref(1, a);
}


Expand Down Expand Up @@ -155,7 +176,7 @@ bool_converter_impl(PyObject *module, int a, int b, int c)
PyObject *obj_a = a ? Py_True : Py_False;
PyObject *obj_b = b ? Py_True : Py_False;
PyObject *obj_c = c ? Py_True : Py_False;
return pack_arguments(3, obj_a, obj_b, obj_c);
return pack_arguments_newref(3, obj_a, obj_b, obj_c);
}


Expand Down Expand Up @@ -550,22 +571,22 @@ py_buffer_converter_impl(PyObject *module, Py_buffer *a, Py_buffer *b)
{
PyObject *new_a = PyBytes_FromStringAndSize(NULL, a->len);
if (!new_a) {
Py_XDECREF(new_a);
return NULL;
}
if (PyBuffer_ToContiguous(((PyBytesObject *) new_a)->ob_sval, a, a->len, 'C') < 0) {
Py_XDECREF(new_a);
if (PyBuffer_ToContiguous(((PyBytesObject *)new_a)->ob_sval, a, a->len, 'C') < 0) {
Py_DECREF(new_a);
return NULL;
}
PyBuffer_Release(a);

PyObject *new_b = PyBytes_FromStringAndSize(NULL, b->len);
if (!new_b) {
Py_XDECREF(new_b);
Py_DECREF(new_a);
return NULL;
}
if (PyBuffer_ToContiguous(((PyBytesObject *) new_b)->ob_sval, b, b->len, 'C') < 0) {
Py_XDECREF(new_b);
if (PyBuffer_ToContiguous(((PyBytesObject *)new_b)->ob_sval, b, b->len, 'C') < 0) {
Py_DECREF(new_a);
Py_DECREF(new_b);
return NULL;
}
PyBuffer_Release(b);
Expand All @@ -586,7 +607,7 @@ static PyObject *
keywords_impl(PyObject *module, PyObject *a, PyObject *b)
/*[clinic end generated code: output=850aaed53e26729e input=f44b89e718c1a93b]*/
{
return pack_arguments(2, a, b);
return pack_arguments_newref(2, a, b);
}


Expand All @@ -603,7 +624,7 @@ static PyObject *
keywords_kwonly_impl(PyObject *module, PyObject *a, PyObject *b)
/*[clinic end generated code: output=a45c48241da584dc input=1f08e39c3312b015]*/
{
return pack_arguments(2, a, b);
return pack_arguments_newref(2, a, b);
}


Expand All @@ -620,7 +641,7 @@ static PyObject *
keywords_opt_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c)
/*[clinic end generated code: output=25e4b67d91c76a66 input=b0ba0e4f04904556]*/
{
return pack_arguments(3, a, b, c);
return pack_arguments_newref(3, a, b, c);
}


Expand All @@ -640,7 +661,7 @@ keywords_opt_kwonly_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c, PyObject *d)
/*[clinic end generated code: output=6aa5b655a6e9aeb0 input=f79da689d6c51076]*/
{
return pack_arguments(4, a, b, c, d);
return pack_arguments_newref(4, a, b, c, d);
}


Expand All @@ -659,7 +680,7 @@ keywords_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c)
/*[clinic end generated code: output=707f78eb0f55c2b1 input=e0fa1a0e46dca791]*/
{
return pack_arguments(3, a, b, c);
return pack_arguments_newref(3, a, b, c);
}


Expand All @@ -676,7 +697,7 @@ static PyObject *
posonly_keywords_impl(PyObject *module, PyObject *a, PyObject *b)
/*[clinic end generated code: output=6ac88f4a5f0bfc8d input=fde0a2f79fe82b06]*/
{
return pack_arguments(2, a, b);
return pack_arguments_newref(2, a, b);
}


Expand All @@ -694,7 +715,7 @@ static PyObject *
posonly_kwonly_impl(PyObject *module, PyObject *a, PyObject *b)
/*[clinic end generated code: output=483e6790d3482185 input=78b3712768da9a19]*/
{
return pack_arguments(2, a, b);
return pack_arguments_newref(2, a, b);
}


Expand All @@ -714,7 +735,7 @@ posonly_keywords_kwonly_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c)
/*[clinic end generated code: output=2fae573e8cc3fad8 input=a1ad5d2295eb803c]*/
{
return pack_arguments(3, a, b, c);
return pack_arguments_newref(3, a, b, c);
}


Expand All @@ -734,7 +755,7 @@ posonly_keywords_opt_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c, PyObject *d)
/*[clinic end generated code: output=f5eb66241bcf68fb input=51c10de2a120e279]*/
{
return pack_arguments(4, a, b, c, d);
return pack_arguments_newref(4, a, b, c, d);
}


Expand All @@ -754,7 +775,7 @@ posonly_opt_keywords_opt_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c, PyObject *d)
/*[clinic end generated code: output=d54a30e549296ffd input=f408a1de7dfaf31f]*/
{
return pack_arguments(4, a, b, c, d);
return pack_arguments_newref(4, a, b, c, d);
}


Expand All @@ -775,7 +796,7 @@ posonly_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c, PyObject *d)
/*[clinic end generated code: output=a20503fe36b4fd62 input=3494253975272f52]*/
{
return pack_arguments(4, a, b, c, d);
return pack_arguments_newref(4, a, b, c, d);
}


Expand All @@ -796,7 +817,7 @@ posonly_opt_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c, PyObject *d)
/*[clinic end generated code: output=64f3204a3a0413b6 input=d17516581e478412]*/
{
return pack_arguments(4, a, b, c, d);
return pack_arguments_newref(4, a, b, c, d);
}


Expand All @@ -818,7 +839,7 @@ posonly_keywords_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
PyObject *c, PyObject *d, PyObject *e)
/*[clinic end generated code: output=dbd7e7ddd6257fa0 input=33529f29e97e5adb]*/
{
return pack_arguments(5, a, b, c, d, e);
return pack_arguments_newref(5, a, b, c, d, e);
}


Expand All @@ -841,7 +862,7 @@ posonly_keywords_opt_kwonly_opt_impl(PyObject *module, PyObject *a,
PyObject *e)
/*[clinic end generated code: output=775d12ae44653045 input=4d4cc62f11441301]*/
{
return pack_arguments(5, a, b, c, d, e);
return pack_arguments_newref(5, a, b, c, d, e);
}


Expand All @@ -863,7 +884,7 @@ posonly_opt_keywords_opt_kwonly_opt_impl(PyObject *module, PyObject *a,
PyObject *d)
/*[clinic end generated code: output=40c6dc422591eade input=3964960a68622431]*/
{
return pack_arguments(4, a, b, c, d);
return pack_arguments_newref(4, a, b, c, d);
}


Expand All @@ -879,7 +900,7 @@ static PyObject *
keyword_only_parameter_impl(PyObject *module, PyObject *a)
/*[clinic end generated code: output=c454b6ce98232787 input=8d2868b8d0b27bdb]*/
{
return pack_arguments(1, a);
return pack_arguments_newref(1, a);
}


Expand All @@ -896,7 +917,7 @@ static PyObject *
vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
/*[clinic end generated code: output=42792f799465a14d input=defe017b19ba52e8]*/
{
return pack_arguments(2, a, Py_NewRef(args));
return pack_arguments_newref(2, a, args);
}


Expand All @@ -912,7 +933,7 @@ static PyObject *
vararg_impl(PyObject *module, PyObject *a, PyObject *args)
/*[clinic end generated code: output=91ab7a0efc52dd5e input=02c0f772d05f591e]*/
{
return pack_arguments(2, a, Py_NewRef(args));
return pack_arguments_newref(2, a, args);
}


Expand All @@ -934,7 +955,7 @@ vararg_with_default_impl(PyObject *module, PyObject *a, PyObject *args,
PyErr_SetString(PyExc_AssertionError, "argument b is not a bool value");
}
PyObject *obj_b = b ? Py_True : Py_False;
return pack_arguments(3, a, Py_NewRef(args), obj_b);
return pack_arguments_newref(3, a, args, obj_b);
}


Expand All @@ -950,7 +971,7 @@ static PyObject *
vararg_with_only_defaults_impl(PyObject *module, PyObject *args, PyObject *b)
/*[clinic end generated code: output=c06b1826d91f2f7b input=678c069bc67550e1]*/
{
return pack_arguments(2, Py_NewRef(args), b);
return pack_arguments_newref(2, args, b);
}


Expand Down
0