[Python-checkins] r65762 - in python/trunk: Misc/NEWS Modules/cjkcodecs/multibytecodec.c

hirokazu.yamamoto python-checkins at python.org
Sun Aug 17 15:10:47 CEST 2008


Author: hirokazu.yamamoto
Date: Sun Aug 17 15:10:46 2008
New Revision: 65762

Log:
Backport r65661, r65760: Issue #3575: Incremental decoder's decode
function now takes bytearray by using 's*' instead of 't#'.

Modified:
   python/trunk/Misc/NEWS
   python/trunk/Modules/cjkcodecs/multibytecodec.c

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Aug 17 15:10:46 2008
@@ -48,6 +48,9 @@
 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)
 

Modified: python/trunk/Modules/cjkcodecs/multibytecodec.c
==============================================================================
--- python/trunk/Modules/cjkcodecs/multibytecodec.c	(original)
+++ python/trunk/Modules/cjkcodecs/multibytecodec.c	Sun Aug 17 15:10:46 2008
@@ -600,18 +600,24 @@
 	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 @@
 		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 @@
 {
 	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 @@
 		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);


More information about the Python-checkins mailing list