source: python/trunk/Modules/cjkcodecs/multibytecodec.h

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 4.2 KB
RevLine 
[2]1/*
2 * multibytecodec.h: Common Multibyte Codec Implementation
3 *
4 * Written by Hye-Shik Chang <perky@FreeBSD.org>
5 */
6
7#ifndef _PYTHON_MULTIBYTECODEC_H_
8#define _PYTHON_MULTIBYTECODEC_H_
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#ifdef uint32_t
14typedef uint32_t ucs4_t;
15#else
16typedef unsigned int ucs4_t;
17#endif
18
19#ifdef uint16_t
20typedef uint16_t ucs2_t, DBCHAR;
21#else
22typedef unsigned short ucs2_t, DBCHAR;
23#endif
24
25typedef union {
[391]26 void *p;
27 int i;
28 unsigned char c[8];
29 ucs2_t u2[4];
30 ucs4_t u4[2];
[2]31} MultibyteCodec_State;
32
33typedef int (*mbcodec_init)(const void *config);
34typedef Py_ssize_t (*mbencode_func)(MultibyteCodec_State *state,
[391]35 const void *config,
36 const Py_UNICODE **inbuf, Py_ssize_t inleft,
37 unsigned char **outbuf, Py_ssize_t outleft,
38 int flags);
[2]39typedef int (*mbencodeinit_func)(MultibyteCodec_State *state,
[391]40 const void *config);
[2]41typedef Py_ssize_t (*mbencodereset_func)(MultibyteCodec_State *state,
[391]42 const void *config,
43 unsigned char **outbuf, Py_ssize_t outleft);
[2]44typedef Py_ssize_t (*mbdecode_func)(MultibyteCodec_State *state,
[391]45 const void *config,
46 const unsigned char **inbuf, Py_ssize_t inleft,
47 Py_UNICODE **outbuf, Py_ssize_t outleft);
[2]48typedef int (*mbdecodeinit_func)(MultibyteCodec_State *state,
[391]49 const void *config);
[2]50typedef Py_ssize_t (*mbdecodereset_func)(MultibyteCodec_State *state,
[391]51 const void *config);
[2]52
53typedef struct {
[391]54 const char *encoding;
55 const void *config;
56 mbcodec_init codecinit;
57 mbencode_func encode;
58 mbencodeinit_func encinit;
59 mbencodereset_func encreset;
60 mbdecode_func decode;
61 mbdecodeinit_func decinit;
62 mbdecodereset_func decreset;
[2]63} MultibyteCodec;
64
65typedef struct {
[391]66 PyObject_HEAD
67 MultibyteCodec *codec;
[2]68} MultibyteCodecObject;
69
70#define MultibyteCodec_Check(op) ((op)->ob_type == &MultibyteCodec_Type)
71
[391]72#define _MultibyteStatefulCodec_HEAD \
73 PyObject_HEAD \
74 MultibyteCodec *codec; \
75 MultibyteCodec_State state; \
76 PyObject *errors;
[2]77typedef struct {
[391]78 _MultibyteStatefulCodec_HEAD
[2]79} MultibyteStatefulCodecContext;
80
[391]81#define MAXENCPENDING 2
82#define _MultibyteStatefulEncoder_HEAD \
83 _MultibyteStatefulCodec_HEAD \
84 Py_UNICODE pending[MAXENCPENDING]; \
85 Py_ssize_t pendingsize;
[2]86typedef struct {
[391]87 _MultibyteStatefulEncoder_HEAD
[2]88} MultibyteStatefulEncoderContext;
89
[391]90#define MAXDECPENDING 8
91#define _MultibyteStatefulDecoder_HEAD \
92 _MultibyteStatefulCodec_HEAD \
93 unsigned char pending[MAXDECPENDING]; \
94 Py_ssize_t pendingsize;
[2]95typedef struct {
[391]96 _MultibyteStatefulDecoder_HEAD
[2]97} MultibyteStatefulDecoderContext;
98
99typedef struct {
[391]100 _MultibyteStatefulEncoder_HEAD
[2]101} MultibyteIncrementalEncoderObject;
102
103typedef struct {
[391]104 _MultibyteStatefulDecoder_HEAD
[2]105} MultibyteIncrementalDecoderObject;
106
107typedef struct {
[391]108 _MultibyteStatefulDecoder_HEAD
109 PyObject *stream;
[2]110} MultibyteStreamReaderObject;
111
112typedef struct {
[391]113 _MultibyteStatefulEncoder_HEAD
114 PyObject *stream;
[2]115} MultibyteStreamWriterObject;
116
117/* positive values for illegal sequences */
[391]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 */
[2]121
[391]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)) { \
128 Py_DECREF(p); \
129 } \
[2]130} while (0);
131
[391]132#define MBENC_FLUSH 0x0001 /* encode all characters encodable */
133#define MBENC_MAX MBENC_FLUSH
[2]134
[391]135#define PyMultibyteCodec_CAPSULE_NAME "multibytecodec.__map_*"
136
137
[2]138#ifdef __cplusplus
139}
140#endif
141#endif
Note: See TracBrowser for help on using the repository browser.