From: Alin Soare <as1789@gmail.com>
To: herring@lanl.gov
Cc: Emacs Dev <emacs-devel@gnu.org>
Subject: Re: please help concerning specpdl
Date: Tue, 14 Dec 2010 23:25:41 +0200 [thread overview]
Message-ID: <AANLkTintAorQs8E_BnN2ULX1LPBFFjupO8eBFpWD_HZp@mail.gmail.com> (raw)
In-Reply-To: <35942.130.55.118.19.1291652550.squirrel@webmail.lanl.gov>
[-- Attachment #1: Type: text/plain, Size: 2324 bytes --]
> > 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.
[-- Attachment #2: Type: text/html, Size: 2983 bytes --]
next prev parent reply other threads:[~2010-12-14 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-04 5:33 please help concerning specpdl Alin Soare
2010-12-06 16:22 ` Davis Herring
2010-12-14 21:25 ` Alin Soare [this message]
2010-12-15 0:14 ` Davis Herring
2010-12-15 0:53 ` Ken Raeburn
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTintAorQs8E_BnN2ULX1LPBFFjupO8eBFpWD_HZp@mail.gmail.com \
--to=as1789@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=herring@lanl.gov \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.