[PATCH 1 of 2] bdiff: use Py_ssize_t instead of int

Adrian Buehlmann adrian at cadifra.com
Tue May 15 15:41:54 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1337114187 -7200
# Node ID db0b25613afdeec4573288e8390ec0dd01981436
# Parent  99f369f5a8dbc192cd520aece8437f3182b1ac50
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.

diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c
--- a/mercurial/bdiff.c
+++ b/mercurial/bdiff.c
@@ -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))


More information about the Mercurial-devel mailing list