warnings.simplefilter('error', DeprecationWarning)
self.assertRaises(DeprecationWarning, getargs_Z_hash, 'abc\xe9')
+ 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):
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
static PyObject *getargs_s_hash_int(PyObject *, PyObject *, PyObject*);
static PyObject *getargs_s_hash_int2(PyObject *, PyObject *, PyObject*);
+static PyObject *gh_99240_clear_args(PyObject *, PyObject *);
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
METH_VARARGS|METH_KEYWORDS},
{"getargs_s_hash_int2", _PyCFunction_CAST(getargs_s_hash_int2),
METH_VARARGS|METH_KEYWORDS},
+ {"gh_99240_clear_args", gh_99240_clear_args, METH_VARARGS},
{"getargs_z", getargs_z, METH_VARARGS},
{"getargs_z_star", getargs_z_star, METH_VARARGS},
{"getargs_z_hash", getargs_z_hash, METH_VARARGS},
PyBuffer_Release(&buf);
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 are not cleared.");
+ }
+ return NULL;
+ }
+ PyMem_Free(a);
+ PyMem_Free(b);
+ Py_RETURN_NONE;
+}
static int
cleanup_ptr(PyObject *self, void *ptr)
{
- if (ptr) {
- PyMem_Free(ptr);
- }
+ void **pptr = (void **)ptr;
+ PyMem_Free(*pptr);
+ *pptr = NULL;
return 0;
}
PyErr_NoMemory();
RETURN_ERR_OCCURRED;
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(buffer, freelist, cleanup_ptr)) {
Py_DECREF(s);
return converterr(
"(cleanup problem)",
PyErr_NoMemory();
RETURN_ERR_OCCURRED;
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(buffer, freelist, cleanup_ptr)) {
Py_DECREF(s);
return converterr("(cleanup problem)",
arg, msgbuf, bufsize);