]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport r65661, r65760: Issue #3575: Incremental decoder's decode
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Sun, 17 Aug 2008 13:10:46 +0000 (13:10 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Sun, 17 Aug 2008 13:10:46 +0000 (13:10 +0000)
function now takes bytearray by using 's*' instead of 't#'.

Misc/NEWS
Modules/cjkcodecs/multibytecodec.c

index cd056a9e8e367d7b23b6d37631c9309fe5e7013b..4a9218613471659e517b61809e26b60448c8879c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #3575: Incremental decoder's decode function now takes bytearray
+  by using 's*' instead of 't#'.
+
 - Issue #2222: Fixed reference leak when occured os.rename()
   fails unicode conversion on 2nd parameter. (windows only)
 
index 2bd8b0dcce77765e3c1916ca6391310d58a47095..695df028d09c401c2f4151cf661a86a4e7129573 100644 (file)
@@ -600,18 +600,24 @@ MultibyteCodec_Decode(MultibyteCodecObject *self,
        MultibyteCodec_State state;
        MultibyteDecodeBuffer buf;
        PyObject *errorcb;
+       Py_buffer pdata;
        const char *data, *errors = NULL;
        Py_ssize_t datalen, finalsize;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|z:decode",
-                               codeckwarglist, &data, &datalen, &errors))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|z:decode",
+                               codeckwarglist, &pdata, &errors))
                return NULL;
+       data = pdata.buf;
+       datalen = pdata.len;
 
        errorcb = internal_error_callback(errors);
-       if (errorcb == NULL)
+       if (errorcb == NULL) {
+               PyBuffer_Release(&pdata);
                return NULL;
+       }
 
        if (datalen == 0) {
+               PyBuffer_Release(&pdata);
                ERROR_DECREF(errorcb);
                return make_tuple(PyUnicode_FromUnicode(NULL, 0), 0);
        }
@@ -651,11 +657,13 @@ MultibyteCodec_Decode(MultibyteCodecObject *self,
                if (PyUnicode_Resize(&buf.outobj, finalsize) == -1)
                        goto errorexit;
 
+       PyBuffer_Release(&pdata);
        Py_XDECREF(buf.excobj);
        ERROR_DECREF(errorcb);
        return make_tuple(buf.outobj, datalen);
 
 errorexit:
+       PyBuffer_Release(&pdata);
        ERROR_DECREF(errorcb);
        Py_XDECREF(buf.excobj);
        Py_XDECREF(buf.outobj);
@@ -1018,12 +1026,15 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
 {
        MultibyteDecodeBuffer buf;
        char *data, *wdata = NULL;
+       Py_buffer pdata;
        Py_ssize_t wsize, finalsize = 0, size, origpending;
        int final = 0;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "t#|i:decode",
-                       incrementalkwarglist, &data, &size, &final))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|i:decode",
+                       incrementalkwarglist, &pdata, &final))
                return NULL;
+       data = pdata.buf;
+       size = pdata.len;
 
        buf.outobj = buf.excobj = NULL;
        origpending = self->pendingsize;
@@ -1072,12 +1083,14 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
                if (PyUnicode_Resize(&buf.outobj, finalsize) == -1)
                        goto errorexit;
 
+       PyBuffer_Release(&pdata);
        if (wdata != data)
                PyMem_Del(wdata);
        Py_XDECREF(buf.excobj);
        return buf.outobj;
 
 errorexit:
+       PyBuffer_Release(&pdata);
        if (wdata != NULL && wdata != data)
                PyMem_Del(wdata);
        Py_XDECREF(buf.excobj);