Skip to content

Commit 7f21a3f

Browse files
dra27gasche
authored andcommitted
Translate OCAML_STDLIB_DIR correctly on Windows (#1448)
The build generates invalid code in byterun/dynlink.c if LIBDIR contains non-1252 characters. Use iconv to translate LIBDIR to JAVA which, unlike C99 will produce only \u sequences with no \U sequences. The \u is then translated to \x which is the only form recognised pre-Visual Studio 2013. (cherry picked from commit 3b434eb)
1 parent 3687dc9 commit 7f21a3f

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

Changes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ Release branch for 4.06:
405405
### Runtime system:
406406

407407
* MPR#3771, GPR#153, GPR#1200, GPR#1357, GPR#1362, GPR#1363, GPR#1369, GPR#1398,
408-
GPR#1446: Unicode support for the Windows runtime.
408+
GPR#1446, GPR#1448: Unicode support for the Windows runtime.
409409
(ygrek, Nicolas Ojeda Bar, review by Alain Frisch, David Allsopp, Damien
410410
Doligez)
411411

byterun/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ endif
4949
# On Windows, OCAML_STDLIB_DIR needs to be defined dynamically
5050

5151
ifeq "$(UNIX_OR_WIN32)" "win32"
52-
CFLAGS += -DOCAML_STDLIB_DIR='"$(LIBDIR)"'
52+
# OCAML_STDLIB_DIR needs to arrive in dynlink.c as a string which both gcc and
53+
# msvc are willing parse without warning. This means we can't pass UTF-8
54+
# directly since, as far as I can tell, cl can cope, but the pre-processor
55+
# can't. So the string needs to be directly translated to L"" form. To do this,
56+
# we take advantage of the fact that Cygwin uses GNU libiconv which includes a
57+
# Java pseudo-encoding which translates any UTF-8 sequences to \uXXXX (and,
58+
# unlike the C99 pseudo-encoding, emits two surrogate values when needed, rather
59+
# than \UXXXXXXXX). The \u is then translated to \x in order to accommodate
60+
# pre-Visual Studio 2013 compilers where \x is a non-standard alias for \u.
61+
OCAML_STDLIB_DIR = $(shell echo $(LIBDIR)| iconv -t JAVA | sed -e 's/\\u/\\x/g')
62+
CFLAGS += -DOCAML_STDLIB_DIR='L"$(OCAML_STDLIB_DIR)"'
5363
endif
5464

5565
CFLAGS += $(IFLEXDIR)

byterun/dynlink.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static c_primitive lookup_primitive(char * name)
7777

7878
static char_os * parse_ld_conf(void)
7979
{
80-
char_os * stdlib, * ldconfname, * wconfig, * p, * q, * tofree = NULL;
80+
char_os * stdlib, * ldconfname, * wconfig, * p, * q;
8181
char * config;
8282
#ifdef _WIN32
8383
struct _stati64 st;
@@ -88,9 +88,8 @@ static char_os * parse_ld_conf(void)
8888

8989
stdlib = caml_secure_getenv(_T("OCAMLLIB"));
9090
if (stdlib == NULL) stdlib = caml_secure_getenv(_T("CAMLLIB"));
91-
if (stdlib == NULL) stdlib = tofree = caml_stat_strdup_to_os(OCAML_STDLIB_DIR);
91+
if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR;
9292
ldconfname = caml_stat_strconcat_os(3, stdlib, _T("/"), LD_CONF_NAME);
93-
if (tofree != NULL) caml_stat_free(tofree);
9493
if (stat_os(ldconfname, &st) == -1) {
9594
caml_stat_free(ldconfname);
9695
return NULL;

0 commit comments

Comments
 (0)