[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Catch arbitrary signal and throw it later in C

From: Yuan Fu
Subject: Catch arbitrary signal and throw it later in C
Date: Thu, 13 Apr 2023 00:24:18 -0700

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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]