Merge ssize_t branch.
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 78e80c7..9012257 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -372,7 +372,7 @@
 
 typedef struct {
     PyObject_HEAD
-    int length;			/* Length of raw Unicode data in buffer */
+    Py_ssize_t length;		/* Length of raw Unicode data in buffer */
     Py_UNICODE *str;		/* Raw Unicode buffer */
     long hash;			/* Hash value; -1 if not set */
     PyObject *defenc;		/* (Default) Encoded version as Python
@@ -420,7 +420,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
     const Py_UNICODE *u,        /* Unicode buffer */
-    int size                    /* size of buffer */
+    Py_ssize_t size             /* size of buffer */
     );
 
 /* Return a read-only pointer to the Unicode object's internal
@@ -432,7 +432,7 @@
 
 /* Get the length of the Unicode object. */
 
-PyAPI_FUNC(int) PyUnicode_GetSize(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
     PyObject *unicode	 	/* Unicode object */
     );
 
@@ -455,7 +455,7 @@
 
 PyAPI_FUNC(int) PyUnicode_Resize(
     PyObject **unicode,		/* Pointer to the Unicode object */
-    int length			/* New length */
+    Py_ssize_t length		/* New length */
     );
 
 /* Coerce obj to an Unicode object and return a reference with
@@ -509,7 +509,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(
     register const wchar_t *w,  /* wchar_t buffer */
-    int size                    /* size of buffer */
+    Py_ssize_t size             /* size of buffer */
     );
 
 /* Copies the Unicode Object contents into the wchar_t buffer w.  At
@@ -524,10 +524,10 @@
    possibly trailing 0-termination character) or -1 in case of an
    error. */
 
-PyAPI_FUNC(int) PyUnicode_AsWideChar(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
     PyUnicodeObject *unicode,   /* Unicode object */
     register wchar_t *w,        /* wchar_t buffer */
-    int size                    /* size of buffer */
+    Py_ssize_t size             /* size of buffer */
     );
 
 #endif
@@ -609,7 +609,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_Decode(
     const char *s,              /* encoded string */
-    int size,                   /* size of buffer */
+    Py_ssize_t size,            /* size of buffer */
     const char *encoding,       /* encoding */
     const char *errors          /* error handling */
     );
@@ -619,7 +619,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_Encode(
     const Py_UNICODE *s,        /* Unicode char buffer */
-    int size,                   /* number of Py_UNICODE chars to encode */
+    Py_ssize_t size,            /* number of Py_UNICODE chars to encode */
     const char *encoding,       /* encoding */
     const char *errors          /* error handling */
     );
@@ -646,13 +646,13 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(
     const char *string, 	/* UTF-7 encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors		/* error handling */
     );
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 		/* number of Py_UNICODE chars to encode */
     int encodeSetO,             /* force the encoder to encode characters in
                                    Set O, as described in RFC2152 */
     int encodeWhiteSpace,       /* force the encoder to encode space, tab,
@@ -664,15 +664,15 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8(
     const char *string, 	/* UTF-8 encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors		/* error handling */
     );
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful(
     const char *string, 	/* UTF-8 encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors,		/* error handling */
-    int *consumed		/* bytes consumed */
+    Py_ssize_t *consumed		/* bytes consumed */
     );
 
 PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
@@ -681,7 +681,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 		/* number of Py_UNICODE chars to encode */
     const char *errors		/* error handling */
     );
 
@@ -712,7 +712,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16(
     const char *string, 	/* UTF-16 encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors,		/* error handling */
     int *byteorder		/* pointer to byteorder to use
 				   0=native;-1=LE,1=BE; updated on
@@ -721,12 +721,12 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful(
     const char *string, 	/* UTF-16 encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors,		/* error handling */
     int *byteorder,		/* pointer to byteorder to use
 				   0=native;-1=LE,1=BE; updated on
 				   exit */
-    int *consumed		/* bytes consumed */
+    Py_ssize_t *consumed		/* bytes consumed */
     );
 
 /* Returns a Python string using the UTF-16 encoding in native byte
@@ -758,7 +758,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 		/* number of Py_UNICODE chars to encode */
     const char *errors,		/* error handling */
     int byteorder		/* byteorder to use 0=BOM+native;-1=LE,1=BE */
     );
@@ -767,7 +767,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(
     const char *string, 	/* Unicode-Escape encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors		/* error handling */
     );
 
@@ -777,14 +777,14 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length	 		/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length	 		/* Number of Py_UNICODE chars to encode */
     );
 
 /* --- Raw-Unicode-Escape Codecs ------------------------------------------ */
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape(
     const char *string, 	/* Raw-Unicode-Escape encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors		/* error handling */
     );
 
@@ -794,7 +794,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length	 		/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length	 		/* Number of Py_UNICODE chars to encode */
     );
 
 /* --- Unicode Internal Codec ---------------------------------------------
@@ -803,7 +803,7 @@
 
 PyObject *_PyUnicode_DecodeUnicodeInternal(
     const char *string,
-    int length,
+    Py_ssize_t length,
     const char *errors
     );
 
@@ -815,7 +815,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1(
     const char *string, 	/* Latin-1 encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors		/* error handling */
     );
 
