Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Functions | Variables
cjkcodecs.h File Reference
#include "Python.h"
#include "multibytecodec.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dbcs_index
struct  widedbcs_index
struct  unim_index
struct  unim_index_bytebased
struct  dbcs_map
struct  pair_encodemap

Defines

#define PY_SSIZE_T_CLEAN
#define UNIINV   0xFFFE
#define NOCHAR   0xFFFF
#define MULTIC   0xFFFE
#define DBCINV   0xFFFD
#define U   UNIINV
#define N   NOCHAR
#define M   MULTIC
#define D   DBCINV
#define CODEC_INIT(encoding)   static int encoding##_codec_init(const void *config)
#define ENCODER_INIT(encoding)
#define ENCODER(encoding)
#define ENCODER_RESET(encoding)
#define DECODER_INIT(encoding)
#define DECODER(encoding)
#define DECODER_RESET(encoding)
#define UCS4INVALID(code)   if (0) ;
#define NEXT_IN(i)
#define NEXT_OUT(o)
#define NEXT(i, o)   NEXT_IN(i) NEXT_OUT(o)
#define REQUIRE_INBUF(n)
#define REQUIRE_OUTBUF(n)
#define IN1   ((*inbuf)[0])
#define IN2   ((*inbuf)[1])
#define IN3   ((*inbuf)[2])
#define IN4   ((*inbuf)[3])
#define OUT1(c)   ((*outbuf)[0]) = (c);
#define OUT2(c)   ((*outbuf)[1]) = (c);
#define OUT3(c)   ((*outbuf)[2]) = (c);
#define OUT4(c)   ((*outbuf)[3]) = (c);
#define WRITE1(c1)
#define WRITE2(c1, c2)
#define WRITE3(c1, c2, c3)
#define WRITE4(c1, c2, c3, c4)
#define WRITEUCS4(c)
#define _TRYMAP_ENC(m, assi, val)
#define TRYMAP_ENC_COND(charset, assi, uni)   _TRYMAP_ENC(&charset##_encmap[(uni) >> 8], assi, (uni) & 0xff)
#define TRYMAP_ENC(charset, assi, uni)   if TRYMAP_ENC_COND(charset, assi, uni)
#define _TRYMAP_DEC(m, assi, val)
#define TRYMAP_DEC(charset, assi, c1, c2)   if _TRYMAP_DEC(&charset##_decmap[c1], assi, c2)
#define _TRYMAP_ENC_MPLANE(m, assplane, asshi, asslo, val)
#define TRYMAP_ENC_MPLANE(charset, assplane, asshi, asslo, uni)
#define TRYMAP_DEC_MPLANE(charset, assi, plane, c1, c2)   if _TRYMAP_DEC(&charset##_decmap[plane][c1], assi, c2)
#define DECODE_SURROGATE(c)   {;}
#define GET_INSIZE(c)   1
#define BEGIN_MAPPINGS_LIST   static const struct dbcs_map _mapping_list[] = {
#define MAPPING_ENCONLY(enc)   {#enc, (void*)enc##_encmap, NULL},
#define MAPPING_DECONLY(enc)   {#enc, NULL, (void*)enc##_decmap},
#define MAPPING_ENCDEC(enc)   {#enc, (void*)enc##_encmap, (void*)enc##_decmap},
#define END_MAPPINGS_LIST
#define BEGIN_CODECS_LIST   static const MultibyteCodec _codec_list[] = {
#define _STATEFUL_METHODS(enc)
#define _STATELESS_METHODS(enc)
#define CODEC_STATEFUL(enc)
#define CODEC_STATELESS(enc)
#define CODEC_STATELESS_WINIT(enc)
#define END_CODECS_LIST
#define I_AM_A_MODULE_FOR(loc)

Typedefs

typedef struct dbcs_index
typedef struct widedbcs_index
typedef struct unim_index

Functions

