mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +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
|
@ -898,22 +898,28 @@ typedef struct {
|
|||
Py_UCS4 maxchar;
|
||||
Py_ssize_t size;
|
||||
Py_ssize_t pos;
|
||||
/* minimum length of the buffer when overallocation is enabled,
|
||||
see _PyUnicodeWriter_Init() */
|
||||
|
||||
/* minimum number of allocated characters (default: 0) */
|
||||
Py_ssize_t min_length;
|
||||
|
||||
/* minimum character (default: 127, ASCII) */
|
||||
Py_UCS4 min_char;
|
||||
|
||||
/* If non-zero, overallocate the buffer by 25% (default: 0). */
|
||||
unsigned char overallocate;
|
||||
|
||||
/* If readonly is 1, buffer is a shared string (cannot be modified)
|
||||
and size is set to 0. */
|
||||
unsigned char readonly;
|
||||
} _PyUnicodeWriter ;
|
||||
|
||||
/* Initialize a Unicode writer.
|
||||
|
||||
If min_length is greater than zero, _PyUnicodeWriter_Prepare()
|
||||
overallocates the buffer and min_length is the minimum length in characters
|
||||
of the buffer. */
|
||||
*
|
||||
* By default, the minimum buffer size is 0 character and overallocation is
|
||||
* disabled. Set min_length, min_char and overallocate attributes to control
|
||||
* the allocation of the buffer. */
|
||||
PyAPI_FUNC(void)
|
||||
_PyUnicodeWriter_Init(_PyUnicodeWriter *writer, Py_ssize_t min_length);
|
||||
_PyUnicodeWriter_Init(_PyUnicodeWriter *writer);
|
||||
|
||||
/* Prepare the buffer to write 'length' characters
|
||||
with the specified maximum character.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue