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

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 17, 2015, 9:09 p.m.
Message ID <53361dee10538c0a2b08.1450386554@bryano-mbp.local>
Download mbox | patch
Permalink /patch/12128/
State Accepted
Headers show

Comments

Bryan O'Sullivan - Dec. 17, 2015, 9:09 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bos@serpentine.com>
# Date 1450386454 28800
#      Thu Dec 17 13:07:34 2015 -0800
# Node ID 53361dee10538c0a2b08bf076ec96a822b0128ea
# Parent  4eeef1b2d689bad18f473b5e118cca061f6ca560
parsers: use PyTuple_Pack instead of manual list-filling

Suggested by Yuya.
Augie Fackler - Dec. 18, 2015, 3:32 p.m.
On Thu, Dec 17, 2015 at 01:09:14PM -0800, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bos@serpentine.com>
> # Date 1450386454 28800
> #      Thu Dec 17 13:07:34 2015 -0800
> # Node ID 53361dee10538c0a2b08bf076ec96a822b0128ea
> # Parent  4eeef1b2d689bad18f473b5e118cca061f6ca560
> parsers: use PyTuple_Pack instead of manual list-filling

Queued, thanks.

>
> Suggested by Yuya.
>
> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -1351,15 +1351,7 @@ 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);
>
>  release:
>       Py_XDECREF(phaseslist);
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1351,15 +1351,7 @@  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);
 
 release:
 	Py_XDECREF(phaseslist);