Skip to content

Commit

Permalink
FIX: making macOS version be compile-able again with the recent `icon…
Browse files Browse the repository at this point in the history
…v` 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.
  • Loading branch information
Oldes committed Mar 26, 2019
1 parent 2e1a8b5 commit 9aa122b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
31 changes: 16 additions & 15 deletions src/core/u-iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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` */
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/tests/units/series-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions src/tools/systems.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9aa122b

Please sign in to comment.