Visitar URL original
gh-103583: Add codecs and maps to _codecs_* module state by erlend-aasland · Pull Request #103540 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Hide ugly code in macro
  • Loading branch information
erlend-aasland committed Apr 16, 2023
commit 65af11088e2d25b359ad81e88df8e6a5c668c969
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) \

@corona10 corona10 Apr 16, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, readability will be frustrating (it's not your fault), I will think about a better way.. :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, readability is already frustrating with these modules. If we are to keep the diff down, we just have to go with the macro template style already used. An alternative is to refactor the modules first, but that bears a risk.

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