diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2006-03-26 06:21:34 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2006-03-26 06:21:34 (GMT) |
commit | 9f4b632212742fbcd91e921e2516a6285fd7728b (patch) | |
tree | f1a1574241882414c5ce0e5042e349b604526013 /Modules/cjkcodecs | |
parent | 7545a6bac2827c5f1d6feb85c41dd19544d4d626 (diff) | |
download | cpython-9f4b632212742fbcd91e921e2516a6285fd7728b.zip cpython-9f4b632212742fbcd91e921e2516a6285fd7728b.tar.gz cpython-9f4b632212742fbcd91e921e2516a6285fd7728b.tar.bz2 |
Allow long objects as a position value of error callbacks returned.
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r-- | Modules/cjkcodecs/multibytecodec.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 26d5c94..c19da9c 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -304,7 +304,8 @@ multibytecodec_encerror(MultibyteCodec *codec, if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 || !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) || - !PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) { + !(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) || + PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) { PyErr_SetString(PyExc_TypeError, "encoding error handler must return " "(unicode, int) tuple"); @@ -328,12 +329,13 @@ multibytecodec_encerror(MultibyteCodec *codec, buf->outbuf += retstrsize; newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); - if (newpos < 0) + if (newpos < 0 && !PyErr_Occurred()) newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top); if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) { + PyErr_Clear(); PyErr_Format(PyExc_IndexError, - "position %d from error handler out of bounds", - (int)newpos); + "position %ld from error handler out of bounds", + (long)newpos); goto errorexit; } buf->inbuf = buf->inbuf_top + newpos; @@ -421,7 +423,8 @@ multibytecodec_decerror(MultibyteCodec *codec, if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 || !PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0))) || - !PyInt_Check(PyTuple_GET_ITEM(retobj, 1))) { + !(PyInt_Check(PyTuple_GET_ITEM(retobj, 1)) || + PyLong_Check(PyTuple_GET_ITEM(retobj, 1)))) { PyErr_SetString(PyExc_TypeError, "decoding error handler must return " "(unicode, int) tuple"); @@ -437,12 +440,13 @@ multibytecodec_decerror(MultibyteCodec *codec, } newpos = PyInt_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)); - if (newpos < 0) + if (newpos < 0 && !PyErr_Occurred()) newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top); if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) { + PyErr_Clear(); PyErr_Format(PyExc_IndexError, - "position %d from error handler out of bounds", - (int)newpos); + "position %ld from error handler out of bounds", + (long)newpos); goto errorexit; } buf->inbuf = buf->inbuf_top + newpos; |