From: Ian Price <ianprice90@googlemail.com>
To: Andrew Psaltis <ampsaltis@gmail.com>
Cc: 10581@debbugs.gnu.org
Subject: bug#10581: exit-hook is undocumented and is not called from a non-interactive environment
Date: Mon, 23 Jan 2012 02:08:14 +0000 [thread overview]
Message-ID: <8739b7dvch.fsf@Kagami.home> (raw)
In-Reply-To: <CAM1tujKQ66Roq5D1UkKQLdcaZdSiO2tNVTa03Z+ctFJ0icZNHg@mail.gmail.com> (Andrew Psaltis's message of "Sun, 22 Jan 2012 14:58:51 -0500")
[-- Attachment #1: Type: text/plain, Size: 1390 bytes --]
Andrew Psaltis <ampsaltis@gmail.com> writes:
> Second:
> When I write a scheme script that adds some function to exit-hook, it
> is not invoked from a non-interactive call to guile. I have a file
> test.scm that looks like so:
>
> (add-hook! exit-hook (lambda () (display "bye\n")))
>
> In an interactive environment:
>
> $ guile -l test.scm
> guile> (exit)
> bye
> $
>
> In a non-interactive environment:
> $ guile -s test.scm
> $
>
> Nothing is printed. As far as I can tell, exit-hook should be made
> available in a non-interactive environment so that modules loading
> libraries can cleanup easily.
Assuming exit-hook is supposed to do this, and I would presume it is
meant to. I have a patch which will implement this for
stable-2.0. Basically, I wrap everything in a large catch, and when
guile gets a 'quit exception it runs the exit hooks before throwing the
exception again.
As far as I can see, this covers the case where guile exits normally
either by use of quit/exit, or just by finishing the script. It does
_not_ perform the cleanup if guile quits because of an uncaught
exception, but if someone thinks this is desirable, it should be a
matter of changing the catch.
I'm not quite sure how to add a test case for this though.
--
Ian Price
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: exit-hook patch --]
[-- Type: text/x-patch, Size: 3738 bytes --]
From baaf226cb91a41de66b7dc663c433c67f1c0f0e5 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Sun, 22 Jan 2012 19:47:16 +0000
Subject: [PATCH] Run exit-hook when scripts finish normally.
* module/ice-9/command-line.scm (compile-shell-switches): Wrap the
body of the output expression in a catch for `quit' exceptions, so
that we can run the `exit-hook'.
---
module/ice-9/command-line.scm | 68 +++++++++++++++++++++-------------------
1 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm
index 8aed74e..e33fac8 100644
--- a/module/ice-9/command-line.scm
+++ b/module/ice-9/command-line.scm
@@ -385,38 +385,42 @@ If FILE begins with `-' the -s switch is mandatory.
`(;; It would be nice not to load up (ice-9 control), but the
;; default-prompt-handler is nontrivial.
(@ (ice-9 control) %)
- (begin
- ;; If we didn't end with a -c or a -s and didn't supply a -q, load
- ;; the user's customization file.
- ,@(if (and interactive? (not inhibit-user-init?))
- '((load-user-init))
- '())
-
- ;; Use-specified extensions.
- ,@(map (lambda (ext)
- `(set! %load-extensions (cons ,ext %load-extensions)))
- user-extensions)
-
- ;; Add the user-specified load path here, so it won't be in
- ;; effect during the loading of the user's customization file.
- ,@(map (lambda (path)
- `(set! %load-path (cons ,path %load-path)))
- user-load-path)
-
- ;; Put accumulated actions in their correct order.
- ,@(reverse! out)
-
- ;; Handle the `-e' switch, if it was specified.
- ,@(if entry-point
- `((,entry-point (command-line)))
- '())
- ,(if interactive?
- ;; If we didn't end with a -c or a -s, start the
- ;; repl.
- '((@ (ice-9 top-repl) top-repl))
- ;; Otherwise, after doing all the other actions
- ;; prescribed by the command line, quit.
- '(quit)))))
+ (catch 'quit
+ (lambda ()
+ ;; If we didn't end with a -c or a -s and didn't supply a -q, load
+ ;; the user's customization file.
+ ,@(if (and interactive? (not inhibit-user-init?))
+ '((load-user-init))
+ '())
+
+ ;; Use-specified extensions.
+ ,@(map (lambda (ext)
+ `(set! %load-extensions (cons ,ext %load-extensions)))
+ user-extensions)
+
+ ;; Add the user-specified load path here, so it won't be in
+ ;; effect during the loading of the user's customization file.
+ ,@(map (lambda (path)
+ `(set! %load-path (cons ,path %load-path)))
+ user-load-path)
+
+ ;; Put accumulated actions in their correct order.
+ ,@(reverse! out)
+
+ ;; Handle the `-e' switch, if it was specified.
+ ,@(if entry-point
+ `((,entry-point (command-line)))
+ '())
+ ,(if interactive?
+ ;; If we didn't end with a -c or a -s, start the
+ ;; repl.
+ '((@ (ice-9 top-repl) top-repl))
+ ;; Otherwise, after doing all the other actions
+ ;; prescribed by the command line, quit.
+ '(quit)))
+ (lambda args
+ (run-hook exit-hook)
+ (apply throw args)))))
(if (pair? args)
(begin
--
1.7.7.5
next prev parent reply other threads:[~2012-01-23 2:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-22 19:58 bug#10581: exit-hook is undocumented and is not called from a non-interactive environment Andrew Psaltis
2012-01-23 2:08 ` Ian Price [this message]
2012-02-05 11:50 ` Andy Wingo
2012-02-05 19:20 ` Andrew Psaltis
2012-07-06 11:21 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8739b7dvch.fsf@Kagami.home \
--to=ianprice90@googlemail.com \
--cc=10581@debbugs.gnu.org \
--cc=ampsaltis@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).