Skip to content

Commit

Permalink
Fix (documentation #'function t)
Browse files Browse the repository at this point in the history
(defun test () "xx" nil)
(setf (documentation 'test 'function) "test")
(list (documentation #'test t) (documentation 'test 'function)))
returned ("xx" "test").
  • Loading branch information
stassats committed Feb 4, 2013
1 parent bcd323c commit 2e52fa0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
5 changes: 4 additions & 1 deletion NEWS
Expand Up @@ -23,13 +23,16 @@ changes relative to sbcl-1.1.4:
SB-DEBUG:BACKTRACE-AS-LIST.
** SB-DEBUG:*SHOW-ENTRY-POINT-DETAILS** has been deprecated, as the same
information is available in less intrusive form as frame annotations.
* enhancement: SB-POSIX now supports provides MAP-ANON.
* enhancement: SB-POSIX now provides MAP-ANON.
* bug fix: no more unused variable style warnings from RESTART-CASE
macroexpansion (lp#1113859)
* bug fix: deleting a package removes it from implementation-package
lists of other packages.
* bug fix: SB-SPROF:WITH-PROFILING is now usable in the Slime REPL on Darwin.
This does not fix the occasional "interrupt already pending" issue, though.
* bug fix: (setf (documentation 'x 'function)) and
(setf (documentation #'x t)) set documentation in different places.
(regression since 1.0.43.63)

changes in sbcl-1.1.4 relative to sbcl-1.1.3:
* optimization: LOOP expressions using "of-type character" have slightly
Expand Down
35 changes: 31 additions & 4 deletions src/pcl/documentation.lisp
Expand Up @@ -18,6 +18,35 @@
(setf (slot-value x '%documentation) new-value)
(setf (%fun-doc x) new-value)))

(defun real-function-name (name)
;; Resolve the actual name of the function named by NAME
;; e.g. (setf (name-function 'x) #'car)
;; (real-function-name 'x) => CAR
(cond ((not (fboundp name))
nil)
((and (symbolp name)
(special-operator-p name))
(%fun-name (fdefinition name)))
((and (symbolp name)
(macro-function name))
(let ((name (%fun-name (macro-function name))))
(and (consp name)
(eq (car name) 'macro-function)
(cadr name))))
(t
(sb-impl::fun-name (fdefinition name)))))

(defun set-function-name-documentation (name documentation)
(cond ((not (legal-fun-name-p name))
nil)
((not (equal (real-function-name name) name))
(setf (random-documentation name 'function) documentation))
(t
(setf (fun-doc (or (and (symbolp name)
(macro-function name))
(fdefinition name)))
documentation))))

;;; functions, macros, and special forms
(defmethod documentation ((x function) (doc-type (eql 't)))
(fun-doc x))
Expand Down Expand Up @@ -62,16 +91,14 @@
(setf (fun-doc x) new-value))

(defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
(when (legal-fun-name-p x)
(setf (random-documentation x 'function) new-value)))
(set-function-name-documentation x new-value))

(defmethod (setf documentation) (new-value (x list) (doc-type (eql 'compiler-macro)))
(awhen (compiler-macro-function x)
(setf (documentation it t) new-value)))

(defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'function)))
(when (legal-fun-name-p x)
(setf (random-documentation x 'function) new-value)))
(set-function-name-documentation x new-value))

(defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'compiler-macro)))
(awhen (compiler-macro-function x)
Expand Down
15 changes: 15 additions & 0 deletions tests/interface.impure.lisp
Expand Up @@ -297,5 +297,20 @@
(assert
(or (member :big-endian *features*)
(member :little-endian *features*))))

(with-test (:name :function-documentation-mismatch)
(defun test ()
"X"
nil)
(setf (symbol-function 'test2) #'test)
(setf (documentation 'test 'function) "Y")
(assert (equal (documentation #'test t)
(documentation 'test 'function)))
(setf (documentation 'test2 'function) "Z")
(assert (not
(equal (documentation 'test 'function)
(documentation 'test2 'function)))))



;;;; success

0 comments on commit 2e52fa0

Please sign in to comment.