Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 20007:56ffee1eeeec legacy-trunk
Fix Unicode .join() method to raise a TypeError for sequence
elements which are not Unicode objects or strings. (This matches
the string.join() behaviour.)
Fix a memory leak in the .join() method which occurs in case
the Unicode resize fails.
Restore the test_unicode output.
| author | Marc-André Lemburg <mal@egenix.com> |
|---|---|
| date | Thu, 20 Sep 2001 17:22:58 +0000 |
| parents | 1f4e2627b627 |
| children | 8aa1ada33f64 |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Thu Sep 20 16:37:23 2001 +0000 +++ b/Objects/unicodeobject.c Thu Sep 20 17:22:58 2001 +0000 @@ -3197,6 +3197,14 @@ } if (!PyUnicode_Check(item)) { PyObject *v; + if (!PyString_Check(item)) { + PyErr_Format(PyExc_TypeError, + "sequence item %i: expected string or Unicode," + " %.80s found", + i, item->ob_type->tp_name); + Py_DECREF(item); + goto onError; + } v = PyUnicode_FromObject(item); Py_DECREF(item); item = v; @@ -3205,8 +3213,10 @@ } itemlen = PyUnicode_GET_SIZE(item); while (reslen + itemlen + seplen >= sz) { - if (_PyUnicode_Resize(&res, sz*2)) + if (_PyUnicode_Resize(&res, sz*2)) { + Py_DECREF(item); goto onError; + } sz *= 2; p = PyUnicode_AS_UNICODE(res) + reslen; }
