diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-04-17 21:02:17 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-04-17 21:02:17 (GMT) |
commit | 8f674ccd6442fd4d415f2d9d1ad8b09c1b4f9f30 (patch) | |
tree | 8c66aa5789027ee1ed14128aa6ad6d85e1b076a7 /Include/unicodeobject.h | |
parent | e84a51c38edc35e4c1e1df6b28b1e3be95ba8d00 (diff) | |
download | cpython-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 'Include/unicodeobject.h')
-rw-r--r-- | Include/unicodeobject.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index d613311..ed7db28 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -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. |