0.6.12.23:
[sbcl.git] / tests / interface.pure.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
6 ;;;; from CMU CL.
7 ;;;; 
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
11
12 (in-package :cl-user)
13
14 ;;; Check for fbound external symbols in public packages that have no
15 ;;; argument list information. (This can happen if we get carried away
16 ;;; with byte compilation, since at least in sbcl-0.6.12 the byte
17 ;;; compiler can't record argument list information.)
18 (defvar *public-package-names*
19   '("SB-ALIEN" "SB-C-CALL" "SB-DEBUG" "SB-EXT" "SB-GRAY" "SB-MP"
20     "SB-PROFILE" "SB-PCL" "COMMON-LISP"))
21 (defun has-arglist-info-p (function)
22   (declare (type function function))
23   ;; The Lisp-level type FUNCTION can conceal a multitude of sins..
24   (case (sb-kernel:get-type function)
25     (#.sb-vm:function-header-type (sb-kernel:%function-arglist function))
26     (#.sb-vm:closure-function-header-type (has-arglist-info-p
27                                            (sb-kernel:%closure-function
28                                             function)))
29     ;; (There might be other cases with arglist info also.
30     ;; FUNCTION-HEADER-TYPE and CLOSURE-FUNCTION-HEADER-TYPE just
31     ;; happen to be the two case that I had my nose rubbed in when
32     ;; debugging a GC problem caused by applying %FUNCTION-ARGLIST to
33     ;; a closure. -- WHN 2001-06-05)
34     (t nil)))
35 (defun check-ext-symbols-arglist (package)
36   (format t "~% looking at package: ~A" package)
37   (do-external-symbols (ext-sym package)
38     (when (fboundp ext-sym)
39       (let ((fun (symbol-function ext-sym)))
40         (cond ((macro-function ext-sym)
41                ;; FIXME: Macro functions should have their argument list
42                ;; information checked separately. Just feeding them into
43                ;; the ordinary-function logic below doesn't work right,
44                ;; though, and I haven't figured out what does work
45                ;; right. For now we just punt.
46                (values))
47               #+nil 
48               ((sb-int:info :function :accessor-for ext-sym)
49                (values))
50               ((typep fun 'generic-function)
51                ;; FIXME: Check the argument lists of generic functions,
52                ;; instead of just punting like this. (DESCRIBE seems
53                ;; to know how to do it, at least for #'DOCUMENTATION.)
54                (values))
55               (;; FIXME: CONDITION slot accessors (e.g.
56                ;; PRINT-NOT-READABLE-OBJECT) fall into this category.
57                ;; They seem to have argument lists -- since at least
58                ;; DESCRIBE knows how to find them -- but I have
59                ;; neither reverse engineered how it's finding them,
60                ;; nor factored that into a function which can be
61                ;; shared with the logic here..
62                (= (sb-kernel:get-type fun) sb-vm:closure-header-type)
63                (values)) ; ..so for now we just punt.
64               (t
65                (let ((fun (symbol-function ext-sym)))
66                  (unless (has-arglist-info-p fun)
67                    (error "Function ~A has no arg-list information available."
68                           ext-sym)))))))))
69 (dolist (public-package *public-package-names*)
70   (when (find-package public-package)
71     (check-ext-symbols-arglist public-package)))
72 (terpri)
73
74 ;;; FIXME: It would probably be good to require here that every
75 ;;; external symbol either has a doc string or has some good excuse
76 ;;; (like being an accessor for a structure which has a doc string).
77
78 (print "done with interface.pure.lisp")
79