Skip to content

Commit

Permalink
Add PoC of pythonGH-99233
Browse files Browse the repository at this point in the history
  • Loading branch information
colorfulappl committed Nov 8, 2022
1 parent cf77785 commit 10ce3c7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,12 @@ def test_gh_32092_oob(self):
def test_gh_32092_kw_pass(self):
ac_tester.gh_32092_kw_pass(1, 2, 3)

def test_gh_99233_refcount(self):
arg = '*A unique string is not referenced by anywhere else.*'
arg_refcount_origin = sys.getrefcount(arg)
ac_tester.gh_99233_refcount(arg)
arg_refcount_after = sys.getrefcount(arg)
self.assertEqual(arg_refcount_origin, arg_refcount_after)

if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,29 @@ gh_32092_kw_pass_impl(PyObject *module, PyObject *pos, PyObject *args,
}


/*[clinic input]
gh_99233_refcount
*args: object
/
Proof-of-concept of GH-99233 refcount error bug.
While AC-generated code is packing varargs to a tuple, the arguments' refcounts are not increased.
So all the packed arguments‘ refcounts are decreased 1 improperly when the tuple is released later.
Call this function with whatever arguments and check if the arguments' refcount is correct.
[clinic start generated code]*/

static PyObject *
gh_99233_refcount_impl(PyObject *module, PyObject *args)
/*[clinic end generated code: output=585855abfbca9a7f input=574e697575fafec5]*/
{
Py_RETURN_NONE;
}


static PyMethodDef tester_methods[] = {
TEST_EMPTY_FUNCTION_METHODDEF
OBJECTS_CONVERTER_METHODDEF
Expand Down Expand Up @@ -1077,6 +1100,7 @@ static PyMethodDef tester_methods[] = {
VARARG_WITH_ONLY_DEFAULTS_METHODDEF
GH_32092_OOB_METHODDEF
GH_32092_KW_PASS_METHODDEF
GH_99233_REFCOUNT_METHODDEF
{NULL, NULL}
};

Expand Down
39 changes: 38 additions & 1 deletion Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10ce3c7

Please sign in to comment.