From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hans Aberg Newsgroups: gmane.lisp.guile.user Subject: Re: C++ wrap Date: Tue, 23 Feb 2010 15:10:38 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1266934253 32279 80.91.229.12 (23 Feb 2010 14:10:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 23 Feb 2010 14:10:53 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Feb 23 15:10:48 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NjvTM-0001Ck-Bm for guile-user@m.gmane.org; Tue, 23 Feb 2010 15:10:48 +0100 Original-Received: from localhost ([127.0.0.1]:37671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjvTL-000206-Ka for guile-user@m.gmane.org; Tue, 23 Feb 2010 09:10:47 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NjvTH-0001zt-OT for guile-user@gnu.org; Tue, 23 Feb 2010 09:10:43 -0500 Original-Received: from [140.186.70.92] (port=54198 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjvTG-0001zk-TQ for guile-user@gnu.org; Tue, 23 Feb 2010 09:10:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NjvTG-0007W9-3U for guile-user@gnu.org; Tue, 23 Feb 2010 09:10:42 -0500 Original-Received: from pne-smtpout2-sn2.hy.skanova.net ([81.228.8.164]:38617) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NjvTF-0007Vg-Ua for guile-user@gnu.org; Tue, 23 Feb 2010 09:10:42 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by pne-smtpout2-sn2.hy.skanova.net (7.3.140.3) (authenticated as u26619134) id 4B5C677E0040822F for guile-user@gnu.org; Tue, 23 Feb 2010 15:10:39 +0100 In-Reply-To: X-Mailer: Apple Mail (2.936) X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7658 Archived-At: 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