diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2009-05-29 14:47:46 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2009-05-29 14:47:46 (GMT) |
commit | c15bdef8190241357970c9d65783c929860b933a (patch) | |
tree | 41a040a97ca95f748b6b4bc0ed4f2b39e5f729b1 /Modules/_testcapimodule.c | |
parent | 2703fd9134e46146df51b1af383632d5769faebd (diff) | |
download | cpython-c15bdef8190241357970c9d65783c929860b933a.zip cpython-c15bdef8190241357970c9d65783c929860b933a.tar.gz cpython-c15bdef8190241357970c9d65783c929860b933a.tar.bz2 |
Issue #6012: Add cleanup support to O& argument parsing.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index b1a7093..5532e07 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1415,6 +1415,36 @@ raise_memoryerror(PyObject *self) return NULL; } +/* Issue 6012 */ +static PyObject *str1, *str2; +static int +failing_converter(PyObject *obj, void *arg) +{ + /* Clone str1, then let the conversion fail. */ + assert(str1); + str2 = str1; + Py_INCREF(str2); + return 0; +} +static PyObject* +argparsing(PyObject *o, PyObject *args) +{ + PyObject *res; + str1 = str2 = NULL; + if (!PyArg_ParseTuple(args, "O&O&", + PyUnicode_FSConverter, &str1, + failing_converter, &str2)) { + if (!str2) + /* argument converter not called? */ + return NULL; + /* Should be 1 */ + res = PyLong_FromLong(Py_REFCNT(str2)); + Py_DECREF(str2); + PyErr_Clear(); + return res; + } + Py_RETURN_NONE; +} static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, @@ -1433,7 +1463,6 @@ static PyMethodDef TestMethods[] = { PyDoc_STR("This is a pretty normal docstring.")}, {"test_string_to_double", (PyCFunction)test_string_to_double, METH_NOARGS}, {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS}, - {"getargs_tuple", getargs_tuple, METH_VARARGS}, {"getargs_keywords", (PyCFunction)getargs_keywords, METH_VARARGS|METH_KEYWORDS}, @@ -1468,6 +1497,7 @@ static PyMethodDef TestMethods[] = { #endif {"traceback_print", traceback_print, METH_VARARGS}, {"exception_print", exception_print, METH_VARARGS}, + {"argparsing", argparsing, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; |