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

amaury.forgeotdarc python-checkins at python.org
Mon Dec 29 22:16:54 CET 2008


Author: amaury.forgeotdarc
Date: Mon Dec 29 22:16:53 2008
New Revision: 68029

Log:
Move a variable to the top of the function, and untabify.


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	Mon Dec 29 22:16:53 2008
@@ -723,8 +723,8 @@
             Py_DECREF(state);
             return -1;
         }
-	Py_INCREF(dec_buffer);
-	Py_INCREF(dec_flags);
+        Py_INCREF(dec_buffer);
+        Py_INCREF(dec_flags);
         Py_DECREF(state);
     }
 
@@ -1089,6 +1089,7 @@
 TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
 {
     PyObject *cookieObj;
+    CookieStruct cookie;
     int whence = 0;
     static PyObject *zero = NULL;
     PyObject *res;
@@ -1117,38 +1118,38 @@
         /* seek relative to current position */
         cmp = PyObject_RichCompareBool(cookieObj, zero, Py_EQ);
         if (cmp < 0)
-	    goto fail;
+            goto fail;
 
         if (cmp == 0) {
             PyErr_SetString(PyExc_IOError,
                             "can't do nonzero cur-relative seeks");
-	    goto fail;
+            goto fail;
         }
 
         /* Seeking to the current position should attempt to
          * sync the underlying buffer with the current position.
          */
-	Py_DECREF(cookieObj);
+        Py_DECREF(cookieObj);
         cookieObj = PyObject_CallMethod((PyObject *)self, "tell", NULL);
-	if (cookieObj == NULL)
-	    goto fail;
+        if (cookieObj == NULL)
+            goto fail;
     }
     else if (whence == 2) {
         /* seek relative to end of file */
 
         cmp = PyObject_RichCompareBool(cookieObj, zero, Py_EQ);
         if (cmp < 0)
-	    goto fail;
+            goto fail;
 
         if (cmp == 0) {
             PyErr_SetString(PyExc_IOError,
                             "can't do nonzero end-relative seeks");
-	    goto fail;
+            goto fail;
         }
 
         res = PyObject_CallMethod((PyObject *)self, "flush", NULL);
         if (res == NULL)
-	    goto fail;
+            goto fail;
         Py_DECREF(res);
 
         TextIOWrapper_set_decoded_chars(self, NULL);
@@ -1156,7 +1157,7 @@
         if (self->decoder) {
             res = PyObject_CallMethod(self->decoder, "reset", NULL);
             if (res == NULL)
-		goto fail;
+                goto fail;
             Py_DECREF(res);
         }
 
@@ -1166,7 +1167,7 @@
     else if (whence != 0) {
         PyErr_Format(PyExc_ValueError,
                      "invalid whence (%d, should be 0, 1 or 2)", whence);
-	goto fail;
+        goto fail;
     }
 
     cmp = PyObject_RichCompareBool(cookieObj, zero, Py_LT);
@@ -1187,65 +1188,61 @@
     /* The strategy of seek() is to go back to the safe start point
      * and replay the effect of read(chars_to_skip) from there.
      */
-    {
-	CookieStruct cookie;
+    if (TextIOWrapper_parseCookie(&cookie, cookieObj) < 0)
+        goto fail;
 
-	if (TextIOWrapper_parseCookie(&cookie, cookieObj) < 0)
-	    goto fail;
+    /* Seek back to the safe start point. */
+    res = PyObject_CallMethod(self->buffer, "seek",
+                              "L", (PY_LONG_LONG)cookie.start_pos);
+    if (res == NULL)
+        goto fail;
+    Py_DECREF(res);
 
-        /* Seek back to the safe start point. */
-	res = PyObject_CallMethod(self->buffer, "seek",
-				  "L", (PY_LONG_LONG)cookie.start_pos);
-	if (res == NULL)
-	    goto fail;
-	Py_DECREF(res);
-
-	TextIOWrapper_set_decoded_chars(self, NULL);
-	Py_CLEAR(self->snapshot);
-
-        /* Restore the decoder to its state from the safe start point. */
-	if (self->decoder || cookie.dec_flags || cookie.chars_to_skip) {
-	    res = PyObject_CallMethod(self->decoder, "setstate",
-				      "((yi))", "", cookie.dec_flags);
-	    if (res == NULL)
-		goto fail;
-	    Py_DECREF(res);
-
-	    self->snapshot = Py_BuildValue("((iy))", cookie.dec_flags, "");
-	    if (self->snapshot == NULL)
-		goto fail;
-	}
-
-	if (cookie.chars_to_skip) {
-	    /* Just like _read_chunk, feed the decoder and save a snapshot. */
-	    PyObject *input_chunk = PyObject_CallMethod(
-		self->buffer, "read", "i", cookie.bytes_to_feed);
-	    PyObject *decoded;
-
-	    if (input_chunk == NULL)
-		goto fail;
-
-	    self->snapshot = Py_BuildValue("((iO))", cookie.dec_flags, input_chunk);
-	    if (self->snapshot == NULL) {
-		Py_DECREF(input_chunk);
-		goto fail;
-	    }
-
-	    decoded = PyObject_CallMethod(self->decoder, "decode",
-					  "Ni", input_chunk, (int)cookie.need_eof);
-
-	    if (decoded == NULL)
-		goto fail;
-
-	    TextIOWrapper_set_decoded_chars(self, decoded);
-
-	    /* Skip chars_to_skip of the decoded characters. */
-	    if (PyUnicode_GetSize(self->decoded_chars) < cookie.chars_to_skip) {
-		PyErr_SetString(PyExc_IOError, "can't restore logical file position");
-		goto fail;
-	    }
-            self->decoded_chars_used = cookie.chars_to_skip;
-	}
+    TextIOWrapper_set_decoded_chars(self, NULL);
+    Py_CLEAR(self->snapshot);
+
+    /* Restore the decoder to its state from the safe start point. */
+    if (self->decoder || cookie.dec_flags || cookie.chars_to_skip) {
+        res = PyObject_CallMethod(self->decoder, "setstate",
+                                  "((yi))", "", cookie.dec_flags);
+        if (res == NULL)
+            goto fail;
+        Py_DECREF(res);
+
+        self->snapshot = Py_BuildValue("((iy))", cookie.dec_flags, "");
+        if (self->snapshot == NULL)
+            goto fail;
+    }
+
+    if (cookie.chars_to_skip) {
+        /* Just like _read_chunk, feed the decoder and save a snapshot. */
+        PyObject *input_chunk = PyObject_CallMethod(
+            self->buffer, "read", "i", cookie.bytes_to_feed);
+        PyObject *decoded;
+
+        if (input_chunk == NULL)
+            goto fail;
+
+        self->snapshot = Py_BuildValue("((iO))", cookie.dec_flags, input_chunk);
+        if (self->snapshot == NULL) {
+            Py_DECREF(input_chunk);
+            goto fail;
+        }
+
+        decoded = PyObject_CallMethod(self->decoder, "decode",
+                                      "Ni", input_chunk, (int)cookie.need_eof);
+
+        if (decoded == NULL)
+            goto fail;
+
+        TextIOWrapper_set_decoded_chars(self, decoded);
+
+        /* Skip chars_to_skip of the decoded characters. */
+        if (PyUnicode_GetSize(self->decoded_chars) < cookie.chars_to_skip) {
+            PyErr_SetString(PyExc_IOError, "can't restore logical file position");
+            goto fail;
+        }
+        self->decoded_chars_used = cookie.chars_to_skip;
     }
 
     return cookieObj;


More information about the Python-checkins mailing list