[KoCo-CVS] [Commit] cjkcodecs/src codeccommon.h multibytecodec.c multibytecodec.h
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-07-01 19:35:16
|
perky 03/07/01 12:33:43 Modified: src codeccommon.h multibytecodec.c multibytecodec.h Log: - Prepare buffering encoder framework for jisx0213 and surrogates - Set '\U+xxxxxxxx' instead of '\u..' on python versions under 2.2 Revision Changes Path 1.14 +2 -1 cjkcodecs/src/codeccommon.h Index: codeccommon.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/codeccommon.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- codeccommon.h 20 Jun 2003 17:22:59 -0000 1.13 +++ codeccommon.h 1 Jul 2003 19:33:43 -0000 1.14 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: codeccommon.h,v 1.13 2003/06/20 17:22:59 perky Exp $ + * $Id: codeccommon.h,v 1.14 2003/07/01 19:33:43 perky Exp $ */ #include "Python.h" @@ -50,6 +50,7 @@ #define ENCODER_RESET(encoding) \ static int encoding##_encode_reset( \ MultibyteCodec_State *state, \ + const Py_UNICODE **inbuf, size_t inleft, \ unsigned char **outbuf, size_t outleft) #define DECODER_INIT(encoding) \ 1.18 +16 -9 cjkcodecs/src/multibytecodec.c Index: multibytecodec.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- multibytecodec.c 6 Jun 2003 06:56:01 -0000 1.17 +++ multibytecodec.c 1 Jul 2003 19:33:43 -0000 1.18 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: multibytecodec.c,v 1.17 2003/06/06 06:56:01 perky Exp $ + * $Id: multibytecodec.c,v 1.18 2003/07/01 19:33:43 perky Exp $ */ #include "Python.h" @@ -236,11 +236,18 @@ end = start + esize; #ifdef NO_ERROR_CALLBACKS - if (esize == 1) - PyErr_Format(PyExc_UnicodeError, - "'%s' codec can't encode byte '\\u%04x' in position %d: %s", - codec->encoding, *buf->inbuf, start, reason); - else + if (esize == 1) { +#if Py_UNICODE_SIZE == 4 + if (*buf->inbuf >= 0x10000) + PyErr_Format(PyExc_UnicodeError, + "'%s' codec can't encode byte '\\U%08x' in position %d: %s", + codec->encoding, *buf->inbuf, start, reason); + else +#endif + PyErr_Format(PyExc_UnicodeError, + "'%s' codec can't encode byte '\\u%04x' in position %d: %s", + codec->encoding, *buf->inbuf, start, reason); + } else PyErr_Format(PyExc_UnicodeError, "'%s' codec can't encode bytes in position %d-%d: %s", codec->encoding, start, end, reason); @@ -480,7 +487,7 @@ size_t outleft; outleft = (size_t)(buf.outbuf_end - buf.outbuf); - r = codec->encreset(state, &buf.outbuf, outleft); + r = codec->encreset(state, NULL, 0, &buf.outbuf, outleft); if (r == 0) break; else if (multibytecodec_encerror(codec, state, &buf, errors, r)) @@ -783,7 +790,7 @@ /* we can't assume that pendingsize is still 0 here. because * this function can be called recursively from error callback */ npendings = (size_t)(buf.inbuf_end - buf.inbuf); - if (npendings + self->pendingsize > MAXPENDING) { + if (npendings + self->pendingsize > MAXDECPENDING) { PyErr_SetString(PyExc_RuntimeError, "pending buffer overflow"); goto errorexit; @@ -1062,7 +1069,7 @@ rsbuf_cur = rsbuf_top + rsbufnc; r = self->codec->encreset(&self->state, - &rsbuf_cur, rsbufsiz - rsbufnc); + NULL, 0, &rsbuf_cur, rsbufsiz - rsbufnc); rsbufnc = (size_t)(rsbuf_cur - rsbuf_top); if (r == MBERR_TOOSMALL) continue; 1.8 +7 -3 cjkcodecs/src/multibytecodec.h Index: multibytecodec.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- multibytecodec.h 31 May 2003 11:50:19 -0000 1.7 +++ multibytecodec.h 1 Jul 2003 19:33:43 -0000 1.8 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: multibytecodec.h,v 1.7 2003/05/31 11:50:19 perky Exp $ + * $Id: multibytecodec.h,v 1.8 2003/07/01 19:33:43 perky Exp $ */ #ifndef _PYTHON_MULTIBYTECODEC_H_ @@ -45,6 +45,7 @@ unsigned char **outbuf, size_t outleft); typedef int (*mbencodeinit_func)(MultibyteCodec_State *state); typedef int (*mbencodereset_func)(MultibyteCodec_State *state, + const Py_UNICODE **inbuf, size_t inleft, unsigned char **outbuf, size_t outleft); typedef int (*mbdecode_func)(MultibyteCodec_State *state, const unsigned char **inbuf, size_t inleft, @@ -67,20 +68,23 @@ MultibyteCodec *codec; } MultibyteCodecObject; -#define MAXPENDING 8 +#define MAXDECPENDING 8 typedef struct { PyObject_HEAD MultibyteCodec *codec; MultibyteCodec_State state; - unsigned char pending[MAXPENDING]; + unsigned char pending[MAXDECPENDING]; int pendingsize; PyObject *stream, *errors; } MultibyteStreamReaderObject; +#define MAXENCPENDING 2 typedef struct { PyObject_HEAD MultibyteCodec *codec; MultibyteCodec_State state; + Py_UNICODE pending[MAXENCPENDING]; + int pendingsize; PyObject *stream, *errors; } MultibyteStreamWriterObject; |