emacs-devel
[Top][All Lists]
Advanced

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

Re: Calling Lisp in C functions


From: Yuan Fu
Subject: Re: Calling Lisp in C functions
Date: Wed, 22 Sep 2021 20:59:00 -0700


> On Sep 21, 2021, at 10:45 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Tue, 21 Sep 2021 12:38:21 -0700
>> 
>> What’s the best way to evaluate Lisp or call a Lisp function that could 
>> signal in a C function and then free allocated memory? I assume that I can’t 
>> just call the Lisp function and hope it doesn’t signal.
> 
> You want to catch the errors in Lisp that you call from C?  If so, use
> the safe_call functions we already have.
> 
> If all you want is make sure memory will be allocated, but don't mind
> if the signal thrown by Lisp gets back to command loop, use
> record_unwind_protect to register a function which will release the
> memory.

Thanks, I still don’t know how does stack works so here’s some naive questions:

I tried to write

ptrdiff_t count = SPECPDL_INDEX ();
record_unwind_protect_ptr (ts_delete_cursor, cursor);
...
return unbind_to (count, xxx);

But it give a type error, because ts_delete_cursor doesn’t take a void*. I 
guess I need to define a wrapper function to avoid that error? Can I use 
record_unwind_protect_ptr more than once? What does that count mean? What is 
specpdl?

Yuan


reply via email to

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