From 9aa122be31bb31a6b097295f52705e39ceacb859 Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 26 Mar 2019 13:56:56 +0100 Subject: [PATCH] FIX: making macOS version be compile-able again with the recent `iconv` addition. Also it looks that macOS' version of `iconv` does not have aliases for UTF16 (and similar) and supports only UTF-16 etc.. so the tests were modified to use the long variant only too. --- src/core/u-iconv.c | 31 ++++++++++++++++--------------- src/tests/units/series-test.r3 | 10 +++++----- src/tools/systems.r | 7 ++++--- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/core/u-iconv.c b/src/core/u-iconv.c index 8076e8f49a..7829d0bead 100644 --- a/src/core/u-iconv.c +++ b/src/core/u-iconv.c @@ -47,40 +47,40 @@ // Codepage aliases borrowed from: https://github.com/win-iconv/win-iconv/blob/master/win_iconv.c // (slightly modified for preferences, because it looks some iconv posix variants does not recognize CP1200 etc) +// On macOS it looks there are not aliased utf16 variants, one must use utf-16! // static struct { REBINT codepage; const char *name; } codepage_alias[] = { - {65001, "UTF8"}, {65001, "UTF-8"}, + {65001, "UTF8"}, {65001, "CP65001"}, - - {1200, "UTF16LE"}, {1200, "UTF-16LE"}, - {1200, "UCS2LE"}, + {1200, "UTF16LE"}, {1200, "UCS-2LE"}, + {1200, "UCS2LE"}, {1200, "UCS-2-INTERNAL"}, {1200, "CP1200"}, - {1201, "UTF16BE"}, {1201, "UTF-16BE"}, - {1201, "UCS2BE"}, + {1201, "UTF16BE"}, {1201, "UCS-2BE"}, + {1201, "UCS2BE"}, {1201, "unicodeFFFE"}, {1201, "CP1201"}, {12000, "CP12000"}, - {12000, "UTF32LE"}, {12000, "UTF-32LE"}, - {12000, "UCS4LE"}, + {12000, "UTF32LE"}, {12000, "UCS-4LE"}, + {12000, "UCS4LE"}, - {12001, "UTF32BE"}, {12001, "UTF-32BE"}, - {12001, "UCS4BE"}, + {12001, "UTF32BE"}, {12001, "UCS-4BE"}, + {12001, "UCS4BE"}, {12001, "CP12001"}, //#ifndef GLIB_COMPILATION @@ -98,14 +98,14 @@ static struct { // {12001, "UCS4"}, //#else /* Default is little endian, because the platform is */ - {1200, "UTF16"}, {1200, "UTF-16"}, - {1200, "UCS2"}, + {1200, "UTF16"}, {1200, "UCS-2"}, - {12000, "UTF32"}, + {1200, "UCS2"}, {12000, "UTF-32"}, - {12000, "UCS4"}, + {12000, "UTF32"}, {12000, "UCS-4"}, + {12000, "UCS4"}, //#endif /* copy from libiconv `iconv -l` */ @@ -715,9 +715,10 @@ static REBYTE* get_codepage_name(REBVAL *cp) if (!tocode) Trap1(RE_INVALID_ARG, val_to); wide = 1; // result is raw binary series } else { - tocode = "UTF16LE"; + tocode = "UTF-16LE"; wide = 2; // result is string } + //printf("iconv_open %s %s\n", tocode, fromcode); cd = iconv_open(tocode, fromcode); if (cd == (iconv_t)-1) { if (get_codepage_id(val_from) < 0) Trap1(RE_INVALID_ARG, val_from); diff --git a/src/tests/units/series-test.r3 b/src/tests/units/series-test.r3 index 93de6b5d38..dc1ec443d7 100644 --- a/src/tests/units/series-test.r3 +++ b/src/tests/units/series-test.r3 @@ -198,14 +198,14 @@ Rebol [ ;- using UTF-16LE instead of just UTF-16 as iconv function on posix adds BOM if just UTF16 is used --assert #{50005901} = iconv/to #{50F8} 28592 'UTF-16LE --assert #{5901} = iconv/to next #{50F8} 28592 'UTF-16LE - --assert #{50005100} = iconv/to #{50005100} 'UTF16LE 'UTF16LE - --assert #{00500051} = iconv/to #{00500051} 'UTF16BE 'UTF16BE + --assert #{50005100} = iconv/to #{50005100} 'UTF-16LE 'UTF-16LE + --assert #{00500051} = iconv/to #{00500051} 'UTF-16BE 'UTF-16BE --assert #{00500159} = iconv/to #{50F8} 28592 'UTF-16BE --assert #{0159} = iconv/to next #{50F8} 28592 'UTF-16BE - --assert #{00500051} = bin: iconv/to #{50005100} 'UTF16LE 'UTF16BE - --assert #{50005100} = iconv/to bin 'UTF16BE 'UTF16LE - --assert "PQ" = iconv bin 'UTF16BE + --assert #{00500051} = bin: iconv/to #{50005100} 'UTF-16LE 'UTF-16BE + --assert #{50005100} = iconv/to bin 'UTF-16BE 'UTF-16LE + --assert "PQ" = iconv bin 'UTF-16BE --test-- "ICONV with nonsense codepages" --assert error? try [iconv #{30} 'foo] diff --git a/src/tools/systems.r b/src/tools/systems.r index c57fe79b12..3e81e1ce4d 100644 --- a/src/tools/systems.r +++ b/src/tools/systems.r @@ -21,9 +21,9 @@ REBOL [ systems: [ [plat os-name os-base build-flags] [0.1.03 "amiga" posix [BEN HID NPS +SC CMT COP -SP -LM]] - [0.2.04 "osx" posix [BEN +OS NCM -LM UOP]] ; OSX/PPC; no shared lib possible - [0.2.05 "osxi" posix [LEN +O1 PIC NPS NCM HID STX -LM UOP ARC FCS FCM]] - [0.2.40 "osx_x64" posix [LEN +O1 PIC NPS NCM HID STX -LM UOP L64 FCS FCM]] + [0.2.04 "osx" posix [BEN +OS NCM -LM UOP LIC]] ; OSX/PPC; no shared lib possible + [0.2.05 "osxi" posix [LEN +OS PIC NPS NCM HID STX -LM UOP ARC FCS FCM LIC]] + [0.2.40 "osx_x64" posix [LEN +OS PIC NPS NCM HID STX -LM UOP L64 FCS FCM LIC]] [0.3.01 "win32" win32 [LEN +O2 UNI M32 W32 CON S4M EXE DIR -LM]] [0.3.40 "win32_x64" win32 [LEN +O2 UNI M64 W32 CON S4M EXE DIR -LM P64]] [0.4.02 "linux" posix [LEN +O2 PIC LDL ST1 -LM]] ; libc 2.3 @@ -70,6 +70,7 @@ linker-flags: [ MAP: "-Wl,-M" ; output a map STA: "--strip-all" LDL: "-ldl" ; link with dynamic lib lib + LIC: "-liconv" ; macOS (clang?) needs iconv to be explicitly linked (for iconv native function) LLOG: "-llog" ; on Android, link with liblog.so ARC: "-arch i386" ; x86 32 bit architecture (OSX) M32: "-m32" ; use 32-bit memory model (Linux x64)