From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Price Newsgroups: gmane.lisp.guile.bugs 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 Message-ID: <8739b7dvch.fsf@Kagami.home> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1327284961 20134 80.91.229.12 (23 Jan 2012 02:16:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2012 02:16:01 +0000 (UTC) Cc: 10581@debbugs.gnu.org To: Andrew Psaltis Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Jan 23 03:15:55 2012 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rp9Rr-0003OE-51 for guile-bugs@m.gmane.org; Mon, 23 Jan 2012 03:15:55 +0100 Original-Received: from localhost ([::1]:39232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rp9Rq-0006Sf-HN for guile-bugs@m.gmane.org; Sun, 22 Jan 2012 21:15:54 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:53044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rp9Ro-0006Sa-6Z for bug-guile@gnu.org; Sun, 22 Jan 2012 21:15:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rp9Rm-0000CF-WE for bug-guile@gnu.org; Sun, 22 Jan 2012 21:15:52 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34972) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rp9Rm-0000CB-Qt for bug-guile@gnu.org; Sun, 22 Jan 2012 21:15:50 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Rp9Ry-0006HH-DD for bug-guile@gnu.org; Sun, 22 Jan 2012 21:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ian Price Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 23 Jan 2012 02:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10581 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 10581-submit@debbugs.gnu.org id=B10581.132728491624080 (code B ref 10581); Mon, 23 Jan 2012 02:16:02 +0000 Original-Received: (at 10581) by debbugs.gnu.org; 23 Jan 2012 02:15:16 +0000 Original-Received: from localhost ([127.0.0.1]:40359 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Rp9RD-0006GK-DT for submit@debbugs.gnu.org; Sun, 22 Jan 2012 21:15:15 -0500 Original-Received: from mail-we0-f172.google.com ([74.125.82.172]:63383) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Rp9R9-0006G5-0p for 10581@debbugs.gnu.org; Sun, 22 Jan 2012 21:15:12 -0500 Original-Received: by werp11 with SMTP id p11so1658507wer.3 for <10581@debbugs.gnu.org>; Sun, 22 Jan 2012 18:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=nE2mqvbTCdZTzMqFEhXBKdeFFpC637Z37uCz4SfPlZU=; b=IZHpE7kd7NLB2JLhSpVyLK+uh+/AOsreML7Sswi/HZUN6XF4qty1/u+o8wuJVOE9gw DFG3sxYbay9KbsDVRoS2C2TU+JQ9gfvUQ+jN/bwuAmeVS8iahvv+ZdgiC/rVYVm0oRPl 4hYYXgxp6lQAfFjhUc9N6d0kxqIdL+bzaHeSY= Original-Received: by 10.216.138.220 with SMTP id a70mr3571418wej.24.1327284893427; Sun, 22 Jan 2012 18:14:53 -0800 (PST) Original-Received: from Kagami.home (host109-158-226-141.range109-158.btcentralplus.com. [109.158.226.141]) by mx.google.com with ESMTPS id q7sm10430361wix.5.2012.01.22.18.14.51 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 Jan 2012 18:14:52 -0800 (PST) In-Reply-To: (Andrew Psaltis's message of "Sun, 22 Jan 2012 14:58:51 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:6075 Archived-At: --=-=-= Andrew Psaltis 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" --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Run-exit-hook-when-scripts-finish-normally.patch Content-Description: exit-hook patch >From baaf226cb91a41de66b7dc663c433c67f1c0f0e5 Mon Sep 17 00:00:00 2001 From: Ian Price 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 --=-=-=--