Antoine Pitrou <[EMAIL PROTECTED]> added the comment:
I'm attaching a patch for getargs.c and another patch for the codecs
module.
Added file: http://bugs.python.org/file11032/codecs.patch
Added file: http://bugs.python.org/file11033/getargs.patch
_______________________________________
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue3139>
_______________________________________
diff -r 989576c66c9a Modules/_codecsmodule.c
--- a/Modules/_codecsmodule.c Fri Aug 01 20:49:15 2008 +0200
+++ b/Modules/_codecsmodule.c Fri Aug 01 21:30:03 2008 +0200
@@ -232,20 +232,20 @@ utf_7_decode(PyObject *self,
utf_7_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int final = 0;
Py_ssize_t consumed;
PyObject *decoded = NULL;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_7_decode",
- &data, &size, &errors, &final))
- return NULL;
- consumed = size;
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_7_decode",
+ &pbuf, &errors, &final))
+ return NULL;
+ consumed = pbuf.len;
- decoded = PyUnicode_DecodeUTF7Stateful(data, size, errors,
- final ? NULL : &consumed);
+ decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
+ final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
@@ -255,24 +255,20 @@ utf_8_decode(PyObject *self,
utf_8_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int final = 0;
Py_ssize_t consumed;
PyObject *decoded = NULL;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_8_decode",
+ &pbuf, &errors, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size;
-
- decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
+ consumed = pbuf.len;
+
+ decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
@@ -282,24 +278,20 @@ utf_16_decode(PyObject *self,
utf_16_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = 0;
int final = 0;
Py_ssize_t consumed;
PyObject *decoded;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_16_decode",
+ &pbuf, &errors, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
- final ? NULL : &consumed);
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
+ &byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
@@ -309,53 +301,45 @@ utf_16_le_decode(PyObject *self,
utf_16_le_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = -1;
int final = 0;
Py_ssize_t consumed;
PyObject *decoded = NULL;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_16_le_decode",
+ &pbuf, &errors, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
&byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
-
}
static PyObject *
utf_16_be_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = 1;
int final = 0;
Py_ssize_t consumed;
PyObject *decoded = NULL;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_16_be_decode",
+ &pbuf, &errors, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
+
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
&byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
@@ -373,24 +357,20 @@ utf_16_ex_decode(PyObject *self,
utf_16_ex_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = 0;
PyObject *unicode, *tuple;
int final = 0;
Py_ssize_t consumed;
- if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
- &data, &size, &errors, &byteorder, &final))
+ if (!PyArg_ParseTuple(args, "s*|zii:utf_16_ex_decode",
+ &pbuf, &errors, &byteorder, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
- final ? NULL : &consumed);
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
+ &byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (unicode == NULL)
return NULL;
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
@@ -402,24 +382,20 @@ utf_32_decode(PyObject *self,
utf_32_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = 0;
int final = 0;
Py_ssize_t consumed;
PyObject *decoded;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_32_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_32_decode",
+ &pbuf, &errors, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder,
- final ? NULL : &consumed);
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
+ &byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
@@ -429,53 +405,43 @@ utf_32_le_decode(PyObject *self,
utf_32_le_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = -1;
int final = 0;
Py_ssize_t consumed;
- PyObject *decoded = NULL;
+ PyObject *decoded;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_32_le_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_32_le_decode",
+ &pbuf, &errors, &final))
return NULL;
-
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors,
- &byteorder, final ? NULL : &consumed);
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
+ &byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
-
}
static PyObject *
utf_32_be_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = 1;
int final = 0;
Py_ssize_t consumed;
- PyObject *decoded = NULL;
+ PyObject *decoded;
- if (!PyArg_ParseTuple(args, "t#|zi:utf_32_be_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:utf_32_be_decode",
+ &pbuf, &errors, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors,
- &byteorder, final ? NULL : &consumed);
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
+ &byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (decoded == NULL)
return NULL;
return codec_tuple(decoded, consumed);
@@ -493,24 +459,20 @@ utf_32_ex_decode(PyObject *self,
utf_32_ex_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
int byteorder = 0;
PyObject *unicode, *tuple;
int final = 0;
Py_ssize_t consumed;
- if (!PyArg_ParseTuple(args, "t#|zii:utf_32_ex_decode",
- &data, &size, &errors, &byteorder, &final))
+ if (!PyArg_ParseTuple(args, "s*|zii:utf_32_ex_decode",
+ &pbuf, &errors, &byteorder, &final))
return NULL;
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative argument");
- return 0;
- }
- consumed = size; /* This is overwritten unless final is true. */
- unicode = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder,
- final ? NULL : &consumed);
+ consumed = pbuf.len; /* This is overwritten unless final is true. */
+ unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
+ &byteorder, final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
if (unicode == NULL)
return NULL;
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
@@ -522,83 +484,88 @@ unicode_escape_decode(PyObject *self,
unicode_escape_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
+ PyObject *unicode;
- if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
- &data, &size, &errors))
+ if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode",
+ &pbuf, &errors))
return NULL;
- return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors),
- size);
+ unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
+ PyBuffer_Release(&pbuf);
+ return codec_tuple(unicode, pbuf.len);
}
static PyObject *
raw_unicode_escape_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
const char *errors = NULL;
+ PyObject *unicode;
- if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
- &data, &size, &errors))
+ if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
+ &pbuf, &errors))
return NULL;
- return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors),
- size);
+ unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
+ PyBuffer_Release(&pbuf);
+ return codec_tuple(unicode, pbuf.len);
}
static PyObject *
latin_1_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
+ PyObject *unicode;
const char *errors = NULL;
- if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
- &data, &size, &errors))
+ if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode",
+ &pbuf, &errors))
return NULL;
- return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors),
- size);
+ unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
+ PyBuffer_Release(&pbuf);
+ return codec_tuple(unicode, pbuf.len);
}
static PyObject *
ascii_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
+ PyObject *unicode;
const char *errors = NULL;
- if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
- &data, &size, &errors))
+ if (!PyArg_ParseTuple(args, "s*|z:ascii_decode",
+ &pbuf, &errors))
return NULL;
- return codec_tuple(PyUnicode_DecodeASCII(data, size, errors),
- size);
+ unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
+ PyBuffer_Release(&pbuf);
+ return codec_tuple(unicode, pbuf.len);
}
static PyObject *
charmap_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size;
+ Py_buffer pbuf;
+ PyObject *unicode;
const char *errors = NULL;
PyObject *mapping = NULL;
- if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode",
- &data, &size, &errors, &mapping))
+ if (!PyArg_ParseTuple(args, "s*|zO:charmap_decode",
+ &pbuf, &errors, &mapping))
return NULL;
if (mapping == Py_None)
mapping = NULL;
- return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors),
- size);
+ unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
+ PyBuffer_Release(&pbuf);
+ return codec_tuple(unicode, pbuf.len);
}
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
@@ -607,21 +574,23 @@ mbcs_decode(PyObject *self,
mbcs_decode(PyObject *self,
PyObject *args)
{
- const char *data;
- Py_ssize_t size, consumed;
+ Py_buffer pbuf;
const char *errors = NULL;
int final = 0;
- PyObject *decoded;
+ Py_ssize_t consumed;
+ PyObject *decoded = NULL;
- if (!PyArg_ParseTuple(args, "t#|zi:mbcs_decode",
- &data, &size, &errors, &final))
+ if (!PyArg_ParseTuple(args, "s*|zi:mbcs_decode",
+ &pbuf, &errors, &final))
return NULL;
+ consumed = pbuf.len;
- decoded = PyUnicode_DecodeMBCSStateful(
- data, size, errors, final ? NULL : &consumed);
- if (!decoded)
+ decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
+ final ? NULL : &consumed);
+ PyBuffer_Release(&pbuf);
+ if (decoded == NULL)
return NULL;
- return codec_tuple(decoded, final ? size : consumed);
+ return codec_tuple(decoded, consumed);
}
#endif /* MS_WINDOWS */
diff -r 0c0dac5e7c60 Python/getargs.c
--- a/Python/getargs.c Fri Aug 01 20:38:32 2008 +0200
+++ b/Python/getargs.c Fri Aug 01 20:42:27 2008 +0200
@@ -1224,16 +1224,19 @@ convertsimple(PyObject *arg, const char
if ((*pb->bf_getsegcount)(arg, NULL) != 1)
return converterr("single-segment read-write buffer",
arg, msgbuf, bufsize);
- if ((count = pb->bf_getwritebuffer(arg, 0, res)) < 0)
+ if ((count = pb->bf_getwritebuffer(arg, 0, &res)) < 0)
return converterr("(unspecified)", arg, msgbuf,
bufsize);
if (*format == '*') {
PyBuffer_FillInfo((Py_buffer*)p, arg, res, count, 1, 0);
format++;
}
- else if (*format == '#') {
- FETCH_SIZE;
- STORE_SIZE(count);
- format++;
+ else {
+ *p = res;
+ if (*format == '#') {
+ FETCH_SIZE;
+ STORE_SIZE(count);
+ format++;
+ }
}
break;
}
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com