unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Taahir Ahmed <ahmed.taahir@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: Exception-safety for C++ code integrated with Guile.
Date: Tue, 10 Mar 2015 22:15:26 +0100	[thread overview]
Message-ID: <87vbi8y2oh.fsf@pobox.com> (raw)
In-Reply-To: <474913203.jcqxqasMgP@basis> (Taahir Ahmed's message of "Mon, 23 Feb 2015 15:59:43 -0600")

Hi Taahir,

On Mon 23 Feb 2015 22:59, Taahir Ahmed <ahmed.taahir@gmail.com> writes:

> Over the past few days, I've been working on reducing the amount of
> defensive coding that is required when writing Guile extensions using
> C++.
>
> My primary goal is to ensure that destructors of automatic variables
> are called if any Guile non-local control flow passes through a C++
> stack frame.

I was thinking about this recently too, in the context of GDB's upcoming
switch to C++, though I didn't get very far in the thinking.

>   1) To check that I'm not duplicating any other ongoing work,

Not that I know of.  Doesn't matter anyway, a good solution is always
acceptable :)

>   2) To float two different implementation strategies and see which
>      one is the best choice going forward, and
>
>   3) To get clarification on some issues that I've encountered with a
>      prototype implementation.

Cool.

> The two major strategies I considered are:
>
>   1) Replace all uses of set/longjmp in the Guile source with C++
>      exceptions.  This approach is simple in some ways, and
>      complicated in others.  I would hesitate to pursue this unless
>      Guile has some sort of longer-term plan to move towards C++.

I am not C++-averse but a hypothetical move towards C++ in a Guile
context doesn't necessarily mean moving towards use of exceptions.
Scheme has fairly complicated control flow and embracing C++ exceptions
doesn't necessarily solve things.  For example an exception propagating
over natively-compiled Scheme code would have to run dynwinds.  Calling
out to C++ would have to set up some sort of try/catch.  Is that the
right design?  I don't know.

(I do think that the C-stack-saving aspect of Guile's continuations is a
silly thing, given that delimited continuations are more expressive, we
can have escape-only continuations either way, and our VM and future
native compilation pipeline means that we don't have so much rewinding
of C stack frames, and in any case rewinding is unexpected and untested
by most Guile core code, not to mention user code.)

>   2) Replace all uses of set/longjmp with replacements (call them
>      eh_setjmp and eh_longjmp) that are based on libunwind [1].

No opinion other than a vague aversion to dependencies.

> However, I've run into an issue --- many of Guile's uses of setjmp
> don't conform to the C standard.  In particular, after experiencing a
> non-local return from setjmp, you're not allowed to access any
> non-volatile local variables, but Guile does (see the local variable
> mx in eval()).

You are allowed to access variables that could never be assigned after
the setjmp, AFAIK?  Anyway how is mx accessed before being re-set after
a prompt longjmp?

Cheers, and thanks for looking at this,

Andy
-- 
http://wingolog.org/



      parent reply	other threads:[~2015-03-10 21:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-23 21:59 Exception-safety for C++ code integrated with Guile Taahir Ahmed
2015-02-24 18:52 ` Eli Zaretskii
2015-02-24 19:21   ` Taahir Ahmed
2015-02-24 19:36     ` Eli Zaretskii
2015-02-24 19:59   ` Taahir Ahmed
2015-03-10 21:15 ` Andy Wingo [this message]

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vbi8y2oh.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=ahmed.taahir@gmail.com \
    --cc=guile-devel@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).