summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-02-08 17:03:27 (GMT)
committerGuido van Rossum <guido@python.org>1999-02-08 17:03:27 (GMT)
commit68de0641ce97d820999b6ce8d67aa9b08823b8bf (patch)
treecd8d34826049736c7d5d7514a016d6ebceaaefbe
parentc55b0ca60186d021fb08557ab487b123bc06fcc8 (diff)
downloadcpython-68de0641ce97d820999b6ce8d67aa9b08823b8bf.zip
cpython-68de0641ce97d820999b6ce8d67aa9b08823b8bf.tar.gz
cpython-68de0641ce97d820999b6ce8d67aa9b08823b8bf.tar.bz2
The writelines() function was never tested and contained numerous bugs
(including a docstring saying "blah"). Fixed all this. (Please review for potential memory leaks!)
-rw-r--r--Modules/cStringIO.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 27be498..bc37984 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -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[] = {