guile-devel
[Top][All Lists]
Advanced

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

Re: Compilation and load-extension


From: Andy Wingo
Subject: Re: Compilation and load-extension
Date: Sun, 03 Jan 2010 11:25:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Hi Tristan,

On Wed 30 Dec 2009 16:27, Tristan Colgate <address@hidden> writes:

> 2009/12/28 Andy Wingo <address@hidden>:
>> I can't see how this is happening, though I am sure it is indeed
>> happening for you :) Can you put a tarball up somewhere so that we can
>> have a look at it?
>
> I've created a stripped down module that uses that same style as the
> swig ones and attached it to the following
> bug report
>
> http://savannah.gnu.org/bugs/index.php?28442

Thanks for the test case. Here's dir/mymodule.scm:

    (define-module (dir mymodule))
    (load-extension "test-module.so" "scm_init_my_module")
    (use-modules ((dir mymodule-prim) :renamer (symbol-prefix-proc 
'primitive:)))

What happens when Guile tries to compile this file is that the forms are
expanded one by one, then compiled all together. Since expanders are
written in Scheme they can do any computation -- and indeed we have
`define-module' and `use-modules' hooked up to define and import modules
at expansion-time as well as when you load the compiled file
(load-time).

But the problem is that the load-extension form is just a function call,
not a macro, so it's not going to cause any code to run at expand-time.
Specifically it will not cause the extension to be loaded at expand
time, so later when you try to use (dir mymodule-prim) Guile rightly
complains about there being no such module.

Guile then switches to the interpreter, after compilation failed -- and
since the interpreter evaluates each form after expanding it, indeed the
extension does get loaded in time for the use-modules to see it.

The solution is to enclose the (load-extension ...) in an eval-when:

    (eval-when (eval load compile)
      (load-extension "test-module.so" "scm_init_my_module"))

This ensures that the primitives module gets defined at compile-time.

See also the NEWS section entitled, "Functions needed by macros at
expand-time need to be present at expand-time.".

If this code is generated by SWIG, as you had mentioned before, please
let the SWIG maintainers know about this issue, and point them to this
message.

Regards,

Andy
-- 
http://wingolog.org/




reply via email to

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