From: Alan Mackenzie <acm@muc.de>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: Michael Heerdegen <michael_heerdegen@web.de>,
acm@muc.de, 65620@debbugs.gnu.org
Subject: bug#65620: void function edebug-after
Date: Fri, 1 Sep 2023 21:27:12 +0000 [thread overview]
Message-ID: <ZPJXMHC2WRZ-oDyS@ACM> (raw)
In-Reply-To: <f9e1bdd9-c5b0-e58f-ce63-8c4bd3830333@gmail.com>
Hello, Gerd.
On Fri, Sep 01, 2023 at 14:27:42 +0200, Gerd Möllmann wrote:
> On 01.09.23 11:23, Alan Mackenzie wrote:
> > I think a better way of handling this would be to have a "base function"
> > for edebug-after (and for edebug-before), as opposed to the nil that each
> > of these currently has. These functions would throw an error asking the
> > user to check the edebug spec. Something like (untested):
> >
> > (defun edebug-after (before-index after-index form)
> > "Version of `edebug-after' to call when edebug is not yet set up.
> > This function gets temporarily replaced by a real function when
> > edebug becomes active."
> > (error "Invalid call to `edebug-after' for %S: Is your debug spec \
> > correct?" form))
> >
> > .. What do you think?
> I find that an excellent idea! The error "void function edebug-after"
> might indeed be considered a bit unhelpful by some :-). Haven't tested
> anything either, though...
Here's a working patch with a slight improvement: the error message
identifies the macro suspected of having an erroneous edebug spec.
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 9a06807bcdc..a6153d599ac 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -2469,12 +2469,50 @@ edebug-run-fast
(setf (cdr (assq 'edebug edebug-behavior-alist))
'(edebug-default-enter edebug-fast-before edebug-fast-after)))
-(defalias 'edebug-before nil
+;; The following versions of `edebug-before' and `edebug-after' exist
+;; to handle the error which occurs if either of them gets called
+;; without an enclosing `edebug-enter'. This can happen, for example,
+;; when a macro mistakenly has a `form' element in its edebug spec,
+;; and it additionally, at macro-expansion time, calls `eval',
+;; `apply', or `funcall' (etc.) on the corresponding argument. This
+;; is intended to fix bug#65620.
+
+(defun edebug-b/a-error (func)
+ "Throw an error for an invalid call of FUNC.
+FUNC is expected to be `edebug-before' or `edebug-after'."
+ (let (this-macro
+ (n 0)
+ bt-frame)
+ (while (and (setq bt-frame (backtrace-frame n))
+ (not (and (car bt-frame)
+ (eq (cadr bt-frame) 'macroexpand-1))))
+ (setq n (1+ n)))
+ (when bt-frame
+ (setq this-macro (caaddr bt-frame)))
+
+ (error
+ (concat "Invalid call to `" (symbol-name func) "'"
+ (if this-macro
+ (concat ". Is the edebug spec for `"
+ (symbol-name this-macro)
+ "' correct?")
+ "")))))
+
+(defun edebug-before (_before-index)
"Function called by Edebug before a form is evaluated.
-See `edebug-behavior-alist' for implementations.")
-(defalias 'edebug-after nil
+See `edebug-behavior-alist' for other implementations. This
+version of `edebug-before' gets called when edebug is not yet set
+up. `edebug-enter' binds the function cell to a real function
+when edebug becomes active."
+ (edebug-b/a-error 'edebug-before))
+
+(defun edebug-after (_before-index _after-index _form)
"Function called by Edebug after a form is evaluated.
-See `edebug-behavior-alist' for implementations.")
+See `edebug-behavior-alist' for other implementations. This
+version of `edebug-after' gets called when edebug is not yet set
+up. `edebug-enter' binds the function cell to a real function
+when edebug becomes active."
+ (edebug-b/a-error 'edebug-after))
(defun edebug--update-coverage (after-index value)
(let ((old-result (aref edebug-coverage after-index)))
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2023-09-01 21:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 12:57 bug#65620: void function edebug-after Alan Mackenzie
2023-08-30 23:09 ` Michael Heerdegen
2023-08-31 7:55 ` Gerd Möllmann
2023-08-31 8:02 ` Gerd Möllmann
2023-08-31 13:50 ` Alan Mackenzie
2023-08-31 14:41 ` Gerd Möllmann
2023-09-01 9:23 ` Alan Mackenzie
2023-09-01 12:27 ` Gerd Möllmann
2023-09-01 21:27 ` Alan Mackenzie [this message]
2023-09-02 4:27 ` Gerd Möllmann
2023-09-02 13:10 ` Alan Mackenzie
2023-09-02 13:15 ` Gerd Möllmann
2023-09-02 13:57 ` Alan Mackenzie
2023-09-03 4:29 ` 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=ZPJXMHC2WRZ-oDyS@ACM \
--to=acm@muc.de \
--cc=65620@debbugs.gnu.org \
--cc=gerd.moellmann@gmail.com \
--cc=michael_heerdegen@web.de \
/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.