Skip to content

Commit a4c7964

Browse files
Add cjk module state pointer to MultibyteCodec struct
Lifetime should be guaranteed, since each MultibyteCodecObjects owns a reference the cjk codec module that owns the memory of the MultibyteCodec struct.
1 parent 6cf4b53 commit a4c7964

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Modules/cjkcodecs/cjkcodecs.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct pair_encodemap {
6060
DBCHAR code;
6161
};
6262

63-
typedef struct {
63+
typedef struct _cjk_mod_state {
6464
int num_mappings;
6565
int num_codecs;
6666
struct dbcs_map *mapping_list;
@@ -271,9 +271,12 @@ add_codecs(cjkcodecs_module_state *st) \
271271
#define CODEC_STATELESS_WINIT(enc) \
272272
NEXT_CODEC = (MultibyteCodec){#enc, NULL, enc##_codec_init, _STATELESS_METHODS(enc)};
273273

274-
#define END_CODECS_LIST \
275-
assert(st->num_codecs == idx); \
276-
return 0; \
274+
#define END_CODECS_LIST \
275+
assert(st->num_codecs == idx); \
276+
for (int i = 0; i < st->num_codecs; i++) { \
277+
st->codec_list[i].modstate = st; \
278+
} \
279+
return 0; \
277280
}
278281

279282

Modules/cjkcodecs/multibytecodec.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct {
2727
unsigned char c[8];
2828
} MultibyteCodec_State;
2929

30+
struct _cjk_mod_state;
3031
struct _multibyte_codec;
3132

3233
typedef int (*mbcodec_init)(const struct _multibyte_codec *codec);
@@ -60,6 +61,7 @@ typedef struct _multibyte_codec {
6061
mbdecode_func decode;
6162
mbdecodeinit_func decinit;
6263
mbdecodereset_func decreset;
64+
struct _cjk_mod_state *modstate;
6365
} MultibyteCodec;
6466

6567
typedef struct {

0 commit comments

Comments
 (0)