1 From e9097ab24832e42df6e16093e5c3b775dbcf2367 Mon Sep 17 00:00:00 2001
2 From: Mirko Vogt <mirko-openwrt@nanl.de>
3 Date: Fri, 5 Jun 2020 12:46:36 +0000
4 Subject: [PATCH] GNU iconv() - at least in OpenWrt - behaves like POSIX
7 GNU iconv() had the terrible idea of introducing a build variant for its
8 iconv() function, where the second argument can either be a `char **` or
9 a `const char **` depending on a macro set under whatever certain
10 circumstances at build time, resulting in different function signatures.
12 Despite those two possible variants, the project only mentions the
13 non-const one in their manual page.
15 Since this didn't seem to be enough trouble for its users, they seem to
16 have changed the default variant from `const char **` to `char **` at
17 some point, while leaving the manual page as it is, now stating the
18 non-default, hence in most cases probably wrong, signature.
20 Qt assumes GNU iconv() has the nowadays non-default function signature
21 (`const char **`), and distiguishes that way from the POSIX one.
22 Another issue with Qt and GNU iconv(): While we can easily make the test
23 work for GNU iconv with its default iconv()-signature, Qt assumes that if
24 the GNU-iconv succeeds, the present version of iconv is POSIX-
25 incompatible - which however isn't true in our case.
27 However we also can't just use the POSIX iconv test, as the Qt test for
28 POSIX iconv fails on GNU iconv for another reason: GNU iconv requires
29 explicit linker flags (`-liconv`), which the Qt test for POSIX iconv
30 however implicitly drops when the target system is linux.
32 This was extensively discussed in a Qt bug report:
33 https://bugreports.qt.io/projects/QTBUG/issues/QTBUG-84708
35 The only good thing seems to be that Qt's configure script is also buggy
36 and counter-intuitive, resulting in 'gnu' not being accepted as iconv
37 variant when using the default single-dash format for specifying
39 https://bugreports.qt.io/projects/QTBUG/issues/QTBUG-84687
40 So most likely there's nobody using Qt with GNU iconv anyway.
42 This patch is what I came up with being the smallest changeset.
45 src/corelib/codecs/qiconvcodec.cpp | 5 -----
46 src/corelib/configure.json | 2 +-
47 2 files changed, 1 insertion(+), 6 deletions(-)
49 diff --git a/src/corelib/codecs/qiconvcodec.cpp b/src/corelib/codecs/qiconvcodec.cpp
50 index 9c397279..8d43e6c8 100644
51 --- a/src/corelib/codecs/qiconvcodec.cpp
52 +++ b/src/corelib/codecs/qiconvcodec.cpp
53 @@ -180,12 +180,7 @@ QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState
54 IconvState *state = *pstate;
55 size_t inBytesLeft = len;
56 // best case assumption, each byte is converted into one UTF-16 character, plus 2 bytes for the BOM
57 -#if !QT_CONFIG(posix_libiconv)
58 - // GNU doesn't disagree with POSIX :/
59 - const char *inBytes = chars;
61 char *inBytes = const_cast<char *>(chars);
66 diff --git a/src/corelib/configure.json b/src/corelib/configure.json
67 index c5e04232..32237bc4 100644
68 --- a/src/corelib/configure.json
69 +++ b/src/corelib/configure.json
73 "iconv_t x = iconv_open(\"\", \"\");",
77 "size_t inbytes, outbytes;",
78 "iconv(x, &inp, &inbytes, &outp, &outbytes);",