From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: A [serious] problem with module integration Date: Fri, 16 Nov 2012 11:41:14 -0500 Message-ID: <874nkpts9h.fsf@tines.lan> References: <1353081839.32769.YahooMailNeo@web120405.mail.ne1.yahoo.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1353084099 22576 80.91.229.3 (16 Nov 2012 16:41:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 16 Nov 2012 16:41:39 +0000 (UTC) Cc: guile-user@gnu.org To: Mike Gran Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Nov 16 17:41:50 2012 Return-path: Envelope-to: guile-user@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 1TZOzE-0006Kw-Vg for guile-user@m.gmane.org; Fri, 16 Nov 2012 17:41:49 +0100 Original-Received: from localhost ([::1]:56961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZOz5-0004Cc-2I for guile-user@m.gmane.org; Fri, 16 Nov 2012 11:41:39 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:40084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZOyy-00046X-8D for guile-user@gnu.org; Fri, 16 Nov 2012 11:41:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZOyv-0007KK-6N for guile-user@gnu.org; Fri, 16 Nov 2012 11:41:32 -0500 Original-Received: from world.peace.net ([96.39.62.75]:41770) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZOyv-0007K8-1f for guile-user@gnu.org; Fri, 16 Nov 2012 11:41:29 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TZOyn-0004Hr-Pd; Fri, 16 Nov 2012 11:41:21 -0500 In-Reply-To: <1353081839.32769.YahooMailNeo@web120405.mail.ne1.yahoo.com> (Mike Gran's message of "Fri, 16 Nov 2012 08:03:59 -0800 (PST)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 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-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9689 Archived-At: Mike Gran writes: >> From: Panicz Maciej Godek >> And now I have a problem: the modules that I wrote make use >> of the symbols defined by my application (using scm_c_define...), >> but they are unavailable outside my application, i.e. for external >> modules. > > If I recall correctly, (cause I haven't touched this code > in a while), in my C code that defines the Guile exports, > I did this. > > - created a new module called 'zile' to hold my functions using > =C2=A0 scm_c_resolve_module("zile") > - defined my functions into that module with=20 > =C2=A0=C2=A0scm_c_export > - switched back to the (guile user) environment > =C2=A0 with scm_c_resolve_module("guile-user") > - loaded my newly defined module using > =C2=A0 scm_c_use_module("zile") What Mike wrote here is almost correct, but there were a few mistakes. First, I should explain what went wrong with what Panicz did. 'scm_c_define' and 'scm_c_define_gsubr' add the new bindings to the current module, but they are not exported by default. Unless you have set it yourself, the current module in Guile 2.0 will probably be "guile-user", but it's best not to depend on that. Better to arrange for your C bindings to go into a specific module. Mike tried to do that with 'scm_c_resolve_module', but that only *returns* the named module, it does not change the current module. The preferred way to do this is to use 'scm_c_define_module'. Use it to call an auxillary C function INIT, where all the 'scm_c_define', 'scm_c_define_gsubr', and 'scm_c_export' calls are done. During execution of INIT, the current module will be temporarily set to the new module, but the current module will be automatically restored to its previous setting before returning. Then, I'd recommend calling 'use-modules' from within any Scheme module that needs to access your C bindings. A relevant example can be found near the end of the following page: http://www.gnu.org/software/guile/manual/html_node/C-Extensions.html Although that example assumes that the C code is in a shared library, it should work just as well if the C code is the main program. Just leave out the call to 'load-extension', but keep the call to 'use-modules'. Mark