From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Taahir Ahmed Newsgroups: gmane.lisp.guile.devel Subject: Prototype for C++-compatible Guile Exceptions. Date: Tue, 14 Jul 2015 13:07:26 -0500 Message-ID: <1436897249-18167-1-git-send-email-ahmed.taahir@gmail.com> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1436897305 18068 80.91.229.3 (14 Jul 2015 18:08:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 14 Jul 2015 18:08:25 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jul 14 20:08:19 2015 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZF4cs-0000D4-H4 for guile-devel@m.gmane.org; Tue, 14 Jul 2015 20:08:18 +0200 Original-Received: from localhost ([::1]:60739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZF4cr-0000V1-CQ for guile-devel@m.gmane.org; Tue, 14 Jul 2015 14:08:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZF4cm-0000Un-2b for guile-devel@gnu.org; Tue, 14 Jul 2015 14:08:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZF4ch-0004zz-0I for guile-devel@gnu.org; Tue, 14 Jul 2015 14:08:12 -0400 Original-Received: from mail-ob0-x22c.google.com ([2607:f8b0:4003:c01::22c]:33759) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZF4cg-0004yJ-SL for guile-devel@gnu.org; Tue, 14 Jul 2015 14:08:06 -0400 Original-Received: by obbgp5 with SMTP id gp5so11225664obb.0 for ; Tue, 14 Jul 2015 11:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=+ZHhqYoWmZsoNhGM6yhvX+JODHowb0Ufh/VOdRkeVFc=; b=Pzw6zE0+wxSYHuQaXpyLl2FuCc+izg3nzJWll4KekTh4bb9dQww/n3S2WLdN2XyF5/ LrOOy1mHy6cAQjzE034CuSxjQx0n9JBOUGXDwWdaW8TX+l8Lt5+xl1Ox56dmyKvMjeqk ad5BOG5BvomTEhNedg2qs1sHg/LMOWoc8/IukS2IEtO7UB4bG7qpY3kNCh7QhqiySmfD lK2EjaugEhRYJglmAuKb97Tee9lY/g9BrUucntznPHa+2lflqWvdEu6SLkMvd+I5Klic a4QUUHUAG94597AzaDjUcMuHuJRbS+9G+DTMRqamJUtD5RNckNc90L6Hp4uIW80RXe7/ 1Cvg== X-Received: by 10.60.179.13 with SMTP id dc13mr35854819oec.42.1436897285549; Tue, 14 Jul 2015 11:08:05 -0700 (PDT) Original-Received: from localhost.localdomain (nat-165-91-12-35.tamulink.tamu.edu. [165.91.12.35]) by smtp.gmail.com with ESMTPSA id p184sm890501oig.10.2015.07.14.11.08.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jul 2015 11:08:05 -0700 (PDT) X-Mailer: git-send-email 2.3.6 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::22c X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17761 Archived-At: I'm posting these patches to feel out the likelihood of this approach to C++ exception compatibility ever getting adopted into Guile. They still need some work in terms of function documentation, and one test failure. ---------------------------------------------------------------------- Currently, the use of libguile functions from C++ is fraught with danger. C++ destructors are not triggered by guile exceptions, and the dynwind mechanism is ill-suited for application to C++ data structures (in particular, STL structures). In my experience, writing a C++ function that takes data from guile code in a truly safe manner roughly doubles the required amount of code, because of the generally-required pattern: // ... // Some code to check that a SCM really is an int. int dummy = scm_to_int(my_scm); // Below this point, no guile exceptions may be thrown. // Now, we can create a std::vector, or what-have-you, and put our // int into it. std::vector my_vector; my_vector.push_back(scm_to_int(my_scm)); // ... This sequence of patches addresses this shortcoming by using hidden C++ exceptions to perform the stack unwinding when a guile exception is thrown, so that the pre-checking demonstrated above is not needed. # How is this implemented? This sequence of patches does four things: - Enables autotools C++ support. - Adds -fexceptions to the compiler command line to enable C++ exceptions to traverse C stack frames. - Adds extern "C" guards to the internal libguile headers. - Adds a single C++ source file to libguile that contains set/longjmp workalikes for prompt and exception handling. Prompt and exception-related uses of set/longjmp are replaced with these functions. (This is the third patch, and the real meat of the work). # What are the downsides of this prototype implementation? The use of -fexceptions and a C++ source file limit the choice of compiler. GCC, Clang, and ICC should be fine. I have no idea about some of the more esoteric compilers. On most platforms, -fexceptions entails some space overhead. In my testing, libguile gets bumped from 4.8 MiB to about 5 MiB. The last two test cases in test-out-of-memory ("the kicker" and "ouch") fail. I'm still investigating the root cause. All other tests pass.