dirs._addpath: reinstate use of Py_CLEAR
authorSiddharth Agarwal <sid0@fb.com>
Tue, 07 Apr 2015 20:43:04 -0700
changeset 24651 67241ee427cf
parent 24650 b83a8f512a80
child 24652 232bf0028596
dirs._addpath: reinstate use of Py_CLEAR I changed this to an explicit Py_DECREF + set to null in 6f0e6fa9fdd7. This was a silly misunderstanding on my part -- for some reason I thought Py_CLEAR set its argument to null only if its refcount reached 0. Turns out that's not actually the case -- Py_CLEAR is just Py_DECREF + set to null with some additional precautions around destructors that aren't relevant here. The real bug that 6f0e6fa9fdd7 fixed was the fact that we were mutating the string after setting it in the Python dictionary.
mercurial/dirs.c
--- a/mercurial/dirs.c	Mon Apr 06 18:31:59 2015 -0700
+++ b/mercurial/dirs.c	Tue Apr 07 20:43:04 2015 -0700
@@ -94,10 +94,8 @@
 			goto bail;
 
 		/* Clear the key out since we've already exposed it to Python
-		   and can't mutate it further. key's refcount is currently 2 so
-		   we can't just use Py_CLEAR. */
-		Py_DECREF(key);
-		key = NULL;
+		   and can't mutate it further. */
+		Py_CLEAR(key);
 	}
 	ret = 0;