Patchwork [6,of,6] phases: move short-lived PyObject pointers to local scope

login
register
mail settings
Submitter Yuya Nishihara
Date July 18, 2020, 10:13 a.m.
Message ID <f06af9c28b02653015dc.1595067182@mimosa>
Download mbox | patch
Permalink /patch/46802/
State Accepted
Headers show

Comments

Yuya Nishihara - July 18, 2020, 10:13 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1595065126 -32400
#      Sat Jul 18 18:38:46 2020 +0900
# Node ID f06af9c28b02653015dc85049ee3d2f0df228b10
# Parent  fe02e378f9bfd1606b405001871ae7052d68157e
phases: move short-lived PyObject pointers to local scope

It helps understand which object should be decrefed on goto release.
Augie Fackler - July 20, 2020, 4:16 p.m.
On Sat, Jul 18, 2020 at 07:13:02PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1595065126 -32400
> #      Sat Jul 18 18:38:46 2020 +0900
> # Node ID f06af9c28b02653015dc85049ee3d2f0df228b10
> # Parent  fe02e378f9bfd1606b405001871ae7052d68157e
> phases: move short-lived PyObject pointers to local scope

queued, thanks

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -786,10 +786,7 @@  static PyObject *compute_phases_map_sets
 	   96: internal */
 	static const char trackedphases[] = {1, 2, 32, 96};
 	PyObject *roots = Py_None;
-	PyObject *pyphase = NULL;
-	PyObject *pyrev = NULL;
 	PyObject *phasesetsdict = NULL;
-	PyObject *phaseroots = NULL;
 	PyObject *phasesets[4] = {NULL, NULL, NULL, NULL};
 	Py_ssize_t len = index_length(self);
 	char *phases = NULL;
@@ -810,7 +807,8 @@  static PyObject *compute_phases_map_sets
 	}
 
 	for (i = 0; i < numphases; ++i) {
-		pyphase = PyInt_FromLong(trackedphases[i]);
+		PyObject *pyphase = PyInt_FromLong(trackedphases[i]);
+		PyObject *phaseroots = NULL;
 		if (pyphase == NULL)
 			goto release;
 		phaseroots = PyDict_GetItem(roots, pyphase);
@@ -819,7 +817,6 @@  static PyObject *compute_phases_map_sets
 			continue;
 		rev = add_roots_get_min(self, phaseroots, phases,
 		                        trackedphases[i]);
-		phaseroots = NULL;
 		if (rev == -2)
 			goto release;
 		if (rev != -1 && (minphaserev == -1 || rev < minphaserev))
@@ -835,6 +832,8 @@  static PyObject *compute_phases_map_sets
 	if (minphaserev == -1)
 		minphaserev = len;
 	for (rev = minphaserev; rev < len; ++rev) {
+		PyObject *pyphase = NULL;
+		PyObject *pyrev = NULL;
 		int parents[2];
 		/*
 		 * The parent lookup could be skipped for phaseroots, but
@@ -881,7 +880,7 @@  static PyObject *compute_phases_map_sets
 	if (phasesetsdict == NULL)
 		goto release;
 	for (i = 0; i < numphases; ++i) {
-		pyphase = PyInt_FromLong(trackedphases[i]);
+		PyObject *pyphase = PyInt_FromLong(trackedphases[i]);
 		if (pyphase == NULL)
 			goto release;
 		if (PyDict_SetItem(phasesetsdict, pyphase, phasesets[i]) ==