summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2009-05-29 14:47:46 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2009-05-29 14:47:46 (GMT)
commitc15bdef8190241357970c9d65783c929860b933a (patch)
tree41a040a97ca95f748b6b4bc0ed4f2b39e5f729b1 /Modules
parent2703fd9134e46146df51b1af383632d5769faebd (diff)
downloadcpython-c15bdef8190241357970c9d65783c929860b933a.zip
cpython-c15bdef8190241357970c9d65783c929860b933a.tar.gz
cpython-c15bdef8190241357970c9d65783c929860b933a.tar.bz2
Issue #6012: Add cleanup support to O& argument parsing.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c32
-rw-r--r--Modules/posixmodule.c2
2 files changed, 31 insertions, 3 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 */
};
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 7f6568c..d25034f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -804,8 +804,6 @@ posix_2str(PyObject *args,
if (!PyArg_ParseTuple(args, format,
PyUnicode_FSConverter, &opath1,
PyUnicode_FSConverter, &opath2)) {
- Py_XDECREF(opath1);
- Py_XDECREF(opath2);
return NULL;
}
path1 = bytes2str(opath1, 1);