static PyObjectgetmultibytecodec (void)
static PyObjectgetcodec (PyObject *self, PyObject *encoding)
static int register_maps (PyObject *module)

Variables

static const MultibyteCodeccodec_list
static struct dbcs_mapmapping_list
static struct PyMethodDef []

Class Documentation

struct dbcs_index

Definition at line 29 of file cjkcodecs.h.

Class Members
unsigned char bottom
const ucs2_t * map
unsigned char top
struct widedbcs_index

Definition at line 35 of file cjkcodecs.h.

Class Members
unsigned char bottom
const ucs4_t * map
unsigned char top
struct unim_index

Definition at line 41 of file cjkcodecs.h.

Class Members
unsigned char bottom
const DBCHAR * map
unsigned char top
struct unim_index_bytebased

Definition at line 47 of file cjkcodecs.h.

Class Members
unsigned char bottom
const unsigned char * map
unsigned char top
struct dbcs_map

Definition at line 52 of file cjkcodecs.h.

Collaboration diagram for dbcs_map:
Class Members
const char * charset
struct dbcs_index * decmap
struct unim_index * encmap
struct pair_encodemap

Definition at line 58 of file cjkcodecs.h.

Class Members
DBCHAR code
ucs4_t uniseq

Define Documentation

#define _STATEFUL_METHODS (   enc)
Value:
enc##_encode,                       \
    enc##_encode_init,                  \
    enc##_encode_reset,                 \
    enc##_decode,                       \
    enc##_decode_init,                  \
    enc##_decode_reset,

Definition at line 214 of file cjkcodecs.h.

#define _STATELESS_METHODS (   enc)
Value:
enc##_encode, NULL, NULL,           \
    enc##_decode, NULL, NULL,

Definition at line 221 of file cjkcodecs.h.

#define _TRYMAP_DEC (   m,
  assi,
  val 
)
Value:
((m)->map != NULL && (val) >= (m)->bottom &&                \
        (val)<= (m)->top && ((assi) = (m)->map[(val) -          \
        (m)->bottom]) != UNIINV)

Definition at line 170 of file cjkcodecs.h.

#define _TRYMAP_ENC (   m,
  assi,
  val 
)
Value:
((m)->map != NULL && (val) >= (m)->bottom &&                \
        (val)<= (m)->top && ((assi) = (m)->map[(val) -          \
        (m)->bottom]) != NOCHAR)

Definition at line 161 of file cjkcodecs.h.

#define _TRYMAP_ENC_MPLANE (   m,
  assplane,
  asshi,
  asslo,
  val 
)
Value:
((m)->map != NULL && (val) >= (m)->bottom &&                \
        (val)<= (m)->top &&                                     \
        ((assplane) = (m)->map[((val) - (m)->bottom)*3]) != 0 && \
        (((asshi) = (m)->map[((val) - (m)->bottom)*3 + 1]), 1) && \
        (((asslo) = (m)->map[((val) - (m)->bottom)*3 + 2]), 1))

Definition at line 177 of file cjkcodecs.h.

#define BEGIN_CODECS_LIST   static const MultibyteCodec _codec_list[] = {

Definition at line 213 of file cjkcodecs.h.

#define BEGIN_MAPPINGS_LIST   static const struct dbcs_map _mapping_list[] = {

Definition at line 204 of file cjkcodecs.h.

#define CODEC_INIT (   encoding)    static int encoding##_codec_init(const void *config)

Definition at line 66 of file cjkcodecs.h.

#define CODEC_STATEFUL (   enc)
Value:
{           \
    #enc, NULL, NULL,                   \
    _STATEFUL_METHODS(enc)              \
},

Definition at line 224 of file cjkcodecs.h.

#define CODEC_STATELESS (   enc)
Value:
{          \
    #enc, NULL, NULL,                   \
    _STATELESS_METHODS(enc)             \
},

Definition at line 228 of file cjkcodecs.h.

