unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#45339: Readline filename completion
@ 2020-12-20 10:37 Jakub Wojciech
  2021-05-19 15:24 ` jakub-w
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Wojciech @ 2020-12-20 10:37 UTC (permalink / raw)
  To: 45339


[-- Attachment #1.1: Type: text/plain, Size: 1787 bytes --]

Hi. Filename completion just doesn't work at all. Using
filename-completion-function as a completer for readline always throws
an error.

Minimal example:
  (use-modules (ice-9 readline))

  (with-readline-completion-function
   filename-completion-function
   readline)

Hitting TAB when prompted results in:
  File: Backtrace:
  In ice-9/boot-9.scm:
    1736:10  8 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
  In unknown file:
             7 (apply-smob/0 #<thunk 7ffa51f5e500>)
  In ice-9/boot-9.scm:
      718:2  6 (call-with-prompt _ _ #<procedure default-prompt-handler (k proc)>)
  In ice-9/eval.scm:
      619:8  5 (_ #(#(#<directory (guile-user) 7ffa51f63c80>)))
  In ice-9/boot-9.scm:
     2806:4  4 (save-module-excursion _)
    4351:12  3 (_)
  In ice-9/readline.scm:
      213:4  2 (with-readline-completion-function _ #<procedure 7ffa4f684328 at /data/lampilelo/Misc-Scripts/install-wizard.scm:27:1 ()>)
  In unknown file:
             1 (%readline "File: " #<input: file /dev/pts/1> #<undefined> #<undefined>)
             0 (filename-completion-function "" #t)

  ERROR: In procedure filename-completion-function:
  In procedure scm_from_stringn: NULL string pointer

My version of Guile is 3.0.4 but I expect it to fail on every version.
It results in an error because the scm_filename_completion_function()
calls readline's rl_filename_completion_function() and doesn't check if
it returned NULL instead of a string.
Readline's info manual states:
"The generator function returns '(char *)NULL' to inform
'rl_completion_matches()' that there are no more possibilities left."
So it's impossible for the current implementation to work, since
scm_filename_completion_function() throws an error every time NULL is
returned.

I'm attaching a patch.

Jakub

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Fixed-filename-completion-function-for-readline-comp.patch --]
[-- Type: text/x-patch, Size: 1240 bytes --]

From 1f8fce206dc657a04694f8b546df5d1fe1ca1856 Mon Sep 17 00:00:00 2001
From: Jakub Wojciech <jakub-w@riseup.net>
Date: Sun, 20 Dec 2020 10:56:51 +0100
Subject: [PATCH] Fixed filename-completion-function for readline completion

* guile-readline/readline.c (scm_filename_completion_function):
  A completion function should return #f when there's no more
  candidates.  Since the result of readline's
  rl_filename_completion_function was never checked it was impossible
  for it to work as intended and instead of #f it threw an error from
  trying to convert NULL to an scm string.
---
 guile-readline/readline.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/guile-readline/readline.c b/guile-readline/readline.c
index 5c4a32689..7bb2394ba 100644
--- a/guile-readline/readline.c
+++ b/guile-readline/readline.c
@@ -386,8 +386,11 @@ SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2,
 #else
   s = filename_completion_function (c_text, scm_is_true (continuep));
 #endif
-  ans = scm_take_locale_string (s);
   free (c_text);
+  if (!s) {
+    return SCM_BOOL_F;
+  }
+  ans = scm_take_locale_string (s);
   return ans;
 }
 #undef FUNC_NAME
--
2.29.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

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

* bug#45339: Readline filename completion
  2020-12-20 10:37 bug#45339: Readline filename completion Jakub Wojciech
@ 2021-05-19 15:24 ` jakub-w
  2021-05-19 19:31   ` lloda
  0 siblings, 1 reply; 3+ messages in thread
From: jakub-w @ 2021-05-19 15:24 UTC (permalink / raw)
  To: 45339


[-- Attachment #1.1: Type: text/plain, Size: 72 bytes --]

Since my patch didn't follow GNU C style here's an update.
Sorry guys!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Fixed-style-for-02439a124.patch --]
[-- Type: text/x-patch, Size: 1278 bytes --]

From 0a62b75813cd8a94b87284395ee8d97e16069bb0 Mon Sep 17 00:00:00 2001
From: jakub-w <jakub-w@riseup.net>
Date: Wed, 19 May 2021 17:14:35 +0200
Subject: [PATCH] Fixed style for 02439a124

* guile-readline/readline.c (scm_filename_completion_function)
---
 guile-readline/readline.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/guile-readline/readline.c b/guile-readline/readline.c
index 7bb2394ba..469d6ec7d 100644
--- a/guile-readline/readline.c
+++ b/guile-readline/readline.c
@@ -379,7 +379,6 @@ SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2,
 #define FUNC_NAME s_scm_filename_completion_function
 {
   char *s;
-  SCM ans;
   char *c_text = scm_to_locale_string (text);
 #ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION
   s = rl_filename_completion_function (c_text, scm_is_true (continuep));
@@ -387,11 +386,10 @@ SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2,
   s = filename_completion_function (c_text, scm_is_true (continuep));
 #endif
   free (c_text);
-  if (!s) {
+  if (!s)
     return SCM_BOOL_F;
-  }
-  ans = scm_take_locale_string (s);
-  return ans;
+
+  return scm_take_locale_string (s);
 }
 #undef FUNC_NAME
 
-- 
2.31.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

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

* bug#45339: Readline filename completion
  2021-05-19 15:24 ` jakub-w
