1 ;;;; stuff originally from CMU CL's error.lisp which can or should
2 ;;;; come late (mostly related to the CONDITION class itself)
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
14 (in-package "SB!KERNEL")
16 ;;;; miscellaneous support utilities
18 ;;; Signalling an error when trying to print an error condition is
19 ;;; generally a PITA, so whatever the failure encountered when
20 ;;; wondering about FILE-POSITION within a condition printer, 'tis
21 ;;; better silently to give up than to try to complain.
22 (defun file-position-or-nil-for-error (stream &optional
(pos nil posp
))
23 ;; Arguably FILE-POSITION shouldn't be signalling errors at all; but
24 ;; "NIL if this cannot be determined" in the ANSI spec doesn't seem
25 ;; absolutely unambiguously to prohibit errors when, e.g., STREAM
26 ;; has been closed so that FILE-POSITION is a nonsense question. So
27 ;; my (WHN) impression is that the conservative approach is to
28 ;; IGNORE-ERRORS. (I encountered this failure from within a homebrew
29 ;; defsystemish operation where the ERROR-STREAM had been CL:CLOSEd,
30 ;; I think by nonlocally exiting through a WITH-OPEN-FILE, by the
31 ;; time an error was reported.)
33 (ignore-errors (file-position stream pos
))
34 (ignore-errors (file-position stream
))))
36 ;;;; the CONDITION class
38 (/show0
"condition.lisp 20")
40 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
42 (/show0
"condition.lisp 24")
44 (def!struct
(condition-classoid (:include classoid
)
45 (:constructor make-condition-classoid
))
46 ;; list of CONDITION-SLOT structures for the direct slots of this
48 (slots nil
:type list
)
49 ;; list of CONDITION-SLOT structures for all of the effective class
50 ;; slots of this class
51 (class-slots nil
:type list
)
52 ;; report function or NIL
53 (report nil
:type
(or function null
))
54 ;; list of alternating initargs and initforms
55 (default-initargs () :type list
)
56 ;; class precedence list as a list of CLASS objects, with all
57 ;; non-CONDITION classes removed
59 ;; a list of all the effective instance allocation slots of this
60 ;; class that have a non-constant initform or default-initarg.
61 ;; Values for these slots must be computed in the dynamic
62 ;; environment of MAKE-CONDITION.
63 (hairy-slots nil
:type list
))
65 (/show0
"condition.lisp 49")
69 (!defstruct-with-alternate-metaclass condition
70 :slot-names
(actual-initargs assigned-slots
)
71 :boa-constructor %make-condition-object
73 :metaclass-name condition-classoid
74 :metaclass-constructor make-condition-classoid
77 (defun make-condition-object (actual-initargs)
78 (%make-condition-object actual-initargs nil
))
80 (defstruct (condition-slot (:copier nil
))
81 (name (missing-arg) :type symbol
)
82 ;; list of all applicable initargs
83 (initargs (missing-arg) :type list
)
84 ;; names of reader and writer functions
85 (readers (missing-arg) :type list
)
86 (writers (missing-arg) :type list
)
87 ;; true if :INITFORM was specified
88 (initform-p (missing-arg) :type
(member t nil
))
89 ;; If this is a function, call it with no args. Otherwise, it's the
91 (initform (missing-arg) :type t
)
92 ;; allocation of this slot, or NIL until defaulted
93 (allocation nil
:type
(member :instance
:class nil
))
94 ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value.
95 (cell nil
:type
(or cons null
))
97 (documentation nil
:type
(or string null
)))
99 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
100 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
101 ;;; have themselves listed in their CPLs. This behavior is inherited
102 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
103 ;;; figured out whether it's right. -- WHN 19990612
104 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
105 (/show0
"condition.lisp 103")
106 (let ((condition-class (locally
107 ;; KLUDGE: There's a DEFTRANSFORM
108 ;; FIND-CLASSOID for constant class names
109 ;; which creates fast but
110 ;; non-cold-loadable, non-compact code. In
111 ;; this context, we'd rather have compact,
112 ;; cold-loadable code. -- WHN 19990928
113 (declare (notinline find-classoid
))
114 (find-classoid 'condition
))))
115 (setf (condition-classoid-cpl condition-class
)
116 (list condition-class
)))
117 (/show0
"condition.lisp 103"))
119 (setf (condition-classoid-report (locally
120 ;; KLUDGE: There's a DEFTRANSFORM
121 ;; FIND-CLASSOID for constant class
122 ;; names which creates fast but
123 ;; non-cold-loadable, non-compact
124 ;; code. In this context, we'd
125 ;; rather have compact,
126 ;; cold-loadable code. -- WHN
128 (declare (notinline find-classoid
))
129 (find-classoid 'condition
)))
130 (lambda (cond stream
)
131 (format stream
"Condition ~S was signalled." (type-of cond
))))
133 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
135 (defun find-condition-layout (name parent-types
)
136 (let* ((cpl (remove-duplicates
140 (condition-classoid-cpl
143 (cond-layout (info :type
:compiler-layout
'condition
))
144 (olayout (info :type
:compiler-layout name
))
145 ;; FIXME: Does this do the right thing in case of multiple
146 ;; inheritance? A quick look at DEFINE-CONDITION didn't make
147 ;; it obvious what ANSI intends to be done in the case of
148 ;; multiple inheritance, so it's not actually clear what the
151 (order-layout-inherits (concatenate 'simple-vector
152 (layout-inherits cond-layout
)
153 (mapcar #'classoid-layout cpl
)))))
155 (not (mismatch (layout-inherits olayout
) new-inherits
)))
157 (make-layout :classoid
(make-undefined-classoid name
)
158 :inherits new-inherits
160 :length
(layout-length cond-layout
)))))
164 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
165 ;;; Condition reporting is mediated through the PRINT-OBJECT method
166 ;;; for the condition type in question, with *PRINT-ESCAPE* always
167 ;;; being nil. Specifying (:REPORT REPORT-NAME) in the definition of
168 ;;; a condition type C is equivalent to:
169 ;;; (defmethod print-object ((x c) stream)
170 ;;; (if *print-escape* (call-next-method) (report-name x stream)))
171 ;;; The current code doesn't seem to quite match that.
172 (def!method print-object
((x condition
) stream
)
174 (print-unreadable-object (x stream
:type t
:identity t
))
175 ;; KLUDGE: A comment from CMU CL here said
176 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
177 ;; superclasses in define-condition call!
178 (dolist (class (condition-classoid-cpl (classoid-of x
))
179 (error "no REPORT? shouldn't happen!"))
180 (let ((report (condition-classoid-report class
)))
182 (return (funcall report x stream
)))))))
184 ;;;; slots of CONDITION objects
186 (defvar *empty-condition-slot
* '(empty))
188 (defun find-slot-default (class slot
)
189 (let ((initargs (condition-slot-initargs slot
))
190 (cpl (condition-classoid-cpl class
)))
192 (let ((default-initargs (condition-classoid-default-initargs class
)))
193 (dolist (initarg initargs
)
194 (let ((val (getf default-initargs initarg
*empty-condition-slot
*)))
195 (unless (eq val
*empty-condition-slot
*)
196 (return-from find-slot-default
201 (if (condition-slot-initform-p slot
)
202 (let ((initform (condition-slot-initform slot
)))
203 (if (functionp initform
)
206 (error "unbound condition slot: ~S" (condition-slot-name slot
)))))
208 (defun find-condition-class-slot (condition-class slot-name
)
210 (condition-classoid-cpl condition-class
)
211 (error "There is no slot named ~S in ~S."
212 slot-name condition-class
))
213 (dolist (slot (condition-classoid-slots sclass
))
214 (when (eq (condition-slot-name slot
) slot-name
)
215 (return-from find-condition-class-slot slot
)))))
217 (defun condition-writer-function (condition new-value name
)
218 (dolist (cslot (condition-classoid-class-slots
219 (layout-classoid (%instance-layout condition
)))
220 (setf (getf (condition-assigned-slots condition
) name
)
222 (when (eq (condition-slot-name cslot
) name
)
223 (return (setf (car (condition-slot-cell cslot
)) new-value
)))))
225 (defun condition-reader-function (condition name
)
226 (let ((class (layout-classoid (%instance-layout condition
))))
227 (dolist (cslot (condition-classoid-class-slots class
))
228 (when (eq (condition-slot-name cslot
) name
)
229 (return-from condition-reader-function
230 (car (condition-slot-cell cslot
)))))
231 (let ((val (getf (condition-assigned-slots condition
) name
232 *empty-condition-slot
*)))
233 (if (eq val
*empty-condition-slot
*)
234 (let ((actual-initargs (condition-actual-initargs condition
))
235 (slot (find-condition-class-slot class name
)))
237 (error "missing slot ~S of ~S" name condition
))
238 (do ((initargs actual-initargs
(cddr initargs
)))
240 (setf (getf (condition-assigned-slots condition
) name
)
241 (find-slot-default class slot
)))
242 (when (member (car initargs
) (condition-slot-initargs slot
))
243 (return-from condition-reader-function
244 (setf (getf (condition-assigned-slots condition
)
251 (defun make-condition (type &rest args
)
253 "Make an instance of a condition object using the specified initargs."
254 ;; Note: ANSI specifies no exceptional situations in this function.
255 ;; signalling simple-type-error would not be wrong.
256 (let* ((type (or (and (symbolp type
) (find-classoid type nil
))
258 (class (typecase type
259 (condition-classoid type
)
262 (return-from make-condition
(apply #'make-instance type args
)))
264 (error 'simple-type-error
266 :expected-type
'condition-class
267 :format-control
"~S is not a condition class."
268 :format-arguments
(list type
)))
270 (error 'simple-type-error
272 :expected-type
'condition-class
273 :format-control
"Bad type argument:~% ~S"
274 :format-arguments
(list type
)))))
275 (res (make-condition-object args
)))
276 (setf (%instance-layout res
) (classoid-layout class
))
277 ;; Set any class slots with initargs present in this call.
278 (dolist (cslot (condition-classoid-class-slots class
))
279 (dolist (initarg (condition-slot-initargs cslot
))
280 (let ((val (getf args initarg
*empty-condition-slot
*)))
281 (unless (eq val
*empty-condition-slot
*)
282 (setf (car (condition-slot-cell cslot
)) val
)))))
283 ;; Default any slots with non-constant defaults now.
284 (dolist (hslot (condition-classoid-hairy-slots class
))
285 (when (dolist (initarg (condition-slot-initargs hslot
) t
)
286 (unless (eq (getf args initarg
*empty-condition-slot
*)
287 *empty-condition-slot
*)
289 (setf (getf (condition-assigned-slots res
) (condition-slot-name hslot
))
290 (find-slot-default class hslot
))))
293 ;;;; DEFINE-CONDITION
295 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
296 (defun %compiler-define-condition
(name direct-supers layout
297 all-readers all-writers
)
298 (with-single-package-locked-error
299 (:symbol name
"defining ~A as a condition")
300 (sb!xc
:proclaim
`(ftype (function (t) t
) ,@all-readers
))
301 (sb!xc
:proclaim
`(ftype (function (t t
) t
) ,@all-writers
))
302 (multiple-value-bind (class old-layout
)
303 (insured-find-classoid name
304 #'condition-classoid-p
305 #'make-condition-classoid
)
306 (setf (layout-classoid layout
) class
)
307 (setf (classoid-direct-superclasses class
)
308 (mapcar #'find-classoid direct-supers
))
309 (cond ((not old-layout
)
310 (register-layout layout
))
311 ((not *type-system-initialized
*)
312 (setf (layout-classoid old-layout
) class
)
313 (setq layout old-layout
)
314 (unless (eq (classoid-layout class
) layout
)
315 (register-layout layout
)))
316 ((redefine-layout-warning "current"
319 (layout-length layout
)
320 (layout-inherits layout
)
321 (layout-depthoid layout
)
322 (layout-n-untagged-slots layout
))
323 (register-layout layout
:invalidate t
))
324 ((not (classoid-layout class
))
325 (register-layout layout
)))
327 (setf (layout-info layout
)
329 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
330 ;; names which creates fast but non-cold-loadable, non-compact
331 ;; code. In this context, we'd rather have compact, cold-loadable
332 ;; code. -- WHN 19990928
333 (declare (notinline find-classoid
))
334 (layout-info (classoid-layout (find-classoid 'condition
)))))
336 (setf (find-classoid name
) class
)
338 ;; Initialize CPL slot.
339 (setf (condition-classoid-cpl class
)
340 (remove-if-not #'condition-classoid-p
341 (std-compute-class-precedence-list class
)))))
345 ;;; Compute the effective slots of CLASS, copying inherited slots and
346 ;;; destructively modifying direct slots.
348 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
349 ;;; direct slots. Presumably it follows from the semantics of
350 ;;; inheritance and redefinition of conditions, but finding the cite
351 ;;; and documenting it here would be good. (Or, if this is not in fact
352 ;;; ANSI-compliant, fixing it would also be good.:-)
353 (defun compute-effective-slots (class)
354 (collect ((res (copy-list (condition-classoid-slots class
))))
355 (dolist (sclass (cdr (condition-classoid-cpl class
)))
356 (dolist (sslot (condition-classoid-slots sclass
))
357 (let ((found (find (condition-slot-name sslot
) (res)
358 :key
#'condition-slot-name
)))
360 (setf (condition-slot-initargs found
)
361 (union (condition-slot-initargs found
)
362 (condition-slot-initargs sslot
)))
363 (unless (condition-slot-initform-p found
)
364 (setf (condition-slot-initform-p found
)
365 (condition-slot-initform-p sslot
))
366 (setf (condition-slot-initform found
)
367 (condition-slot-initform sslot
)))
368 (unless (condition-slot-allocation found
)
369 (setf (condition-slot-allocation found
)
370 (condition-slot-allocation sslot
))))
372 (res (copy-structure sslot
)))))))
375 ;;; Early definitions of slot accessor creators.
377 ;;; Slot accessors must be generic functions, but ANSI does not seem
378 ;;; to specify any of them, and we cannot support it before end of
379 ;;; warm init. So we use ordinary functions inside SBCL, and switch to
380 ;;; GFs only at the end of building.
381 (declaim (notinline install-condition-slot-reader
382 install-condition-slot-writer
))
383 (defun install-condition-slot-reader (name condition slot-name
)
384 (declare (ignore condition
))
385 (setf (fdefinition name
)
387 (condition-reader-function condition slot-name
))))
388 (defun install-condition-slot-writer (name condition slot-name
)
389 (declare (ignore condition
))
390 (setf (fdefinition name
)
391 (lambda (new-value condition
)
392 (condition-writer-function condition new-value slot-name
))))
394 (defvar *define-condition-hooks
* nil
)
396 (defun %define-condition
(name parent-types layout slots documentation
397 report default-initargs all-readers all-writers
399 (with-single-package-locked-error
400 (:symbol name
"defining ~A as a condition")
401 (%compiler-define-condition name parent-types layout all-readers all-writers
)
402 (sb!c
:with-source-location
(source-location)
403 (setf (layout-source-location layout
)
405 (let ((class (find-classoid name
)))
406 (setf (condition-classoid-slots class
) slots
)
407 (setf (condition-classoid-report class
) report
)
408 (setf (condition-classoid-default-initargs class
) default-initargs
)
409 (setf (fdocumentation name
'type
) documentation
)
413 ;; Set up reader and writer functions.
414 (let ((slot-name (condition-slot-name slot
)))
415 (dolist (reader (condition-slot-readers slot
))
416 (install-condition-slot-reader reader name slot-name
))
417 (dolist (writer (condition-slot-writers slot
))
418 (install-condition-slot-writer writer name slot-name
))))
420 ;; Compute effective slots and set up the class and hairy slots
421 ;; (subsets of the effective slots.)
422 (let ((eslots (compute-effective-slots class
))
425 (mapcar #'condition-classoid-default-initargs
426 (condition-classoid-cpl class
)))))
427 (dolist (slot eslots
)
428 (ecase (condition-slot-allocation slot
)
430 (unless (condition-slot-cell slot
)
431 (setf (condition-slot-cell slot
)
432 (list (if (condition-slot-initform-p slot
)
433 (let ((initform (condition-slot-initform slot
)))
434 (if (functionp initform
)
437 *empty-condition-slot
*))))
438 (push slot
(condition-classoid-class-slots class
)))
440 (setf (condition-slot-allocation slot
) :instance
)
441 (when (or (functionp (condition-slot-initform slot
))
442 (dolist (initarg (condition-slot-initargs slot
) nil
)
443 (when (functionp (getf e-def-initargs initarg
))
445 (push slot
(condition-classoid-hairy-slots class
)))))))
446 (when (boundp '*define-condition-hooks
*)
447 (dolist (fun *define-condition-hooks
*)
448 (funcall fun class
))))
451 (defmacro define-condition
(name (&rest parent-types
) (&rest slot-specs
)
454 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
455 Define NAME as a condition type. This new type inherits slots and its
456 report function from the specified PARENT-TYPEs. A slot spec is a list of:
457 (slot-name :reader <rname> :initarg <iname> {Option Value}*
459 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
460 and :TYPE and the overall options :DEFAULT-INITARGS and
461 [type] :DOCUMENTATION are also allowed.
463 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
464 a string or a two-argument lambda or function name. If a function, the
465 function is called with the condition and stream to report the condition.
466 If a string, the string is printed.
468 Condition types are classes, but (as allowed by ANSI and not as described in
469 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
470 SLOT-VALUE may not be used on condition objects."
471 (let* ((parent-types (or parent-types
'(condition)))
472 (layout (find-condition-layout name parent-types
))
475 (default-initargs ()))
477 (all-readers nil append
)
478 (all-writers nil append
))
479 (dolist (spec slot-specs
)
480 (when (keywordp spec
)
481 (warn "Keyword slot name indicates probable syntax error:~% ~S"
483 (let* ((spec (if (consp spec
) spec
(list spec
)))
484 (slot-name (first spec
))
485 (allocation :instance
)
492 (do ((options (rest spec
) (cddr options
)))
494 (unless (and (consp options
) (consp (cdr options
)))
495 (error "malformed condition slot spec:~% ~S." spec
))
496 (let ((arg (second options
)))
497 (case (first options
)
498 (:reader
(readers arg
))
499 (:writer
(writers arg
))
502 (writers `(setf ,arg
)))
505 (error "more than one :INITFORM in ~S" spec
))
508 (:initarg
(initargs arg
))
510 (setq allocation arg
))
513 (error "more than one :DOCUMENTATION in ~S" spec
))
514 (unless (stringp arg
)
515 (error "slot :DOCUMENTATION argument is not a string: ~S"
517 (setq documentation arg
))
520 (error "unknown slot option:~% ~S" (first options
))))))
522 (all-readers (readers))
523 (all-writers (writers))
524 (slots `(make-condition-slot
526 :initargs
',(initargs)
529 :initform-p
',initform-p
530 :documentation
',documentation
532 ,(if (sb!xc
:constantp initform
)
533 `',(constant-form-value initform
)
534 `#'(lambda () ,initform
)))))))
536 (dolist (option options
)
537 (unless (consp option
)
538 (error "bad option:~% ~S" option
))
540 (:documentation
(setq documentation
(second option
)))
542 (let ((arg (second option
)))
545 `#'(lambda (condition stream
)
546 (declare (ignore condition
))
547 (write-string ,arg stream
))
548 `#'(lambda (condition stream
)
549 (funcall #',arg condition stream
))))))
551 (do ((initargs (rest option
) (cddr initargs
)))
553 (let ((val (second initargs
)))
554 (setq default-initargs
555 (list* `',(first initargs
)
556 (if (sb!xc
:constantp val
)
557 `',(constant-form-value val
)
559 default-initargs
)))))
561 (error "unknown option: ~S" (first option
)))))
564 (eval-when (:compile-toplevel
)
565 (%compiler-define-condition
',name
',parent-types
',layout
566 ',(all-readers) ',(all-writers)))
567 (eval-when (:load-toplevel
:execute
)
568 (%define-condition
',name
574 (list ,@default-initargs
)
577 (sb!c
:source-location
)))))))
579 ;;;; DESCRIBE on CONDITIONs
581 ;;; a function to be used as the guts of DESCRIBE-OBJECT (CONDITION T)
582 ;;; eventually (once we get CLOS up and running so that we can define
584 (defun describe-condition (condition stream
)
586 "~&~@<~S ~_is a ~S. ~_Its slot values are ~_~S.~:>~%"
590 (condition-actual-initargs condition
)
591 (condition-assigned-slots condition
))))
593 ;;;; various CONDITIONs specified by ANSI
595 (define-condition serious-condition
(condition) ())
597 (define-condition error
(serious-condition) ())
599 (define-condition warning
(condition) ())
600 (define-condition style-warning
(warning) ())
602 (defun simple-condition-printer (condition stream
)
605 (simple-condition-format-control condition
)
606 (simple-condition-format-arguments condition
)))
608 (define-condition simple-condition
()
609 ((format-control :reader simple-condition-format-control
610 :initarg
:format-control
611 :type format-control
)
612 (format-arguments :reader simple-condition-format-arguments
613 :initarg
:format-arguments
616 (:report simple-condition-printer
))
618 (define-condition simple-warning
(simple-condition warning
) ())
620 (define-condition simple-error
(simple-condition error
) ())
622 (define-condition storage-condition
(serious-condition) ())
624 (define-condition type-error
(error)
625 ((datum :reader type-error-datum
:initarg
:datum
)
626 (expected-type :reader type-error-expected-type
:initarg
:expected-type
))
628 (lambda (condition stream
)
630 "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
631 (type-error-datum condition
)
632 (type-error-expected-type condition
)))))
634 ;;; not specified by ANSI, but too useful not to have around.
635 (define-condition simple-style-warning
(simple-condition style-warning
) ())
636 (define-condition simple-type-error
(simple-condition type-error
) ())
638 (define-condition program-error
(error) ())
639 (define-condition parse-error
(error) ())
640 (define-condition control-error
(error) ())
641 (define-condition stream-error
(error)
642 ((stream :reader stream-error-stream
:initarg
:stream
)))
644 (define-condition end-of-file
(stream-error) ()
646 (lambda (condition stream
)
649 (stream-error-stream condition
)))))
651 (define-condition closed-stream-error
(stream-error) ()
653 (lambda (condition stream
)
654 (format stream
"~S is closed" (stream-error-stream condition
)))))
656 (define-condition file-error
(error)
657 ((pathname :reader file-error-pathname
:initarg
:pathname
))
659 (lambda (condition stream
)
660 (format stream
"error on file ~S" (file-error-pathname condition
)))))
662 (define-condition package-error
(error)
663 ((package :reader package-error-package
:initarg
:package
)))
665 (define-condition cell-error
(error)
666 ((name :reader cell-error-name
:initarg
:name
)))
668 (def!method print-object
((condition cell-error
) stream
)
669 (if (and *print-escape
* (slot-boundp condition
'name
))
670 (print-unreadable-object (condition stream
:type t
:identity t
)
671 (princ (cell-error-name condition
) stream
))
674 (define-condition unbound-variable
(cell-error) ()
676 (lambda (condition stream
)
678 "The variable ~S is unbound."
679 (cell-error-name condition
)))))
681 (define-condition undefined-function
(cell-error) ()
683 (lambda (condition stream
)
685 "The function ~S is undefined."
686 (cell-error-name condition
)))))
688 (define-condition special-form-function
(undefined-function) ()
690 (lambda (condition stream
)
692 "Cannot FUNCALL the SYMBOL-FUNCTION of special operator ~S."
693 (cell-error-name condition
)))))
695 (define-condition arithmetic-error
(error)
696 ((operation :reader arithmetic-error-operation
699 (operands :reader arithmetic-error-operands
701 (:report
(lambda (condition stream
)
703 "arithmetic error ~S signalled"
705 (when (arithmetic-error-operation condition
)
707 "~%Operation was ~S, operands ~S."
708 (arithmetic-error-operation condition
)
709 (arithmetic-error-operands condition
))))))
711 (define-condition division-by-zero
(arithmetic-error) ())
712 (define-condition floating-point-overflow
(arithmetic-error) ())
713 (define-condition floating-point-underflow
(arithmetic-error) ())
714 (define-condition floating-point-inexact
(arithmetic-error) ())
715 (define-condition floating-point-invalid-operation
(arithmetic-error) ())
717 (define-condition print-not-readable
(error)
718 ((object :reader print-not-readable-object
:initarg
:object
))
720 (lambda (condition stream
)
721 (let ((obj (print-not-readable-object condition
))
723 (format stream
"~S cannot be printed readably." obj
)))))
725 (define-condition reader-error
(parse-error stream-error
) ()
726 (:report
(lambda (condition stream
)
727 (%report-reader-error condition stream
))))
729 ;;; a READER-ERROR whose REPORTing is controlled by FORMAT-CONTROL and
730 ;;; FORMAT-ARGS (the usual case for READER-ERRORs signalled from
731 ;;; within SBCL itself)
733 ;;; (Inheriting CL:SIMPLE-CONDITION here isn't quite consistent with
734 ;;; the letter of the ANSI spec: this is not a condition signalled by
735 ;;; SIGNAL when a format-control is supplied by the function's first
736 ;;; argument. It seems to me (WHN) to be basically in the spirit of
737 ;;; the spec, but if not, it'd be straightforward to do our own
738 ;;; DEFINE-CONDITION SB-INT:SIMPLISTIC-CONDITION with
739 ;;; FORMAT-CONTROL and FORMAT-ARGS slots, and use that condition in
740 ;;; place of CL:SIMPLE-CONDITION here.)
741 (define-condition simple-reader-error
(reader-error simple-condition
)
743 (:report
(lambda (condition stream
)
744 (%report-reader-error condition stream
:simple t
))))
746 ;;; base REPORTing of a READER-ERROR
748 ;;; When SIMPLE, we expect and use SIMPLE-CONDITION-ish FORMAT-CONTROL
749 ;;; and FORMAT-ARGS slots.
750 (defun %report-reader-error
(condition stream
&key simple
)
751 (let* ((error-stream (stream-error-stream condition
))
752 (pos (file-position-or-nil-for-error error-stream
)))
755 (< pos sb
!xc
:array-dimension-limit
)
756 ;; KLUDGE: lseek() (which is what FILE-POSITION
757 ;; reduces to on file-streams) is undefined on
758 ;; "some devices", which in practice means that it
759 ;; can claim to succeed on /dev/stdin on Darwin
760 ;; and Solaris. This is obviously bad news,
761 ;; because the READ-SEQUENCE below will then
762 ;; block, not complete, and the report will never
763 ;; be printed. As a workaround, we exclude
764 ;; interactive streams from this attempt to report
765 ;; positions. -- CSR, 2003-08-21
766 (not (interactive-stream-p error-stream
))
767 (file-position error-stream
:start
))
770 :element-type
(stream-element-type
772 (when (= pos
(read-sequence string error-stream
))
773 (setq lineno
(1+ (count #\Newline string
))
775 (or (position #\Newline string
:from-end t
) -
1)
777 (file-position-or-nil-for-error error-stream pos
))
778 (pprint-logical-block (stream nil
)
781 ~@[(line ~W~]~@[, column ~W) ~]~
783 (class-name (class-of condition
))
784 pos lineno colno error-stream
)
786 (format stream
":~2I~_~?"
787 (simple-condition-format-control condition
)
788 (simple-condition-format-arguments condition
)))))))
790 ;;;; special SBCL extension conditions
792 ;;; an error apparently caused by a bug in SBCL itself
794 ;;; Note that we don't make any serious effort to use this condition
795 ;;; for *all* errors in SBCL itself. E.g. type errors and array
796 ;;; indexing errors can occur in functions called from SBCL code, and
797 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
798 ;;; because the signalling code has no good way to know that the
799 ;;; underlying problem is a bug in SBCL. But in the fairly common case
800 ;;; that the signalling code does know that it's found a bug in SBCL,
801 ;;; this condition is appropriate, reusing boilerplate and helping
802 ;;; users to recognize it as an SBCL bug.
803 (define-condition bug
(simple-error)
806 (lambda (condition stream
)
809 (simple-condition-format-control condition
)
810 (simple-condition-format-arguments condition
)
811 "~@<This is probably a bug in SBCL itself. (Alternatively, ~
812 SBCL might have been corrupted by bad user code, e.g. by an ~
813 undefined Lisp operation like ~S, or by stray pointers from ~
814 alien code or from unsafe Lisp code; or there might be a bug ~
815 in the OS or hardware that SBCL is running on.) If it seems to ~
816 be a bug in SBCL itself, the maintainers would like to know ~
817 about it. Bug reports are welcome on the SBCL ~
818 mailing lists, which you can find at ~
819 <http://sbcl.sourceforge.net/>.~:@>"
820 '((fmakunbound 'compile
))))))
822 (define-condition simple-storage-condition
(storage-condition simple-condition
)
825 ;;; a condition for use in stubs for operations which aren't supported
826 ;;; on some platforms
828 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
829 ;;; #-(or freebsd linux)
830 ;;; (defun load-foreign (&rest rest)
831 ;;; (error 'unsupported-operator :name 'load-foreign))
832 ;;; #+(or freebsd linux)
833 ;;; (defun load-foreign ... actual definition ...)
834 ;;; By signalling a standard condition in this case, we make it
835 ;;; possible for test code to distinguish between (1) intentionally
836 ;;; unimplemented and (2) unintentionally just screwed up somehow.
837 ;;; (Before this condition was defined, test code tried to deal with
838 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
839 ;;; sbcl-0.7.0, a package screwup left the definition of
840 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
841 ;;; architectures where it was supposed to be supported, and the
842 ;;; regression tests cheerfully passed because they assumed that
843 ;;; unFBOUNDPness meant they were running on an system which didn't
844 ;;; support the extension.)
845 (define-condition unsupported-operator
(simple-error) ())
847 ;;; (:ansi-cl :function remove)
848 ;;; (:ansi-cl :section (a b c))
849 ;;; (:ansi-cl :glossary "similar")
851 ;;; (:sbcl :node "...")
852 ;;; (:sbcl :variable *ed-functions*)
854 ;;; FIXME: this is not the right place for this.
855 (defun print-reference (reference stream
)
856 (ecase (car reference
)
858 (format stream
"AMOP")
860 (destructuring-bind (type data
) (cdr reference
)
862 (:readers
"Readers for ~:(~A~) Metaobjects"
863 (substitute #\
#\-
(symbol-name data
)))
865 (format stream
"Initialization of ~:(~A~) Metaobjects"
866 (substitute #\
#\-
(symbol-name data
))))
867 (:generic-function
(format stream
"Generic Function ~S" data
))
868 (:function
(format stream
"Function ~S" data
))
869 (:section
(format stream
"Section ~{~D~^.~}" data
)))))
871 (format stream
"The ANSI Standard")
873 (destructuring-bind (type data
) (cdr reference
)
875 (:function
(format stream
"Function ~S" data
))
876 (:special-operator
(format stream
"Special Operator ~S" data
))
877 (:macro
(format stream
"Macro ~S" data
))
878 (:section
(format stream
"Section ~{~D~^.~}" data
))
879 (:glossary
(format stream
"Glossary entry for ~S" data
))
880 (:issue
(format stream
"writeup for Issue ~A" data
)))))
882 (format stream
"The SBCL Manual")
884 (destructuring-bind (type data
) (cdr reference
)
886 (:node
(format stream
"Node ~S" data
))
887 (:variable
(format stream
"Variable ~S" data
))
888 (:function
(format stream
"Function ~S" data
)))))
889 ;; FIXME: other documents (e.g. CLIM, Franz documentation :-)
891 (define-condition reference-condition
()
892 ((references :initarg
:references
:reader reference-condition-references
)))
893 (defvar *print-condition-references
* t
)
894 (def!method print-object
:around
((o reference-condition
) s
)
896 (unless (or *print-escape
* *print-readably
*)
897 (when (and *print-condition-references
*
898 (reference-condition-references o
))
899 (format s
"~&See also:~%")
900 (pprint-logical-block (s nil
:per-line-prefix
" ")
901 (do* ((rs (reference-condition-references o
) (cdr rs
))
902 (r (car rs
) (car rs
)))
904 (print-reference r s
)
905 (unless (null (cdr rs
))
908 (define-condition simple-reference-error
(reference-condition simple-error
)
911 (define-condition simple-reference-warning
(reference-condition simple-warning
)
914 (define-condition duplicate-definition
(reference-condition warning
)
915 ((name :initarg
:name
:reader duplicate-definition-name
))
916 (:report
(lambda (c s
)
917 (format s
"~@<Duplicate definition for ~S found in ~
919 (duplicate-definition-name c
))))
920 (:default-initargs
:references
(list '(:ansi-cl
:section
(3 2 2 3)))))
922 (define-condition constant-modified
(reference-condition warning
)
923 ((fun-name :initarg
:fun-name
:reader constant-modified-fun-name
))
924 (:report
(lambda (c s
)
925 (format s
"~@<Destructive function ~S called on ~
927 (constant-modified-fun-name c
))))
928 (:default-initargs
:references
(list '(:ansi-cl
:special-operator quote
)
929 '(:ansi-cl
:section
(3 2 2 3)))))
931 (define-condition package-at-variance
(reference-condition simple-warning
)
933 (:default-initargs
:references
(list '(:ansi-cl
:macro defpackage
))))
935 (define-condition defconstant-uneql
(reference-condition error
)
936 ((name :initarg
:name
:reader defconstant-uneql-name
)
937 (old-value :initarg
:old-value
:reader defconstant-uneql-old-value
)
938 (new-value :initarg
:new-value
:reader defconstant-uneql-new-value
))
940 (lambda (condition stream
)
942 "~@<The constant ~S is being redefined (from ~S to ~S)~@:>"
943 (defconstant-uneql-name condition
)
944 (defconstant-uneql-old-value condition
)
945 (defconstant-uneql-new-value condition
))))
946 (:default-initargs
:references
(list '(:ansi-cl
:macro defconstant
)
947 '(:sbcl
:node
"Idiosyncrasies"))))
949 (define-condition array-initial-element-mismatch
950 (reference-condition simple-warning
)
954 '(:ansi-cl
:function make-array
)
955 '(:ansi-cl
:function sb
!xc
:upgraded-array-element-type
))))
957 (define-condition displaced-to-array-too-small-error
958 (reference-condition simple-error
)
961 :references
(list '(:ansi-cl
:function adjust-array
))))
963 (define-condition type-warning
(reference-condition simple-warning
)
965 (:default-initargs
:references
(list '(:sbcl
:node
"Handling of Types"))))
967 (define-condition local-argument-mismatch
(reference-condition simple-warning
)
969 (:default-initargs
:references
(list '(:ansi-cl
:section
(3 2 2 3)))))
971 (define-condition format-args-mismatch
(reference-condition)
973 (:default-initargs
:references
(list '(:ansi-cl
:section
(22 3 10 2)))))
975 (define-condition format-too-few-args-warning
976 (format-args-mismatch simple-warning
)
978 (define-condition format-too-many-args-warning
979 (format-args-mismatch simple-style-warning
)
982 (define-condition implicit-generic-function-warning
(style-warning)
983 ((name :initarg
:name
:reader implicit-generic-function-name
))
985 (lambda (condition stream
)
986 (format stream
"~@<Implicitly creating new generic function ~S.~:@>"
987 (implicit-generic-function-name condition
)))))
989 (define-condition extension-failure
(reference-condition simple-error
)
992 (define-condition structure-initarg-not-keyword
993 (reference-condition simple-style-warning
)
995 (:default-initargs
:references
(list '(:ansi-cl
:section
(2 4 8 13)))))
1000 (define-condition package-lock-violation
(reference-condition package-error
)
1001 ((format-control :initform nil
:initarg
:format-control
1002 :reader package-error-format-control
)
1003 (format-arguments :initform nil
:initarg
:format-arguments
1004 :reader package-error-format-arguments
))
1006 (lambda (condition stream
)
1007 (let ((control (package-error-format-control condition
)))
1009 (apply #'format stream
1010 (format nil
"~~@<Lock on package ~A violated when ~A.~~:@>"
1011 (package-name (package-error-package condition
))
1013 (package-error-format-arguments condition
))
1014 (format stream
"~@<Lock on package ~A violated.~:@>"
1015 (package-name (package-error-package condition
)))))))
1016 ;; no :default-initargs -- reference-stuff provided by the
1017 ;; signalling form in target-package.lisp
1020 "Subtype of CL:PACKAGE-ERROR. A subtype of this error is signalled
1021 when a package-lock is violated."))
1023 (define-condition package-locked-error
(package-lock-violation) ()
1026 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
1027 signalled when an operation on a package violates a package lock."))
1029 (define-condition symbol-package-locked-error
(package-lock-violation)
1030 ((symbol :initarg
:symbol
:reader package-locked-error-symbol
))
1033 "Subtype of SB-EXT:PACKAGE-LOCK-VIOLATION. An error of this type is
1034 signalled when an operation on a symbol violates a package lock. The
1035 symbol that caused the violation is accessed by the function
1036 SB-EXT:PACKAGE-LOCKED-ERROR-SYMBOL."))
1040 (define-condition undefined-alien-error
(cell-error) ()
1042 (lambda (condition stream
)
1043 (if (slot-boundp condition
'name
)
1044 (format stream
"Undefined alien: ~S" (cell-error-name condition
))
1045 (format stream
"Undefined alien symbol.")))))
1047 (define-condition undefined-alien-variable-error
(undefined-alien-error) ()
1049 (lambda (condition stream
)
1050 (declare (ignore condition
))
1051 (format stream
"Attempt to access an undefined alien variable."))))
1053 (define-condition undefined-alien-function-error
(undefined-alien-error) ()
1055 (lambda (condition stream
)
1056 (declare (ignore condition
))
1057 (format stream
"Attempt to call an undefined alien function."))))
1060 ;;;; various other (not specified by ANSI) CONDITIONs
1062 ;;;; These might logically belong in other files; they're here, after
1063 ;;;; setup of CONDITION machinery, only because that makes it easier to
1064 ;;;; get cold init to work.
1066 ;;; OAOOM warning: see cross-condition.lisp
1067 (define-condition encapsulated-condition
(condition)
1068 ((condition :initarg
:condition
:reader encapsulated-condition
)))
1070 (define-condition values-type-error
(type-error)
1073 (lambda (condition stream
)
1075 "~@<The values set ~2I~:_[~{~S~^ ~}] ~I~_is not of type ~2I~_~S.~:>"
1076 (type-error-datum condition
)
1077 (type-error-expected-type condition
)))))
1079 ;;; KLUDGE: a condition for floating point errors when we can't or
1080 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
1081 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
1082 ;;; know how but the old code was broken by the conversion to POSIX
1083 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
1085 ;;; FIXME: Perhaps this should also be a base class for all
1086 ;;; floating point exceptions?
1087 (define-condition floating-point-exception
(arithmetic-error)
1088 ((flags :initarg
:traps
1090 :reader floating-point-exception-traps
))
1091 (:report
(lambda (condition stream
)
1093 "An arithmetic error ~S was signalled.~%"
1094 (type-of condition
))
1095 (let ((traps (floating-point-exception-traps condition
)))
1098 "Trapping conditions are: ~%~{ ~S~^~}~%"
1101 "No traps are enabled? How can this be?"
1104 (define-condition index-too-large-error
(type-error)
1107 (lambda (condition stream
)
1109 "The index ~S is too large."
1110 (type-error-datum condition
)))))
1112 (define-condition bounding-indices-bad-error
(reference-condition type-error
)
1113 ((object :reader bounding-indices-bad-object
:initarg
:object
))
1115 (lambda (condition stream
)
1116 (let* ((datum (type-error-datum condition
))
1119 (object (bounding-indices-bad-object condition
)))
1123 "The bounding indices ~S and ~S are bad ~
1124 for a sequence of length ~S."
1125 start end
(length object
)))
1127 ;; from WITH-ARRAY-DATA
1129 "The START and END parameters ~S and ~S are ~
1130 bad for an array of total size ~S."
1131 start end
(array-total-size object
)))))))
1134 (list '(:ansi-cl
:glossary
"bounding index designator")
1135 '(:ansi-cl
:issue
"SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR"))))
1137 (define-condition nil-array-accessed-error
(reference-condition type-error
)
1139 (:report
(lambda (condition stream
)
1140 (declare (ignore condition
))
1142 "An attempt to access an array of element-type ~
1143 NIL was made. Congratulations!")))
1145 :references
(list '(:ansi-cl
:function sb
!xc
:upgraded-array-element-type
)
1146 '(:ansi-cl
:section
(15 1 2 1))
1147 '(:ansi-cl
:section
(15 1 2 2)))))
1149 (define-condition namestring-parse-error
(parse-error)
1150 ((complaint :reader namestring-parse-error-complaint
:initarg
:complaint
)
1151 (args :reader namestring-parse-error-args
:initarg
:args
:initform nil
)
1152 (namestring :reader namestring-parse-error-namestring
:initarg
:namestring
)
1153 (offset :reader namestring-parse-error-offset
:initarg
:offset
))
1155 (lambda (condition stream
)
1157 "parse error in namestring: ~?~% ~A~% ~V@T^"
1158 (namestring-parse-error-complaint condition
)
1159 (namestring-parse-error-args condition
)
1160 (namestring-parse-error-namestring condition
)
1161 (namestring-parse-error-offset condition
)))))
1163 (define-condition simple-package-error
(simple-condition package-error
) ())
1165 (define-condition simple-reader-package-error
(simple-reader-error) ())
1167 (define-condition reader-eof-error
(end-of-file)
1168 ((context :reader reader-eof-error-context
:initarg
:context
))
1170 (lambda (condition stream
)
1172 "unexpected end of file on ~S ~A"
1173 (stream-error-stream condition
)
1174 (reader-eof-error-context condition
)))))
1176 (define-condition reader-impossible-number-error
(simple-reader-error)
1177 ((error :reader reader-impossible-number-error-error
:initarg
:error
))
1179 (lambda (condition stream
)
1180 (let ((error-stream (stream-error-stream condition
)))
1182 "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
1183 (file-position-or-nil-for-error error-stream
) error-stream
1184 (simple-condition-format-control condition
)
1185 (simple-condition-format-arguments condition
)
1186 (reader-impossible-number-error-error condition
))))))
1188 (define-condition timeout
(serious-condition)
1189 ((seconds :initarg
:seconds
:initform nil
:reader timeout-seconds
))
1190 (:report
(lambda (condition stream
)
1191 (format stream
"Timeout occurred~@[ after ~A seconds~]."
1192 (timeout-seconds condition
)))))
1194 (define-condition io-timeout
(stream-error timeout
)
1195 ((direction :reader io-timeout-direction
:initarg
:direction
))
1197 (lambda (condition stream
)
1198 (declare (type stream stream
))
1200 "I/O timeout ~(~A~)ing ~S."
1201 (io-timeout-direction condition
)
1202 (stream-error-stream condition
)))))
1204 (define-condition deadline-timeout
(timeout) ()
1205 (:report
(lambda (condition stream
)
1206 (format stream
"A deadline was reached after ~A seconds."
1207 (timeout-seconds condition
)))))
1209 (define-condition declaration-type-conflict-error
(reference-condition
1213 :format-control
"symbol ~S cannot be both the name of a type and the name of a declaration"
1214 :references
(list '(:ansi-cl
:section
(3 8 21)))))
1216 ;;; Single stepping conditions
1218 (define-condition step-condition
()
1219 ((form :initarg
:form
:reader step-condition-form
))
1222 (:documentation
"Common base class of single-stepping conditions.
1223 STEP-CONDITION-FORM holds a string representation of the form being
1227 (setf (fdocumentation 'step-condition-form
'function
)
1228 "Form associated with the STEP-CONDITION.")
1230 (define-condition step-form-condition
(step-condition)
1231 ((args :initarg
:args
:reader step-condition-args
))
1233 (lambda (condition stream
)
1234 (let ((*print-circle
* t
)
1236 (*print-readably
* nil
))
1238 "Evaluating call:~%~< ~@;~A~:>~%~
1239 ~:[With arguments:~%~{ ~S~%~}~;With unknown arguments~]~%"
1240 (list (step-condition-form condition
))
1241 (eq (step-condition-args condition
) :unknown
)
1242 (step-condition-args condition
)))))
1244 (:documentation
"Condition signalled by code compiled with
1245 single-stepping information when about to execute a form.
1246 STEP-CONDITION-FORM holds the form, STEP-CONDITION-PATHNAME holds the
1247 pathname of the original file or NIL, and STEP-CONDITION-SOURCE-PATH
1248 holds the source-path to the original form within that file or NIL.
1249 Associated with this condition are always the restarts STEP-INTO,
1250 STEP-NEXT, and STEP-CONTINUE."))
1253 (setf (fdocumentation 'step-condition-source-path
'function
)
1254 "Source-path of the original form associated with the
1255 STEP-FORM-CONDITION or NIL."
1256 (fdocumentation 'step-condition-pathname
'function
)
1257 "Pathname of the original source-file associated with the
1258 STEP-FORM-CONDITION or NIL.")
1260 (define-condition step-result-condition
(step-condition)
1261 ((result :initarg
:result
:reader step-condition-result
)))
1264 (setf (fdocumentation 'step-condition-result
'function
)
1265 "Return values associated with STEP-VALUES-CONDITION as a list,
1266 or the variable value associated with STEP-VARIABLE-CONDITION.")
1268 (define-condition step-values-condition
(step-result-condition)
1271 (:documentation
"Condition signalled by code compiled with
1272 single-stepping information after executing a form.
1273 STEP-CONDITION-FORM holds the form, and STEP-CONDITION-RESULT holds
1274 the values returned by the form as a list. No associated restarts."))
1276 (define-condition step-finished-condition
(step-condition)
1279 (lambda (condition stream
)
1280 (declare (ignore condition
))
1281 (format stream
"Returning from STEP")))
1283 (:documentation
"Condition signaled when STEP returns."))
1285 ;;; A knob for muffling warnings, mostly for use while loading files.
1286 (defvar *muffled-warnings
* 'uninteresting-redefinition
1287 "A type that ought to specify a subtype of WARNING. Whenever a
1288 warning is signaled, if the warning if of this type and is not
1289 handled by any other handler, it will be muffled.")
1291 ;;; Various STYLE-WARNING signaled in the system.
1292 ;; For the moment, we're only getting into the details for function
1293 ;; redefinitions, but other redefinitions could be done later
1295 (define-condition redefinition-warning
(style-warning)
1298 (define-condition function-redefinition-warning
(redefinition-warning)
1299 ((name :initarg
:name
:reader function-redefinition-warning-name
)
1300 (old :initarg
:old
:reader function-redefinition-warning-old-fdefinition
)
1301 ;; For DEFGENERIC and perhaps others, the redefinition
1302 ;; destructively modifies the original, rather than storing a new
1303 ;; object, so there's no NEW here, but only in subclasses.
1306 (define-condition redefinition-with-defun
(function-redefinition-warning)
1307 ((new :initarg
:new
:reader redefinition-with-defun-new-fdefinition
)
1308 ;; KLUDGE: it would be nice to fix the unreasonably late
1309 ;; back-patching of DEBUG-SOURCEs in the DEBUG-INFO during
1310 ;; fasloading and just use the new fdefinition, but for the moment
1311 ;; we'll compare the SOURCE-LOCATION created during DEFUN with the
1312 ;; previous DEBUG-SOURCE.
1313 (new-location :initarg
:new-location
1314 :reader redefinition-with-defun-new-location
))
1315 (:report
(lambda (warning stream
)
1316 (format stream
"redefining ~S in DEFUN"
1317 (function-redefinition-warning-name warning
)))))
1319 (define-condition redefinition-with-defgeneric
(function-redefinition-warning)
1320 ((new-location :initarg
:new-location
1321 :reader redefinition-with-defgeneric-new-location
))
1322 (:report
(lambda (warning stream
)
1323 (format stream
"redefining ~S in DEFGENERIC"
1324 (function-redefinition-warning-name warning
)))))
1326 (define-condition redefinition-with-defmethod
(redefinition-warning)
1327 ((gf :initarg
:generic-function
1328 :reader redefinition-with-defmethod-generic-function
)
1329 (qualifiers :initarg
:qualifiers
1330 :reader redefinition-with-defmethod-qualifiers
)
1331 (specializers :initarg
:specializers
1332 :reader redefinition-with-defmethod-specializers
)
1333 (new-location :initarg
:new-location
1334 :reader redefinition-with-defmethod-new-location
)
1335 (old-method :initarg
:old-method
1336 :reader redefinition-with-defmethod-old-method
))
1337 (:report
(lambda (warning stream
)
1338 (format stream
"redefining ~S~{ ~S~} ~S in DEFMETHOD"
1339 (redefinition-with-defmethod-generic-function warning
)
1340 (redefinition-with-defmethod-qualifiers warning
)
1341 (redefinition-with-defmethod-specializers warning
)))))
1343 ;; FIXME: see the FIXMEs in defmacro.lisp, then maybe instantiate this.
1344 (define-condition redefinition-with-defmacro
(function-redefinition-warning)
1347 ;; Here are a few predicates for what people might find interesting
1348 ;; about redefinitions.
1350 ;; DEFUN can replace a generic function with an ordinary function.
1351 ;; (Attempting to replace an ordinary function with a generic one
1352 ;; causes an error, though.)
1353 (defun redefinition-replaces-generic-function-p (warning)
1354 (and (typep warning
'redefinition-with-defun
)
1355 (typep (function-redefinition-warning-old-fdefinition warning
)
1356 'generic-function
)))
1358 (defun redefinition-replaces-compiled-function-with-interpreted-p (warning)
1359 (and (typep warning
'redefinition-with-defun
)
1360 (compiled-function-p
1361 (function-redefinition-warning-old-fdefinition warning
))
1362 (not (compiled-function-p
1363 (redefinition-with-defun-new-fdefinition warning
)))))
1365 ;; Most people seem to agree that re-running a DEFUN in a file is
1366 ;; completely uninteresting.
1367 (defun uninteresting-ordinary-function-redefinition-p (warning)
1368 ;; OAOO violation: this duplicates code in SB-INTROSPECT.
1369 ;; Additionally, there are some functions that aren't
1370 ;; funcallable-instances for which finding the source location is
1371 ;; complicated (e.g. DEFSTRUCT-defined predicates and accessors),
1372 ;; but I don't think they're defined with %DEFUN, so the warning
1374 (flet ((fdefinition-file-namestring (fdefn)
1376 (when (typep fdefn
'sb
!eval
:interpreted-function
)
1377 (return-from fdefinition-file-namestring
1378 (sb!c
:definition-source-location-namestring
1379 (sb!eval
:interpreted-function-source-location fdefn
))))
1380 ;; All the following accesses are guarded with conditionals
1381 ;; because it's not clear whether any of the slots we're
1382 ;; chasing down are guaranteed to be filled in.
1384 ;; KLUDGE: although this looks like it only works
1385 ;; for %SIMPLE-FUNs, in fact there's a pun such
1386 ;; that %SIMPLE-FUN-SELF returns the simple-fun
1387 ;; object for closures and
1388 ;; funcallable-instances. -- CSR, circa 2005
1389 (sb!kernel
:%simple-fun-self fdefn
))
1390 (code (if fdefn
(sb!kernel
:fun-code-header fdefn
)))
1391 (debug-info (if code
(sb!kernel
:%code-debug-info code
)))
1392 (debug-source (if debug-info
1393 (sb!c
::debug-info-source debug-info
)))
1394 (namestring (if debug-source
1395 (sb!c
::debug-source-namestring debug-source
))))
1398 ;; There's garbage in various places when the first DEFUN runs in
1400 sb
!kernel
::*cold-init-complete-p
*
1401 (typep warning
'redefinition-with-defun
)
1403 (function-redefinition-warning-old-fdefinition warning
))
1405 (redefinition-with-defun-new-fdefinition warning
)))
1406 ;; Replacing a compiled function with a compiled function is
1407 ;; clearly uninteresting, and we'll say arbitrarily that
1408 ;; replacing an interpreted function with an interpreted
1409 ;; function is uninteresting, too, but leave out the
1410 ;; compiled-to-interpreted case.
1413 '(or #!+sb-eval sb
!eval
:interpreted-function
))
1414 (and (typep old-fdefn
1415 '(and compiled-function
1416 (not funcallable-instance
)))
1417 ;; Since this is a REDEFINITION-WITH-DEFUN,
1418 ;; NEW-FDEFN can't be a FUNCALLABLE-INSTANCE.
1419 (typep new-fdefn
'compiled-function
)))
1420 (let* ((old-namestring (fdefinition-file-namestring old-fdefn
))
1422 (or (fdefinition-file-namestring new-fdefn
)
1424 (redefinition-with-defun-new-location warning
)))
1426 (sb!c
::definition-source-location-namestring
1430 (equal old-namestring new-namestring
))))))))
1432 (defun uninteresting-generic-function-redefinition-p (warning)
1433 (and (typep warning
'redefinition-with-defgeneric
)
1435 (function-redefinition-warning-old-fdefinition warning
))
1437 (if (typep old-fdefn
'generic-function
)
1438 (sb!pcl
::definition-source old-fdefn
)))
1441 (sb!c
:definition-source-location-namestring old-location
)))
1443 (redefinition-with-defgeneric-new-location warning
))
1446 (sb!c
:definition-source-location-namestring new-location
))))
1449 (equal old-namestring new-namestring
)))))
1451 (defun uninteresting-method-redefinition-p (warning)
1452 (and (typep warning
'redefinition-with-defmethod
)
1453 (let* ((old-method (redefinition-with-defmethod-old-method warning
))
1454 (old-location (sb!pcl
::definition-source old-method
))
1455 (old-namestring (if old-location
1456 (sb!c
:definition-source-location-namestring
1458 (new-location (redefinition-with-defmethod-new-location warning
))
1459 (new-namestring (if new-location
1460 (sb!c
:definition-source-location-namestring
1464 (equal new-namestring old-namestring
)))))
1466 (deftype uninteresting-redefinition
()
1467 '(or (satisfies uninteresting-ordinary-function-redefinition-p
)
1468 (satisfies uninteresting-generic-function-redefinition-p
)
1469 (satisfies uninteresting-method-redefinition-p
)))
1471 (define-condition redefinition-with-deftransform
(redefinition-warning)
1472 ((transform :initarg
:transform
1473 :reader redefinition-with-deftransform-transform
))
1474 (:report
(lambda (warning stream
)
1475 (format stream
"Overwriting ~S"
1476 (redefinition-with-deftransform-transform warning
)))))
1478 ;;; Various other STYLE-WARNINGS
1479 (define-condition dubious-asterisks-around-variable-name
1480 (style-warning simple-condition
)
1482 (:report
(lambda (warning stream
)
1483 (format stream
"~@?, even though the name follows~@
1484 the usual naming convention (names like *FOO*) for special variables"
1485 (simple-condition-format-control warning
)
1486 (simple-condition-format-arguments warning
)))))
1488 (define-condition asterisks-around-lexical-variable-name
1489 (dubious-asterisks-around-variable-name)
1492 (define-condition asterisks-around-constant-variable-name
1493 (dubious-asterisks-around-variable-name)
1496 ;; We call this UNDEFINED-ALIEN-STYLE-WARNING because there are some
1497 ;; subclasses of ERROR above having to do with undefined aliens.
1498 (define-condition undefined-alien-style-warning
(style-warning)
1499 ((symbol :initarg
:symbol
:reader undefined-alien-symbol
))
1500 (:report
(lambda (warning stream
)
1501 (format stream
"Undefined alien: ~S"
1502 (undefined-alien-symbol warning
)))))
1505 (define-condition lexical-environment-too-complex
(style-warning)
1506 ((form :initarg
:form
:reader lexical-environment-too-complex-form
)
1507 (lexenv :initarg
:lexenv
:reader lexical-environment-too-complex-lexenv
))
1508 (:report
(lambda (warning stream
)
1510 "~@<Native lexical environment too complex for ~
1511 SB-EVAL to evaluate ~S, falling back to ~
1512 SIMPLE-EVAL-IN-LEXENV. Lexenv: ~S~:@>"
1513 (lexical-environment-too-complex-form warning
)
1514 (lexical-environment-too-complex-lexenv warning
)))))
1516 ;; Although this has -ERROR- in the name, it's just a STYLE-WARNING.
1517 (define-condition character-decoding-error-in-comment
(style-warning)
1518 ((stream :initarg
:stream
:reader decoding-error-in-comment-stream
)
1519 (position :initarg
:position
:reader decoding-error-in-comment-position
))
1520 (:report
(lambda (warning stream
)
1522 "Character decoding error in a ~A-comment at ~
1523 position ~A reading source stream ~A, ~
1525 (decoding-error-in-comment-macro warning
)
1526 (decoding-error-in-comment-position warning
)
1527 (decoding-error-in-comment-stream warning
)))))
1529 (define-condition character-decoding-error-in-macro-char-comment
1530 (character-decoding-error-in-comment)
1531 ((char :initform
#\
; :initarg :char
1532 :reader character-decoding-error-in-macro-char-comment-char
)))
1534 (define-condition character-decoding-error-in-dispatch-macro-char-comment
1535 (character-decoding-error-in-comment)
1536 ;; ANSI doesn't give a way for a reader function invoked by a
1537 ;; dispatch macro character to determine which dispatch character
1538 ;; was used, so if a user wants to signal one of these from a custom
1539 ;; comment reader, he'll have to supply the :DISP-CHAR himself.
1540 ((disp-char :initform
#\
# :initarg
:disp-char
1541 :reader character-decoding-error-in-macro-char-comment-disp-char
)
1542 (sub-char :initarg
:sub-char
1543 :reader character-decoding-error-in-macro-char-comment-sub-char
)))
1545 (defun decoding-error-in-comment-macro (warning)
1547 (character-decoding-error-in-macro-char-comment
1548 (character-decoding-error-in-macro-char-comment-char warning
))
1549 (character-decoding-error-in-dispatch-macro-char-comment
1552 (character-decoding-error-in-macro-char-comment-disp-char warning
)
1553 (character-decoding-error-in-macro-char-comment-sub-char warning
)))))
1555 (define-condition deprecated-eval-when-situations
(style-warning)
1556 ((situations :initarg
:situations
1557 :reader deprecated-eval-when-situations-situations
))
1558 (:report
(lambda (warning stream
)
1559 (format stream
"using deprecated EVAL-WHEN situation names~{ ~S~}"
1560 (deprecated-eval-when-situations-situations warning
)))))
1562 (define-condition proclamation-mismatch
(style-warning)
1563 ((name :initarg
:name
:reader proclamation-mismatch-name
)
1564 (old :initarg
:old
:reader proclamation-mismatch-old
)
1565 (new :initarg
:new
:reader proclamation-mismatch-new
)))
1567 (define-condition type-proclamation-mismatch
(proclamation-mismatch)
1569 (:report
(lambda (warning stream
)
1571 "The new TYPE proclamation~% ~S for ~S does not ~
1572 match the old TYPE proclamation ~S"
1573 (proclamation-mismatch-new warning
)
1574 (proclamation-mismatch-name warning
)
1575 (proclamation-mismatch-old warning
)))))
1577 (define-condition ftype-proclamation-mismatch
(proclamation-mismatch)
1579 (:report
(lambda (warning stream
)
1581 "The new FTYPE proclamation~% ~S for ~S does not ~
1582 match the old FTYPE proclamation ~S"
1583 (proclamation-mismatch-new warning
)
1584 (proclamation-mismatch-name warning
)
1585 (proclamation-mismatch-old warning
)))))
1587 ;;;; restart definitions
1589 (define-condition abort-failure
(control-error) ()
1591 "An ABORT restart was found that failed to transfer control dynamically."))
1593 (defun abort (&optional condition
)
1595 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
1597 (invoke-restart (find-restart-or-control-error 'abort condition
))
1598 ;; ABORT signals an error in case there was a restart named ABORT
1599 ;; that did not transfer control dynamically. This could happen with
1601 (error 'abort-failure
))
1603 (defun muffle-warning (&optional condition
)
1605 "Transfer control to a restart named MUFFLE-WARNING, signalling a
1606 CONTROL-ERROR if none exists."
1607 (invoke-restart (find-restart-or-control-error 'muffle-warning condition
)))
1609 (defun try-restart (name condition
&rest arguments
)
1610 (let ((restart (find-restart name condition
)))
1612 (apply #'invoke-restart restart arguments
))))
1614 (macrolet ((define-nil-returning-restart (name args doc
)
1615 #!-sb-doc
(declare (ignore doc
))
1616 `(defun ,name
(,@args
&optional condition
)
1618 (try-restart ',name condition
,@args
))))
1619 (define-nil-returning-restart continue
()
1620 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
1621 (define-nil-returning-restart store-value
(value)
1622 "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
1624 (define-nil-returning-restart use-value
(value)
1625 "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
1628 ;;; single-stepping restarts
1630 (macrolet ((def (name doc
)
1631 #!-sb-doc
(declare (ignore doc
))
1632 `(defun ,name
(condition)
1634 (invoke-restart (find-restart-or-control-error ',name condition
)))))
1636 "Transfers control to the STEP-CONTINUE restart associated with
1637 the condition, continuing execution without stepping. Signals a
1638 CONTROL-ERROR if the restart does not exist.")
1640 "Transfers control to the STEP-NEXT restart associated with the
1641 condition, executing the current form without stepping and continuing
1642 stepping with the next form. Signals CONTROL-ERROR is the restart does
1645 "Transfers control to the STEP-INTO restart associated with the
1646 condition, stepping into the current form. Signals a CONTROL-ERROR is
1647 the restart does not exist."))
1649 (/show0
"condition.lisp end of file")