[PATCH 1 of 4] dirs: inline string macros

Gregory Szorc gregory.szorc at gmail.com
Sat Oct 8 15:00:45 UTC 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1475935371 -7200
#      Sat Oct 08 16:02:51 2016 +0200
# Node ID 33589809a2a64ceeb2828bbfe6e9126d6997bf94
# Parent  2def3d55b1b9ec2acd53f96ca755d778b5ec865b
dirs: inline string macros

The old code happened to work because of how the macro was defined.
This no longer works in Python 3. Furthermore, assigning to a macro
just feels weird. So just inline the macro.

diff --git a/mercurial/dirs.c b/mercurial/dirs.c
--- a/mercurial/dirs.c
+++ b/mercurial/dirs.c
@@ -60,10 +60,10 @@ static int _addpath(PyObject *dirs, PyOb
 							 pos < 2 ? 2 : pos);
 			if (key == NULL)
 				goto bail;
 		}
-		PyString_GET_SIZE(key) = pos;
-		PyString_AS_STRING(key)[pos] = '\0';
+		Py_SIZE(key) = pos;
+		((PyStringObject *)key)->ob_sval[pos] = '\0';
 
 		val = PyDict_GetItem(dirs, key);
 		if (val != NULL) {
 			PyInt_AS_LONG(val) += 1;


More information about the Mercurial-devel mailing list