unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect
@ 2016-07-13  6:28 Markus Triska
  2018-01-27 21:17 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Triska @ 2016-07-13  6:28 UTC (permalink / raw)
  To: 23963


The manual entry of `unwind-protect' shows an example whose essence is:

    (unwind-protect
        (progn
          (setq process (ftp-...))
          ;; use process
      (delete-process process))

It adds the following important explanation:

    This example has a small [sic] bug: if the user types `C-g' to quit,
    and the quit happens immediately after the function `ftp-...'
    returns but before the variable `process' is set, *the process will
    not be killed*. There is no easy way to fix this bug, but at least
    it is very unlikely.

Would it be good to make such resource leak *impossible* instead? This
seems quite desirable and could be done with a complementing primitive.

Please consider a new primitive `setup-unwind-protect' with 3 arguments:

    1. SETUPFORM, called in such a way that it *cannot be interrupted*
    2. BODYFORM, like in unwind-protect, called after SETUPFORM
    3. UNWINDFORMS, like in unwind-protect

With this primitive, we could write the example above as:

    (setup-unwind-protect
        (setq process (ftp-...))
     (progn
       ;; use process ...
     (delete-process process))

Please consider adding such a construct to Emacs.

A precedence for such a construct is setup_call_cleanup/3 which appears
in the Prolog ISO draft standard and is already included in many systems:

    https://www.complang.tuwien.ac.at/ulrich/iso-prolog/N215

Thank you and all the best!
Markus


In GNU Emacs 25.0.95.4 (x86_64-apple-darwin15.5.0, X toolkit, Xaw scroll bars)
 of 2016-07-05 built on mt-imac
Repository revision: e3b039d1a0e611d6619ed3ce67d125160d644ebc
Windowing system distributor 'The X.Org Foundation', version 11.0.11502000
Configured using:
 'configure --without-ns CFLAGS=-I/opt/local/include
 LDFLAGS=-L/opt/local/lib'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK GSETTINGS NOTIFY ACL GNUTLS
LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix






^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect
  2016-07-13  6:28 bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect Markus Triska
@ 2018-01-27 21:17 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2018-01-27 21:17 UTC (permalink / raw)
  To: Markus Triska; +Cc: 23963

Markus Triska <triska@metalevel.at> writes:

> With this primitive, we could write the example above as:
>
>     (setup-unwind-protect
>         (setq process (ftp-...))
>      (progn
>        ;; use process ...
>      (delete-process process))

Given my dislike of `setq` I'd rather use something else.

This said, we also have another problem: if the user hits C-g twice
in a row, the second may interrupt the `delete-process` itself.

So I think what we "really" want is more like

    (let ((oi inhibit-quit)
          (inhibit-quit t))
      (let ((process (ftp-...)))
         (unwind-protect
             (let ((inhibit-quit oi))
               ..use process..)
           (delete-process process))))

At the same time, any function whose name starts with "ftp-" is likely
a bad candidate for running it in a context where it can't be
interrupted (it's likely that in various circumstances it could hang, in
which case the user should be able to hit C-g).


        Stefan





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-27 21:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-13  6:28 bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect Markus Triska
2018-01-27 21:17 ` Stefan Monnier

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).