Patchwork [1,of,4] dirs: inline string macros

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 8, 2016, 3 p.m.
Message ID <33589809a2a64ceeb282.1475938845@gps-mbp.local>
Download mbox | patch
Permalink /patch/16925/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 8, 2016, 3 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.

Patch

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;