mercurial/mpatch.c
changeset 5459 b0e5f44fdeb3
parent 5444 a0952e4e52eb
child 5460 fe9b0bb3eb1c
equal deleted inserted replaced
5457:7372b6bbc5e6 5459:b0e5f44fdeb3
    21 */
    21 */
    22 
    22 
    23 #include <Python.h>
    23 #include <Python.h>
    24 #include <stdlib.h>
    24 #include <stdlib.h>
    25 #include <string.h>
    25 #include <string.h>
       
    26 
       
    27 /* Definitions to get compatibility with python 2.4 and earlier which
       
    28    does not have Py_ssize_t. See also PEP 353.
       
    29    Note: msvc (8 or earlier) does not have ssize_t, so we use Py_ssize_t.
       
    30 */
       
    31 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
       
    32 typedef int Py_ssize_t;
       
    33 #define PY_SSIZE_T_MAX INT_MAX
       
    34 #define PY_SSIZE_T_MIN INT_MIN
       
    35 #endif
    26 
    36 
    27 #ifdef _WIN32
    37 #ifdef _WIN32
    28 # ifdef _MSC_VER
    38 # ifdef _MSC_VER
    29 /* msvc 6.0 has problems */
    39 /* msvc 6.0 has problems */
    30 #  define inline __inline
    40 #  define inline __inline
   310 
   320 
   311 /* recursively generate a patch of all bins between start and end */
   321 /* recursively generate a patch of all bins between start and end */
   312 static struct flist *fold(PyObject *bins, int start, int end)
   322 static struct flist *fold(PyObject *bins, int start, int end)
   313 {
   323 {
   314 	int len;
   324 	int len;
   315 	ssize_t blen;
   325 	Py_ssize_t blen;
   316 	const char *buffer;
   326 	const char *buffer;
   317 
   327 
   318 	if (start + 1 == end) {
   328 	if (start + 1 == end) {
   319 		/* trivial case, output a decoded list */
   329 		/* trivial case, output a decoded list */
   320 		PyObject *tmp = PyList_GetItem(bins, start);
   330 		PyObject *tmp = PyList_GetItem(bins, start);
   337 	PyObject *text, *bins, *result;
   347 	PyObject *text, *bins, *result;
   338 	struct flist *patch;
   348 	struct flist *patch;
   339 	const char *in;
   349 	const char *in;
   340 	char *out;
   350 	char *out;
   341 	int len, outlen;
   351 	int len, outlen;
   342 	ssize_t inlen;
   352 	Py_ssize_t inlen;
   343 
   353 
   344 	if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
   354 	if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
   345 		return NULL;
   355 		return NULL;
   346 
   356 
   347 	len = PyList_Size(bins);
   357 	len = PyList_Size(bins);