Fix Windows build after D1874
authorTamar Christina <tamar@zhox.com>
Tue, 2 Feb 2016 11:36:52 +0000 (12:36 +0100)
committerBen Gamari <ben@smart-cactus.org>
Sun, 10 Apr 2016 23:11:29 +0000 (01:11 +0200)
Windows uses wchar_t* for paths. The code committed won't compile for
Windows as the types are incorrect and the types in the branches of the
ternary operator aren't consistent.

Test Plan: ./validate --fast

Reviewers: austin, rwbarton, erikd, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1878

(cherry picked from commit 01c587c03764de52cd01a3464c1a4a5c5bce7c00)

rts/Linker.c

index c225ab6..c7c61cf 100644 (file)
@@ -199,6 +199,21 @@ static pathchar* pathdup(pathchar *path)
     return ret;
 }
 
+static pathchar* mkPath(char* path)
+{
+#if defined(mingw32_HOST_OS)
+    size_t required = mbstowcs(NULL, path, 0);
+    pathchar *ret = stgMallocBytes(sizeof(pathchar) * (required + 1), "mkPath");
+    if (mbstowcs(ret, path, required) == (size_t)-1)
+    {
+        barf("mkPath failed converting char* to wchar_t*");
+    }
+
+    return ret;
+#else
+    return pathdup(path);
+#endif
+}
 
 #if defined(OBJFORMAT_ELF)
 static int ocVerifyImage_ELF    ( ObjectCode* oc );
@@ -425,6 +440,7 @@ static int ghciInsertSymbolTable(
       pinfo->weak = HS_BOOL_FALSE;
       return 1;
    }
+   pathchar* archiveName = NULL;
    debugBelch(
       "GHC runtime linker: fatal error: I found a duplicate definition for symbol\n"
       "   %s\n"
@@ -439,10 +455,16 @@ static int ghciInsertSymbolTable(
       "     loaded twice.\n",
       (char*)key,
       obj_name,
-      pinfo->owner == NULL ? "(GHCi built-in symbols)" :
-      pinfo->owner->archiveMemberName ? pinfo->owner->archiveMemberName
+      pinfo->owner == NULL ? WSTR("(GHCi built-in symbols)") :
+      pinfo->owner->archiveMemberName ? archiveName = mkPath(pinfo->owner->archiveMemberName)
       : pinfo->owner->fileName
    );
+
+   if (archiveName)
+   {
+       stgFree(archiveName);
+       archiveName = NULL;
+   }
    return 0;
 }