changeset 45180:a6fde9d789d9

phases: move short-lived PyObject pointers to local scope It helps understand which object should be decrefed on goto release.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 18 Jul 2020 18:38:46 +0900
parents ba5e4b11d085
children 28163c5de797 509f5b6c0b7e
files mercurial/cext/revlog.c
diffstat 1 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Sat Jul 18 18:35:17 2020 +0900
+++ b/mercurial/cext/revlog.c	Sat Jul 18 18:38:46 2020 +0900
@@ -791,10 +791,7 @@
 	   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;
@@ -815,7 +812,8 @@
 	}
 
 	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);
@@ -824,7 +822,6 @@
 			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))
@@ -840,6 +837,8 @@
 	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
@@ -886,7 +885,7 @@
 	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]) ==