#define CODEC_STATELESS_WINIT (   enc)
Value:
{    \
    #enc, NULL,                         \
    enc##_codec_init,                   \
    _STATELESS_METHODS(enc)             \
},

Definition at line 232 of file cjkcodecs.h.

#define D   DBCINV

Definition at line 27 of file cjkcodecs.h.

#define DBCINV   0xFFFD

Definition at line 21 of file cjkcodecs.h.

#define DECODE_SURROGATE (   c)    {;}

Definition at line 200 of file cjkcodecs.h.

#define DECODER (   encoding)
Value:
static Py_ssize_t encoding##_decode(                                \
        MultibyteCodec_State *state, const void *config,                \
        const unsigned char **inbuf, Py_ssize_t inleft,                 \
        Py_UNICODE **outbuf, Py_ssize_t outleft)

Definition at line 85 of file cjkcodecs.h.

#define DECODER_INIT (   encoding)
Value:
static int encoding##_decode_init(                                  \
        MultibyteCodec_State *state, const void *config)

Definition at line 82 of file cjkcodecs.h.

#define DECODER_RESET (   encoding)
Value:
static Py_ssize_t encoding##_decode_reset(                          \
        MultibyteCodec_State *state, const void *config)

Definition at line 90 of file cjkcodecs.h.

#define ENCODER (   encoding)
Value:
static Py_ssize_t encoding##_encode(                                \
        MultibyteCodec_State *state, const void *config,                \
        const Py_UNICODE **inbuf, Py_ssize_t inleft,                    \
        unsigned char **outbuf, Py_ssize_t outleft, int flags)

Definition at line 72 of file cjkcodecs.h.

#define ENCODER_INIT (   encoding)
Value:
static int encoding##_encode_init(                                  \
        MultibyteCodec_State *state, const void *config)

Definition at line 69 of file cjkcodecs.h.

#define ENCODER_RESET (   encoding)
Value:
static Py_ssize_t encoding##_encode_reset(                          \
        MultibyteCodec_State *state, const void *config,                \
        unsigned char **outbuf, Py_ssize_t outleft)

Definition at line 77 of file cjkcodecs.h.

#define END_CODECS_LIST
Value:
{"", NULL,} };                                      \
    static const MultibyteCodec *codec_list =           \
        (const MultibyteCodec *)_codec_list;

Definition at line 237 of file cjkcodecs.h.

Value:
{"", NULL, NULL} };                                 \
    static const struct dbcs_map *mapping_list =        \
        (const struct dbcs_map *)_mapping_list;

Definition at line 208 of file cjkcodecs.h.

#define GET_INSIZE (   c)    1

Definition at line 201 of file cjkcodecs.h.

#define I_AM_A_MODULE_FOR (   loc)
Value:
static struct PyModuleDef __module = {                              \
        PyModuleDef_HEAD_INIT,                                          \
        "_codecs_"#loc,                                                 \
        NULL,                                                           \
        0,                                                              \
        __methods,                                                      \
        NULL,                                                           \
        NULL,                                                           \
        NULL,                                                           \
        NULL                                                            \
    };                                                                  \
    PyObject*                                                           \
    PyInit__codecs_##loc(void)                                          \
    {                                                                   \
        PyObject *m = PyModule_Create(&__module);                       \
        if (m != NULL)                                                  \
            (void)register_maps(m);                                     \
        return m;                                                       \
    }

Definition at line 393 of file cjkcodecs.h.

#define IN1   ((*inbuf)[0])

Definition at line 119 of file cjkcodecs.h.

#define IN2   ((*inbuf)[1])

Definition at line 120 of file cjkcodecs.h.

#define IN3   ((*inbuf)[2])

Definition at line 121 of file cjkcodecs.h.

#define IN4   ((*inbuf)[3])

Definition at line 122 of file cjkcodecs.h.

#define M   MULTIC

Definition at line 26 of file cjkcodecs.h.

#define MAPPING_DECONLY (   enc)    {#enc, NULL, (void*)enc##_decmap},

