unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Catch arbitrary signal and throw it later in C
Date: Thu, 13 Apr 2023 00:24:18 -0700	[thread overview]
Message-ID: <DC7475BC-0ECD-40C2-B4B5-2E638315BFAC@gmail.com> (raw)

Say I have an arbitrary Lisp function func, and need to evaluate it in C. But after evaluating the function, I need to do some clean up (freeing something). Would be be possible to catch any signal thrown by evaluating the function func, and throw it after cleaning up?

I’m aware of safe_call and internal_condition_case_n. In particular, what I described can probably be implemented with internal_condition_case_n with a handler. But I wonder if there are better/existing ways to do this?

The real scenarios is this: treesit-search-forward and friends takes a PRED argument, which can be either a regexp string or a predicate function. In the meantime, treesit-search-forward and friends need to clean up a tree-sitter cursor object before they return. So if this predicate function signals in the middle of treesit-search-forward, the tree-sitter cursor would be leaked. I can slap on a safe_call when evaluating the predicate function, but I think throwing the signal would be more user-friendly. (Plus safe_call will say “An error occurred during redisplay”, which isn’t necessarily true)

Yuan





             reply	other threads:[~2023-04-13  7:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13  7:24 Yuan Fu [this message]
2023-04-13  7:33 ` Catch arbitrary signal and throw it later in C Ruijie Yu via Emacs development discussions.
2023-04-13  8:12   ` Yuan Fu
2023-04-13  8:20     ` Eli Zaretskii
2023-04-13  8:22     ` Po Lu
2023-04-13 22:18       ` Yuan Fu
2023-04-13 23:48         ` Po Lu
2023-04-13  8:24     ` Andreas Schwab

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=DC7475BC-0ECD-40C2-B4B5-2E638315BFAC@gmail.com \
    --to=casouri@gmail.com \
    --cc=emacs-devel@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).