Skip to content

Commit

Permalink
Hide ugly code in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Apr 16, 2023
1 parent 605c4fb commit 65af110
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/_codecs_iso2022.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ BEGIN_MAPPINGS_LIST(0)
END_MAPPINGS_LIST

#define ISO2022_CODEC(variation) \
st->codec_list[idx++] = (MultibyteCodec){ \
NEXT_CODEC = (MultibyteCodec){ \
"iso2022_" #variation, \
&iso2022_##variation##_config, \
iso2022_codec_init, \
Expand Down
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/_codecs_jp.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ BEGIN_MAPPINGS_LIST(11)
END_MAPPINGS_LIST

#define CODEC_CUSTOM(NAME, N, METH) \
st->codec_list[idx++] = (MultibyteCodec){NAME, (void *)N, NULL, _STATELESS_METHODS(METH)};
NEXT_CODEC = (MultibyteCodec){NAME, (void *)N, NULL, _STATELESS_METHODS(METH)};

BEGIN_CODECS_LIST(7)
CODEC_STATELESS(shift_jis)
Expand Down
9 changes: 6 additions & 3 deletions Modules/cjkcodecs/cjkcodecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,15 @@ add_codecs(cjkcodecs_module_state *st) \
enc##_encode, NULL, NULL, \
enc##_decode, NULL, NULL,

#define NEXT_CODEC \
st->codec_list[idx++]

#define CODEC_STATEFUL(enc) \
st->codec_list[idx++] = (MultibyteCodec){#enc, NULL, NULL, _STATEFUL_METHODS(enc)};
NEXT_CODEC = (MultibyteCodec){#enc, NULL, NULL, _STATEFUL_METHODS(enc)};
#define CODEC_STATELESS(enc) \
st->codec_list[idx++] = (MultibyteCodec){#enc, NULL, NULL, _STATELESS_METHODS(enc)};
NEXT_CODEC = (MultibyteCodec){#enc, NULL, NULL, _STATELESS_METHODS(enc)};
#define CODEC_STATELESS_WINIT(enc) \
st->codec_list[idx++] = (MultibyteCodec){#enc, NULL, enc##_codec_init, _STATELESS_METHODS(enc)};
NEXT_CODEC = (MultibyteCodec){#enc, NULL, enc##_codec_init, _STATELESS_METHODS(enc)};

#define END_CODECS_LIST \
assert(st->num_codecs == idx); \
Expand Down

0 comments on commit 65af110

Please sign in to comment.