Definition at line 206 of file cjkcodecs.h.

#define MAPPING_ENCDEC (   enc)    {#enc, (void*)enc##_encmap, (void*)enc##_decmap},

Definition at line 207 of file cjkcodecs.h.

#define MAPPING_ENCONLY (   enc)    {#enc, (void*)enc##_encmap, NULL},

Definition at line 205 of file cjkcodecs.h.

#define MULTIC   0xFFFE

Definition at line 20 of file cjkcodecs.h.

#define N   NOCHAR

Definition at line 25 of file cjkcodecs.h.

#define NEXT (   i,
  o 
)    NEXT_IN(i) NEXT_OUT(o)

Definition at line 109 of file cjkcodecs.h.

#define NEXT_IN (   i)
Value:
(*inbuf) += (i);                            \
    (inleft) -= (i);

Definition at line 103 of file cjkcodecs.h.

#define NEXT_OUT (   o)
Value:
(*outbuf) += (o);                           \
    (outleft) -= (o);

Definition at line 106 of file cjkcodecs.h.

#define NOCHAR   0xFFFF

Definition at line 19 of file cjkcodecs.h.

#define OUT1 (   c)    ((*outbuf)[0]) = (c);

Definition at line 124 of file cjkcodecs.h.

#define OUT2 (   c)    ((*outbuf)[1]) = (c);

Definition at line 125 of file cjkcodecs.h.

#define OUT3 (   c)    ((*outbuf)[2]) = (c);

Definition at line 126 of file cjkcodecs.h.

#define OUT4 (   c)    ((*outbuf)[3]) = (c);

Definition at line 127 of file cjkcodecs.h.

Definition at line 10 of file cjkcodecs.h.

#define REQUIRE_INBUF (   n)
Value:
if (inleft < (n))                           \
        return MBERR_TOOFEW;

Definition at line 112 of file cjkcodecs.h.

#define REQUIRE_OUTBUF (   n)
Value:
if (outleft < (n))                          \
        return MBERR_TOOSMALL;

Definition at line 115 of file cjkcodecs.h.

#define TRYMAP_DEC (   charset,
  assi,
  c1,
  c2 
)    if _TRYMAP_DEC(&charset##_decmap[c1], assi, c2)

Definition at line 174 of file cjkcodecs.h.

#define TRYMAP_DEC_MPLANE (   charset,
  assi,
  plane,
  c1,
  c2 
)    if _TRYMAP_DEC(&charset##_decmap[plane][c1], assi, c2)

Definition at line 186 of file cjkcodecs.h.

#define TRYMAP_ENC (   charset,
  assi,
  uni 
)    if TRYMAP_ENC_COND(charset, assi, uni)

Definition at line 167 of file cjkcodecs.h.

#define TRYMAP_ENC_COND (   charset,
  assi,
  uni 
)    _TRYMAP_ENC(&charset##_encmap[(uni) >> 8], assi, (uni) & 0xff)

Definition at line 165 of file cjkcodecs.h.

#define TRYMAP_ENC_MPLANE (   charset,
  assplane,
  asshi,
  asslo,
  uni 
)
Value:
if _TRYMAP_ENC_MPLANE(&charset##_encmap[(uni) >> 8], \
                       assplane, asshi, asslo, (uni) & 0xff)

Definition at line 183 of file cjkcodecs.h.

#define U   UNIINV

Definition at line 24 of file cjkcodecs.h.

#define UCS4INVALID (   code)    if (0) ;

Definition at line 99 of file cjkcodecs.h.

#define UNIINV   0xFFFE

Definition at line 16 of file cjkcodecs.h.

#define WRITE1 (   c1)
Value:
REQUIRE_OUTBUF(1)           \
    (*outbuf)[0] = (c1);

Definition at line 129 of file cjkcodecs.h.

#define WRITE2 (   c1,
  c2 
)
Value:
REQUIRE_OUTBUF(2)           \
    (*outbuf)[0] = (c1);        \
    (*outbuf)[1] = (c2);

