Skip to content

Commit 664f961

Browse files
PoC: put big5 codec in cjk module state
1 parent 03e16a8 commit 664f961

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Modules/cjkcodecs/_codecs_hk.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
#define USING_IMPORTED_MAPS
88

9+
#define CJK_MOD_SPECIFIC_STATE \
10+
const encode_map *big5_encmap; \
11+
const decode_map *big5_decmap;
12+
913
#include "cjkcodecs.h"
1014
#include "mappings_hk.h"
1115

1216
/*
1317
* BIG5HKSCS codec
1418
*/
1519

16-
static const encode_map *big5_encmap = NULL;
17-
static const decode_map *big5_decmap = NULL;
18-
1920
CODEC_INIT(big5hkscs)
2021
{
21-
static int initialized = 0;
22-
23-
if (!initialized && IMPORT_MAP(tw, big5, &big5_encmap, &big5_decmap))
22+
cjkcodecs_module_state *st = codec->modstate;
23+
if (IMPORT_MAP(tw, big5, &st->big5_encmap, &st->big5_decmap)) {
2424
return -1;
25-
initialized = 1;
25+
}
2626
return 0;
2727
}
2828

@@ -81,7 +81,7 @@ ENCODER(big5hkscs)
8181
}
8282
}
8383
}
84-
else if (TRYMAP_ENC(big5, code, c))
84+
else if (TRYMAP_ENC_ST(big5, code, c))
8585
;
8686
else
8787
return 1;
@@ -122,7 +122,7 @@ DECODER(big5hkscs)
122122
REQUIRE_INBUF(2);
123123

124124
if (0xc6 > c || c > 0xc8 || (c < 0xc7 && INBYTE2 < 0xa1)) {
125-
if (TRYMAP_DEC(big5, decoded, c, INBYTE2)) {
125+
if (TRYMAP_DEC_ST(big5, decoded, c, INBYTE2)) {
126126
OUTCHAR(decoded);
127127
NEXT_IN(2);
128128
continue;

Modules/cjkcodecs/cjkcodecs.h

+5
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ get_module_state(PyObject *mod)
211211
(m)->bottom]) != NOCHAR)
212212
#define TRYMAP_ENC(charset, assi, uni) \
213213
_TRYMAP_ENC(&charset##_encmap[(uni) >> 8], assi, (uni) & 0xff)
214+
#define TRYMAP_ENC_ST(charset, assi, uni) \
215+
_TRYMAP_ENC(&(codec->modstate->charset##_encmap)[(uni) >> 8], \
216+
assi, (uni) & 0xff)
214217

215218
#define _TRYMAP_DEC(m, assi, val) \
216219
((m)->map != NULL && \
@@ -219,6 +222,8 @@ get_module_state(PyObject *mod)
219222
((assi) = (m)->map[(val) - (m)->bottom]) != UNIINV)
220223
#define TRYMAP_DEC(charset, assi, c1, c2) \
221224
_TRYMAP_DEC(&charset##_decmap[c1], assi, c2)
225+
#define TRYMAP_DEC_ST(charset, assi, c1, c2) \
226+
_TRYMAP_DEC(&(codec->modstate->charset##_decmap)[c1], assi, c2)
222227

223228
#define BEGIN_MAPPINGS_LIST(NUM) \
224229
static int \

0 commit comments

Comments
 (0)