summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-05-05 05:36:48 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-05-05 05:36:48 (GMT)
commit2cfe36828342e16cd274b968736a01aed5c49557 (patch)
tree8ee8bf38509e6abf06a98d561973d3a3eccee01d /Objects/stringobject.c
parent432b42aa4c31fd473690ffeee446dcd493f8a8aa (diff)
downloadcpython-2cfe36828342e16cd274b968736a01aed5c49557.zip
cpython-2cfe36828342e16cd274b968736a01aed5c49557.tar.gz
cpython-2cfe36828342e16cd274b968736a01aed5c49557.tar.bz2
Make unicode.join() work nice with iterators. This also required a change
to string.join(), so that when the latter figures out in midstream that it really needs unicode.join() instead, unicode.join() can actually get all the sequence elements (i.e., there's no guarantee that the sequence passed to string.join() can be iterated over *again* by unicode.join(), so string.join() must not pass on the original sequence object anymore).
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index b905679..87d7c195 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -861,8 +861,15 @@ string_join(PyStringObject *self, PyObject *args)
item = PySequence_Fast_GET_ITEM(seq, i);
if (!PyString_Check(item)){
if (PyUnicode_Check(item)) {
+ /* Defer to Unicode join.
+ * CAUTION: There's no gurantee that the
+ * original sequence can be iterated over
+ * again, so we must pass seq here.
+ */
+ PyObject *result;
+ result = PyUnicode_Join((PyObject *)self, seq);
Py_DECREF(seq);
- return PyUnicode_Join((PyObject *)self, orig);
+ return result;
}
PyErr_Format(PyExc_TypeError,
"sequence item %i: expected string,"