unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmail.com>
To: 33034@debbugs.gnu.org
Subject: bug#33034: `unwind-protect' cleanup form is not executed if body dies in stack overflow
Date: Sat, 13 Oct 2018 12:07:48 +0200	[thread overview]
Message-ID: <CAG7BparyujS9CKTv54N-brS_KMu5H=XY3KjhQoS3nRD_rZ-L9A@mail.gmail.com> (raw)

To reproduce:

    (defun overflow ()
      (overflow))
    (defun test ()
      (interactive)
      (message "BEFORE")
      (unwind-protect
          (overflow)
        (message "CLEANUP")))

Invocation of `test' never issues message "CLEANUP", whether it is run
interactively or non-interactively.

By comparison, if you _catch_ the error with `condition-case':

    (defun test-2 ()
      (interactive)
      (message "BEFORE")
      (unwind-protect
          (ignore-errors (overflow))
        (message "CLEANUP")))

then cleanup form is executed properly.

But if your error catcher is "above" the `unwind-protect' form, the
cleanup is not executed again, even though the error is eaten as
expected:

    (defun test-3 ()
      (interactive)
      (message "BEFORE")
      (ignore-errors
        (unwind-protect
            (overflow)
          (message "CLEANUP"))))

This is a perfect way to screw up your Emacs permanently (until full
restart): when some `unwind-protect' cleanups are not run, you can be
left with unexpected function advices, permanently altered global
state etc., without any good way to undestand what's wrong.

Paul





             reply	other threads:[~2018-10-13 10:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-13 10:07 Paul Pogonyshev [this message]
2018-10-13 10:29 ` bug#33034: `unwind-protect' cleanup form is not executed if body dies in stack overflow Eli Zaretskii
2018-10-13 10:35   ` Paul Pogonyshev
2018-10-13 10:45     ` Eli Zaretskii
2018-10-13 10:52       ` Paul Pogonyshev
2018-10-13 11:01         ` Eli Zaretskii
2018-10-13 11:29           ` Eli Zaretskii
2018-10-13 11:38             ` Paul Pogonyshev
2018-10-13 12:35               ` Eli Zaretskii
2018-10-13 14:02                 ` Paul Pogonyshev
2018-10-14 17:02 ` Paul Eggert

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG7BparyujS9CKTv54N-brS_KMu5H=XY3KjhQoS3nRD_rZ-L9A@mail.gmail.com' \
    --to=pogonyshev@gmail.com \
    --cc=33034@debbugs.gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).