Speed up vector extension in VECTOR-PUSH-EXTEND.
[sbcl.git] / src / code / error-error.lisp
blob1463c8f39bba24b944a12879a0f75a61c77db7fa
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB!IMPL")
12 ;;; These specials are used by ERROR-ERROR to track the success of recovery
13 ;;; attempts. Not to be confused with SB-KERNEL::*CURRENT-ERROR-DEPTH*.
14 (defvar *error-error-depth* 0)
16 ;;; ERROR-ERROR can be called when the error system is in trouble and needs to
17 ;;; punt fast. It prints a message without using FORMAT. If we get into this
18 ;;; recursively, then we halt.
19 (defun error-error (&rest messages)
20 ;; Be very conservative until nesting is dealt with, including consing.
21 (let ((*error-error-depth* (1+ *error-error-depth*)))
22 (when (> *error-error-depth* 4)
23 (/show0 "*ERROR-ERROR-DEPTH* too big, trying HALT")
24 (%primitive sb!c:halt)
25 (/show0 "*ERROR-ERROR-DEPTH* too big, trying THROW")
26 (throw 'toplevel-catcher nil))
27 ;; We can be somewhat more relaxed now, the above will save us.
28 (with-standard-io-syntax
29 (let ((*print-readably* nil))
30 (flet
31 ((try-to-invoke-debugger ()
32 ;; Try to print something useful for debugging and try to invoke the debugger.
33 ;; Many things can trigger potentially nested errors beyond this point.
34 (dolist (item messages)
35 (princ item *terminal-io*))
36 (terpri *terminal-io*)
37 (sb!debug:print-backtrace :stream *terminal-io* :emergency-best-effort t)
38 (force-output *terminal-io*)
39 (invoke-debugger
40 (coerce-to-condition "Maximum error nesting depth exceeded" nil
41 'simple-error
42 'error)))
43 (safely-print (message)
44 (handler-case
45 (progn
46 (princ "Help! ERROR-ERROR is " *terminal-io*)
47 (princ *error-error-depth* *terminal-io*)
48 (princ " levels deep. " *terminal-io*)
49 (princ message *terminal-io*)
50 (terpri *terminal-io*))
51 (t ()))))
52 (declare (inline safely-print))
53 (case *error-error-depth*
55 ;; Don't scream on the first invocation.
56 (try-to-invoke-debugger))
58 (safely-print "Will try to reset the IO streams by calling STREAM-COLD-INIT-OR-RESET.")
59 (stream-cold-init-or-reset)
60 (try-to-invoke-debugger))
62 (safely-print "Will try to THROW this thread to the toplevel.")
63 (/show0 "*ERROR-ERROR-DEPTH* too big, trying THROW")
64 ;; FIXME: TOPLEVEL-REPL installs a (catch 'toplevel-catcher ...)
65 ;; inside its LOOP. If any error nesting happens while inside that
66 ;; LOOP (e.g. due to a "Broken pipe" on stderr, which is used by the
67 ;; debugger), then when we get here this throw below will only unwind
68 ;; until inside this LOOP, and thus the repl will loop forever busy
69 ;; printing errors. https://bugs.launchpad.net/sbcl/+bug/1520694
70 (throw 'toplevel-catcher nil))
72 (safely-print "Will try to halt this thread as a last resort.")
73 (/show0 "*ERROR-ERROR-DEPTH* too big, trying HALT")
74 (%primitive sb!c:halt)
75 (/show0 "*ERROR-ERROR-DEPTH* too big, trying THROW")
76 (throw '%abort-thread nil))))))))