[m-rev.] for review: unicode paths on windows

Peter Wang novalazy at gmail.com
Wed Dec 14 16:24:08 AEDT 2011


On Wed, 14 Dec 2011 14:41:52 +1100 (EST), Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> 
> I suggest that you explicitly deallocate the result of the call to
> ML_utf8_to_wide after the call to FindFirstFile using MR_GC_free.
> (Any anywhere else that function is called.)
> Doing so will be a bit nicer for the nogc grades.

You mean every instance of ML_utf8_to_wide?  That's rather ugly to
almost no end.  If you insist, I can do it in a later change.

Meanwhile I found more functions.  Committed with these additional
changes.

Peter

diff --git a/library/dir.m b/library/dir.m
index 3c4a4a0..4de00ae 100644
--- a/library/dir.m
+++ b/library/dir.m
@@ -866,6 +866,21 @@ dir.relative_path_name_from_components(Components) = PathName :-
     ** the global lock.
     */
 
+#ifdef MR_WIN32
+    wchar_t     *wbuf;
+    MR_String   str;
+
+    wbuf = _wgetcwd(NULL, 1);
+    if (wbuf != NULL) {
+        str = ML_wide_to_utf8(wbuf, MR_ALLOC_ID);
+        Res = ML_make_io_res_1_ok_string(str);
+        free(wbuf);
+    } else {
+        ML_make_io_res_1_error_string(errno,
+            MR_make_string_const(""dir.current_directory failed: ""),
+            &Res);
+    }
+#else
     size_t      size = 256;
     MR_Word     ptr;
     char        *buf;
@@ -890,6 +905,7 @@ dir.relative_path_name_from_components(Components) = PathName :-
         /* Buffer too small.  Resize and try again. */
         size *= 1.5;
     }
+#endif
 ").
 
 :- pragma foreign_proc("C#",
@@ -1534,6 +1550,7 @@ check_for_symlink_loop(SymLinkParent, DirName, LoopRes, !ParentIds, !IO) :-
 
 #if defined(MR_WIN32) && defined(MR_HAVE_WINDOWS_H)
   #include ""mercury_windows.h""
+  #include <direct.h>   /* for _wgetcwd */
 #endif
 
 #ifdef HAVE_UNISTD_H
diff --git a/library/io.m b/library/io.m
index 8efa737..9a13c75 100644
--- a/library/io.m
+++ b/library/io.m
@@ -9685,7 +9685,12 @@ io.close_binary_output(binary_output_stream(Stream), !IO) :-
 
 #else   /* !MR_THREAD_SAFE || !MR_HAVE_POSIX_SPAWN || !MR_HAVE_ENVIRON */
 
+  #ifdef MR_WIN32
+    Status = _wsystem(ML_utf8_to_wide(Command));
+  #else
     Status = system(Command);
+  #endif
+
     if (Status == -1) {
         /*
         ** Return values of 127 or -1 from system() indicate that
@@ -10033,7 +10038,16 @@ command_line_argument(_, "") :-
     [promise_semipure, will_not_call_mercury, tabled_for_io,
         does_not_affect_liveness, no_sharing],
 "
+#ifdef MR_WIN32
+    wchar_t *ValueW = _wgetenv(ML_utf8_to_wide(Var));
+    if (ValueW != NULL) {
+        Value = ML_wide_to_utf8(ValueW, MR_ALLOC_ID);
+    } else {
+        Value = NULL;
+    }
+#else
     Value = getenv(Var);
+#endif
     SUCCESS_INDICATOR = (Value != 0);
 ").
 
@@ -10081,7 +10095,11 @@ io.setenv(Var, Value) :-
     [will_not_call_mercury, tabled_for_io, does_not_affect_liveness,
         no_sharing],
 "
+#ifdef MR_WIN32
+    SUCCESS_INDICATOR = (_wputenv(ML_utf8_to_wide(VarAndValue)) == 0);
+#else
     SUCCESS_INDICATOR = (putenv(VarAndValue) == 0);
+#endif
 ").
 
 :- pragma foreign_proc("C#",

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list