@ 2021-05-19 19:31   ` lloda
  0 siblings, 0 replies; 3+ messages in thread
From: lloda @ 2021-05-19 19:31 UTC (permalink / raw)
  To: jakub-w; +Cc: 45339-done

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


Applied in f3a23edf9ed111caab7bbad583874ad34ff8652d. Thanks!


> On 19 May 2021, at 17:24, "" <jakub-w@riseup.net> <jakub-w@riseup.net> wrote:
> 
> Since my patch didn't follow GNU C style here's an update.
> Sorry guys!
> 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fixed-style-for-02439a124.patch --]
[-- Type: text/x-patch; x-unix-mode=0644; name="Fixed-style-for-02439a124.patch", Size: 1278 bytes --]

From 0a62b75813cd8a94b87284395ee8d97e16069bb0 Mon Sep 17 00:00:00 2001
From: jakub-w <jakub-w@riseup.net>
Date: Wed, 19 May 2021 17:14:35 +0200
Subject: [PATCH] Fixed style for 02439a124

* guile-readline/readline.c (scm_filename_completion_function)
---
 guile-readline/readline.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/guile-readline/readline.c b/guile-readline/readline.c
index 7bb2394ba..469d6ec7d 100644
--- a/guile-readline/readline.c
+++ b/guile-readline/readline.c
@@ -379,7 +379,6 @@ SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2,
 #define FUNC_NAME s_scm_filename_completion_function
 {
   char *s;
-  SCM ans;
   char *c_text = scm_to_locale_string (text);
 #ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION
   s = rl_filename_completion_function (c_text, scm_is_true (continuep));
@@ -387,11 +386,10 @@ SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2,
   s = filename_completion_function (c_text, scm_is_true (continuep));
 #endif
   free (c_text);
-  if (!s) {
+  if (!s)
     return SCM_BOOL_F;
-  }
-  ans = scm_take_locale_string (s);
-  return ans;
+
+  return scm_take_locale_string (s);
 }
 #undef FUNC_NAME
 
-- 
2.31.1


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



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

end of thread, other threads:[~2021-05-19 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20 10:37 bug#45339: Readline filename completion Jakub Wojciech
2021-05-19 15:24 ` jakub-w
2021-05-19 19:31   ` lloda

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).