1.0.32.20: bug fixes in unibyte external formats
[sbcl.git] / src / code / fdefinition.lisp
index f4bd831..0dd857c 100644 (file)
 
 ;;; This is like FIND-IF, except that we do it on a compiled closure's
 ;;; environment.
-(defun find-if-in-closure (test fun)
-  (declare (type function test))
-  (dotimes (index (1- (get-closure-length fun)))
-    (let ((elt (%closure-index-ref fun index)))
-      (when (funcall test elt)
-        (return elt)))))
+(defun find-if-in-closure (test closure)
+  (declare (closure closure))
+  (do-closure-values (value closure)
+    (when (funcall test value)
+      (return value))))
 
 ;;; Find the encapsulation info that has been closed over.
 (defun encapsulation-info (fun)
-  (and (functionp fun)
-       (= (widetag-of fun) sb!vm:closure-header-widetag)
-       (find-if-in-closure #'encapsulation-info-p fun)))
+  (when (closurep fun)
+    (find-if-in-closure #'encapsulation-info-p fun)))
 
 ;;; When removing an encapsulation, we must remember that
 ;;; encapsulating definitions close over a reference to the
   "Set NAME's global function definition."
   (declare (type function new-value) (optimize (safety 1)))
   (with-single-package-locked-error (:symbol name "setting fdefinition of ~A")
+
+    ;; Check for hash-table stuff. Woe onto him that mixes encapsulation
+    ;; with this.
+    (when (and (symbolp name) (fboundp name)
+               (boundp '*user-hash-table-tests*))
+      (let ((old (symbol-function name)))
+        (declare (special *user-hash-table-tests*))
+        (dolist (spec *user-hash-table-tests*)
+          (cond ((eq old (second spec))
+                 ;; test-function
+                 (setf (second spec) new-value))
+                ((eq old (third spec))
+                 ;; hash-function
+                 (setf (third spec) new-value))))))
+
+    ;; FIXME: This is a good hook to have, but we should probably
+    ;; reserve it for users.
     (let ((fdefn (fdefinition-object name t)))
       ;; *SETF-FDEFINITION-HOOK* won't be bound when initially running
       ;; top level forms in the kernel core startup.