Repository navigation
Tolerate duplicate iconv aliases on macOS - #81
Conversation
macOS libiconv lists some names (e.g. WINDOWS-874) under more than one charset group. Treat the first binding as authoritative so module_iconv initialization no longer fails during the check phase on Darwin.
|
For reference, the macOS job in the existing CI already fails on
I've opened #82 with those workflow changes, adding Intel macOS and fixing the Homebrew paths and the ASAN preload. It depends on this PR, so the two can be reviewed and merged together. |
Drop the empty else-if branch; only declare aliases that are not already known, with the explanatory comment moved above the check.
b83b13d to
ba15819
Compare
|
Thanks for this! |
|
As this is triggering a build failure for fortune in nixpkgs - can you guys perhaps give us a hint when this will be released? |
|
Hi @dwt ! Agreed this needs a release for packagers. The fix is already on master (#81, slightly simplified by @rrthomas on merge); #82 also landed so macOS CI (arm64 + Intel) is green again. A new release is up to @rrthomas (likely 3.7.17). Once that tag/tarball is out, nixpkgs can bump recode from 3.7.16. Until then, from my side, I'm currently applying a small overlay to have fortune-mod + recode build on nix-darwin (It's basically the same change included in this PR) Sharing here in case you find it useful : overlays/recode.nix # macOS libiconv lists some aliases (e.g. WINDOWS-874) under more than one
# charset group. recode 3.7.16 treats that as a fatal init error and fails
# its check phase on aarch64-darwin. Keep the first binding instead.
final: prev: {
recode = prev.recode.overrideAttrs (old: {
patches = (old.patches or []) ++ [
./recode-darwin-iconv-aliases.patch
];
});
}overlays/recode-darwin-iconv-aliases.patch diff --git a/src/iconv.c b/src/iconv.c
index a44fd8c..c96fed0 100644
--- a/src/iconv.c
+++ b/src/iconv.c
@@ -272,11 +272,18 @@ module_iconv (RECODE_OUTER outer)
RECODE_ALIAS alias
= recode_find_alias (outer, *cursor, ALIAS_FIND_AS_CHARSET);
- /* If there is a charset contradiction, call recode_declare_alias
- nevertheless, as the error processing will occur there. */
- if (!alias || alias->symbol->name != charset_name)
- if (!recode_declare_alias (outer, *cursor, charset_name))
- return false;
+ if (!alias)
+ {
+ if (!recode_declare_alias (outer, *cursor, charset_name))
+ return false;
+ }
+ else if (alias->symbol->name != charset_name)
+ {
+ /* Some iconv implementations (notably macOS libiconv) list the
+ same alias under more than one charset group — e.g.
+ WINDOWS-874 appears with both CP1162 and CP874. Keep the
+ first binding instead of aborting initialization. */
+ }
}
}
diff --git a/tables.py b/tables.py
index 1d7bc9a..aecaade 100755
--- a/tables.py
+++ b/tables.py
@@ -468,6 +468,7 @@ class Iconv(Options):
libc = None
import os
names = []
+ seen = set()
for line in os.popen('iconv -l'):
if libc is None:
libc = len(line.split('/')) == 3
@@ -484,7 +485,19 @@ class Iconv(Options):
if alias in canonical:
alias = canonical[alias]
aliases.append(alias)
- self.data.append((aliases[0], aliases[1:]))
+ # Prefer the first charset group for each alias name. Some
+ # iconv implementations (macOS libiconv) repeat names across
+ # groups — e.g. WINDOWS-874 under both CP1162 and CP874 —
+ # which would otherwise make module_iconv abort.
+ filtered = []
+ for alias in aliases:
+ key = alias.upper()
+ if key in seen:
+ continue
+ seen.add(key)
+ filtered.append(alias)
+ if filtered:
+ self.data.append((filtered[0], filtered[1:]))
def complete(self, french):
def write_charset(format, charset): |
|
Releasing 3.7.17 now. |
|
Thanks a lot Reuben ! |
|
Bot already created the PR on nixpkgs : NixOS/nixpkgs#571390 Let's see if this gets merged soon. |
On macOS,
iconv -llists some charset aliases under more than one group. In particular,WINDOWS-874appears with bothCP1162andCP874. Whentables.pyturns that listing intoiconvdecl.h,module_iconvthen tries to declare the same alias for two different charsets and aborts initialization with a contradiction error. That makes the check phase fail on aarch64-darwin (and likely x86_64-darwin as well).This change:
tables.py, when digestingiconv -l, keep only the first occurrence of each alias name.module_iconv, if an alias is already bound to a different charset, keep the existing binding instead of failing.Verified on aarch64-darwin with recode 3.7.16: 488 good tests.