help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is this a bug?


From: Tassilo Horn
Subject: Re: Is this a bug?
Date: Tue, 03 Dec 2013 09:46:19 +0100
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

Perry Smith <address@hidden> writes:

Hi Perry,

> Now the non-working case.  Repeat the above after adding advice:
>
> (defadvice load (before load-log activate)
>   (message "Loading %s" (ad-get-arg 0)))
>
> and I get an error with the stack:
>
> Debugger entered--Lisp error: (wrong-type-argument subrp (lambda (file
> &optional noerror nomessage n$
>   subr-name((lambda (file &optional noerror nomessage nosuffix must-suffix)

It seems like a bug in 24.3 since your example now works with the
current bzr trunk.  Nevertheless, the docs explicitly warn about
advising subrs like `load':

,----[ (info "(elisp)Advising Functions") ]
|    Unless you know what you are doing, do _not_ advise a primitive
| (*note What Is a Function::).  Some primitives are used by the advice
| mechanism; advising them could cause an infinite recursion.  Also, many
| primitives are called directly from C code.  Calls to the primitive from
| Lisp code will take note of the advice, but calls from C code will
| ignore the advice.
`----

The concrete problem is that `help-C-file-name' assumes that a function
defined in C is a subr.  But when you add a piece of advice, the subr
is wrapped in a lisp function, and then `subr-name' fails.

--8<---------------cut here---------------start------------->8---
ELISP> (symbol-function 'load)
#<subr load>
ELISP> (defadvice load (before load-log activate)
  (message "Loading %s" (ad-get-arg 0)))
load
ELISP> (symbol-function 'load)
#[128 "\300\301\302.#\207"
      [apply ad-Advice-load #<subr load> nil]
      5
      #("Advised function" 0 16
        (dynamic-docstring-function advice--make-docstring))]
--8<---------------cut here---------------end--------------->8---

After defining the advice with the current bzr version, the help buffer
states "load is a compiled Lisp function" without any file link.  That's
better than an error, but still not perfect.  One could get the original
subr with (ad-get-orig-definition 'load) to also include a link to the C
source.

I just checked: with emacs 23, when you advised load or any other subr,
C-h f still had a link to the C source, so IMHO that counts as a
regression.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]