@@ -825,7 +825,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 		/* Number of Py_UNICODE chars to encode */
     const char *errors		/* error handling */
     );
 
@@ -837,7 +837,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII(
     const char *string, 	/* ASCII encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     const char *errors		/* error handling */
     );
 
@@ -847,7 +847,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 		/* Number of Py_UNICODE chars to encode */
     const char *errors		/* error handling */
     );
 
@@ -875,7 +875,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap(
     const char *string, 	/* Encoded string */
-    int length,	 		/* size of string */
+    Py_ssize_t length,	 	/* size of string */
     PyObject *mapping,		/* character mapping 
 				   (char ordinal -> unicode ordinal) */
     const char *errors		/* error handling */
@@ -889,7 +889,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 	/* Number of Py_UNICODE chars to encode */
     PyObject *mapping,		/* character mapping 
 				   (unicode ordinal -> char ordinal) */
     const char *errors		/* error handling */
@@ -910,7 +910,7 @@
 
 PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
     const Py_UNICODE *data, 	/* Unicode char buffer */
-    int length,	 		/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length,	 		/* Number of Py_UNICODE chars to encode */
     PyObject *table,		/* Translate table */
     const char *errors		/* error handling */
     );
@@ -921,7 +921,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS(
     const char *string,         /* MBCS encoded string */
-    int length,                 /* size of string */
+    Py_ssize_t length,              /* size of string */
     const char *errors          /* error handling */
     );
 
@@ -931,7 +931,7 @@
 
 PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
     const Py_UNICODE *data,     /* Unicode char buffer */
-    int length,                 /* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length,              /* Number of Py_UNICODE chars to encode */
     const char *errors          /* error handling */
     );
 
@@ -963,7 +963,7 @@
 
 PyAPI_FUNC(int) PyUnicode_EncodeDecimal(
     Py_UNICODE *s,		/* Unicode buffer */
-    int length,			/* Number of Py_UNICODE chars to encode */
+    Py_ssize_t length,			/* Number of Py_UNICODE chars to encode */
     char *output,		/* Output buffer; must have size >= length */
     const char *errors		/* error handling */
     );
@@ -995,7 +995,7 @@
 PyAPI_FUNC(PyObject*) PyUnicode_Split(
     PyObject *s,		/* String to split */
     PyObject *sep,		/* String separator */
-    int maxsplit		/* Maxsplit count */
+    Py_ssize_t maxsplit		/* Maxsplit count */
     );		
 
 /* Dito, but split at line breaks.
@@ -1024,7 +1024,7 @@
 PyAPI_FUNC(PyObject*) PyUnicode_RSplit(
     PyObject *s,		/* String to split */
     PyObject *sep,		/* String separator */
-    int maxsplit		/* Maxsplit count */
+    Py_ssize_t maxsplit		/* Maxsplit count */
     );		
 
 /* Translate a string by applying a character mapping table to it and
@@ -1056,11 +1056,11 @@
 /* Return 1 if substr matches str[start:end] at the given tail end, 0
    otherwise. */
 
-PyAPI_FUNC(int) PyUnicode_Tailmatch(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch(
     PyObject *str,		/* String */ 
     PyObject *substr,		/* Prefix or Suffix string */
-    int start,			/* Start index */
-    int end,			/* Stop index */
+    Py_ssize_t start,		/* Start index */
+    Py_ssize_t end,		/* Stop index */
     int direction		/* Tail end: -1 prefix, +1 suffix */
     );
 
@@ -1068,21 +1068,21 @@
    given search direction or -1 if not found. -2 is returned in case
    an error occurred and an exception is set. */
 
-PyAPI_FUNC(int) PyUnicode_Find(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Find(
     PyObject *str,		/* String */ 
     PyObject *substr,		/* Substring to find */
-    int start,			/* Start index */
-    int end,			/* Stop index */
+    Py_ssize_t start,		/* Start index */
+    Py_ssize_t end,		/* Stop index */
     int direction		/* Find direction: +1 forward, -1 backward */
     );
 
 /* Count the number of occurrences of substr in str[start:end]. */
 
-PyAPI_FUNC(int) PyUnicode_Count(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Count(
     PyObject *str,		/* String */ 
     PyObject *substr,		/* Substring to count */
-    int start,			/* Start index */
-    int end			/* Stop index */
+    Py_ssize_t start,		/* Start index */
+    Py_ssize_t end		/* Stop index */
     );
 
 /* Replace at most maxcount occurrences of substr in str with replstr
@@ -1092,7 +1092,7 @@
     PyObject *str,		/* String */ 
     PyObject *substr,		/* Substring to find */
     PyObject *replstr,		/* Substring to replace */
-    int maxcount		/* Max. number of replacements to apply;
+    Py_ssize_t maxcount		/* Max. number of replacements to apply;
 				   -1 = all */
     );