mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
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
This commit is contained in:
parent
e84a51c38e
commit
8f674ccd64
7 changed files with 81 additions and 71 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue