emacs-devel
[Top][All Lists]
Advanced

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

Re: please help concerning specpdl


From: Alin Soare
Subject: Re: please help concerning specpdl
Date: Tue, 14 Dec 2010 23:25:41 +0200


> count = SPECPDL_INDEX ();
> record_unwind_protect
> val = Fprogn (args);
> return unbind_to (count, val);

> Can you explain me the logic of specpdl please ?

The specpdl contains information needed to remove variable bindings and
provide other services that are guaranteed even in the case of abnormal
exit.  Abnormal exits operate by calling longjmp(3), so there's no
guaranteed chance to perform cleanup in the normal flow of execution.  But
the function that calls longjmp(3) (`unwind_to_catch') first peruses the
specpdl and handles its elements appropriately, so the guaranteed
operations happen.  The actual unwinding is done by `unbind_to', so if the
body exits normally, we just call that to perform the unwinding operations
without longjmp(3).

I think I understand the analogy with longjmp. It is a stack of Lisp Objects, and this stack is used by C code to protect against errors in lisp interpreter.

The variables defined by let are memorized in this stack using SAFE_ALLOCA.

Why let-binding-variables are memorized exactly here and not elsewhere ?

On the other hand, the macro SAFE_ALLOCA is defined as

do{
}while (0)

why the do-while is good in this case, and not simply brackets?



So: the count identifies how far to unwind in case of normal exit (in case
of abnormal exit, we'll unwind farther anyway, so we don't need `count').
The `record_unwind_protect' registers something to do at unwind-time, and
then `unbind_to' performs it unless `unwind_to_catch' does.  `val' is
passed to `unbind_to' for GC reasons, I believe.

I see that inside unbind_to, the symbols are unbounded 1 by one. Why the
specpdl_ptr is not decremented directly with count ?

while (specpdl_ptr != specpdl + count)

Probably because unbind_to is called from lisp code by (throw 'symbol value), and specpdl_ptr must decrement 1 by 1 until the 'symbol is dound on the stack ?

Apart from (throw ... ), is which other situation unbind_to is called ?

 
I see that GCPROx macros are used to protect the variables of type Lisp Object on the stack of C code (that the compiler creates), not to protect the lisp objects in specpdl. The GCPRO protection is against the algorthm of conservative stack. Am I right ?


Sorry, I think I understand something, but I am far from enough.


Alin.






reply via email to

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