#ifndef _CJKCODECS_H_
#define _CJKCODECS_H_
#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE …
#endif
#include "Python.h"
#include "multibytecodec.h"
#include "pycore_import.h"
#define UNIINV …
#define NOCHAR …
#define MULTIC …
#define DBCINV …
#define U …
#define N …
#define M …
#define D …
struct dbcs_index { … };
decode_map;
struct widedbcs_index { … };
widedecode_map;
struct unim_index { … };
encode_map;
struct unim_index_bytebased { … };
struct dbcs_map { … };
struct pair_encodemap { … };
#ifndef CJK_MOD_SPECIFIC_STATE
#define CJK_MOD_SPECIFIC_STATE
#endif
cjkcodecs_module_state;
static inline cjkcodecs_module_state *
get_module_state(PyObject *mod)
{ … }
#define CODEC_INIT(encoding) …
#define ENCODER_INIT(encoding) …
#define ENCODER(encoding) …
#define ENCODER_RESET(encoding) …
#define DECODER_INIT(encoding) …
#define DECODER(encoding) …
#define DECODER_RESET(encoding) …
#define NEXT_IN(i) …
#define NEXT_INCHAR(i) …
#define NEXT_OUT(o) …
#define NEXT(i, o) …
#define REQUIRE_INBUF(n) …
#define REQUIRE_OUTBUF(n) …
#define INBYTE1 …
#define INBYTE2 …
#define INBYTE3 …
#define INBYTE4 …
#define INCHAR1 …
#define INCHAR2 …
#define OUTCHAR(c) …
#define OUTCHAR2(c1, c2) …
#define OUTBYTEI(c, i) …
#define OUTBYTE1(c) …
#define OUTBYTE2(c) …
#define OUTBYTE3(c) …
#define OUTBYTE4(c) …
#define WRITEBYTE1(c1) …
#define WRITEBYTE2(c1, c2) …
#define WRITEBYTE3(c1, c2, c3) …
#define WRITEBYTE4(c1, c2, c3, c4) …
#define _TRYMAP_ENC(m, assi, val) …
#define TRYMAP_ENC(charset, assi, uni) …
#define TRYMAP_ENC_ST(charset, assi, uni) …
#define _TRYMAP_DEC(m, assi, val) …
#define TRYMAP_DEC(charset, assi, c1, c2) …
#define TRYMAP_DEC_ST(charset, assi, c1, c2) …
#define BEGIN_MAPPINGS_LIST(NUM) …
#define MAPPING_ENCONLY(enc) …
#define MAPPING_DECONLY(enc) …
#define MAPPING_ENCDEC(enc) …
#define END_MAPPINGS_LIST …
#define BEGIN_CODECS_LIST(NUM) …
#define _STATEFUL_METHODS(enc) …
#define _STATELESS_METHODS(enc) …
#define NEXT_CODEC …
#define CODEC_STATEFUL(enc) …
#define CODEC_STATELESS(enc) …
#define CODEC_STATELESS_WINIT(enc) …
#define END_CODECS_LIST …
static PyObject *
getmultibytecodec(void)
{ … }
static void
destroy_codec_capsule(PyObject *capsule)
{ … }
static codec_capsule *
capsulate_codec(PyObject *mod, const MultibyteCodec *codec)
{ … }
static PyObject *
_getcodec(PyObject *self, const MultibyteCodec *codec)
{ … }
static PyObject *
getcodec(PyObject *self, PyObject *encoding)
{ … }
static int add_mappings(cjkcodecs_module_state *);
static int add_codecs(cjkcodecs_module_state *);
static int
register_maps(PyObject *module)
{ … }
#ifdef USING_BINARY_PAIR_SEARCH
static DBCHAR
find_pairencmap(ucs2_t body, ucs2_t modifier,
const struct pair_encodemap *haystack, int haystacksize)
{
int pos, min, max;
Py_UCS4 value = body << 16 | modifier;
min = 0;
max = haystacksize;
for (pos = haystacksize >> 1; min != max; pos = (min + max) >> 1) {
if (value < haystack[pos].uniseq) {
if (max != pos) {
max = pos;
continue;
}
}
else if (value > haystack[pos].uniseq) {
if (min != pos) {
min = pos;
continue;
}
}
break;
}
if (value == haystack[pos].uniseq) {
return haystack[pos].code;
}
return DBCINV;
}
#endif
#ifdef USING_IMPORTED_MAPS
#define IMPORT_MAP …
static int
importmap(const char *modname, const char *symbol,
const void **encmap, const void **decmap)
{
PyObject *o, *mod;
mod = PyImport_ImportModule(modname);
if (mod == NULL)
return -1;
o = PyObject_GetAttrString(mod, symbol);
if (o == NULL)
goto errorexit;
else if (!PyCapsule_IsValid(o, MAP_CAPSULE)) {
PyErr_SetString(PyExc_ValueError,
"map data must be a Capsule.");
goto errorexit;
}
else {
struct dbcs_map *map;
map = PyCapsule_GetPointer(o, MAP_CAPSULE);
if (encmap != NULL)
*encmap = map->encmap;
if (decmap != NULL)
*decmap = map->decmap;
Py_DECREF(o);
}
Py_DECREF(mod);
return 0;
errorexit:
Py_DECREF(mod);
return -1;
}
#endif
static int
_cjk_exec(PyObject *module)
{ … }
static void
_cjk_free(void *mod)
{ … }
static struct PyMethodDef _cjk_methods[] = …;
static PyModuleDef_Slot _cjk_slots[] = …;
#define I_AM_A_MODULE_FOR(loc) …
#endif