Thread: [KoCo-CVS] [Commit] cjkcodecs/src multibytecodec.h
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-18 23:21:30
|
perky 03/05/18 16:21:29 Modified: src multibytecodec.h Log: Introduce new simple design of multibytecodec. Revision Changes Path 1.2 +34 -132 cjkcodecs/src/multibytecodec.h Index: multibytecodec.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- multibytecodec.h 20 Apr 2003 17:35:31 -0000 1.1 +++ multibytecodec.h 18 May 2003 23:21:29 -0000 1.2 @@ -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.1 2003/04/20 17:35:31 perky Exp $ + * $Id: multibytecodec.h,v 1.2 2003/05/18 23:21:29 perky Exp $ */ #ifndef _PYTHON_MULTIBYTECODEC_H_ @@ -35,155 +35,57 @@ extern "C" { #endif -#define MAXENCODINGLEN 64 - -typedef struct { - char encoding[MAXENCODINGLEN]; - void *config; /* intended to use in iconvcodec */ -} PyMultibyteEncoder_Handle; - -typedef void *PyMultibyteEncoder_Context; - -typedef struct { - const Py_UNICODE *inbuf, *inbuf_top, *inbuf_end; - unsigned char *outbuf, *outbuf_end; - PyObject *excobj, *outobj; -} PyMultibyteEncoder_Buffer; - -typedef struct { - Py_UNICODE *object; - /* if object != inbuf_top, error handler will assume object's last - * character is located to inbuf's current position. - * - * +--------+ - * | object | - * +yyyyy---+ - * ^ current buf->inbuf - * +-----------------+ - * | buf->inbuf_top | - * +xxx--------------+ - * yyyyyxxx => first 5 characters came from previous buffer and error is - * caused on feeding 3rd 'x'. - * - * in this case, multibyte subsytem will free the allocation for `object' - * and `start' and `end' is not object's range but a part of buf->inbuf_top - * because we can see all characters of object is the error content. - */ - int objlength; - int start, end; -} PyMultibyteEncoder_Error; - -typedef struct { - const char *name; - int (*init)(PyMultibyteEncoder_Handle *hdl); - void (*shutdown)(PyMultibyteEncoder_Handle *hdl); - int (*open)(PyMultibyteEncoder_Handle *hdl, - PyMultibyteEncoder_Context *ctx); - void (*close)(PyMultibyteEncoder_Handle *hdl, - PyMultibyteEncoder_Context *ctx); - int (*encode)(PyMultibyteEncoder_Handle *hdl, - PyMultibyteEncoder_Context *ctx, - PyMultibyteEncoder_Buffer *buf, - PyMultibyteEncoder_Error *err); - int (*flush)(PyMultibyteEncoder_Handle *hdl, - PyMultibyteEncoder_Context *ctx, - PyMultibyteEncoder_Buffer *buf, - PyMultibyteEncoder_Error *err); - int (*reset)(PyMultibyteEncoder_Handle *hdl, - PyMultibyteEncoder_Context *ctx); - int (*putrepl)(PyMultibyteEncoder_Handle *hdl, - PyMultibyteEncoder_Context *ctx, - PyMultibyteEncoder_Buffer *buf); -} PyMultibyteEncoder_Codec; - - -typedef struct { - char encoding[MAXENCODINGLEN]; - void *config; /* intended to use in iconvcodec */ -} PyMultibyteDecoder_Handle; - -typedef void *PyMultibyteDecoder_Context; - -typedef struct { - const unsigned char *inbuf, *inbuf_top, *inbuf_end; - Py_UNICODE *outbuf, *outbuf_end; - PyObject *excobj, *outobj; -} PyMultibyteDecoder_Buffer; - -typedef struct { - unsigned char *object; - int objlength; - int start, end; -} PyMultibyteDecoder_Error; - -typedef struct { - const char *name; - int (*init)(PyMultibyteDecoder_Handle *hdl); - void (*shutdown)(PyMultibyteDecoder_Handle *hdl); - int (*open)(PyMultibyteDecoder_Handle *hdl, - PyMultibyteDecoder_Context *ctx); - void (*close)(PyMultibyteDecoder_Handle *hdl, - PyMultibyteDecoder_Context *ctx); - int (*decode)(PyMultibyteDecoder_Handle *hdl, - PyMultibyteDecoder_Context *ctx, - PyMultibyteDecoder_Buffer *buf, - PyMultibyteDecoder_Error *err); - int (*flush)(PyMultibyteDecoder_Handle *hdl, - PyMultibyteDecoder_Context *ctx, - PyMultibyteDecoder_Buffer *buf, - PyMultibyteDecoder_Error *err); - int (*reset)(PyMultibyteDecoder_Handle *hdl, - PyMultibyteDecoder_Context *ctx); -} PyMultibyteDecoder_Codec; - +typedef union { + unsigned long i; + void *p; +} PyMultibyteCodec_State; + +typedef int (*mbencode_func)(PyMultibyteCodec_State *state, + const Py_UNICODE **inbuf, int *inleft, + unsigned char **outbuf, int *outleft); +typedef int (*mbdecode_func)(PyMultibyteCodec_State *state, + const unsigned char **inbuf, int *inleft, + Py_UNICODE **outbuf, int *outleft); + +typedef struct { + const char *encoding; + mbencode_func encode; + mbdecode_func decode; +} PyMultibyteCodec; typedef struct { PyObject_HEAD - PyMultibyteEncoder_Codec *codec; - PyMultibyteEncoder_Handle *hdl; -} PyMultibyteEncoderObject; + PyMultibyteCodec *codec; +} PyMultibyteCodecObject; +#define MAXPENDING 8 typedef struct { PyObject_HEAD - PyMultibyteDecoder_Codec *codec; - PyMultibyteDecoder_Handle *hdl; -} PyMultibyteDecoderObject; + PyMultibyteCodec *codec; + PyMultibyteCodec_State *state; + unsigned char pending[MAXPENDING]; + int pendingsize; + PyObject *stream, *errors; +} PyMultibyteStreamReaderObject; typedef struct { PyObject_HEAD - PyMultibyteDecoder_Codec *codec; - PyMultibyteDecoder_Handle *hdl; - PyMultibyteDecoder_Context ctx; + PyMultibyteCodec *codec; + PyMultibyteCodec_State *state; + Py_UNICODE pending[MAXPENDING]; + int pendingsize; PyObject *stream, *errors; - PyObject *decoder; /* just to keep refcount */ -} PyMultibyteStreamReaderObject; +} PyMultibyteStreamWriterObject; +/* positive values for illegal sequences */ #define MBERR_TOOSMALL (-1) /* insufficient output buffer space */ #define MBERR_TOOFEW (-2) /* incomplete input buffer */ -#define MBERR_ILLSEQ (-3) /* illegal multibyte encoding sequence */ -#define MBERR_UNDEFINED (-4) /* undefined character or no map */ -#define MBERR_INTERNAL (-5) /* internal runtime error */ +#define MBERR_INTERNAL (-3) /* internal runtime error */ #define ERROR_STRICT (PyObject *)(1) #define ERROR_IGNORE (PyObject *)(2) #define ERROR_REPLACE (PyObject *)(3) #define ERROR_MAX ERROR_REPLACE - -#define HAS_NOT_ENOUGH_SPACE(buf, size) \ - ((buf)->outbuf + (size) > (buf)->outbuf_end) -#define INBUFPOS(buf) (int)((buf)->inbuf - (buf)->inbuf_top) -#define INBUFLEN(buf) (int)((buf)->inbuf_end - (buf)->inbuf_top) -#define SETERR_INBUF(err, buf) { \ - (err)->object = (void *)(buf)->inbuf_top; /* discard const */ \ - (err)->objlength = INBUFLEN(buf); \ -} - -PyAPI_FUNC(PyObject *) _PyMultibyteEncoder_Create( - PyMultibyteEncoder_Codec *codec, - const char *encoding); -PyAPI_FUNC(PyObject *) _PyMultibyteDecoder_Create( - PyMultibyteDecoder_Codec *codec, - const char *encoding); #ifdef __cplusplus } |
From: Hye-Shik C. <pe...@us...> - 2003-07-12 03:56:05
|
perky 03/07/11 20:48:24 Modified: src multibytecodec.h Log: Revive int type of state union for hz codec. Revision Changes Path 1.11 +2 -1 cjkcodecs/src/multibytecodec.h Index: multibytecodec.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- multibytecodec.h 12 Jul 2003 03:47:15 -0000 1.10 +++ multibytecodec.h 12 Jul 2003 03:48:24 -0000 1.11 @@ -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.10 2003/07/12 03:47:15 perky Exp $ + * $Id: multibytecodec.h,v 1.11 2003/07/12 03:48:24 perky Exp $ */ #ifndef _PYTHON_MULTIBYTECODEC_H_ @@ -39,6 +39,7 @@ typedef union { void *p; + int i; unsigned char c[8]; ucs2_t u2[4]; ucs4_t u4[2]; |