bdiff: use Py_ssize_t instead of int
authorAdrian Buehlmann <adrian@cadifra.com>
Tue, 15 May 2012 22:36:27 +0200
changeset 16749 eab8ca175262
parent 16746 9acb5cd19162
child 16750 5b1f869b5548
bdiff: use Py_ssize_t instead of int Reduces the conversion warnings mercurial/bdiff.c(61) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data mercurial/bdiff.c(307) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'int', possible loss of data mercurial/bdiff.c(308) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'int', possible loss of data mercurial/bdiff.c(362) : warning C4244: '+=' : conversion from '__int64' to 'int', possible loss of data mercurial/bdiff.c(380) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data mercurial/bdiff.c(381) : warning C4244: 'function' : conversion from '__int64' to 'uint32_t', possible loss of data mercurial/bdiff.c(382) : warning C4244: 'function' : conversion from '__int64' to 'uint32_t', possible loss of data mercurial/bdiff.c(416) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data to mercurial/bdiff.c(383) : warning C4244: 'function' : conversion from '__int64' to 'uint32_t', possible loss of data mercurial/bdiff.c(384) : warning C4244: 'function' : conversion from '__int64' to 'uint32_t', possible loss of data mercurial/bdiff.c(385) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'uint32_t', possible loss of data on the three putbe32() calls in the function bdiff when compiling for Windows x64 target using the Microsoft compiler.
mercurial/bdiff.c
--- a/mercurial/bdiff.c	Thu May 17 15:52:14 2012 -0500
+++ b/mercurial/bdiff.c	Tue May 15 22:36:27 2012 +0200
@@ -9,6 +9,7 @@
  Based roughly on Python difflib
 */
 
+#define PY_SSIZE_T_CLEAN
 #include <Python.h>
 #include <stdlib.h>
 #include <string.h>
@@ -17,7 +18,8 @@
 #include "util.h"
 
 struct line {
-	int hash, len, n, e;
+	int hash, n, e;
+	Py_ssize_t len;
 	const char *l;
 };
 
@@ -31,7 +33,7 @@
 	struct hunk *next;
 };
 
-static int splitlines(const char *a, int len, struct line **lr)
+static int splitlines(const char *a, Py_ssize_t len, struct line **lr)
 {
 	unsigned hash;
 	int i;
@@ -338,7 +340,8 @@
 	PyObject *result = NULL;
 	struct line *al, *bl;
 	struct hunk l, *h;
-	int an, bn, len = 0, la, lb, count;
+	int an, bn, count;
+	Py_ssize_t len = 0, la, lb;
 	PyThreadState *_save;
 
 	if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb))
@@ -407,7 +410,7 @@
 	PyObject *s, *result = NULL;
 	char allws, c;
 	const char *r;
-	int i, rlen, wlen = 0;
+	Py_ssize_t i, rlen, wlen = 0;
 	char *w;
 
 	if (!PyArg_ParseTuple(args, "Sb:fixws", &s, &allws))