[PATCH v2] parsers: use PyTuple_Pack instead of manual list-filling

Bryan O'Sullivan bos at serpentine.com
Mon Dec 14 19:03:01 UTC 2015


# HG changeset patch
# User Bryan O'Sullivan <bos at serpentine.com>
# Date 1450119772 28800
#      Mon Dec 14 11:02:52 2015 -0800
# Node ID 15c01045d64513f9ff7063953da8cccf42852cb1
# Parent  13a42f5695ac05f1a684070d5e6516286dc4ce8d
parsers: use PyTuple_Pack instead of manual list-filling

Suggested by Yuya.

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1351,15 +1351,12 @@ static PyObject *compute_phases_map_sets
 			goto release;
 		PyList_SET_ITEM(phaseslist, i, phaseval);
 	}
-	ret = PyList_New(2);
-	if (ret == NULL)
-		goto release;
-
-	PyList_SET_ITEM(ret, 0, phaseslist);
-	PyList_SET_ITEM(ret, 1, phasessetlist);
-	/* We don't release phaseslist and phasessetlist as we return them to
-	 * python */
-	goto done;
+	ret = PyTuple_Pack(2, phaseslist, phasessetlist);
+	if (ret != NULL) {
+		/* We don't release phaseslist and phasessetlist as we
+		 * return them to python */
+		goto done;
+	}
 
 release:
 	Py_XDECREF(phaseslist);


More information about the Mercurial-devel mailing list