From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: good tutorial on extending a c++ project with Guile ? Date: Mon, 26 Jun 2017 19:42:01 +0100 Message-ID: <20170626194201.7100290f@dell.homenet> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1498502566 3214 195.159.176.226 (26 Jun 2017 18:42:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 26 Jun 2017 18:42:46 +0000 (UTC) Cc: samuel.barreto8@gmail.com To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jun 26 20:42:39 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPYxz-000057-1C for guile-user@m.gmane.org; Mon, 26 Jun 2017 20:42:31 +0200 Original-Received: from localhost ([::1]:48049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPYy4-0005r2-As for guile-user@m.gmane.org; Mon, 26 Jun 2017 14:42:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPYxe-0005qq-GX for guile-user@gnu.org; Mon, 26 Jun 2017 14:42:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPYxb-0002UH-AU for guile-user@gnu.org; Mon, 26 Jun 2017 14:42:10 -0400 Original-Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:34958) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPYxb-0002Tk-3U for guile-user@gnu.org; Mon, 26 Jun 2017 14:42:07 -0400 Original-Received: by mail-wm0-x22b.google.com with SMTP id w126so5351668wme.0 for ; Mon, 26 Jun 2017 11:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ENri8ce3lEZY4e+a/OX3cBM9vUGW/6m/MY3z/aiIhZk=; b=Ep8YUFXXP2hDcgHqIe33FPpsCxQlQ/KsZEbFhh6qxwaqkYoYiqZslqRNqk+9+42gry 3V/4R+ZTlnNkVnT9TPGVXMtPWZvshFWrArX9UlnMsEcAj00fxi+TwYDwlgjqmvlThK+Q El1RV+puch4XlpsECieMS4nMZhy6D08vJ3OepUudctDUnf8IfjOSfMFktiI0CgcQn6tp DZ79UyiZ+D6/Ecw9quWn0IuM9XllD8YXjH9OahhMogoFl2PiChspW9kLfcNYdp9Me9YS YTbIXjk9HmHcMQndC9sbCR2PlMykTKPGmEfOBYMHfijFdM7PGNbM12bfpz+nJNdexCC0 yKuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ENri8ce3lEZY4e+a/OX3cBM9vUGW/6m/MY3z/aiIhZk=; b=mteZg2pP7TIvbuP8+cAKPSs+B8MDwr0moY0RgiWbzFFH/WFrrjMSzHOgIDp54nhh3j wM93+AM4QcF9orMuH7TtqfL3OELIGJ6MF097Q/ripMPkaKWObw01vssyTGmv7O2eXMr4 elrMM8NE4Q/2crzBfGh5IrRyvOfBJqudCqqxNY4fJsWZmM4KUeF0WRsu1DelUXgwJE8r UTRmpH5aP2AiA6dmvlAJQ1eVn/INwSLyLzxgETqL671ph4X1jcBrCotLOme+MGMbbzMf kcHTJiwpTGqOSyTLsxCF6jeOh7qwii22UcnV7rWKlDLqs9wGJjXWdYlkixAxlnH9yHeJ fyYA== X-Gm-Message-State: AKS2vOxrt7bFWFolNAvA1ih6kDea0RFi9BvPTDXfSjGv1YgNzxJSymk6 5pHpSc9O2ZernrbD X-Received: by 10.28.210.194 with SMTP id j185mr692950wmg.36.1498502523049; Mon, 26 Jun 2017 11:42:03 -0700 (PDT) Original-Received: from dell.homenet (151.119.114.87.dyn.plus.net. [87.114.119.151]) by smtp.gmail.com with ESMTPSA id p27sm455765wmf.23.2017.06.26.11.42.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jun 2017 11:42:02 -0700 (PDT) Original-Received: from dell.homenet (localhost [127.0.0.1]) by dell.homenet (Postfix) with ESMTP id 1742B443178; Mon, 26 Jun 2017 19:42:01 +0100 (BST) In-Reply-To: X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22b X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13887 Archived-At: On Mon, 26 Jun 2017 14:45:06 +0200 Samuel Barreto wrote: > Hi everyone, > > I want to create a Guile extension to a big C++-based project called > Bio++ (dedicated to bioinformatics and computational biology). > > However I failed to find a good and simple example on how to extend a > C++ program with Guile. My idea was to create a shared library that > can be called from Guile and embedded in a module. I followed > instructions on the Guile reference manual but all of them are > related to C, not C++. I then looked at the source code of LilyPond > and OpenCog but was not able to extract signal from software > idiosyncratic noise. > > So can anyone point me to a good example or a simple tutorial on how > to extend C++ with Guile ? I think the main confusion point to me is > the compilation danse between g++ and gcc. Using guile with C++ is pretty much the same as using it with C except that there is a problem: exceptions. guile exceptions are in effect implemented using setjmp/longjmp or its cognates. C++ exceptions are not. This means that guile exceptions do not take account of the fact that C++ objects in local scope may have user-provided (non-trivial) destructors - if the scope of such objects is jumped out of, there is undefined behaviour. Furthermore C++ exception unwinding does not take account of guile dynamic extents. This means you have to follow two rules: (i) you should not allow a guile exception arising from calls to libguile made by C++ to exit a C++ scope in which there is a local (auto) C++ object which is not trivially destructible; (ii) no C++ exception should transit out of a scm_dynwind_begin()/ scm_dynwind_end() pair. Note also that C and C++ code should not store SCM objects (which are pointers to guile scheme objects) in memory blocks allocated by malloc() or the new expression, or they will not be seen by the garbage collector used by libguile (which is the gc library) and therefore may be prematurely deallocated. To keep such items alive in custom allocators, SCM variables should be kept as local variables or parameter names in functions (and so stored on the stack or in registers, where they will be seen by the garbage collector), or in memory allocated with scm_gc_malloc(), where they will also be seen by the garbage collector. You can see one approach to this at http://cxx-gtk-utils.sourceforge.net/2.2/namespaceCgu_1_1Extension.html . Chris