Rebase patch

This commit is contained in:
Toshio Kuratomi 2010-08-20 17:31:03 -04:00
parent a9aa92da40
commit 3dd910f4da

View File

@ -1,8 +1,8 @@
Index: Objects/unicodeobject.c
Index: Python-3.1.2/Objects/unicodeobject.c
===================================================================
--- Objects/unicodeobject.c (revision 80382)
+++ Objects/unicodeobject.c (revision 80383)
@@ -159,6 +159,12 @@
--- Python-3.1.2.orig/Objects/unicodeobject.c
+++ Python-3.1.2/Objects/unicodeobject.c
@@ -159,6 +159,12 @@ static PyObject *unicode_encode_call_err
const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
Py_ssize_t startpos, Py_ssize_t endpos, Py_ssize_t *newpos);
@ -15,7 +15,7 @@ Index: Objects/unicodeobject.c
/* Same for linebreaks */
static unsigned char ascii_linebreak[] = {
0, 0, 0, 0, 0, 0, 0, 0,
@@ -2461,61 +2467,88 @@
@@ -2461,59 +2467,88 @@ PyUnicode_EncodeUTF8(const Py_UNICODE *s
/* Encode Latin-1 */
*p++ = (char)(0xc0 | (ch >> 6));
*p++ = (char)(0x80 | (ch & 0x3f));
@ -60,6 +60,12 @@ Index: Objects/unicodeobject.c
- (errors, &errorHandler, "utf-8", "surrogates not allowed",
- s, size, &exc, i-1, i, &newpos);
- if (!rep)
- goto error;
- /* Implementation limitations: only support error handler that return
- bytes, and only support up to four replacement bytes. */
- if (!PyBytes_Check(rep)) {
- PyErr_SetString(PyExc_TypeError, "error handler should have returned bytes");
- Py_DECREF(rep);
+ } else {
+ Py_ssize_t newpos;
+ PyObject *rep;
@ -87,12 +93,6 @@ Index: Objects/unicodeobject.c
+ /* integer overflow */
+ PyErr_NoMemory();
goto error;
- /* Implementation limitations: only support error handler that return
- bytes, and only support up to four replacement bytes. */
- if (!PyBytes_Check(rep)) {
- PyErr_SetString(PyExc_TypeError, "error handler should have returned bytes");
- Py_DECREF(rep);
- goto error;
}
- if (PyBytes_Size(rep) > 4) {
- PyErr_SetString(PyExc_TypeError, "error handler returned too many bytes");
@ -140,9 +140,7 @@ Index: Objects/unicodeobject.c
- continue;
+ Py_DECREF(rep);
}
-#ifndef Py_UNICODE_WIDE
- encodeUCS4:
-#endif
+ } else if (ch < 0x10000) {
+ *p++ = (char)(0xe0 | (ch >> 12));
+ *p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
@ -151,11 +149,11 @@ Index: Objects/unicodeobject.c
/* Encode UCS4 Unicode ordinals */
*p++ = (char)(0xf0 | (ch >> 18));
*p++ = (char)(0x80 | ((ch >> 12) & 0x3f));
Index: Lib/test/test_codecs.py
Index: Python-3.1.2/Lib/test/test_codecs.py
===================================================================
--- Lib/test/test_codecs.py (revision 80382)
+++ Lib/test/test_codecs.py (revision 80383)
@@ -571,6 +571,16 @@
--- Python-3.1.2.orig/Lib/test/test_codecs.py
+++ Python-3.1.2/Lib/test/test_codecs.py
@@ -571,6 +571,16 @@ class UTF8Test(ReadTest):
def test_lone_surrogates(self):
self.assertRaises(UnicodeEncodeError, "\ud800".encode, "utf-8")
self.assertRaises(UnicodeDecodeError, b"\xed\xa0\x80".decode, "utf-8")
@ -172,4 +170,3 @@ Index: Lib/test/test_codecs.py
def test_surrogatepass_handler(self):
self.assertEquals("abc\ud800def".encode("utf-8", "surrogatepass"),