Patchwork [3,of,5] cext: fix most truncation warnings in revlog on Windows

login
register
mail settings
Submitter Matt Harbison
Date Aug. 10, 2018, 5:01 a.m.
Message ID <eb3d685ec313b5d5bca7.1533877277@Envy>
Download mbox | patch
Permalink /patch/33627/
State Accepted
Headers show

Comments

Matt Harbison - Aug. 10, 2018, 5:01 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1533874487 14400
#      Fri Aug 10 00:14:47 2018 -0400
# Node ID eb3d685ec313b5d5bca7824e5e3e577509a486de
# Parent  87d4715a29768208e0345cc6314ad267c8711df6
cext: fix most truncation warnings in revlog on Windows

There's one more, and I'm not sure why it isn't being tripped on other
platforms:

    mercurial/cext/revlog.c(430) : warning C4244: '=' : conversion from
        'Py_ssize_t' to 'char', possible loss of data

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -304,7 +304,7 @@  static PyObject *index_append(indexObjec
 		return NULL;
 
 	if (self->nt)
-		nt_insert(self->nt, node, len);
+		nt_insert(self->nt, node, (int)len);
 
 	Py_CLEAR(self->headrevs);
 	Py_RETURN_NONE;
@@ -579,7 +579,7 @@  static PyObject *reachableroots2(indexOb
 			      revstates[parents[1] + 1]) & RS_REACHABLE)
 			    && !(revstates[i + 1] & RS_REACHABLE)) {
 				revstates[i + 1] |= RS_REACHABLE;
-				val = PyInt_FromLong(i);
+				val = PyInt_FromSsize_t(i);
 				if (val == NULL)
 					goto bail;
 				r = PyList_Append(reachable, val);
@@ -666,7 +666,7 @@  static PyObject *compute_phases_map_sets
 		}
 	}
 	/* Transform phase list to a python list */
-	phasessize = PyInt_FromLong(len);
+	phasessize = PyInt_FromSsize_t(len);
 	if (phasessize == NULL)
 		goto release;
 	for (i = 0; i < len; i++) {
@@ -675,7 +675,7 @@  static PyObject *compute_phases_map_sets
 		 * is computed as a difference */
 		if (phase != 0) {
 			phaseset = PyList_GET_ITEM(phasessetlist, phase);
-			rev = PyInt_FromLong(i);
+			rev = PyInt_FromSsize_t(i);
 			if (rev == NULL)
 				goto release;
 			PySet_Add(phaseset, rev);