From: Hans Aberg <haberg@math.su.se>
To: guile-user@gnu.org
Subject: Re: C++ wrap
Date: Tue, 23 Feb 2010 15:10:38 +0100 [thread overview]
Message-ID: <F8467066-7EA3-4DF4-BC3C-C01B340CD13C@math.su.se> (raw)
In-Reply-To: <m3aav11460.fsf@pobox.com>
I have experimented with adding C++ exception handling to the wrap. It
seems, using gcc, that it works fine, as long as one does not try to
pass a C++ exception through a C function call - then it calls the
terminate handler.
So add an exception type to Guile which can hold the thrown data, a
pair (key . args) with a predicate
SCM_API int scm_is_exception(SCM x);
When there is an uncaught exception in a C function returning SCM, it
should instead return this exception type with the thrown data. (So
there would need to be some variable present, changing the behavior of
these C-functions.)
Then write a function (object = C++ version of SCM)
object rethrow(const object& x) {
if (scm_is_exception(x))
throw (exception)x;
else
return x;
}
Then just add this rethrow() to the returns that might be an exception:
number operator/(const number& x, const number& y) { return
rethrow(scm_divide(x, y)); }
instead of
number operator/(const number& x, const number& y) { return
scm_divide(x, y); }
The code should then look normal:
try {
integer x = 1, y = 0;
integer z = x/y; // exception
catch (exception& x) {
out << "Exception: " << x << newline;
}
I did some code using scm_internal_catch(), but it takes a body
function of only one argument:
SCM body(void *data);
So I guess one has to fiddle around with passing suitable structs
using it. - May try it later.
Hans
prev parent reply other threads:[~2010-02-23 14:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-22 14:01 C++ wrap Hans Aberg
2010-02-22 19:06 ` Andy Wingo
2010-02-23 14:10 ` Hans Aberg [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=F8467066-7EA3-4DF4-BC3C-C01B340CD13C@math.su.se \
--to=haberg@math.su.se \
--cc=guile-user@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).