[Python-checkins] r57163 - python/branches/alex-py3k/Modules/_stringiomodule.c

alexandre.vassalotti python-checkins at python.org
Fri Aug 17 23:11:51 CEST 2007


Author: alexandre.vassalotti
Date: Fri Aug 17 23:11:30 2007
New Revision: 57163

Modified:
   python/branches/alex-py3k/Modules/_stringiomodule.c
Log:
Change the return type of resize_buffer() to int.
Remove some unnecessary cruft in resize_buffer().
Add a check to see if PyMem_New() failed in StringIO_new().



Modified: python/branches/alex-py3k/Modules/_stringiomodule.c
==============================================================================
--- python/branches/alex-py3k/Modules/_stringiomodule.c	(original)
+++ python/branches/alex-py3k/Modules/_stringiomodule.c	Fri Aug 17 23:11:30 2007
@@ -45,8 +45,8 @@
 }
 
 /* Internal routine for changing the size of the buffer of StringIO
-   objects. Returns the new buffer size, or -1 on error. */
-static Py_ssize_t
+   objects. Returns 0 on success, -1 otherwise. */
+static int
 resize_buffer(StringIOObject *self, Py_ssize_t new_size)
 {
     /* Here we doing some direct memory manipulation for speed and to keep the
@@ -59,13 +59,11 @@
 
         PyMem_Resize(self->buf, Py_UNICODE, self->buf_size);
         if (self->buf == NULL) {
-            PyErr_SetString(PyExc_MemoryError, "Out of memory");
-            PyMem_Del(self->buf);
-            self->buf_size = self->pos = 0;
+            PyErr_NoMemory();
             return -1;
         }
     }
-    return self->buf_size;
+    return 0;
 }
 
 /* Internal routine for writing a string of bytes to the buffer of a StringIO
@@ -407,6 +405,10 @@
         return NULL;
 
     self->buf = PyMem_New(Py_UNICODE, INIT_BUFSIZE);
+    if (self->buf == NULL) {
+        PyErr_NoMemory();
+        return NULL;
+    }
 
     /* These variables need to be initialized before attempting to write
        anything to the object. */


More information about the Python-checkins mailing list