summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-04-17 21:02:17 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-04-17 21:02:17 (GMT)
commit8f674ccd6442fd4d415f2d9d1ad8b09c1b4f9f30 (patch)
tree8c66aa5789027ee1ed14128aa6ad6d85e1b076a7 /Objects/stringlib
parente84a51c38edc35e4c1e1df6b28b1e3be95ba8d00 (diff)
downloadcpython-8f674ccd6442fd4d415f2d9d1ad8b09c1b4f9f30.zip
cpython-8f674ccd6442fd4d415f2d9d1ad8b09c1b4f9f30.tar.gz
cpython-8f674ccd6442fd4d415f2d9d1ad8b09c1b4f9f30.tar.bz2
Close #17694: Add minimum length to _PyUnicodeWriter
* Add also min_char attribute to _PyUnicodeWriter structure (currently unused) * _PyUnicodeWriter_Init() has no more argument (except the writer itself): min_length and overallocate must be set explicitly * In error handlers, only enable overallocation if the replacement string is longer than 1 character * CJK decoders don't use overallocation anymore * Set min_length, instead of preallocating memory using _PyUnicodeWriter_Prepare(), in many decoders * _PyUnicode_DecodeUnicodeInternal() checks for integer overflow
Diffstat (limited to 'Objects/stringlib')
-rw-r--r--Objects/stringlib/unicode_format.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h
index 2f58946..9429169 100644
--- a/Objects/stringlib/unicode_format.h
+++ b/Objects/stringlib/unicode_format.h
@@ -906,7 +906,6 @@ build_string(SubString *input, PyObject *args, PyObject *kwargs,
int recursion_depth, AutoNumber *auto_number)
{
_PyUnicodeWriter writer;
- Py_ssize_t minlen;
/* check the recursion level */
if (recursion_depth <= 0) {
@@ -915,8 +914,9 @@ build_string(SubString *input, PyObject *args, PyObject *kwargs,
return NULL;
}
- minlen = PyUnicode_GET_LENGTH(input->str) + 100;
- _PyUnicodeWriter_Init(&writer, minlen);
+ _PyUnicodeWriter_Init(&writer);
+ writer.overallocate = 1;
+ writer.min_length = PyUnicode_GET_LENGTH(input->str) + 100;
if (!do_markup(input, args, kwargs, &writer, recursion_depth,
auto_number)) {