[dmd-internals] dmd commit, revision 657

Rainer Schuetze r.sagitario at gmx.de
Sat Sep 4 04:33:12 PDT 2010


Brad Roberts wrote:
> Also of potential interest.. the biggest problem I've had with the windows
> support is switching from / to \ based on os since optlink can't handle it.  It
> looked like everything else was happy -- though dmd might have had some issues,
> I didn't try to isolate the issue between the two.  The o vs obj and nothing vs
> .exe were trivial.  Support for \ is a pain in the ass.. having to \\ in places
> -- right now something somewhere is retaining both \\'s rather than treating it
> as one escaped.  I got frustrated with that and your post so I set aside the
> project for the evening.
>
> I'll finish it tomorrow or this weekend, maybe.
>
>   
I've also tried to make the test suite run under windows (after several 
other tries, MSys seems to be the best shot). I patched some of the 
scripts before I realized that it is way easier to just fix the file 
name handling of dmd and optlink. With this simple patch:

Index: link.c
===================================================================
--- link.c    (revision 657)
+++ link.c    (working copy)
@@ -42,23 +42,23 @@
 {
     /* Loop and see if we need to quote
      */
+    bool needsQuote = false;
     for (size_t i = 0; i < len; i++)
     {   char c = filename[i];
 
-        if (isalnum(c) || c == '_')
-            continue;
+        if (!isalnum(c) && c != '_')
+            needsQuote = true;
+#ifdef _WIN32 // keep optlink happy
+        if (c == '/')
+            filename[i] = '\\';
+#endif
+    }
 
-        /* Need to quote
-         */
+    if(needsQuote)
         buf->writeByte('"');
-        buf->write(filename, len);
+    buf->write(filename, len);
+    if(needsQuote)
         buf->writeByte('"');
-        return;
-    }
-
-    /* No quoting necessary
-     */
-    buf->write(filename, len);
 }
 
 void writeFilename(OutBuffer *buf, char *filename)
@@ -114,7 +114,7 @@
 
     cmdbuf.writeByte(',');
     if (global.params.mapfile)
-        cmdbuf.writestring(global.params.mapfile);
+        writeFilename(&cmdbuf, global.params.mapfile);
     else if (global.params.run)
         cmdbuf.writestring("nul");
     cmdbuf.writeByte(',');

--->8--------------------

any file name passed from dmd to optlink will have '/' translated to '\' 
(this was only done for object files so far). I think this patch will 
remove a lot of confusion for the normal use of dmd, too.

Reversing the behaviour for the object files with this patch

Index: mars.c
===================================================================
--- mars.c    (revision 657)
+++ mars.c    (working copy)
@@ -935,11 +935,11 @@
         p = (char *) files.data[i];
 
 #if _WIN32
-        // Convert / to \ so linker will work
+        // Convert \ to / to be consistent with unix output, 
translation back for linker will be done later
         for (int i = 0; p[i]; i++)
         {
-            if (p[i] == '/')
-                p[i] = '\\';
+            if (p[i] == '\\')
+                p[i] = '/';
         }
 #endif
 

will even make the output files consistent with the unix versions 
(except newlines). This latter patch might break other tools relying on 
output containing back slashes (JSON, dependencies, etc), though.

Rainer



More information about the dmd-internals mailing list