[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Windows file names snafu
From: |
Eli Zaretskii |
Subject: |
Windows file names snafu |
Date: |
Sun, 29 Jun 2014 19:23:48 +0300 |
This issue is caused by code that treats file names like strings.
That fails when the compared strings differ by their directory
separators ('/' vs '\'). I bumped into this in a couple of tests that
failed or even aborted with backtrace.
A related issue is the file names passed to Bash via open-pipe and
friends: Bash treats backslashes as escape characters, so commands
start to fail in mysterious ways.
For these two reasons, I think Guile should strive to keep file names
in Unix-compatible form, i.e. using forward slashes as directory
separators. I originally tried to find some place in the code where
this could be done once and for all, but I see no such place (did I
miss something?). So instead I propose a small number of changes to
make sure %load-path and the value returned by getcwd use forward
slashes no matter what. This fixed all the problems related to this
issue in the test suite.
The patch below is just to show what I modified; if this approach is
accepted, I think it would be better, at least for the C parts of the
patch below, to have a function to do the job, and call it from each
of the few places which I identified.
--- libguile/load.c~1 2014-06-09 13:12:59 +0300
+++ libguile/load.c 2014-06-29 18:56:47 +0300
@@ -290,6 +290,19 @@ scm_init_load_path ()
#ifdef SCM_LIBRARY_DIR
env = getenv ("GUILE_SYSTEM_PATH");
+#ifdef __MINGW32__
+ if (env)
+ {
+ char *p = env;
+
+ while (*p)
+ {
+ if (*p == '\\')
+ *p = '/';
+ p++;
+ }
+ }
+#endif
if (env && strcmp (env, "") == 0)
/* special-case interpret system-path=="" as meaning no system path instead
of '("") */
@@ -303,6 +316,19 @@ scm_init_load_path ()
scm_from_locale_string (SCM_PKGDATA_DIR));
env = getenv ("GUILE_SYSTEM_COMPILED_PATH");
+#ifdef __MINGW32__
+ if (env)
+ {
+ char *p = env;
+
+ while (*p)
+ {
+ if (*p == '\\')
+ *p = '/';
+ p++;
+ }
+ }
+#endif
if (env && strcmp (env, "") == 0)
/* like above */
;
@@ -349,10 +375,36 @@ scm_init_load_path ()
}
env = getenv ("GUILE_LOAD_PATH");
+#ifdef __MINGW32__
+ if (env)
+ {
+ char *p = env;
+
+ while (*p)
+ {
+ if (*p == '\\')
+ *p = '/';
+ p++;
+ }
+ }
+#endif
if (env)
path = scm_parse_path_with_ellipsis (scm_from_locale_string (env), path);
env = getenv ("GUILE_LOAD_COMPILED_PATH");
+#ifdef __MINGW32__
+ if (env)
+ {
+ char *p = env;
+
+ while (*p)
+ {
+ if (*p == '\\')
+ *p = '/';
+ p++;
+ }
+ }
+#endif
if (env)
cpath = scm_parse_path_with_ellipsis (scm_from_locale_string (env), cpath);
--- libguile/filesys.c~0 2014-02-28 23:01:27 +0200
+++ libguile/filesys.c 2014-06-29 18:13:30 +0300
@@ -1235,6 +1235,19 @@ SCM_DEFINE (scm_getcwd, "getcwd", 0, 0,
errno = save_errno;
SCM_SYSERROR;
}
+#ifdef __MINGW32__
+ if (rv)
+ {
+ char *p = wd;
+
+ while (*p)
+ {
+ if (*p == '\\')
+ *p = '/';
+ p++;
+ }
+ }
+#endif
result = scm_from_locale_stringn (wd, strlen (wd));
free (wd);
return result;
--- module/ice-9/boot-9.scm~ 2014-02-15 01:00:33 +0200
+++ module/ice-9/boot-9.scm 2014-06-29 18:15:07 +0300
@@ -1657,7 +1657,7 @@
(or (char=? c #\/)
(char=? c #\\)))
- (define file-name-separator-string "\\")
+ (define file-name-separator-string "/")
(define (absolute-file-name? file-name)
(define (file-name-separator-at-index? idx)
- Windows file names snafu,
Eli Zaretskii <=