Run the handler of SRFI-34's `with-exception-handler' in the right dyn. env.
authorLudovic Courtès <ludo@gnu.org>
Mon, 24 Nov 2008 08:40:00 +0000 (09:40 +0100)
committerLudovic Courtès <ludo@gnu.org>
Mon, 24 Nov 2008 08:40:00 +0000 (09:40 +0100)
* srfi/srfi-34.scm (with-exception-handler): Use `with-throw-handler'
  instead of `lazy-catch'.

* test-suite/tests/srfi-34.test ("SRFI 34")["`with-exception-handler'
  invokes HANDLER in THUNK's dynamic env."]: New test.

* test-suite/tests/srfi-39.test: Use `(srfi srfi-34)'.
  ("SRFI-39")["SRFI-34"]: New test.

* NEWS: Update.

NEWS
srfi/srfi-34.scm
test-suite/tests/srfi-34.test
test-suite/tests/srfi-39.test

diff --git a/NEWS b/NEWS
index 1775ca0..0e6e081 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,8 @@ available: Guile is now always configured in "maintainer mode".
 ** Fix `Stack overflow' errors seen when building on some platforms
 ** Fix bug when `scm_with_guile ()' was called several times from the
    same thread
+** The handler of SRFI-34 `with-exception-handler' is now invoked in the
+   dynamic environment of the call to `raise'
 
 \f
 Changes in 1.8.5 (since 1.8.4)
index 5101b54..18a2fda 100644 (file)
@@ -1,6 +1,6 @@
 ;;; srfi-34.scm --- Exception handling for programs
 
-;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2006, 2008 Free Software Foundation, Inc.
 ;;
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -40,7 +40,7 @@
 procedure that accepts one argument.  It is installed as the current
 exception handler for the dynamic extent (as determined by
 dynamic-wind) of the invocation of THUNK."
-  (lazy-catch throw-key
+  (with-throw-handler throw-key
              thunk
              (lambda (key obj)
                (handler obj))))
index 2c7f4b2..2195d94 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; srfi-34.test --- test suite for SRFI-34 -*- scheme -*-
 ;;;;
-;;;;   Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+;;;;   Copyright (C) 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
 ;;;;
 ;;;; This program is free software; you can redistribute it and/or modify
 ;;;; it under the terms of the GNU General Public License as published by
            ""
            '(b . 23)))
 
-)
+  (pass-if "`with-exception-handler' invokes HANDLER in THUNK's dynamic env."
+           ;; In Guile 1.8.5 and earlier, unwinders would be called before
+           ;; the exception handler, which reads "The handler is called in
+           ;; the dynamic environment of the call to `raise'".
+           (call/cc
+            (lambda (return)
+              (let ((inside? #f))
+                (with-exception-handler
+                 (lambda (c)
+                   ;; This handler must be called before the unwinder below.
+                   (return inside?))
+                 (lambda ()
+                   (dynamic-wind
+                     (lambda ()
+                       (set! inside? #t))
+                     (lambda ()
+                       (raise 'some-exception))
+                     (lambda ()
+                       ;; This unwinder should not be executed before the
+                       ;; handler is called.
+                       (set! inside? #f))))))))))
index 1b7923a..277a3c6 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; srfi-39.test --- -*- scheme -*-
 ;;;;
-;;;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+;;;; Copyright (C) 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
 ;;;; 
 ;;;; This program is free software; you can redistribute it and/or modify
 ;;;; it under the terms of the GNU General Public License as published by
 
 (define-module (test-srfi-39)
   #:use-module (test-suite lib)
-  #:use-module (srfi srfi-39))
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-39)
+  #:duplicates (last) ;; avoid warning about srfi-34 replacing `raise'
+  )
 
 (define a (make-parameter 3))
 (define b (make-parameter 4))
            (check c d 10 9)
            (parameterize ((c (a)) (d (b)))
             (and (check a b 0 1)
-                 (check c d 0 1)))))))
+                 (check c d 0 1))))))
+
+  (pass-if "SRFI-34"
+    (let ((inside? (make-parameter #f)))
+      (call/cc (lambda (return)
+                 (with-exception-handler
+                  (lambda (c)
+                    ;; This handler should be called in the dynamic
+                    ;; environment installed by `parameterize'.
+                    (return (inside?)))
+                  (lambda ()
+                    (parameterize ((inside? #t))
+                      (raise 'some-exception)))))))))
 
 (let ()
   (define (test-ports param new-port new-port-2)