X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/47f01a8af9660c018cafa3a97632c8bcb2417cec..ba03d0d932888f687ae9c9fb12e20908c6b0620f:/lisp/emacs-lisp/advice.el diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el index b99e614bec..a947dceccc 100644 --- a/lisp/emacs-lisp/advice.el +++ b/lisp/emacs-lisp/advice.el @@ -2239,16 +2239,15 @@ definition (see the code for `documentation')." (defun ad-definition-type (definition) "Return symbol that describes the type of DEFINITION." + ;; These symbols are only ever used to check a cache entry's validity. + ;; The suffix `2' reflects the fact that we're using version 2 of advice + ;; representations, so cache entries preactivated with version + ;; 1 can't be used. (cond - ((ad-macro-p definition) 'macro) - ((ad-subr-p definition) - (if (special-form-p definition) - 'special-form - 'subr)) - ((or (ad-lambda-p definition) - (ad-compiled-p definition)) - 'function) - ((ad-advice-p definition) 'advice))) + ((ad-macro-p definition) 'macro2) + ((ad-subr-p definition) 'subr2) + ((or (ad-lambda-p definition) (ad-compiled-p definition)) 'fun2) + ((ad-advice-p definition) 'advice2))) ;; FIXME: Can this ever happen? (defun ad-has-proper-definition (function) "True if FUNCTION is a symbol with a proper definition. @@ -2597,7 +2596,9 @@ in any of these classes." (ad-has-redefining-advice function)) (let* ((origdef (ad-real-orig-definition function)) ;; Construct the individual pieces that we need for assembly: - (orig-arglist (and origdef (ad-arglist origdef))) + (orig-arglist (let ((args (ad-arglist origdef))) + ;; The arglist may still be unknown. + (if (listp args) args '(&rest args)))) (advised-arglist (or (ad-advised-arglist function) orig-arglist)) (interactive-form (ad-advised-interactive-form function)) @@ -2899,19 +2900,18 @@ If COMPILE is non-nil and not a negative number then it returns t. If COMPILE is a negative number then it returns nil. If COMPILE is nil then the result depends on the value of `ad-default-compilation-action' (which see)." - (if (integerp compile) - (>= compile 0) - (if compile - compile - (cond ((eq ad-default-compilation-action 'never) - nil) - ((eq ad-default-compilation-action 'always) - t) - ((eq ad-default-compilation-action 'like-original) - (or (ad-subr-p (ad-get-orig-definition function)) - (ad-compiled-p (ad-get-orig-definition function)))) - ;; everything else means `maybe': - (t (featurep 'byte-compile)))))) + (cond + ;; Don't compile until the real function definition is known (bug#12965). + ((not (ad-real-orig-definition function)) nil) + ((integerp compile) (>= compile 0)) + (compile) + ((eq ad-default-compilation-action 'never) nil) + ((eq ad-default-compilation-action 'always) t) + ((eq ad-default-compilation-action 'like-original) + (or (ad-subr-p (ad-get-orig-definition function)) + (ad-compiled-p (ad-get-orig-definition function)))) + ;; everything else means `maybe': + (t (featurep 'byte-compile)))) (defun ad-activate-advised-definition (function compile) "Redefine FUNCTION with its advised definition from cache or scratch. @@ -2926,7 +2926,7 @@ The current definition and its cache-id will be put into the cache." (ad-make-advised-definition function))) (advice-add function :around advicefunname) (if (ad-should-compile function compile) - (byte-compile advicefunname)) + (ad-compile-function function)) (if verified-cached-definition (if (not (eq verified-cached-definition (symbol-function advicefunname))) @@ -3002,20 +3002,20 @@ definition will always be cached for later usage." (interactive (list (ad-read-advised-function "Activate advice of") current-prefix-arg)) - (if (not (ad-is-advised function)) - (error "ad-activate: `%s' is not advised" function) - ;; Just return for forward advised and not yet defined functions: - (if (ad-get-orig-definition function) - (if (not (ad-has-any-advice function)) - (ad-unadvise function) - ;; Otherwise activate the advice: - (cond ((ad-has-redefining-advice function) - (ad-activate-advised-definition function compile) - (ad-set-advice-info-field function 'active t) - (eval (ad-make-hook-form function 'activation)) - function) - ;; Here we are if we have all disabled advices: - (t (ad-deactivate function))))))) + (cond + ((not (ad-is-advised function)) + (error "ad-activate: `%s' is not advised" function)) + ;; Just return for forward advised and not yet defined functions: + ((not (ad-get-orig-definition function)) nil) + ((not (ad-has-any-advice function)) (ad-unadvise function)) + ;; Otherwise activate the advice: + ((ad-has-redefining-advice function) + (ad-activate-advised-definition function compile) + (ad-set-advice-info-field function 'active t) + (eval (ad-make-hook-form function 'activation)) + function) + ;; Here we are if we have all disabled advices: + (t (ad-deactivate function)))) (defalias 'ad-activate-on 'ad-activate)