cpython: c10a3ddba483 (original) (raw)
Mercurial > cpython
changeset 82059:c10a3ddba483
(Merge 3.3) Issue #17137: When an Unicode string is resized, the internal wide character string (wstr) format is now cleared. [#17137]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Thu, 07 Feb 2013 23:17:34 +0100 |
parents | b8a6bc70fc08(current diff)3b316ea5aa82(diff) |
children | 771a0317da83 |
files | Lib/test/test_unicode.py Misc/NEWS Objects/unicodeobject.c |
diffstat | 3 files changed, 22 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_unicode.py 15 Misc/NEWS 3 Objects/unicodeobject.c 4 |
line wrap: on
line diff
--- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -2191,6 +2191,21 @@ class UnicodeTest(string_tests.CommonTes self.assertEqual(args[0], text) self.assertEqual(len(args), 1)
- def test_resize(self):
for length in range(1, 100, 7):[](#l1.8)
# generate a fresh string (refcount=1)[](#l1.9)
text = 'a' * length + 'b'[](#l1.10)
# fill wstr internal field[](#l1.12)
abc = text.encode('unicode_internal')[](#l1.13)
self.assertEqual(abc.decode('unicode_internal'), text)[](#l1.14)
# resize text: wstr field must be cleared and then recomputed[](#l1.16)
text += 'c'[](#l1.17)
abcdef = text.encode('unicode_internal')[](#l1.18)
self.assertNotEqual(abc, abcdef)[](#l1.19)
self.assertEqual(abcdef.decode('unicode_internal'), text)[](#l1.20)
+ class StringModuleTest(unittest.TestCase): def test_formatter_parser(self):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #17137: When an Unicode string is resized, the internal wide character
--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -717,6 +717,10 @@ resize_compact(PyObject *unicode, Py_ssi if (!PyUnicode_IS_ASCII(unicode)) _PyUnicode_WSTR_LENGTH(unicode) = length; }
- else if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) {
PyObject_DEL(_PyUnicode_WSTR(unicode));[](#l3.8)
_PyUnicode_WSTR(unicode) = NULL;[](#l3.9)
- }
#ifdef Py_DEBUG unicode_fill_invalid(unicode, old_length); #endif