avoid traps in repl except when evaluating the expression
authorAndy Wingo <wingo@pobox.com>
Thu, 23 Sep 2010 11:45:15 +0000 (13:45 +0200)
committerAndy Wingo <wingo@pobox.com>
Thu, 23 Sep 2010 11:45:23 +0000 (13:45 +0200)
* module/system/vm/trap-state.scm (with-default-trap-handler): Don't
  enable traps if we are setting a handler of #f.

* module/system/repl/error-handling.scm (call-with-error-handling): Add
  #:trap-handler arg.

* module/system/repl/repl.scm (run-repl): Only have traps enabled while
  running the thunk. Otherwise we trace on procedures called as part of
  the repl.

module/system/repl/error-handling.scm
module/system/repl/repl.scm
module/system/vm/trap-state.scm

index dc2367b..72193a8 100644 (file)
@@ -45,7 +45,7 @@
 
 (define* (call-with-error-handling thunk #:key
                                    (on-error 'debug) (post-error 'catch)
-                                   (pass-keys '(quit)))
+                                   (pass-keys '(quit)) (trap-handler 'debug))
   (let ((in (current-input-port))
         (out (current-output-port))
         (err (current-error-port)))
            (format #t "Type `,bt' for a backtrace or `,q' to continue.\n")
            ((@ (system repl repl) start-repl) #:debug debug)))))
 
+    (define (null-trap-handler frame trap-idx trap-name)
+      #t)
+
+    (define le-trap-handler
+      (case trap-handler
+        ((debug) debug-trap-handler)
+        ((pass) null-trap-handler)
+        ((disabled) #f)
+        (else (error "Unknown trap-handler strategy" trap-handler))))
+
     (catch #t
       (lambda () 
-        (with-default-trap-handler debug-trap-handler
+        (with-default-trap-handler le-trap-handler
           (lambda () (%start-stack #t thunk))))
 
       (case post-error
                (apply throw key args)
                (begin
                  (pmatch args
-                  ((,subr ,msg ,args . ,rest)
-                   (with-saved-ports
-                    (lambda ()
-                      (run-hook before-error-hook)
-                      (display-error #f err subr msg args rest)
-                      (run-hook after-error-hook)
-                      (force-output err))))
-                  (else
-                   (format err "\nERROR: uncaught throw to `~a', args: ~a\n"
-                           key args)))
+                   ((,subr ,msg ,args . ,rest)
+                    (with-saved-ports
+                     (lambda ()
+                       (run-hook before-error-hook)
+                       (display-error #f err subr msg args rest)
+                       (run-hook after-error-hook)
+                       (force-output err))))
+                   (else
+                    (format err "\nERROR: uncaught throw to `~a', args: ~a\n"
+                            key args)))
                  (if #f #f)))))
         ((catch)
          (lambda (key . args)
                (apply throw key args))))
         (else
          (if (procedure? post-error)
-             post-error ; a handler proc
+             post-error                 ; a handler proc
              (error "Unknown post-error strategy" post-error))))
 
       (case on-error
            #t))
         (else
          (if (procedure? on-error)
-             on-error ; pre-unwind handler
+             on-error                   ; pre-unwind handler
              (error "Unknown on-error strategy" on-error)))))))
 
 (define-syntax with-error-handling
index 8711e1d..efe29ac 100644 (file)
                                     (repl-print repl v))
                                   l))))
                   (lambda (k . args)
-                    (abort args)))))))
+                    (abort args))))
+              #:trap-handler 'disabled)))
            (next-char #f) ;; consume trailing whitespace
            (prompt-loop))))
      (lambda (k status)
index 1e9f9e6..68caf9f 100644 (file)
   (with-fluids ((%default-trap-handler handler))
     (dynamic-wind
       (lambda ()
-        (set-vm-trace-level! (the-vm) (trap-state->trace-level trap-state)))
+        ;; Don't enable hooks if the handler is #f.
+        (if handler
+            (set-vm-trace-level! (the-vm) (trap-state->trace-level trap-state))))
       thunk
       (lambda ()
-        (set-vm-trace-level! (the-vm) 0)))))
+        (if handler
+            (set-vm-trace-level! (the-vm) 0))))))
 
 (define* (list-traps #:optional (trap-state (the-trap-state)))
   (map (lambda (wrapper)