1.0.29.51: correctly compute default initargs for FAST-MAKE-INSTANCE
[sbcl.git] / contrib / sb-introspect / test-driver.lisp
index 8762f2b..c38d9f5 100644 (file)
@@ -7,12 +7,12 @@
 (with-compilation-unit (:source-plist (list :test-outer "OUT"))
   (load (compile-file (merge-pathnames "test.lisp" *load-pathname*))))
 
-(assert (equal (function-arglist 'cl-user::one)
+(assert (equal (function-lambda-list 'cl-user::one)
                '(cl-user::a cl-user::b cl-user::c)))
-(assert (equal (function-arglist 'the)
+(assert (equal (function-lambda-list 'the)
                '(sb-c::value-type sb-c::form)))
 
-(assert (equal (function-arglist #'(sb-pcl::slow-method cl-user::j (t)))
+(assert (equal (function-lambda-list #'(sb-pcl::slow-method cl-user::j (t)))
                '(sb-pcl::method-args sb-pcl::next-methods)))
 
 (let ((source (find-definition-source #'cl-user::one)))
 (assert (matchp-name :method-combination 'cl-user::r 26))
 (assert (matchp-name :setf-expander 'cl-user::s 27))
 
+(let ((fin (make-instance 'sb-mop:funcallable-standard-object)))
+  (sb-mop:set-funcallable-instance-function fin #'cl-user::one)
+  (assert (matchp fin 2)))
+
 (sb-profile:profile cl-user::one)
 (assert (matchp-name :function 'cl-user::one 2))
 (sb-profile:unprofile cl-user::one)
 
 
-;;;; Check correctness of FUNCTION-ARGLIST.
+;;;; Check correctness of FUNCTION-LAMBDA-LIST.
 
-(assert (equal (function-arglist 'cl-user::one)
+(assert (equal (function-lambda-list 'cl-user::one)
                '(cl-user::a cl-user::b cl-user::c)))
-(assert (equal (function-arglist 'the)
+(assert (equal (function-lambda-list 'the)
                '(sb-c::value-type sb-c::form)))
 
 ;;; Check wrt. interplay of generic functions and their methods.
 ;;
 (multiple-value-bind (required optional restp rest keyp keys allowp
                       auxp aux morep more-context more-count)
-    (sb-int:parse-lambda-list (function-arglist #'xuuq))
+    (sb-int:parse-lambda-list (function-lambda-list #'xuuq))
   (assert (equal required '(gf.a gf.b)))
   (assert (null optional))
   (assert (and restp (eql rest 'gf.rest)))
 (defmethod kroolz (r1 r2 &optional opt &aux aux)
   (declare (ignore r1 r2 opt aux))
   'kroolz)
-(assert (equal (function-arglist #'kroolz) '(r1 r2 &optional opt)))
+(assert (equal (function-lambda-list #'kroolz) '(r1 r2 &optional opt)))
 
 ;;;; Test finding a type that isn't one
 (assert (not (find-definition-sources-by-name 'fboundp :type)))
 
 (load (merge-pathnames "xref-test.lisp" *load-pathname*))
 
+;;; Test allocation-information
+
+(defun tai (x kind info)
+  (multiple-value-bind (kind2 info2) (sb-introspect:allocation-information x)
+    (unless (eq kind kind2)
+      (error "wanted ~S, got ~S" kind kind2))
+    (assert (equal info info2))))
+
+(tai nil :heap '(:space :static))
+(tai t :heap '(:space :static))
+(tai 42 :immediate nil)
+(tai #'cons :heap
+     #+(and (not ppc) gencgc)
+     ;; FIXME: This is the canonical GENCGC result, the one below for PPC is
+     ;; what we get there, but :LARGE T doesn't seem right. Figure out what's
+     ;; going on.
+     '(:space :dynamic :generation 6 :write-protected t :pinned nil :large nil)
+     #+(and ppc gencgc)
+     '(:space :dynamic :generation 6 :write-protected t :pinned nil :large t)
+     ;; FIXME: Figure out what's the right cheney-result, and which platforms
+     ;; return something else. The SPARC version here is what we get there,
+     ;; but quite possibly that is the result on all non-GENCGC platforms.
+     #+(and sparc (not gencgc))
+     '(:space :read-only)
+     #+(and (not sparc) (not gencgc))
+     '(:space :dynamic))
+#+sb-thread
+(let ((x (list 1 2 3)))
+  (declare (dynamic-extent x))
+  (tai x :stack sb-thread:*current-thread*))
+#+sb-thread
+(progn
+  (defun thread-tai ()
+    (let ((x (list 1 2 3)))
+      (declare (dynamic-extent x))
+      (let ((child (sb-thread:make-thread
+                    (lambda ()
+                      (sb-introspect:allocation-information x)))))
+        (assert (equal (list :stack sb-thread:*current-thread*)
+                       (multiple-value-list (sb-thread:join-thread child)))))))
+  (thread-tai)
+  (defun thread-tai2 ()
+    (let* ((sem (sb-thread:make-semaphore))
+           (obj nil)
+           (child (sb-thread:make-thread
+                   (lambda ()
+                     (let ((x (list 1 2 3)))
+                       (declare (dynamic-extent x))
+                       (setf obj x)
+                       (sb-thread:wait-on-semaphore sem)))
+                   :name "child")))
+      (loop until obj)
+      (assert (equal (list :stack child)
+                     (multiple-value-list
+                      (sb-introspect:allocation-information obj))))
+      (sb-thread:signal-semaphore sem)
+      (sb-thread:join-thread child)
+      nil))
+  (thread-tai2))
+
 ;;;; Unix success convention for exit codes
 (sb-ext:quit :unix-status 0)
+