Subject: Re: bug#46988: 28.0.50; Documenting and verifying assumptions about C code not calling quit or GCing

From: Matt Armstrong <[email-masked]>
Date: Thu, 11 Mar 2021 15:17:10 -0800

Pip Cet <[email-masked]> writes:

> On Wed, Mar 10, 2021 at 6:28 PM Matt Armstrong <[email-masked]> wrote:
>> Why a linked list/stack implementation?  How about a global count var
>> that is incremented, decremented, and asserted zero?
>
> Emacs' specpdl implementation is independent of, and probably
> predates, the widespread availability of C exceptions. In fact, as it
> is written today, C exceptions will not work in Emacs C code (neither
> will C++ exceptions), because Emacs uses setjmp / longjmp instead, and
> unwinds the stack by itself. Since I was too lazy to fix it to use
> compatible unwinding routines on supported platforms, I simply created
> a linked list on the stack, unwinding it in unwind_to_catch.
>
>> You wrote that this impl depends on the stack direction, but I can't
>> figure out why.  If it is indeed the case, add a comment explaining
>> this?
>
> The unwind_to_catch code checks how far up the stack it has to go by
> comparing the stack pointer to the address of a local variable. You're
> absolutely right about the comment.

Ah, makes perfect sense.  Thanks for this and your other responses.