diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-02-15 17:27:45 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-02-15 17:27:45 (GMT) |
commit | 18e165558b24d29e7e0ca501842b9236589b012a (patch) | |
tree | 841678b5dc1aff3aa48701fee33a6ba7be00a72b /Modules/_codecsmodule.c | |
parent | 44829297348d9121a03fc7df2fac557b583cc7fa (diff) | |
download | cpython-18e165558b24d29e7e0ca501842b9236589b012a.zip cpython-18e165558b24d29e7e0ca501842b9236589b012a.tar.gz cpython-18e165558b24d29e7e0ca501842b9236589b012a.tar.bz2 |
Merge ssize_t branch.
Diffstat (limited to 'Modules/_codecsmodule.c')
-rw-r--r-- | Modules/_codecsmodule.c | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index 8b225c3..39b443b 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -35,6 +35,7 @@ Copyright (c) Corporation for National Research Initiatives. ------------------------------------------------------------------------ */ +#define PY_SSIZE_T_CLEAN #include "Python.h" /* --- Registry ----------------------------------------------------------- */ @@ -196,7 +197,7 @@ escape_decode(PyObject *self, { const char *errors = NULL; const char *data; - int size; + Py_ssize_t size; if (!PyArg_ParseTuple(args, "s#|z:escape_decode", &data, &size, &errors)) @@ -241,7 +242,7 @@ unicode_internal_decode(PyObject *self, PyObject *obj; const char *errors = NULL; const char *data; - int size; + Py_ssize_t size; if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode", &obj, &errors)) @@ -265,7 +266,7 @@ utf_7_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode", @@ -281,15 +282,19 @@ utf_8_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; int final = 0; - int consumed; + Py_ssize_t consumed; PyObject *decoded = NULL; if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode", &data, &size, &errors, &final)) return NULL; + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative argument"); + return 0; + } consumed = size; decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors, @@ -304,16 +309,21 @@ utf_16_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; int byteorder = 0; int final = 0; - int consumed; + Py_ssize_t consumed; PyObject *decoded; if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode", &data, &size, &errors, &final)) return NULL; + /* XXX Why is consumed initialized to size? mvl */ + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative argument"); + return 0; + } consumed = size; decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, final ? NULL : &consumed); @@ -327,16 +337,22 @@ utf_16_le_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; int byteorder = -1; int final = 0; - int consumed; + Py_ssize_t consumed; PyObject *decoded = NULL; if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode", &data, &size, &errors, &final)) return NULL; + + /* XXX Why is consumed initialized to size? mvl */ + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative argument"); + return 0; + } consumed = size; decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, final ? NULL : &consumed); @@ -351,16 +367,21 @@ utf_16_be_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; int byteorder = 1; int final = 0; - int consumed; + Py_ssize_t consumed; PyObject *decoded = NULL; if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode", &data, &size, &errors, &final)) return NULL; + /* XXX Why is consumed initialized to size? mvl */ + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative argument"); + return 0; + } consumed = size; decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, final ? NULL : &consumed); @@ -382,17 +403,21 @@ utf_16_ex_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; int byteorder = 0; PyObject *unicode, *tuple; int final = 0; - int consumed; + Py_ssize_t consumed; if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode", &data, &size, &errors, &byteorder, &final)) return NULL; - + /* XXX Why is consumed initialized to size? mvl */ + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative argument"); + return 0; + } consumed = size; unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, final ? NULL : &consumed); @@ -408,7 +433,7 @@ unicode_escape_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode", @@ -424,7 +449,7 @@ raw_unicode_escape_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode", @@ -440,7 +465,7 @@ latin_1_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode", @@ -456,7 +481,7 @@ ascii_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:ascii_decode", @@ -472,7 +497,7 @@ charmap_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; PyObject *mapping = NULL; @@ -493,7 +518,7 @@ mbcs_decode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode", @@ -513,7 +538,7 @@ readbuffer_encode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode", @@ -529,7 +554,7 @@ charbuffer_encode(PyObject *self, PyObject *args) { const char *data; - int size; + Py_ssize_t size; const char *errors = NULL; if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode", @@ -547,7 +572,7 @@ unicode_internal_encode(PyObject *self, PyObject *obj; const char *errors = NULL; const char *data; - int size; + Py_ssize_t size; if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode", &obj, &errors)) |