From: Mark H Weaver <mhw@netris.org>
To: Mike Gran <spk121@yahoo.com>
Cc: guile-user@gnu.org
Subject: Re: A [serious] problem with module integration
Date: Fri, 16 Nov 2012 11:41:14 -0500 [thread overview]
Message-ID: <874nkpts9h.fsf@tines.lan> (raw)
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)")
Mike Gran <spk121@yahoo.com> writes:
>> From: Panicz Maciej Godek <godek.maciek@gmail.com>
>> 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
> scm_c_resolve_module("zile")
> - defined my functions into that module with
> scm_c_export
> - switched back to the (guile user) environment
> with scm_c_resolve_module("guile-user")
> - loaded my newly defined module using
> 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
next prev parent reply other threads:[~2012-11-16 16:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-16 13:54 A [serious] problem with module integration Panicz Maciej Godek
2012-11-16 16:03 ` Mike Gran
2012-11-16 16:10 ` Mike Gran
2012-11-16 16:38 ` Panicz Maciej Godek
2012-11-16 16:41 ` Mark H Weaver [this message]
2012-11-16 17:10 ` Mike Gran
2012-11-16 20:40 ` Ludovic Courtès
2012-11-17 20:28 ` rixed
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=874nkpts9h.fsf@tines.lan \
--to=mhw@netris.org \
--cc=guile-user@gnu.org \
--cc=spk121@yahoo.com \
/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).