unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#39162: [PATCH] Fix file lookup of modules with a dot in their name.
@ 2020-01-17 15:21 Jan Nieuwenhuizen
  2020-03-21 21:46 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Nieuwenhuizen @ 2020-01-17 15:21 UTC (permalink / raw)
  To: 39162

[-- Attachment #1: Type: text/plain, Size: 934 bytes --]

Hello Guile!

Much to my surprise, Guile (v2.2 and 3.0 alike) fail to load a module
that has a dot in its base name.  Directory names with dots
(e.g. ice.10/boot-10.scm => (ice.10 boot-10)) are fine.

The attached patch now makes this work:

--8<---------------cut here---------------start------------->8---
;;; foo.bar.scm
(display "foo.bar\n")
(define-module (foo.bar))
(display "module: foo.bar\n")

16:15:31 janneke@dundal:~/src/guile [env]
$ GUILE=meta/guile ./meta/guild compile foo.bar.scm -o foo.bar.go
wrote `foo.bar.go'
16:15:46 janneke@dundal:~/src/guile [env]
$ ./meta/guile -q -L . -C . -c '(use-modules (foo.bar))'
foo.bar
module: foo.bar
16:16:03 janneke@dundal:~/src/guile [env]
--8<---------------cut here---------------end--------------->8---

The patch applies to 2.2 as 3.0 as well.  The code that I removed has
some comments about what the code is doing, but I fail to grasp any sort
of why.

Greetings,
janneke


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-file-lookup-of-modules-with-a-dot-in-their-name.patch --]
[-- Type: text/x-patch, Size: 2402 bytes --]

From ad64e3e93b3f5f749d3e3949458ef9d19710b2ee Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <janneke@gnu.org>
Date: Fri, 17 Jan 2020 16:03:13 +0100
Subject: [PATCH] Fix file lookup of modules with a dot in their name.

This fixes lookup of file foo.bar.go, loading

    (define-module (foo.bar))
    ...

* libguile/load.c (load_thunk_from_path): Remove code that decides
foo.bar is not a valid module file base name.
---
 libguile/load.c | 35 +----------------------------------
 1 file changed, 1 insertion(+), 34 deletions(-)

diff --git a/libguile/load.c b/libguile/load.c
index e95c36db1..23409ebd5 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -649,7 +649,6 @@ load_thunk_from_path (SCM filename, SCM source_file_name,
   struct stringbuf buf;
   struct stat stat_buf;
   char *filename_chars;
-  size_t filename_len;
   SCM path, extensions;
   SCM result = SCM_BOOL_F;
   char initial_buffer[256];
@@ -667,7 +666,6 @@ load_thunk_from_path (SCM filename, SCM source_file_name,
   scm_dynwind_begin (0);
 
   filename_chars = scm_to_locale_string (filename);
-  filename_len = strlen (filename_chars);
   scm_dynwind_free (filename_chars);
 
   /* If FILENAME is absolute and is still valid, return it unchanged.  */
@@ -680,38 +678,7 @@ load_thunk_from_path (SCM filename, SCM source_file_name,
       goto end;
     }
 
-  /* If FILENAME has an extension, don't try to add EXTENSIONS to it.  */
-  {
-    char *endp;
-
-    for (endp = filename_chars + filename_len - 1;
-	 endp >= filename_chars;
-	 endp--)
-      {
-	if (*endp == '.')
-	  {
-            if (!string_has_an_ext (filename, extensions))
-              {
-                /* This filename has an extension, but not one of the right
-                   ones... */
-                goto end;
-              }
-	    /* This filename already has an extension, so cancel the
-               list of extensions.  */
-	    extensions = SCM_EOL;
-	    break;
-	  }
-	else if (is_file_name_separator (SCM_MAKE_CHAR (*endp)))
-	  /* This filename has no extension, so keep the current list
-             of extensions.  */
-	  break;
-      }
-  }
-
-  /* This simplifies the loop below a bit.
-   */
-  if (scm_is_null (extensions))
-    extensions = scm_listofnullstr;
+  extensions = scm_append (scm_list_2 (extensions, scm_listofnullstr));
 
   buf.buf_len = sizeof initial_buffer;
   buf.buf = initial_buffer;
-- 
2.24.1


[-- Attachment #3: Type: text/plain, Size: 152 bytes --]


-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#39162: [PATCH] Fix file lookup of modules with a dot in their name.
  2020-01-17 15:21 bug#39162: [PATCH] Fix file lookup of modules with a dot in their name Jan Nieuwenhuizen
@ 2020-03-21 21:46 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2020-03-21 21:46 UTC (permalink / raw)
  To: Jan Nieuwenhuizen; +Cc: 39162

Hi!

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

> Much to my surprise, Guile (v2.2 and 3.0 alike) fail to load a module
> that has a dot in its base name.  Directory names with dots
> (e.g. ice.10/boot-10.scm => (ice.10 boot-10)) are fine.

[...]

> -  /* If FILENAME has an extension, don't try to add EXTENSIONS to it.  */
> -  {
> -    char *endp;
> -
> -    for (endp = filename_chars + filename_len - 1;
> -	 endp >= filename_chars;
> -	 endp--)
> -      {
> -	if (*endp == '.')
> -	  {
> -            if (!string_has_an_ext (filename, extensions))
> -              {
> -                /* This filename has an extension, but not one of the right
> -                   ones... */
> -                goto end;
> -              }
> -	    /* This filename already has an extension, so cancel the
> -               list of extensions.  */
> -	    extensions = SCM_EOL;
> -	    break;
> -	  }
> -	else if (is_file_name_separator (SCM_MAKE_CHAR (*endp)))
> -	  /* This filename has no extension, so keep the current list
> -             of extensions.  */
> -	  break;
> -      }
> -  }

This code mostly dates back to 1999 (commit
563841768b8659dad87296be4ae9ce589cbe99d4).  It has to do with the fact
that you can omit the extension when loading a file, in which case one
of those in ‘%load-extensions’ is picked up:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (primitive-load-path "ice-9/q")
scheme@(ice-9 q)>
--8<---------------cut here---------------end--------------->8---

The usefulness of this mechanism is debatable :-), but I don’t think we
can change it during a stable release.

I wonder if there are other ways we could support file names with dots.

However, note that symbols containing dots are non-standard (R5RS does
not allow it.)

Thoughts?

Ludo’.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-21 21:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-17 15:21 bug#39162: [PATCH] Fix file lookup of modules with a dot in their name Jan Nieuwenhuizen
2020-03-21 21:46 ` 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).