* Windows file names snafu
@ 2014-06-29 16:23 Eli Zaretskii
2014-06-30 11:12 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Eli Zaretskii @ 2014-06-29 16:23 UTC (permalink / raw)
To: Mark H Weaver; +Cc: ludo, guile-devel
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)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Windows file names snafu
2014-06-29 16:23 Windows file names snafu Eli Zaretskii
@ 2014-06-30 11:12 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2014-06-30 11:12 UTC (permalink / raw)
To: Eli Zaretskii, Andy Wingo; +Cc: Mark H Weaver, guile-devel
Eli Zaretskii <eliz@gnu.org> skribis:
> 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 see, makes sense to me.
> 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.
[...]
> --- 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)
That looks good to me, but I’m Windows-oblivious ;-) and I’d like to
hear what Andy thinks, because he did the UNC thing in the past. Andy?
Ludo’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-30 11:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-29 16:23 Windows file names snafu Eli Zaretskii
2014-06-30 11:12 ` Ludovic Courtès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).