![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
Author: alexandre.vassalotti Date: Thu May 31 01:28:06 2007 New Revision: 55700 Modified: python/branches/cpy_merge/Modules/_string_iomodule.c Log: Fix string_io_writelines(). Rename a few variables. Modified: python/branches/cpy_merge/Modules/_string_iomodule.c ============================================================================== --- python/branches/cpy_merge/Modules/_string_iomodule.c (original) +++ python/branches/cpy_merge/Modules/_string_iomodule.c Thu May 31 01:28:06 2007 @@ -56,7 +56,7 @@ /* Internal routine for writing a string of bytes to the buffer of a StringIO object. Returns the number of bytes wrote. */ static Py_ssize_t -write_bytes(StringIOObject *self, const Py_UNICODE *c, Py_ssize_t l) +write_str(StringIOObject *self, const Py_UNICODE *ustr, Py_ssize_t l) { Py_ssize_t newl; @@ -79,7 +79,7 @@ } } - memcpy(self->buf + self->pos, c, l * sizeof(Py_UNICODE)); + memcpy(self->buf + self->pos, ustr, l * sizeof(Py_UNICODE)); assert(self->pos + l < PY_SSIZE_T_MAX); self->pos += l; @@ -320,16 +320,18 @@ static PyObject * string_io_write(StringIOObject *self, PyObject *args) { - const Py_UNICODE *c; - Py_ssize_t l; + const Py_UNICODE *ustr; + Py_ssize_t n; if (self->buf == NULL) return err_closed(); - if (!PyArg_ParseTuple(args, "u#:write", &c, &l)) + if (!PyArg_ParseTuple(args, + "u#;write() may only be called on" + "unicode strings", &ustr, &n)) return NULL; - if (write_bytes(self, c, l) == -1) + if (write_str(self, ustr, n) == -1) return NULL; Py_RETURN_NONE; @@ -349,15 +351,18 @@ while ((item = PyIter_Next(it)) != NULL) { Py_ssize_t n; - Py_UNICODE *c; - if (PyString_AsStringAndSize(item, &c, &n) == -1) { + Py_UNICODE *ustr; + if ((ustr = PyUnicode_AsUnicode(item)) == NULL) { + PyErr_SetString(PyExc_TypeError, + "Need a list of unicode objects"); Py_DECREF(it); Py_DECREF(item); return NULL; } + n = PyUnicode_GetSize(item); Py_DECREF(item); - if (write_bytes(self, c, n) == -1) { + if (write_str(self, ustr, n) == -1) { Py_DECREF(it); return NULL; } @@ -417,7 +422,7 @@ self->string_size = 0; if (n > 0) { - if (write_bytes(self, buf, n) == -1) + if (write_str(self, buf, n) == -1) return NULL; self->pos = 0; }
participants (1)
-
alexandre.vassalotti