mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Backport r65661, r65760: Issue #3575: Incremental decoder's decode
function now takes bytearray by using 's*' instead of 't#'.
This commit is contained in:
parent
c53427087e
commit
41a81eb6cb
2 changed files with 21 additions and 5 deletions
|
@ -48,6 +48,9 @@ Core and Builtins
|
||||||
Library
|
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()
|
- Issue #2222: Fixed reference leak when occured os.rename()
|
||||||
fails unicode conversion on 2nd parameter. (windows only)
|
fails unicode conversion on 2nd parameter. (windows only)
|
||||||
|
|
||||||
|
|
|
@ -600,18 +600,24 @@ MultibyteCodec_Decode(MultibyteCodecObject *self,
|
||||||
MultibyteCodec_State state;
|
MultibyteCodec_State state;
|
||||||
MultibyteDecodeBuffer buf;
|
MultibyteDecodeBuffer buf;
|
||||||
PyObject *errorcb;
|
PyObject *errorcb;
|
||||||
|
Py_buffer pdata;
|
||||||
const char *data, *errors = NULL;
|
const char *data, *errors = NULL;
|
||||||
Py_ssize_t datalen, finalsize;
|
Py_ssize_t datalen, finalsize;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|z:decode",
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|z:decode",
|
||||||
codeckwarglist, &data, &datalen, &errors))
|
codeckwarglist, &pdata, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
data = pdata.buf;
|
||||||
|
datalen = pdata.len;
|
||||||
|
|
||||||
errorcb = internal_error_callback(errors);
|
errorcb = internal_error_callback(errors);
|
||||||
if (errorcb == NULL)
|
if (errorcb == NULL) {
|
||||||
|
PyBuffer_Release(&pdata);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (datalen == 0) {
|
if (datalen == 0) {
|
||||||
|
PyBuffer_Release(&pdata);
|
||||||
ERROR_DECREF(errorcb);
|
ERROR_DECREF(errorcb);
|
||||||
return make_tuple(PyUnicode_FromUnicode(NULL, 0), 0);
|
return make_tuple(PyUnicode_FromUnicode(NULL, 0), 0);
|
||||||
}
|
}
|
||||||
|
@ -651,11 +657,13 @@ MultibyteCodec_Decode(MultibyteCodecObject *self,
|
||||||
if (PyUnicode_Resize(&buf.outobj, finalsize) == -1)
|
if (PyUnicode_Resize(&buf.outobj, finalsize) == -1)
|
||||||
goto errorexit;
|
goto errorexit;
|
||||||
|
|
||||||
|
PyBuffer_Release(&pdata);
|
||||||
Py_XDECREF(buf.excobj);
|
Py_XDECREF(buf.excobj);
|
||||||
ERROR_DECREF(errorcb);
|
ERROR_DECREF(errorcb);
|
||||||
return make_tuple(buf.outobj, datalen);
|
return make_tuple(buf.outobj, datalen);
|
||||||
|
|
||||||
errorexit:
|
errorexit:
|
||||||
|
PyBuffer_Release(&pdata);
|
||||||
ERROR_DECREF(errorcb);
|
ERROR_DECREF(errorcb);
|
||||||
Py_XDECREF(buf.excobj);
|
Py_XDECREF(buf.excobj);
|
||||||
Py_XDECREF(buf.outobj);
|
Py_XDECREF(buf.outobj);
|
||||||
|
@ -1018,12 +1026,15 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
|
||||||
{
|
{
|
||||||
MultibyteDecodeBuffer buf;
|
MultibyteDecodeBuffer buf;
|
||||||
char *data, *wdata = NULL;
|
char *data, *wdata = NULL;
|
||||||
|
Py_buffer pdata;
|
||||||
Py_ssize_t wsize, finalsize = 0, size, origpending;
|
Py_ssize_t wsize, finalsize = 0, size, origpending;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "t#|i:decode",
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|i:decode",
|
||||||
incrementalkwarglist, &data, &size, &final))
|
incrementalkwarglist, &pdata, &final))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
data = pdata.buf;
|
||||||
|
size = pdata.len;
|
||||||
|
|
||||||
buf.outobj = buf.excobj = NULL;
|
buf.outobj = buf.excobj = NULL;
|
||||||
origpending = self->pendingsize;
|
origpending = self->pendingsize;
|
||||||
|
@ -1072,12 +1083,14 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
|
||||||
if (PyUnicode_Resize(&buf.outobj, finalsize) == -1)
|
if (PyUnicode_Resize(&buf.outobj, finalsize) == -1)
|
||||||
goto errorexit;
|
goto errorexit;
|
||||||
|
|
||||||
|
PyBuffer_Release(&pdata);
|
||||||
if (wdata != data)
|
if (wdata != data)
|
||||||
PyMem_Del(wdata);
|
PyMem_Del(wdata);
|
||||||
Py_XDECREF(buf.excobj);
|
Py_XDECREF(buf.excobj);
|
||||||
return buf.outobj;
|
return buf.outobj;
|
||||||
|
|
||||||
errorexit:
|
errorexit:
|
||||||
|
PyBuffer_Release(&pdata);
|
||||||
if (wdata != NULL && wdata != data)
|
if (wdata != NULL && wdata != data)
|
||||||
PyMem_Del(wdata);
|
PyMem_Del(wdata);
|
||||||
Py_XDECREF(buf.excobj);
|
Py_XDECREF(buf.excobj);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue