summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/cl-generic.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2017-07-26 23:22:58 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2017-07-26 23:22:58 -0400
commit86c862767dbb501d27878efdb9f2664ccdd5cc4e (patch)
tree4081f26632bc31c13e6b03b088e364a097e761c4 /lisp/emacs-lisp/cl-generic.el
parente1e8d2e229f48b3cee765f7cf27ae04ee4401d85 (diff)
downloademacs-86c862767dbb501d27878efdb9f2664ccdd5cc4e.tar.gz
emacs-86c862767dbb501d27878efdb9f2664ccdd5cc4e.tar.bz2
emacs-86c862767dbb501d27878efdb9f2664ccdd5cc4e.zip
* lisp/emacs-lisp/cl-generic.el (cl-generic-define-method):
Record this as the function's definition site if it's the first def.
Diffstat (limited to 'lisp/emacs-lisp/cl-generic.el')
-rw-r--r--lisp/emacs-lisp/cl-generic.el35
1 files changed, 18 insertions, 17 deletions
diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el
index 1d29082c621..114468239a5 100644
--- a/lisp/emacs-lisp/cl-generic.el
+++ b/lisp/emacs-lisp/cl-generic.el
@@ -500,25 +500,26 @@ The set of acceptable TYPEs (also called \"specializers\") is defined
(cons method mt)
;; Keep the ordering; important for methods with :extra qualifiers.
(mapcar (lambda (x) (if (eq x (car me)) method x)) mt)))
- (cl-pushnew `(cl-defmethod . ,(cl--generic-load-hist-format
- (cl--generic-name generic)
- qualifiers specializers))
- current-load-list :test #'equal)
- ;; FIXME: Try to avoid re-constructing a new function if the old one
- ;; is still valid (e.g. still empty method cache)?
- (let ((gfun (cl--generic-make-function generic))
- ;; Prevent `defalias' from recording this as the definition site of
- ;; the generic function.
- current-load-list)
- ;; For aliases, cl--generic-name gives us the actual name.
- (let ((purify-flag
- ;; BEWARE! Don't purify this function definition, since that leads
- ;; to memory corruption if the hash-tables it holds are modified
- ;; (the GC doesn't trace those pointers).
- nil))
+ (let ((sym (cl--generic-name generic))) ; Actual name (for aliases).
+ (unless (symbol-function sym)
+ (defalias sym 'dummy)) ;Record definition into load-history.
+ (cl-pushnew `(cl-defmethod . ,(cl--generic-load-hist-format
+ (cl--generic-name generic)
+ qualifiers specializers))
+ current-load-list :test #'equal)
+ ;; FIXME: Try to avoid re-constructing a new function if the old one
+ ;; is still valid (e.g. still empty method cache)?
+ (let ((gfun (cl--generic-make-function generic))
+ ;; Prevent `defalias' from recording this as the definition site of
+ ;; the generic function.
+ current-load-list
+ ;; BEWARE! Don't purify this function definition, since that leads
+ ;; to memory corruption if the hash-tables it holds are modified
+ ;; (the GC doesn't trace those pointers).
+ (purify-flag nil))
;; But do use `defalias', so that it interacts properly with nadvice,
;; e.g. for tracing/debug-on-entry.
- (defalias (cl--generic-name generic) gfun)))))
+ (defalias sym gfun)))))
(defmacro cl--generic-with-memoization (place &rest code)
(declare (indent 1) (debug t))