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 /Modules/cjkcodecs | |
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 'Modules/cjkcodecs')
-rw-r--r-- | Modules/cjkcodecs/multibytecodec.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 4c865ec..33bd779 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -633,7 +633,8 @@ MultibyteCodec_Decode(MultibyteCodecObject *self, return make_tuple(PyUnicode_New(0, 0), 0); } - _PyUnicodeWriter_Init(&buf.writer, datalen); + _PyUnicodeWriter_Init(&buf.writer); + buf.writer.min_length = datalen; buf.excobj = NULL; buf.inbuf = buf.inbuf_top = (unsigned char *)data; buf.inbuf_end = buf.inbuf_top + datalen; @@ -839,7 +840,7 @@ decoder_prepare_buffer(MultibyteDecodeBuffer *buf, const char *data, { buf->inbuf = buf->inbuf_top = (const unsigned char *)data; buf->inbuf_end = buf->inbuf_top + size; - _PyUnicodeWriter_Init(&buf->writer, size); + buf->writer.min_length += size; return 0; } @@ -1037,7 +1038,7 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self, data = pdata.buf; size = pdata.len; - _PyUnicodeWriter_Init(&buf.writer, 1); + _PyUnicodeWriter_Init(&buf.writer); buf.excobj = NULL; origpending = self->pendingsize; @@ -1241,7 +1242,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self, if (sizehint == 0) return PyUnicode_New(0, 0); - _PyUnicodeWriter_Init(&buf.writer, 1); + _PyUnicodeWriter_Init(&buf.writer); buf.excobj = NULL; cres = NULL; |