2 * multibytecodec.h: Common Multibyte Codec Implementation
4 * Written by Hye-Shik Chang <perky@FreeBSD.org>
7 #ifndef _PYTHON_MULTIBYTECODEC_H_
8 #define _PYTHON_MULTIBYTECODEC_H_
14 typedef uint32_t ucs4_t
;
16 typedef unsigned int ucs4_t
;
20 typedef uint16_t ucs2_t
, DBCHAR
;
22 typedef unsigned short ucs2_t
, DBCHAR
;
31 } MultibyteCodec_State
;
33 typedef int (*mbcodec_init
)(const void *config
);
34 typedef Py_ssize_t (*mbencode_func
)(MultibyteCodec_State
*state
,
36 const Py_UNICODE
**inbuf
, Py_ssize_t inleft
,
37 unsigned char **outbuf
, Py_ssize_t outleft
,
39 typedef int (*mbencodeinit_func
)(MultibyteCodec_State
*state
,
41 typedef Py_ssize_t (*mbencodereset_func
)(MultibyteCodec_State
*state
,
43 unsigned char **outbuf
, Py_ssize_t outleft
);
44 typedef Py_ssize_t (*mbdecode_func
)(MultibyteCodec_State
*state
,
46 const unsigned char **inbuf
, Py_ssize_t inleft
,
47 Py_UNICODE
**outbuf
, Py_ssize_t outleft
);
48 typedef int (*mbdecodeinit_func
)(MultibyteCodec_State
*state
,
50 typedef Py_ssize_t (*mbdecodereset_func
)(MultibyteCodec_State
*state
,
56 mbcodec_init codecinit
;
58 mbencodeinit_func encinit
;
59 mbencodereset_func encreset
;
61 mbdecodeinit_func decinit
;
62 mbdecodereset_func decreset
;
67 MultibyteCodec
*codec
;
68 } MultibyteCodecObject
;
70 #define MultibyteCodec_Check(op) ((op)->ob_type == &MultibyteCodec_Type)
72 #define _MultibyteStatefulCodec_HEAD \
74 MultibyteCodec *codec; \
75 MultibyteCodec_State state; \
78 _MultibyteStatefulCodec_HEAD
79 } MultibyteStatefulCodecContext
;
81 #define MAXENCPENDING 2
82 #define _MultibyteStatefulEncoder_HEAD \
83 _MultibyteStatefulCodec_HEAD \
84 Py_UNICODE pending[MAXENCPENDING]; \
85 Py_ssize_t pendingsize;
87 _MultibyteStatefulEncoder_HEAD
88 } MultibyteStatefulEncoderContext
;
90 #define MAXDECPENDING 8
91 #define _MultibyteStatefulDecoder_HEAD \
92 _MultibyteStatefulCodec_HEAD \
93 unsigned char pending[MAXDECPENDING]; \
94 Py_ssize_t pendingsize;
96 _MultibyteStatefulDecoder_HEAD
97 } MultibyteStatefulDecoderContext
;
100 _MultibyteStatefulEncoder_HEAD
101 } MultibyteIncrementalEncoderObject
;
104 _MultibyteStatefulDecoder_HEAD
105 } MultibyteIncrementalDecoderObject
;
108 _MultibyteStatefulDecoder_HEAD
110 } MultibyteStreamReaderObject
;
113 _MultibyteStatefulEncoder_HEAD
115 } MultibyteStreamWriterObject
;
117 /* positive values for illegal sequences */
118 #define MBERR_TOOSMALL (-1) /* insufficient output buffer space */
119 #define MBERR_TOOFEW (-2) /* incomplete input buffer */
120 #define MBERR_INTERNAL (-3) /* internal runtime error */
122 #define ERROR_STRICT (PyObject *)(1)
123 #define ERROR_IGNORE (PyObject *)(2)
124 #define ERROR_REPLACE (PyObject *)(3)
125 #define ERROR_ISCUSTOM(p) ((p) < ERROR_STRICT || ERROR_REPLACE < (p))
126 #define ERROR_DECREF(p) do { \
127 if (p != NULL && ERROR_ISCUSTOM(p)) { \
132 #define MBENC_FLUSH 0x0001 /* encode all characters encodable */
133 #define MBENC_MAX MBENC_FLUSH