From: Michael Heerdegen <michael_heerdegen@web.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 38195@debbugs.gnu.org
Subject: bug#38195: 27.0.50; `edebug-remove-instrumentation' doesn't work for adviced functions
Date: Thu, 14 Nov 2019 21:27:18 +0100 [thread overview]
Message-ID: <87imnm4315.fsf@web.de> (raw)
In-Reply-To: <jwva78y70fq.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 14 Nov 2019 14:08:24 -0500")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > +(defun edebug--advised-p (symbol)
> > + ;; Non-nil when SYMBOL's `symbol-function' is advised. The non-nil
> > + ;; return value is the unwrapped base function if it was wrapped,
> > + ;; and the symbol t else.
>
> Do you really mean "advised"? It seems that this tests whether the code
> is *instrumented* by looking past the (potential) pieces of advice.
It tests both - sorry, a bit ugly - for the sake of fitting into the
existing code. As a predicate it tests whether the thing is advised,
and the return value is the unwrapped original function when it can be
unwrapped, or t if it can't.
> > + (pcase (symbol-function symbol)
> > + ((and (pred advice--p)
> > + (app advice--cd*r orig-f)
> > + (let unwrapped (edebug-unwrap* orig-f)))
> > + (if (equal unwrapped orig-f) t unwrapped))
> > + (`(macro . ,(and (pred advice--p)
> > + (app advice--cd*r orig-f)
> > + (let unwrapped (edebug-unwrap* orig-f))))
> > + (if (equal unwrapped orig-f) t `(macro . ,unwrapped)))))
>
> [ That's pretty ugly. I think I'd move the `app` and the `let` outside
> of those patterns and into the code of the corresponding branch. ]
Hmm, that's what I had first, and I find this better...I guess nobody
else does, so I'll do what you suggest.
> > ;; Remove instrumentation.
> > (dolist (symbol functions)
> > - (setf (symbol-function symbol)
> > - (edebug-unwrap* (symbol-function symbol))))
> > + (if-let ((advised (edebug--advised-p symbol)))
> > + (unless (eq advised t)
> > + (funcall (or (get symbol 'defalias-fset-function) #'fset)
> > + symbol advised))
> > + (setf (symbol-function symbol)
> > + (edebug-unwrap* (symbol-function symbol)))))
>
> Yuck!
>
> Can't we just use `defalias` rather than `fset` (and that should
> take care of calling `defalias-fset-function` when needed)?
That's what I want to know too! I guess we can, but I thought defalias
would change the source file association as a side effect?
> That's because if I have `foo` as an alias for `bar` and I advise `foo`
> I don't want it to affect `bar`: if you want to affect both, then you
> should advise `bar`.
I hoped it would be like that. So after advising `foo` the
`symbol-function' of `foo` is no longer a symbol, so there is no need to
call `indirect-function' in my change. That wasn't clear to me.
Michael.
next prev parent reply other threads:[~2019-11-14 20:27 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-13 13:55 bug#38195: 27.0.50; `edebug-remove-instrumentation' doesn't work for adviced functions Michael Heerdegen
2019-11-14 5:20 ` Lars Ingebrigtsen
2019-11-14 16:51 ` Michael Heerdegen
2019-11-14 22:39 ` Michael Heerdegen
2019-11-15 7:57 ` Lars Ingebrigtsen
2019-11-15 12:39 ` Michael Heerdegen
2019-11-16 4:28 ` Lars Ingebrigtsen
2019-11-16 12:25 ` Michael Heerdegen
2019-11-14 16:55 ` Michael Heerdegen
2019-11-14 19:08 ` Stefan Monnier
2019-11-14 20:27 ` Michael Heerdegen [this message]
2019-11-14 21:33 ` Stefan Monnier
2019-11-15 13:54 ` Michael Heerdegen
2019-11-15 17:30 ` Stefan Monnier
2019-11-17 12:35 ` Michael Heerdegen
2019-11-17 12:55 ` Michael Heerdegen
2019-11-17 16:04 ` Stefan Monnier
2019-11-21 11:49 ` Michael Heerdegen
2019-11-23 13:32 ` Michael Heerdegen
2019-11-26 21:01 ` Michael Heerdegen
2019-11-27 12:17 ` Lars Ingebrigtsen
2020-09-20 10:54 ` Lars Ingebrigtsen
2019-11-14 21:15 ` Michael Heerdegen
2019-11-15 8:03 ` Lars Ingebrigtsen
2019-11-15 12:11 ` Michael Heerdegen
2019-11-15 12:15 ` Lars Ingebrigtsen
2019-11-15 12:34 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87imnm4315.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=38195@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.