Skip to content

Commit 10ce3c7

Browse files
committed
Add PoC of pythonGH-99233
1 parent cf77785 commit 10ce3c7

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

Lib/test/test_clinic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,12 @@ def test_gh_32092_oob(self):
12561256
def test_gh_32092_kw_pass(self):
12571257
ac_tester.gh_32092_kw_pass(1, 2, 3)
12581258

1259+
def test_gh_99233_refcount(self):
1260+
arg = '*A unique string is not referenced by anywhere else.*'
1261+
arg_refcount_origin = sys.getrefcount(arg)
1262+
ac_tester.gh_99233_refcount(arg)
1263+
arg_refcount_after = sys.getrefcount(arg)
1264+
self.assertEqual(arg_refcount_origin, arg_refcount_after)
12591265

12601266
if __name__ == "__main__":
12611267
unittest.main()

Modules/_testclinic.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,29 @@ gh_32092_kw_pass_impl(PyObject *module, PyObject *pos, PyObject *args,
10291029
}
10301030

10311031

1032+
/*[clinic input]
1033+
gh_99233_refcount
1034+
1035+
*args: object
1036+
/
1037+
1038+
Proof-of-concept of GH-99233 refcount error bug.
1039+
1040+
While AC-generated code is packing varargs to a tuple, the arguments' refcounts are not increased.
1041+
So all the packed arguments‘ refcounts are decreased 1 improperly when the tuple is released later.
1042+
1043+
Call this function with whatever arguments and check if the arguments' refcount is correct.
1044+
1045+
[clinic start generated code]*/
1046+
1047+
static PyObject *
1048+
gh_99233_refcount_impl(PyObject *module, PyObject *args)
1049+
/*[clinic end generated code: output=585855abfbca9a7f input=574e697575fafec5]*/
1050+
{
1051+
Py_RETURN_NONE;
1052+
}
1053+
1054+
10321055
static PyMethodDef tester_methods[] = {
10331056
TEST_EMPTY_FUNCTION_METHODDEF
10341057
OBJECTS_CONVERTER_METHODDEF
@@ -1077,6 +1100,7 @@ static PyMethodDef tester_methods[] = {
10771100
VARARG_WITH_ONLY_DEFAULTS_METHODDEF
10781101
GH_32092_OOB_METHODDEF
10791102
GH_32092_KW_PASS_METHODDEF
1103+
GH_99233_REFCOUNT_METHODDEF
10801104
{NULL, NULL}
10811105
};
10821106

Modules/clinic/_testclinic.c.h

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)