[Python-checkins] r68520 - sandbox/trunk/io-c/_textio.c

antoine.pitrou python-checkins at python.org
Sun Jan 11 03:48:38 CET 2009


Author: antoine.pitrou
Date: Sun Jan 11 03:48:38 2009
New Revision: 68520

Log:
Fix failures in test_univnewline. TextIOWrapper_read_chunk was returning 0 (eof)
even if a last byte had been returned by the IncrementalNewlineDecoder
(which happens when a file open in universal newlines mode ends with a '\r').



Modified:
   sandbox/trunk/io-c/_textio.c

Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c	(original)
+++ sandbox/trunk/io-c/_textio.c	Sun Jan 11 03:48:38 2009
@@ -886,9 +886,12 @@
     decoded_chars = PyObject_CallMethod(self->decoder, "decode",
                                         "Oi", input_chunk, eof);
 
+    /* TODO sanity check: isinstance(decoded_chars, unicode) */
     if (decoded_chars == NULL)
         goto fail;
     TextIOWrapper_set_decoded_chars(self, decoded_chars);
+    if (PyUnicode_GET_SIZE(decoded_chars) > 0)
+        eof = 0;
 
     if (self->telling) {
         /* At the snapshot point, len(dec_buffer) bytes before the read, the
@@ -1209,10 +1212,17 @@
             }
         }
     }
-    if (chunks != NULL) {
-        if (remaining != NULL && PyList_Append(chunks, remaining) < 0)
+    if (remaining != NULL) {
+        if (chunks == NULL) {
+            chunks = PyList_New(0);
+            if (chunks == NULL)
+                goto error;
+        }
+        if (PyList_Append(chunks, remaining) < 0)
             goto error;
         Py_CLEAR(remaining);
+    }
+    if (chunks != NULL) {
         if (line != NULL && PyList_Append(chunks, line) < 0)
             goto error;
         Py_CLEAR(line);


More information about the Python-checkins mailing list