all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
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: Sun, 17 Nov 2019 13:55:16 +0100	[thread overview]
Message-ID: <87o8xaoe6j.fsf@web.de> (raw)
In-Reply-To: <87eey9z1mr.fsf@web.de> (Michael Heerdegen's message of "Fri, 15 Nov 2019 14:54:04 +0100")

[-- Attachment #1: Type: text/plain, Size: 303 bytes --]

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Hello again,
>
> I'm preparing a new patch with less quirks.

New patch: not much different but hopefully better understandable now.
I also added a comment about why we are allowed to just strip advises.
Also did some testing - seems to work ok.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP-Try-to-fix-edebug-remove-instrumentation-for-adv.patch --]
[-- Type: text/x-diff, Size: 2834 bytes --]

From 29380dcd30523e057d8fd45106f1d077e4212198 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Thu, 14 Nov 2019 17:47:51 +0100
Subject: [PATCH] WIP: Try to fix edebug-remove-instrumentation for advised
 funs

---
 lisp/emacs-lisp/edebug.el | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 5d52704410..e0fcdf0f86 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -4571,6 +4571,23 @@ edebug-unload-function
   ;; Continue standard unloading.
   nil)

+(defun edebug--unwrap*-symbol-function (symbol)
+  ;; Try to unwrap SYMBOL's symbol function.  The result is suitable
+  ;; to be fbound to SYMBOL with `defalias'.  When no unwrapping could
+  ;; be done return nil.
+  (pcase (symbol-function symbol)
+    ((or (and `(macro . ,(and (pred advice--p) ad)) (let was-macro t))
+         (and (pred advice--p) ad                   (let was-macro nil)))
+     ;; `defalias' takes care of any advises so we can just strip them
+     (let* ((orig-f (advice--cd*r ad))
+            (unwrapped (edebug-unwrap* orig-f)))
+       (cond
+        ((equal unwrapped orig-f) nil)
+        (was-macro               `(macro . ,unwrapped))
+        (t                       unwrapped))))
+    (sym-fun (let ((unwrapped (edebug-unwrap* sym-fun)))
+               (if (equal sym-fun unwrapped) nil unwrapped)))))
+
 (defun edebug-remove-instrumentation (functions)
   "Remove Edebug instrumentation from FUNCTIONS.
 Interactively, the user is prompted for the function to remove
@@ -4582,10 +4599,10 @@ edebug-remove-instrumentation
        (lambda (symbol)
          (when (and (get symbol 'edebug)
                     (or (functionp symbol)
-                        (macrop symbol)))
-           (let ((unwrapped (edebug-unwrap* (symbol-function symbol))))
-             (unless (equal unwrapped (symbol-function symbol))
-               (push symbol functions)))))
+                        (macrop symbol))
+                    (edebug--unwrap*-symbol-function
+                     symbol))
+           (push symbol functions)))
        obarray)
       (unless functions
         (error "Found no functions to remove instrumentation from"))
@@ -4599,8 +4616,9 @@ edebug-remove-instrumentation
           functions)))))
   ;; Remove instrumentation.
   (dolist (symbol functions)
-    (setf (symbol-function symbol)
-          (edebug-unwrap* (symbol-function symbol))))
+    (when-let ((unwrapped
+                (edebug--unwrap*-symbol-function symbol)))
+      (defalias symbol unwrapped)))
   (message "Removed edebug instrumentation from %s"
            (mapconcat #'symbol-name functions ", ")))

--
2.24.0


[-- Attachment #3: Type: text/plain, Size: 20 bytes --]



Thanks,

Michael.

  parent reply	other threads:[~2019-11-17 12:55 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
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 [this message]
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=87o8xaoe6j.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.