Definition at line 132 of file cjkcodecs.h.

#define WRITE3 (   c1,
  c2,
  c3 
)
Value:
REQUIRE_OUTBUF(3)           \
    (*outbuf)[0] = (c1);        \
    (*outbuf)[1] = (c2);        \
    (*outbuf)[2] = (c3);

Definition at line 136 of file cjkcodecs.h.

#define WRITE4 (   c1,
  c2,
  c3,
  c4 
)
Value:
REQUIRE_OUTBUF(4)           \
    (*outbuf)[0] = (c1);        \
    (*outbuf)[1] = (c2);        \
    (*outbuf)[2] = (c3);        \
    (*outbuf)[3] = (c4);

Definition at line 141 of file cjkcodecs.h.

#define WRITEUCS4 (   c)
Value:
REQUIRE_OUTBUF(1)                                           \
    **outbuf = (Py_UNICODE)(c);                                 \
    NEXT_OUT(1)

Definition at line 155 of file cjkcodecs.h.


Typedef Documentation

static struct dbcs_index

Definition at line 33 of file cjkcodecs.h.

static struct unim_index

Definition at line 45 of file cjkcodecs.h.

typedef struct widedbcs_index

Definition at line 39 of file cjkcodecs.h.


Function Documentation

static PyObject* getcodec ( PyObject self,
PyObject encoding 
) [static]

Definition at line 260 of file cjkcodecs.h.

{
    PyObject *codecobj, *r, *cofunc;
    const MultibyteCodec *codec;
    const char *enc;

    if (!PyUnicode_Check(encoding)) {
        PyErr_SetString(PyExc_TypeError,
                        "encoding name must be a string.");
        return NULL;
    }
    enc = _PyUnicode_AsString(encoding);
    if (enc == NULL)
        return NULL;

    cofunc = getmultibytecodec();
    if (cofunc == NULL)
        return NULL;

    for (codec = codec_list; codec->encoding[0]; codec++)
        if (strcmp(codec->encoding, enc) == 0)
            break;

    if (codec->encoding[0] == '\0') {
        PyErr_SetString(PyExc_LookupError,
                        "no such codec is supported.");
        return NULL;
    }

    codecobj = PyCapsule_New((void *)codec, PyMultibyteCodec_CAPSULE_NAME, NULL);
    if (codecobj == NULL)
        return NULL;

    r = PyObject_CallFunctionObjArgs(cofunc, codecobj, NULL);
    Py_DECREF(codecobj);

    return r;
}

Here is the call graph for this function:

static PyObject* getmultibytecodec ( void  ) [static]

Definition at line 245 of file cjkcodecs.h.

{
    static PyObject *cofunc = NULL;

    if (cofunc == NULL) {
        PyObject *mod = PyImport_ImportModuleNoBlock("_multibytecodec");
        if (mod == NULL)
            return NULL;
        cofunc = PyObject_GetAttrString(mod, "__create_codec");
        Py_DECREF(mod);
    }
    return cofunc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int register_maps ( PyObject module) [static]

Definition at line 305 of file cjkcodecs.h.

{
    const struct dbcs_map *h;

    for (h = mapping_list; h->charset[0] != '\0'; h++) {
        char mhname[256] = "__map_";
        int r;
        strcpy(mhname + sizeof("__map_") - 1, h->charset);
        r = PyModule_AddObject(module, mhname,
                        PyCapsule_New((void *)h, PyMultibyteCodec_CAPSULE_NAME, NULL));
        if (r == -1)
            return -1;
    }
    return 0;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 63 of file cjkcodecs.h.

struct dbcs_map* mapping_list [static]

Definition at line 64 of file cjkcodecs.h.

struct PyMethodDef[] [static]
Initial value:
 {
    {"getcodec", (PyCFunction)getcodec, METH_O, ""},
    {NULL, NULL},
}

Definition at line 299 of file cjkcodecs.h.