Skip to content

Commit 9aa122b

Browse files
committed
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.
1 parent 2e1a8b5 commit 9aa122b

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/core/u-iconv.c

+16-15
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,40 @@
4747

4848
// Codepage aliases borrowed from: https://github.com/win-iconv/win-iconv/blob/master/win_iconv.c
4949
// (slightly modified for preferences, because it looks some iconv posix variants does not recognize CP1200 etc)
50+
// On macOS it looks there are not aliased utf16 variants, one must use utf-16!
5051
//
5152
static struct {
5253
REBINT codepage;
5354
const char *name;
5455
} codepage_alias[] = {
55-
{65001, "UTF8"},
5656
{65001, "UTF-8"},
57+
{65001, "UTF8"},
5758
{65001, "CP65001"},
5859

59-
60-
{1200, "UTF16LE"},
6160
{1200, "UTF-16LE"},
62-
{1200, "UCS2LE"},
61+
{1200, "UTF16LE"},
6362
{1200, "UCS-2LE"},
63+
{1200, "UCS2LE"},
6464
{1200, "UCS-2-INTERNAL"},
6565
{1200, "CP1200"},
6666

67-
{1201, "UTF16BE"},
6867
{1201, "UTF-16BE"},
69-
{1201, "UCS2BE"},
68+
{1201, "UTF16BE"},
7069
{1201, "UCS-2BE"},
70+
{1201, "UCS2BE"},
7171
{1201, "unicodeFFFE"},
7272
{1201, "CP1201"},
7373

7474
{12000, "CP12000"},
75-
{12000, "UTF32LE"},
7675
{12000, "UTF-32LE"},
77-
{12000, "UCS4LE"},
76+
{12000, "UTF32LE"},
7877
{12000, "UCS-4LE"},
78+
{12000, "UCS4LE"},
7979

80-
{12001, "UTF32BE"},
8180
{12001, "UTF-32BE"},
82-
{12001, "UCS4BE"},
81+
{12001, "UTF32BE"},
8382
{12001, "UCS-4BE"},
83+
{12001, "UCS4BE"},
8484
{12001, "CP12001"},
8585

8686
//#ifndef GLIB_COMPILATION
@@ -98,14 +98,14 @@ static struct {
9898
// {12001, "UCS4"},
9999
//#else
100100
/* Default is little endian, because the platform is */
101-
{1200, "UTF16"},
102101
{1200, "UTF-16"},
103-
{1200, "UCS2"},
102+
{1200, "UTF16"},
104103
{1200, "UCS-2"},
105-
{12000, "UTF32"},
104+
{1200, "UCS2"},
106105
{12000, "UTF-32"},
107-
{12000, "UCS4"},
106+
{12000, "UTF32"},
108107
{12000, "UCS-4"},
108+
{12000, "UCS4"},
109109
//#endif
110110

111111
/* copy from libiconv `iconv -l` */
@@ -715,9 +715,10 @@ static REBYTE* get_codepage_name(REBVAL *cp)
715715
if (!tocode) Trap1(RE_INVALID_ARG, val_to);
716716
wide = 1; // result is raw binary series
717717
} else {
718-
tocode = "UTF16LE";
718+
tocode = "UTF-16LE";
719719
wide = 2; // result is string
720720
}
721+
//printf("iconv_open %s %s\n", tocode, fromcode);
721722
cd = iconv_open(tocode, fromcode);
722723
if (cd == (iconv_t)-1) {
723724
if (get_codepage_id(val_from) < 0) Trap1(RE_INVALID_ARG, val_from);

src/tests/units/series-test.r3

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ Rebol [
198198
;- using UTF-16LE instead of just UTF-16 as iconv function on posix adds BOM if just UTF16 is used
199199
--assert #{50005901} = iconv/to #{50F8} 28592 'UTF-16LE
200200
--assert #{5901} = iconv/to next #{50F8} 28592 'UTF-16LE
201-
--assert #{50005100} = iconv/to #{50005100} 'UTF16LE 'UTF16LE
202-
--assert #{00500051} = iconv/to #{00500051} 'UTF16BE 'UTF16BE
201+
--assert #{50005100} = iconv/to #{50005100} 'UTF-16LE 'UTF-16LE
202+
--assert #{00500051} = iconv/to #{00500051} 'UTF-16BE 'UTF-16BE
203203

204204
--assert #{00500159} = iconv/to #{50F8} 28592 'UTF-16BE
205205
--assert #{0159} = iconv/to next #{50F8} 28592 'UTF-16BE
206-
--assert #{00500051} = bin: iconv/to #{50005100} 'UTF16LE 'UTF16BE
207-
--assert #{50005100} = iconv/to bin 'UTF16BE 'UTF16LE
208-
--assert "PQ" = iconv bin 'UTF16BE
206+
--assert #{00500051} = bin: iconv/to #{50005100} 'UTF-16LE 'UTF-16BE
207+
--assert #{50005100} = iconv/to bin 'UTF-16BE 'UTF-16LE
208+
--assert "PQ" = iconv bin 'UTF-16BE
209209

210210
--test-- "ICONV with nonsense codepages"
211211
--assert error? try [iconv #{30} 'foo]

src/tools/systems.r

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ REBOL [
2121
systems: [
2222
[plat os-name os-base build-flags]
2323
[0.1.03 "amiga" posix [BEN HID NPS +SC CMT COP -SP -LM]]
24-
[0.2.04 "osx" posix [BEN +OS NCM -LM UOP]] ; OSX/PPC; no shared lib possible
25-
[0.2.05 "osxi" posix [LEN +O1 PIC NPS NCM HID STX -LM UOP ARC FCS FCM]]
26-
[0.2.40 "osx_x64" posix [LEN +O1 PIC NPS NCM HID STX -LM UOP L64 FCS FCM]]
24+
[0.2.04 "osx" posix [BEN +OS NCM -LM UOP LIC]] ; OSX/PPC; no shared lib possible
25+
[0.2.05 "osxi" posix [LEN +OS PIC NPS NCM HID STX -LM UOP ARC FCS FCM LIC]]
26+
[0.2.40 "osx_x64" posix [LEN +OS PIC NPS NCM HID STX -LM UOP L64 FCS FCM LIC]]
2727
[0.3.01 "win32" win32 [LEN +O2 UNI M32 W32 CON S4M EXE DIR -LM]]
2828
[0.3.40 "win32_x64" win32 [LEN +O2 UNI M64 W32 CON S4M EXE DIR -LM P64]]
2929
[0.4.02 "linux" posix [LEN +O2 PIC LDL ST1 -LM]] ; libc 2.3
@@ -70,6 +70,7 @@ linker-flags: [
7070
MAP: "-Wl,-M" ; output a map
7171
STA: "--strip-all"
7272
LDL: "-ldl" ; link with dynamic lib lib
73+
LIC: "-liconv" ; macOS (clang?) needs iconv to be explicitly linked (for iconv native function)
7374
LLOG: "-llog" ; on Android, link with liblog.so
7475
ARC: "-arch i386" ; x86 32 bit architecture (OSX)
7576
M32: "-m32" ; use 32-bit memory model (Linux x64)

0 commit comments

Comments
 (0)