[PATCH 1 of 2] mpatch: use Py_ssize_t

Adrian Buehlmann adrian at cadifra.com
Sun May 20 10:37:34 UTC 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1337465298 -7200
# Node ID dbb2896f75cedcf151f27d5556d57144ca3504df
# Parent  9acb5cd19162bdb1053429df9ce9a13c2d15aea8
mpatch: use Py_ssize_t

Eliminates

  mpatch.c(73) : warning C4244: 'return' : conversion from '__int64' to 'int',
  possible loss of data
  mpatch.c(299) : warning C4244: 'function' : conversion from 'Py_ssize_t' to
  'int', possible loss of data
  mpatch.c(321) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int',
  possible loss of data
  mpatch.c(335) : warning C4244: 'function' : conversion from 'Py_ssize_t' to
  'int', possible loss of data
  mpatch.c(346) : warning C4244: 'function' : conversion from 'Py_ssize_t' to
  'int', possible loss of data

when compiling for Windows x64 target using the Microsoft compiler.

diff --git a/mercurial/mpatch.c b/mercurial/mpatch.c
--- a/mercurial/mpatch.c
+++ b/mercurial/mpatch.c
@@ -38,7 +38,7 @@
 	struct frag *base, *head, *tail;
 };
 
-static struct flist *lalloc(int size)
+static struct flist *lalloc(Py_ssize_t size)
 {
 	struct flist *a = NULL;
 
@@ -68,7 +68,7 @@
 	}
 }
 
-static int lsize(struct flist *a)
+static Py_ssize_t lsize(struct flist *a)
 {
 	return a->tail - a->head;
 }
@@ -197,7 +197,7 @@
 }
 
 /* decode a binary patch into a hunk list */
-static struct flist *decode(const char *bin, int len)
+static struct flist *decode(const char *bin, Py_ssize_t len)
 {
 	struct flist *l;
 	struct frag *lt;
@@ -236,9 +236,9 @@
 }
 
 /* calculate the size of resultant text */
-static int calcsize(int len, struct flist *l)
+static Py_ssize_t calcsize(Py_ssize_t len, struct flist *l)
 {
-	int outlen = 0, last = 0;
+	Py_ssize_t outlen = 0, last = 0;
 	struct frag *f = l->head;
 
 	while (f != l->tail) {
@@ -258,7 +258,7 @@
 	return outlen;
 }
 
-static int apply(char *buf, const char *orig, int len, struct flist *l)
+static int apply(char *buf, const char *orig, Py_ssize_t len, struct flist *l)
 {
 	struct frag *f = l->head;
 	int last = 0;
@@ -283,10 +283,9 @@
 }
 
 /* recursively generate a patch of all bins between start and end */
-static struct flist *fold(PyObject *bins, int start, int end)
+static struct flist *fold(PyObject *bins, Py_ssize_t start, Py_ssize_t end)
 {
-	int len;
-	Py_ssize_t blen;
+	Py_ssize_t len, blen;
 	const char *buffer;
 
 	if (start + 1 == end) {
@@ -312,8 +311,7 @@
 	struct flist *patch;
 	const char *in;
 	char *out;
-	int len, outlen;
-	Py_ssize_t inlen;
+	Py_ssize_t len, outlen, inlen;
 
 	if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
 		return NULL;


More information about the Mercurial-devel mailing list