guile-devel
[Top][All Lists]
Advanced

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

Re: Replacement for SCM_SETJMPBUF?


From: Maciej Stachowiak
Subject: Re: Replacement for SCM_SETJMPBUF?
Date: Sat, 15 Sep 2001 14:53:41 -0700
User-agent: Mutt/1.2.5i

On 14Sep2001 10:53AM (-0500), Rob Browning wrote:
> 
> At Trow's request, I'm trying to port guppi to our guile beta, and it
> has some code (borrowed from scwm apparently), that calls
> SCM_SETJMPBUF.  Since that macro's been eliminated, is there a
> replacement?
> 
> If someone can explain a bit, I'll add the relevant verbage to NEWS.
> 
> I'm not yet completely sure what the code in question is doing, but in
> case it helps (in particular, in case there's a better way to handle
> this altogether) here's the relevant function:
> 
> static SCM
> scm_internal_cwdr_no_unwind (scm_catch_body_t body, void *body_data,
>                            scm_catch_handler_t handler, void *handler_data,
>                            SCM_STACKITEM * stack_start)

SinceI originally wrote this function I figured I'd comment, although
others have explained it pretty well already. This function is meant
for use in invoking Scheme callbacks from C code. It tries to catch
all exceptions and errors so these can be handled. It also blocks
outgoing and incoming continuations to ensure the function returns
exactly once (rather than 0 times or more than once). This is crucial
because very often the point in C code where you make a callback is
not re-entrant. The combination of this function with stack_catch is
intended to allow for providing backtraces.

These are the desirable parts of the behavior of
call-width-dynamic-root; the one undesirable part was unwinding the
dynamic-wind handlers. We found at least one case where doing this
caused bugs when Scheme code with an established wind handler called C
code when then invoked a scheme callback.

Actually, I do not understand why call-with-dynamic-root unwinds the
wind handlers at all. On a practical level, I have not seen a case
where this behavior is useful on a practical level, and on a
theoretical level, this code does not really leave the dynamic extent
of the calling function since it will in fact return to it, so
unwinding the wind handlers here seems counter-intuitive.

So rather than seeing a function like this added to Guile, I'd rather
see the unwinding behavior removed from call-with-dynamic-root, and
better yet, see a nice function for invoking callbacks that has all
the desirable properties but does not require filling out structs or
writing awkward C functions.

Regards,

Maciej





reply via email to

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