[KoCo-CVS] [Commit] cjkcodecs/src codecentry.h _big5.c _cp932.c _cp949.c _cp950.c _euc_jp.c _euc_kr.
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-31 12:10:29
|
perky 03/05/31 04:50:20 Modified: src _big5.c _cp932.c _cp949.c _cp950.c _euc_jp.c _euc_kr.c _gb18030.c _gb2312.c _gbk.c _hz.c _johab.c _shift_jis.c _utf_8.c codeccommon.h multibytecodec.c multibytecodec.h Added: src codecentry.h Log: Activate init, reset methods for the codecs. (these features are mainly iso-2022-* and mac_* codecs.) Revision Changes Path 1.5 +2 -1 cjkcodecs/src/_big5.c Index: _big5.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_big5.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- _big5.c 26 May 2003 07:37:09 -0000 1.4 +++ _big5.c 31 May 2003 11:50:18 -0000 1.5 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _big5.c,v 1.4 2003/05/26 07:37:09 perky Exp $ + * $Id: _big5.c,v 1.5 2003/05/31 11:50:18 perky Exp $ */ #include "codeccommon.h" @@ -86,6 +86,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(big5) MAPOPEN(zh_TW) IMPORTMAP_ENCDEC(big5) 1.2 +2 -1 cjkcodecs/src/_cp932.c Index: _cp932.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_cp932.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- _cp932.c 26 May 2003 07:57:52 -0000 1.1 +++ _cp932.c 31 May 2003 11:50:19 -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: _cp932.c,v 1.1 2003/05/26 07:57:52 perky Exp $ + * $Id: _cp932.c,v 1.2 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -131,6 +131,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(cp932) MAPOPEN(ja_JP) IMPORTMAP_DEC(jisx0208) 1.9 +2 -1 cjkcodecs/src/_cp949.c Index: _cp949.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_cp949.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- _cp949.c 26 May 2003 07:37:09 -0000 1.8 +++ _cp949.c 31 May 2003 11:50:19 -0000 1.9 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _cp949.c,v 1.8 2003/05/26 07:37:09 perky Exp $ + * $Id: _cp949.c,v 1.9 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -90,6 +90,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(cp949) MAPOPEN(ko_KR) IMPORTMAP_DEC(ksx1001) 1.5 +2 -1 cjkcodecs/src/_cp950.c Index: _cp950.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_cp950.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- _cp950.c 26 May 2003 07:37:09 -0000 1.4 +++ _cp950.c 31 May 2003 11:50:19 -0000 1.5 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _cp950.c,v 1.4 2003/05/26 07:37:09 perky Exp $ + * $Id: _cp950.c,v 1.5 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -90,6 +90,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(cp950) MAPOPEN(zh_TW) IMPORTMAP_ENCDEC(big5) 1.3 +2 -1 cjkcodecs/src/_euc_jp.c Index: _euc_jp.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_euc_jp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- _euc_jp.c 26 May 2003 07:37:09 -0000 1.2 +++ _euc_jp.c 31 May 2003 11:50:19 -0000 1.3 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _euc_jp.c,v 1.2 2003/05/26 07:37:09 perky Exp $ + * $Id: _euc_jp.c,v 1.3 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -158,6 +158,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(euc_jp) MAPOPEN(ja_JP) IMPORTMAP_DEC(jisx0208) 1.12 +2 -1 cjkcodecs/src/_euc_kr.c Index: _euc_kr.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_euc_kr.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- _euc_kr.c 26 May 2003 07:37:09 -0000 1.11 +++ _euc_kr.c 31 May 2003 11:50:19 -0000 1.12 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _euc_kr.c,v 1.11 2003/05/26 07:37:09 perky Exp $ + * $Id: _euc_kr.c,v 1.12 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -89,6 +89,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(euc_kr) MAPOPEN(ko_KR) IMPORTMAP_DEC(ksx1001) 1.6 +2 -1 cjkcodecs/src/_gb18030.c Index: _gb18030.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_gb18030.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- _gb18030.c 26 May 2003 07:37:09 -0000 1.5 +++ _gb18030.c 31 May 2003 11:50:19 -0000 1.6 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _gb18030.c,v 1.5 2003/05/26 07:37:09 perky Exp $ + * $Id: _gb18030.c,v 1.6 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -191,6 +191,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(gb18030) MAPOPEN(zh_CN) IMPORTMAP_DEC(gb2312) 1.7 +2 -1 cjkcodecs/src/_gb2312.c Index: _gb2312.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_gb2312.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- _gb2312.c 26 May 2003 07:37:09 -0000 1.6 +++ _gb2312.c 31 May 2003 11:50:19 -0000 1.7 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _gb2312.c,v 1.6 2003/05/26 07:37:09 perky Exp $ + * $Id: _gb2312.c,v 1.7 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -88,6 +88,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(gb2312) MAPOPEN(zh_CN) IMPORTMAP_DEC(gb2312) 1.6 +2 -1 cjkcodecs/src/_gbk.c Index: _gbk.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_gbk.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- _gbk.c 26 May 2003 07:37:09 -0000 1.5 +++ _gbk.c 31 May 2003 11:50:19 -0000 1.6 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _gbk.c,v 1.5 2003/05/26 07:37:09 perky Exp $ + * $Id: _gbk.c,v 1.6 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -95,6 +95,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(gbk) MAPOPEN(zh_CN) IMPORTMAP_DEC(gb2312) 1.2 +2 -1 cjkcodecs/src/_hz.c Index: _hz.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_hz.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- _hz.c 28 May 2003 09:18:14 -0000 1.1 +++ _hz.c 31 May 2003 11:50:19 -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: _hz.c,v 1.1 2003/05/28 09:18:14 perky Exp $ + * $Id: _hz.c,v 1.2 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -129,6 +129,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(hz) MAPOPEN(zh_CN) IMPORTMAP_DEC(gb2312) 1.4 +2 -1 cjkcodecs/src/_johab.c Index: _johab.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_johab.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- _johab.c 31 May 2003 03:05:38 -0000 1.3 +++ _johab.c 31 May 2003 11:50:19 -0000 1.4 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _johab.c,v 1.3 2003/05/31 03:05:38 perky Exp $ + * $Id: _johab.c,v 1.4 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -239,6 +239,7 @@ #undef NONE #undef FILL +#include "codecentry.h" BEGIN_CODEC_REGISTRY(johab) MAPOPEN(ko_KR) IMPORTMAP_DEC(ksx1001) 1.5 +2 -1 cjkcodecs/src/_shift_jis.c Index: _shift_jis.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_shift_jis.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- _shift_jis.c 26 May 2003 15:06:45 -0000 1.4 +++ _shift_jis.c 31 May 2003 11:50:19 -0000 1.5 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _shift_jis.c,v 1.4 2003/05/26 15:06:45 perky Exp $ + * $Id: _shift_jis.c,v 1.5 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -131,6 +131,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(shift_jis) MAPOPEN(ja_JP) IMPORTMAP_DEC(jisx0208) 1.3 +2 -1 cjkcodecs/src/_utf_8.c Index: _utf_8.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_utf_8.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- _utf_8.c 31 May 2003 03:41:14 -0000 1.2 +++ _utf_8.c 31 May 2003 11:50:19 -0000 1.3 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _utf_8.c,v 1.2 2003/05/31 03:41:14 perky Exp $ + * $Id: _utf_8.c,v 1.3 2003/05/31 11:50:19 perky Exp $ */ #include "codeccommon.h" @@ -190,6 +190,7 @@ return 0; } +#include "codecentry.h" BEGIN_CODEC_REGISTRY(utf_8) /* no maps */ END_CODEC_REGISTRY(utf_8) 1.10 +19 -102 cjkcodecs/src/codeccommon.h Index: codeccommon.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/codeccommon.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- codeccommon.h 26 May 2003 07:37:09 -0000 1.9 +++ codeccommon.h 31 May 2003 11:50:19 -0000 1.10 @@ -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.9 2003/05/26 07:37:09 perky Exp $ + * $Id: codeccommon.h,v 1.10 2003/05/31 11:50:19 perky Exp $ */ #include "Python.h" @@ -38,16 +38,30 @@ #define DECMAP(encoding) \ const static decode_map *encoding##decmap; +#define ENCODER_INIT(encoding) \ + static int encoding##_encode_init( \ + MultibyteCodec_State *state) #define ENCODER(encoding) \ static int encoding##_encode( \ MultibyteCodec_State *state, \ const Py_UNICODE **inbuf, size_t inleft, \ unsigned char **outbuf, size_t outleft) +#define ENCODER_RESET(encoding) \ + static int encoding##_encode_reset( \ + MultibyteCodec_State *state, \ + unsigned char **outbuf, size_t outleft) + +#define DECODER_INIT(encoding) \ + static int encoding##_decode_init( \ + MultibyteCodec_State *state) #define DECODER(encoding) \ static int encoding##_decode( \ MultibyteCodec_State *state, \ const unsigned char **inbuf, size_t inleft, \ Py_UNICODE **outbuf, size_t outleft) +#define DECODER_RESET(encoding) \ + static int encoding##_decode_reset( \ + MultibyteCodec_State *state) #if Py_UNICODE_SIZE == 4 #define UCS4INVALID(code) \ @@ -58,70 +72,13 @@ if (0) ; #endif -#define BEGIN_CODEC_REGISTRY(encoding) \ - static MultibyteCodec __codec = { \ - #encoding, encoding##_encode, encoding##_decode \ - }; \ - \ - static struct PyMethodDef __methods[] = { \ - {NULL, NULL}, \ - }; \ - \ - void \ - init_##encoding(void) \ - { \ - PyObject *codec; \ - PyObject *m = NULL, *mod = NULL, *o = NULL; \ - \ - m = Py_InitModule("_" #encoding, __methods); - -#define MAPOPEN(locale) \ - mod = PyImport_ImportModule("mapdata_" #locale); \ - if (mod == NULL) goto errorexit; \ - if ( -#define IMPORTMAP_ENCDEC(charset) \ - importmap(mod, "__map_" #charset, &charset##encmap, \ - &charset##decmap) || -#define IMPORTMAP_ENC(charset) \ - importmap(mod, "__map_" #charset, &charset##encmap, \ - NULL) || -#define IMPORTMAP_DEC(charset) \ - importmap(mod, "__map_" #charset, NULL, \ - &charset##decmap) || -#define MAPCLOSE() \ - 0) goto errorexit; \ - Py_DECREF(mod); - -#define END_CODEC_REGISTRY(encoding) \ - mod = PyImport_ImportModule("multibytecodec"); \ - if (mod == NULL) goto errorexit; \ - o = PyObject_GetAttrString(mod, "__create_codec"); \ - if (o == NULL || !PyCallable_Check(o)) \ - goto errorexit; \ - \ - codec = createcodec(o, &__codec); \ - if (codec == NULL) \ - goto errorexit; \ - PyModule_AddObject(m, "codec", codec); \ - Py_DECREF(o); Py_DECREF(mod); \ - \ - if (PyErr_Occurred()) \ - Py_FatalError("can't initialize the _" #encoding \ - " module"); \ - \ - return; \ - \ -errorexit: \ - Py_XDECREF(m); \ - Py_XDECREF(mod); \ - Py_XDECREF(o); \ -} - -#define NEXT(i, o) \ +#define NEXT_IN(i) \ (*inbuf) += (i); \ - (inleft) -= (i); \ + (inleft) -= (i); +#define NEXT_OUT(o) \ (*outbuf) += (o); \ (outleft) -= (o); +#define NEXT(i, o) NEXT_IN(i) NEXT_OUT(o) #define RESERVE_INBUF(n) \ if (inleft < (n)) \ @@ -142,46 +99,6 @@ (m)->bottom]) != UNIINV) #define TRYMAP_DEC(charset, assi, c1, c2) \ _TRYMAP_DEC(&charset##decmap[c1], assi, c2) - -static int -importmap(PyObject *mod, const char *symbol, - const struct unim_index **encmap, const struct dbcs_index **decmap) -{ - PyObject *o; - - o = PyObject_GetAttrString(mod, (char*)symbol); - if (o == NULL) - return -1; - else if (!PyCObject_Check(o)) { - PyErr_SetString(PyExc_ValueError, "map data must be a CObject."); - return -1; - } else { - struct dbcs_map *map; - map = PyCObject_AsVoidPtr(o); - if (encmap != NULL) - *encmap = map->encmap; - if (decmap != NULL) - *decmap = map->decmap; - Py_DECREF(o); - } - - return 0; -} - -static PyObject * -createcodec(PyObject *cofunc, MultibyteCodec *codec) -{ - PyObject *args, *r; - - args = PyTuple_New(1); - if (args == NULL) return NULL; - PyTuple_SET_ITEM(args, 0, PyCObject_FromVoidPtr(codec, NULL)); - - r = PyObject_CallObject(cofunc, args); - Py_DECREF(args); - - return r; -} /* * ex: ts=8 sts=4 et 1.13 +67 -15 cjkcodecs/src/multibytecodec.c Index: multibytecodec.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- multibytecodec.c 27 May 2003 06:32:36 -0000 1.12 +++ multibytecodec.c 31 May 2003 11:50:19 -0000 1.13 @@ -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.12 2003/05/27 06:32:36 perky Exp $ + * $Id: multibytecodec.c,v 1.13 2003/05/31 11:50:19 perky Exp $ */ #include "Python.h" @@ -466,7 +466,8 @@ if (errorcb == NULL) return NULL; - state.p = NULL; + if (self->codec->encinit != NULL && self->codec->encinit(&state) != 0) + goto errorexit; r = multibytecodec_encode(self->codec, &state, data, datalen, errorcb); if (r == NULL) goto errorexit; @@ -516,7 +517,9 @@ buf.outbuf = PyUnicode_AS_UNICODE(buf.outobj); buf.outbuf_end = buf.outbuf + PyUnicode_GET_SIZE(buf.outobj); - state.p = NULL; + if (self->codec->decinit != NULL && self->codec->decinit(&state) != 0) + goto errorexit; + while (buf.inbuf < buf.inbuf_end) { size_t inleft, outleft; int r; @@ -829,7 +832,9 @@ static PyObject * mbstreamreader_reset(MultibyteStreamReaderObject *self) { - self->state.p = NULL; + if (self->codec->decreset != NULL && + self->codec->decreset(&self->state) != 0) + return NULL; self->pendingsize = 0; Py_INCREF(Py_None); @@ -975,7 +980,48 @@ static PyObject * mbstreamwriter_reset(MultibyteStreamWriterObject *self) { - self->state.p = NULL; + if (self->codec->encreset != NULL) { + PyObject *rsbuf = NULL; + size_t rsbufsiz, rsbufnc; + int r; + unsigned char *rsbuf_top, *rsbuf_cur; + + rsbufnc = 0; + for (rsbufsiz = NULL;;rsbufsiz *= 2) { + if (rsbuf == NULL) { + rsbuf = PyString_FromStringAndSize(NULL, rsbufsiz); + if (rsbuf == NULL) + return NULL; + } else { + if (_PyString_Resize(&rsbuf, rsbufsiz)) + goto errorexit; + } + rsbuf_top = (unsigned char *)PyString_AS_STRING(rsbuf); + rsbuf_cur = rsbuf_top + rsbufnc; + + r = self->codec->encreset(&self->state, + &rsbuf_cur, rsbufsiz - rsbufnc); + rsbufnc = (size_t)(rsbuf_cur - rsbuf_top); + if (r == MBERR_TOOSMALL) + continue; + else { + if (r != 0) + goto errorexit; + else + break; + } + } + + if (_PyString_Resize(&rsbuf, rsbufnc)) { +errorexit: Py_DECREF(rsbuf); + return NULL; + } + + r = mbstreamwriter_iwrite(self, rsbuf); + Py_DECREF(rsbuf); + if (r == -1) + return NULL; + } Py_INCREF(Py_None); return Py_None; @@ -1067,15 +1113,18 @@ self->codec = codec; self->stream = stream; Py_INCREF(stream); - self->state.p = NULL; self->pendingsize = 0; self->errors = get_errorcallback(errors); - if (self->errors == NULL) { - Py_DECREF(self); - return NULL; - } + if (self->errors == NULL) + goto errorexit; + if (self->codec->decinit != NULL && self->codec->decinit(&self->state) != 0) + goto errorexit; return (PyObject *)self; + +errorexit: + Py_XDECREF(self); + return NULL; } static PyObject * @@ -1092,14 +1141,17 @@ self->codec = codec; self->stream = stream; Py_INCREF(stream); - self->state.p = NULL; self->errors = get_errorcallback(errors); - if (self->errors == NULL) { - Py_DECREF(self); - return NULL; - } + if (self->errors == NULL) + goto errorexit; + if (self->codec->encinit != NULL && self->codec->encinit(&self->state) != 0) + goto errorexit; return (PyObject *)self; + +errorexit: + Py_XDECREF(self); + return NULL; } static struct PyMethodDef __methods[] = { 1.7 +13 -4 cjkcodecs/src/multibytecodec.h Index: multibytecodec.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- multibytecodec.h 22 May 2003 00:01:50 -0000 1.6 +++ multibytecodec.h 31 May 2003 11:50:19 -0000 1.7 @@ -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.6 2003/05/22 00:01:50 perky Exp $ + * $Id: multibytecodec.h,v 1.7 2003/05/31 11:50:19 perky Exp $ */ #ifndef _PYTHON_MULTIBYTECODEC_H_ @@ -43,14 +43,23 @@ typedef int (*mbencode_func)(MultibyteCodec_State *state, const Py_UNICODE **inbuf, size_t inleft, unsigned char **outbuf, size_t outleft); +typedef int (*mbencodeinit_func)(MultibyteCodec_State *state); +typedef int (*mbencodereset_func)(MultibyteCodec_State *state, + unsigned char **outbuf, size_t outleft); typedef int (*mbdecode_func)(MultibyteCodec_State *state, const unsigned char **inbuf, size_t inleft, Py_UNICODE **outbuf, size_t outleft); +typedef int (*mbdecodeinit_func)(MultibyteCodec_State *state); +typedef int (*mbdecodereset_func)(MultibyteCodec_State *state); typedef struct { - const char *encoding; - mbencode_func encode; - mbdecode_func decode; + const char *encoding; + mbencode_func encode; + mbencodeinit_func encinit; + mbencodereset_func encreset; + mbdecode_func decode; + mbdecodeinit_func decinit; + mbdecodereset_func decreset; } MultibyteCodec; typedef struct { 1.1 cjkcodecs/src/codecentry.h Index: codecentry.h =================================================================== /* * codecentry.h: Common Codec Entry Routines * * Copyright (C) 2003 Hye-Shik Chang <pe...@Fr...>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: codecentry.h,v 1.1 2003/05/31 11:50:19 perky Exp $ */ #ifdef HAVE_ENCODER_INIT #define ENCODER_INIT_FUNC(encoding) encoding##_encode_init #else #define ENCODER_INIT_FUNC(encoding) NULL #endif #ifdef HAVE_ENCODER_RESET #define ENCODER_RESET_FUNC(encoding) encoding##_encode_reset #else #define ENCODER_RESET_FUNC(encoding) NULL #endif #ifdef HAVE_DECODER_INIT #define DECODER_INIT_FUNC(encoding) encoding##_decode_init #else #define DECODER_INIT_FUNC(encoding) NULL #endif #ifdef HAVE_DECODER_RESET #define DECODER_RESET_FUNC(encoding) encoding##_decode_reset #else #define DECODER_RESET_FUNC(encoding) NULL #endif #define BEGIN_CODEC_REGISTRY(encoding) \ static MultibyteCodec __codec = { \ #encoding, \ encoding##_encode, \ ENCODER_INIT_FUNC(encoding), \ ENCODER_RESET_FUNC(encoding), \ encoding##_decode, \ DECODER_INIT_FUNC(encoding), \ DECODER_RESET_FUNC(encoding), \ }; \ \ static struct PyMethodDef __methods[] = { \ {NULL, NULL}, \ }; \ \ void \ init_##encoding(void) \ { \ PyObject *codec; \ PyObject *m = NULL, *mod = NULL, *o = NULL; \ \ m = Py_InitModule("_" #encoding, __methods); #define MAPOPEN(locale) \ mod = PyImport_ImportModule("mapdata_" #locale); \ if (mod == NULL) goto errorexit; \ if ( #define IMPORTMAP_ENCDEC(charset) \ importmap(mod, "__map_" #charset, &charset##encmap, \ &charset##decmap) || #define IMPORTMAP_ENC(charset) \ importmap(mod, "__map_" #charset, &charset##encmap, \ NULL) || #define IMPORTMAP_DEC(charset) \ importmap(mod, "__map_" #charset, NULL, \ &charset##decmap) || #define MAPCLOSE() \ 0) goto errorexit; \ Py_DECREF(mod); #define END_CODEC_REGISTRY(encoding) \ mod = PyImport_ImportModule("multibytecodec"); \ if (mod == NULL) goto errorexit; \ o = PyObject_GetAttrString(mod, "__create_codec"); \ if (o == NULL || !PyCallable_Check(o)) \ goto errorexit; \ \ codec = createcodec(o, &__codec); \ if (codec == NULL) \ goto errorexit; \ PyModule_AddObject(m, "codec", codec); \ Py_DECREF(o); Py_DECREF(mod); \ \ if (PyErr_Occurred()) \ Py_FatalError("can't initialize the _" #encoding \ " module"); \ \ return; \ \ errorexit: \ Py_XDECREF(m); \ Py_XDECREF(mod); \ Py_XDECREF(o); \ } static int importmap(PyObject *mod, const char *symbol, const struct unim_index **encmap, const struct dbcs_index **decmap) { PyObject *o; o = PyObject_GetAttrString(mod, (char*)symbol); if (o == NULL) return -1; else if (!PyCObject_Check(o)) { PyErr_SetString(PyExc_ValueError, "map data must be a CObject."); return -1; } else { struct dbcs_map *map; map = PyCObject_AsVoidPtr(o); if (encmap != NULL) *encmap = map->encmap; if (decmap != NULL) *decmap = map->decmap; Py_DECREF(o); } return 0; } static PyObject * createcodec(PyObject *cofunc, MultibyteCodec *codec) { PyObject *args, *r; args = PyTuple_New(1); if (args == NULL) return NULL; PyTuple_SET_ITEM(args, 0, PyCObject_FromVoidPtr(codec, NULL)); r = PyObject_CallObject(cofunc, args); Py_DECREF(args); return r; } /* * ex: ts=8 sts=4 et */ |