[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A [serious] problem with module integration

From: Mark H Weaver
Subject: Re: A [serious] problem with module integration
Date: Fri, 16 Nov 2012 11:41:14 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Mike Gran <address@hidden> writes:

>> From: Panicz Maciej Godek <address@hidden>
>> 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:

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'.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]