summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorcolorfulappl <colorfulappl@qq.com>2022-11-24 12:24:18 (GMT)
committerGitHub <noreply@github.com>2022-11-24 12:24:18 (GMT)
commit69f6cc77d0f1664f983a83b6ae707d99a99f5c4f (patch)
tree4efabca7535e491a1e43901ab255b8cd1c65beec /Modules
parentae185fdcca9d48aef425468de8a8a31300280932 (diff)
downloadcpython-69f6cc77d0f1664f983a83b6ae707d99a99f5c4f.zip
cpython-69f6cc77d0f1664f983a83b6ae707d99a99f5c4f.tar.gz
cpython-69f6cc77d0f1664f983a83b6ae707d99a99f5c4f.tar.bz2
gh-64490: Fix refcount error when arguments are packed to tuple in argument clinic (#99233)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testclinic.c37
-rw-r--r--Modules/clinic/_testclinic.c.h67
2 files changed, 103 insertions, 1 deletions
diff --git a/Modules/_testclinic.c b/Modules/_testclinic.c
index c9858e9..a23ece2 100644
--- a/Modules/_testclinic.c
+++ b/Modules/_testclinic.c
@@ -892,6 +892,41 @@ keyword_only_parameter_impl(PyObject *module, PyObject *a)
}
+/*[clinic input]
+vararg_and_posonly
+
+ a: object
+ *args: object
+ /
+
+[clinic start generated code]*/
+
+static PyObject *
+vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
+/*[clinic end generated code: output=42792f799465a14d input=defe017b19ba52e8]*/
+{
+ return pack_arguments_newref(2, a, args);
+}
+
+
+/*[clinic input]
+gh_99233_refcount
+
+ *args: object
+ /
+
+Proof-of-concept of GH-99233 refcount error bug.
+
+[clinic start generated code]*/
+
+static PyObject *
+gh_99233_refcount_impl(PyObject *module, PyObject *args)
+/*[clinic end generated code: output=585855abfbca9a7f input=85f5fb47ac91a626]*/
+{
+ Py_RETURN_NONE;
+}
+
+
static PyMethodDef tester_methods[] = {
TEST_EMPTY_FUNCTION_METHODDEF
OBJECTS_CONVERTER_METHODDEF
@@ -933,6 +968,8 @@ static PyMethodDef tester_methods[] = {
POSONLY_KEYWORDS_OPT_KWONLY_OPT_METHODDEF
POSONLY_OPT_KEYWORDS_OPT_KWONLY_OPT_METHODDEF
KEYWORD_ONLY_PARAMETER_METHODDEF
+ VARARG_AND_POSONLY_METHODDEF
+ GH_99233_REFCOUNT_METHODDEF
{NULL, NULL}
};
diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h
index b0ac4c2..eb42582 100644
--- a/Modules/clinic/_testclinic.c.h
+++ b/Modules/clinic/_testclinic.c.h
@@ -2288,4 +2288,69 @@ keyword_only_parameter(PyObject *module, PyObject *const *args, Py_ssize_t nargs
exit:
return return_value;
}
-/*[clinic end generated code: output=a9212f8e6ba18bba input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(vararg_and_posonly__doc__,
+"vararg_and_posonly($module, a, /, *args)\n"
+"--\n"
+"\n");
+
+#define VARARG_AND_POSONLY_METHODDEF \
+ {"vararg_and_posonly", _PyCFunction_CAST(vararg_and_posonly), METH_FASTCALL, vararg_and_posonly__doc__},
+
+static PyObject *
+vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args);
+
+static PyObject *
+vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *a;
+ PyObject *__clinic_args = NULL;
+
+ if (!_PyArg_CheckPositional("vararg_and_posonly", nargs, 1, PY_SSIZE_T_MAX)) {
+ goto exit;
+ }
+ a = args[0];
+ __clinic_args = PyTuple_New(nargs - 1);
+ for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
+ PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
+ }
+ return_value = vararg_and_posonly_impl(module, a, __clinic_args);
+
+exit:
+ Py_XDECREF(__clinic_args);
+ return return_value;
+}
+
+PyDoc_STRVAR(gh_99233_refcount__doc__,
+"gh_99233_refcount($module, /, *args)\n"
+"--\n"
+"\n"
+"Proof-of-concept of GH-99233 refcount error bug.");
+
+#define GH_99233_REFCOUNT_METHODDEF \
+ {"gh_99233_refcount", _PyCFunction_CAST(gh_99233_refcount), METH_FASTCALL, gh_99233_refcount__doc__},
+
+static PyObject *
+gh_99233_refcount_impl(PyObject *module, PyObject *args);
+
+static PyObject *
+gh_99233_refcount(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *__clinic_args = NULL;
+
+ if (!_PyArg_CheckPositional("gh_99233_refcount", nargs, 0, PY_SSIZE_T_MAX)) {
+ goto exit;
+ }
+ __clinic_args = PyTuple_New(nargs - 0);
+ for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
+ PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
+ }
+ return_value = gh_99233_refcount_impl(module, __clinic_args);
+
+exit:
+ Py_XDECREF(__clinic_args);
+ return return_value;
+}
+/*[clinic end generated code: output=a5c9f181f3a32d85 input=a9049054013a1b77]*/