changeset 5459:b0e5f44fdeb3

mpatch: Define Py_ssize_t for old pythons and use it instead of ssize_t. See also PEP 353. NOTE: Microsoft compilers (8 or earlier) does not have ssize_t.
author Shun-ichi GOTO <shunichi.goto@gmail.com>
date Fri, 12 Oct 2007 11:46:49 +0900
parents 7372b6bbc5e6
children fe9b0bb3eb1c
files mercurial/mpatch.c
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mpatch.c	Thu Oct 11 17:46:06 2007 -0500
+++ b/mercurial/mpatch.c	Fri Oct 12 11:46:49 2007 +0900
@@ -24,6 +24,16 @@
 #include <stdlib.h>
 #include <string.h>
 
+/* Definitions to get compatibility with python 2.4 and earlier which
+   does not have Py_ssize_t. See also PEP 353.
+   Note: msvc (8 or earlier) does not have ssize_t, so we use Py_ssize_t.
+*/
+#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+#endif
+
 #ifdef _WIN32
 # ifdef _MSC_VER
 /* msvc 6.0 has problems */
@@ -312,7 +322,7 @@
 static struct flist *fold(PyObject *bins, int start, int end)
 {
 	int len;
-	ssize_t blen;
+	Py_ssize_t blen;
 	const char *buffer;
 
 	if (start + 1 == end) {
@@ -339,7 +349,7 @@
 	const char *in;
 	char *out;
 	int len, outlen;
-	ssize_t inlen;
+	Py_ssize_t inlen;
 
 	if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
 		return NULL;