]> granicus.if.org Git - python/commitdiff
The writelines() function was never tested and contained numerous bugs
authorGuido van Rossum <guido@python.org>
Mon, 8 Feb 1999 17:03:27 +0000 (17:03 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 8 Feb 1999 17:03:27 +0000 (17:03 +0000)
(including a docstring saying "blah").  Fixed all this.

(Please review for potential memory leaks!)

Modules/cStringIO.c

index 27be4980bf7fe4550f03cf1edf14b71802293819..bc37984cf86b5c366e7b327b930d05548fb2114b 100644 (file)
@@ -343,13 +343,14 @@ O_flush(Oobject *self, PyObject *args) {
 }
 
 
-static char O_writelines__doc__[] = "blah";
+static char O_writelines__doc__[] =
+"writelines(sequence_of_strings): write each string";
 static PyObject *
 O_writelines(Oobject *self, PyObject *args) {
   PyObject *string_module = 0;
   static PyObject *string_joinfields = 0;
 
-  UNLESS(PyArg_ParseTuple(args, "O", args)) {
+  UNLESS(PyArg_ParseTuple(args, "O", &args)) {
     return NULL;
   }
 
@@ -370,8 +371,19 @@ O_writelines(Oobject *self, PyObject *args) {
     return NULL;
   }
 
-  return O_write(self, 
-      PyObject_CallFunction(string_joinfields, "Os", args, ""));
+  {
+         PyObject *x = PyObject_CallFunction(string_joinfields,
+                                             "Os", args, "");
+         if (x == NULL)
+                 return NULL;
+         args = Py_BuildValue("(O)", x);
+         Py_DECREF(x);
+         if (args == NULL)
+                 return NULL;
+         x = O_write(self, args);
+         Py_DECREF(args);
+         return x;
+  }
 }
 
 static struct PyMethodDef O_methods[] = {