Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Add test
  • Loading branch information
colorfulappl committed Dec 15, 2022
commit ef866b2e1531135b709f162bf5dae6633e3990f6
4 changes: 4 additions & 0 deletions Lib/test/test_capi/test_getargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ def test_Z_hash(self):
with self.assertWarns(DeprecationWarning):
self.assertIsNone(getargs_Z_hash(None))

def test_gh_99240_clear_args(self):
from _testcapi import gh_99240_clear_args
self.assertRaises(TypeError, gh_99240_clear_args, 'a', '\0b')


class Object_TestCase(unittest.TestCase):
def test_S(self):
Expand Down
18 changes: 18 additions & 0 deletions Modules/_testcapi/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,23 @@ getargs_s_hash_int2(PyObject *self, PyObject *args, PyObject *kwargs)
Py_RETURN_NONE;
}

static PyObject *
gh_99240_clear_args(PyObject *self, PyObject *args) {
char *a = NULL;
char *b = NULL;

if (!PyArg_ParseTuple(args, "eses", "idna", &a, "idna", &b)) {
if (a || b) {
PyErr_Clear();
PyErr_SetString(PyExc_AssertionError, "Arguments is not cleared.");
}
return NULL;
}
Py_DECREF(a);
Py_DECREF(b);
Py_RETURN_NONE;
}

static PyMethodDef test_methods[] = {
{"get_args", get_args, METH_VARARGS},
{"get_kwargs", _PyCFunction_CAST(get_kwargs), METH_VARARGS|METH_KEYWORDS},
Expand Down Expand Up @@ -906,6 +923,7 @@ static PyMethodDef test_methods[] = {
{"test_empty_argparse", test_empty_argparse, METH_NOARGS},
{"test_k_code", test_k_code, METH_NOARGS},
{"test_s_code", test_s_code, METH_NOARGS},
{"gh_99240_clear_args", gh_99240_clear_args, METH_VARARGS},
{NULL},
};

Expand Down