Skip to content

Commit f1d734b

Browse files
pks-tgitster
authored andcommitted
meson: detect broken iconv that requires ICONV_RESTART_RESET
In d0cec08 (utf8.c: prepare workaround for iconv under macOS 14/15, 2026-01-12) we have introduced a new workaround for a broken version of libiconv on macOS. This workaround has for now only been wired up for our Makefile, so using Meson with such a broken version will fail. We can rather easily detect the broken behaviour. Some encodings have different modes that can be switched to via an escape sequence. In the case of ISO-2022-JP this can be done via "<Esc>$B" and "<Esc>(J" to switch between ASCII and JIS modes. The bug now triggers when one does multiple calls to iconv(3p) to convert a string piece by piece, where the first call enters JIS mode. The second call forgets about the fact that it is still in JIS mode, and consequently it will incorrectly treat the input as ASCII, and thus the produced output is of course garbage. Wire up a test that exercises this in Meson and, if it fails, set the `ICONV_RESTART_RESET` define. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4cae584 commit f1d734b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

meson.build

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,32 @@ if iconv.found()
10531053
).returncode() != 0
10541054
libgit_c_args += '-DICONV_OMITS_BOM'
10551055
endif
1056+
1057+
if compiler.run('''
1058+
#include <iconv.h>
1059+
#include <string.h>
1060+
1061+
int main(int argc, const char *argv[])
1062+
{
1063+
char in[] = "\x1b\x24\x42\x24\x22\x24\x22\x1b\x28\x42", *inpos = in;
1064+
char out[7] = { 0 }, *outpos = out;
1065+
size_t insz = sizeof(in) - 1, outsz = 4;
1066+
iconv_t conv = iconv_open("UTF-8", "ISO-2022-JP");
1067+
if (!conv)
1068+
return 1;
1069+
if (iconv(conv, (void *) &inpos, &insz, &outpos, &outsz) != (size_t) -1)
1070+
return 2;
1071+
outsz = sizeof(out) - (outpos - out);
1072+
if (iconv(conv, (void *) &inpos, &insz, &outpos, &outsz) == (size_t) -1)
1073+
return 3;
1074+
return strcmp("\343\201\202\343\201\202", out) ? 4 : 0;
1075+
}
1076+
''',
1077+
dependencies: iconv,
1078+
name: 'iconv handles restarts properly',
1079+
).returncode() != 0
1080+
libgit_c_args += '-DICONV_RESTART_RESET'
1081+
endif
10561082
endif
10571083
else
10581084
libgit_c_args += '-DNO_ICONV'

0 commit comments

Comments
 (0)