Portable dynamic library loading for Guile

dynamic-link and load-extension work without passing the .so or .dll as
the shared library extension, so these have been dropped so the examples
and test-suite work on Cygwin.

Also update documentation and use the 'lib' prefix as that is what we
commonly name the shared libraries.
This commit is contained in:
William S Fulton 2013-05-08 12:42:17 +01:00
commit 70b9df5ee9
31 changed files with 54 additions and 44 deletions

View file

@ -115,7 +115,7 @@ libraries into Guile.</p>
<div class="targetlang">
<pre>
(define-module (my module))
(define my-so (dynamic-link "./example.so"))
(define my-so (dynamic-link "./libexample.so"))
(dynamic-call "SWIG_init" my-so) ; make SWIG bindings
;; Scheme definitions can go here
</pre>
@ -128,7 +128,17 @@ and <code>dynamic-call</code>:
<div class="targetlang">
<pre>
(load-extension "./example.so" "SWIG_init")
(load-extension "./libexample.so" "SWIG_init")
</pre>
</div>
<p>
A more portable approach would be to drop the shared library extension:
</p>
<div class="targetlang">
<pre>
(load-extension "./libexample" "SWIG_init")
</pre>
</div>
@ -171,7 +181,7 @@ information by including a directive like this in the interface file:
<div class="code">
<pre>
%scheme %{ (load-extension "./example.so" "SWIG_init") %}
%scheme %{ (load-extension "./libexample.so" "SWIG_init") %}
</pre>
</div>
@ -225,7 +235,7 @@ shared libraries into Guile; all bindings are automatically put in
newly created Guile modules.
<div class="targetlang">
<pre>
(define my-so (dynamic-link "./foo.so"))
(define my-so (dynamic-link "./libfoo.so"))
;; create new module and put bindings there:
(dynamic-call "scm_init_my_modules_foo_module" my-so)
</pre>
@ -233,7 +243,7 @@ newly created Guile modules.
Newer Guile versions have a shorthand procedure for this:
<div class="targetlang">
<pre>
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
</pre>
</div>
</ul>
@ -768,10 +778,10 @@ and might conflict with names from the GOOPS guile-module (see above). Pass the
argument to solve this problem. If the <code>-exportprimitive</code> option is passed to SWIG the
<code>(export ...)</code> code that would be exported into the scmstub file is exported at the bottom
of the generated GOOPS guile-module.
The <code>%goops</code> directive should contain code to load the .so library.
The <code>%goops</code> directive should contain code to load the shared library.
<div class="code"><pre>
%goops %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
%goops %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
</pre></div>
<p>
@ -783,7 +793,7 @@ Produces the following code at the top of the generated GOOPS guile-module
(define-module (my modules foo))
;; %goops directive goes here
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
(use-modules (oop goops) (Swig common))
</pre></div>
@ -791,7 +801,7 @@ Produces the following code at the top of the generated GOOPS guile-module
<li><p><b>Passive Linkage with -scmstub</b>: Here, the name of the scmstub file should be
<code>Module-primitive.scm</code> (with <i>primitive</i> replaced with whatever is given with the <code>-primsuffix</code>
argument. The code to load the <code>.so</code> library should be located in the <code>%scheme</code> directive,
argument. The code to load the shared library should be located in the <code>%scheme</code> directive,
which will then be added to the scmstub file.
SWIG will automatically generate the line <code>(use-modules (<i>Package</i> <i>Module-primitive</i>))</code>
into the GOOPS guile-module. So if <i>Module-primitive.scm</i> is on the autoload path for guile, the
@ -799,7 +809,7 @@ into the GOOPS guile-module. So if <i>Module-primitive.scm</i> is on the autolo
whatever code is needed to load the <i>Module-primitive.scm</i> file into guile.</p>
<div class="targetlang"><pre>
%scheme %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
%scheme %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
// only include the following definition if (my modules foo) cannot
// be loaded automatically
%goops %{
@ -832,7 +842,7 @@ SWIG will also automatically generate the line <code>(use-modules
directive should contain whatever code is needed to get that module loaded into guile.</p>
<div class="code"><pre>
%goops %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
%goops %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
</pre></div>
<p>
@ -843,7 +853,7 @@ Produces the following code at the top of the generated GOOPS guile-module
(define-module (my modules foo))
;; %goops directive goes here (if any)
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
(use-modules (oop goops) (Swig common))
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc

View file

@ -1,6 +1,6 @@
;;; Test out some multi-argument typemaps
(dynamic-call "scm_init_example_module" (dynamic-link "./libexample.so"))
(dynamic-call "scm_init_example_module" (dynamic-link "./libexample"))
; Call the GCD function

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_casts_module" (dynamic-link "./libcasts.so"))
(dynamic-call "scm_init_casts_module" (dynamic-link "./libcasts"))
(load "../schemerunme/casts.scm")

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_char_constant_module" (dynamic-link "./libchar_constant.so"))
(dynamic-call "scm_init_char_constant_module" (dynamic-link "./libchar_constant"))
(load "../schemerunme/char_constant.scm")

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_class_ignore_module" (dynamic-link "./libclass_ignore.so"))
(dynamic-call "scm_init_class_ignore_module" (dynamic-link "./libclass_ignore"))
(load "../schemerunme/class_ignore.scm")

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_constover_module" (dynamic-link "./libconstover.so"))
(dynamic-call "scm_init_constover_module" (dynamic-link "./libconstover"))
(load "../schemerunme/constover.scm")

View file

@ -1,6 +1,6 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_contract_module" (dynamic-link "./libcontract.so"))
(dynamic-call "scm_init_contract_module" (dynamic-link "./libcontract"))
(load "testsuite.scm")
(load "../schemerunme/contract.scm")

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_cpp_enum_module" (dynamic-link "./libcpp_enum.so"))
(dynamic-call "scm_init_cpp_enum_module" (dynamic-link "./libcpp_enum"))
(load "../schemerunme/cpp_enum.scm")

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_cpp_namespace_module" (dynamic-link "./libcpp_namespace.so"))
(dynamic-call "scm_init_cpp_namespace_module" (dynamic-link "./libcpp_namespace"))
(load "../schemerunme/cpp_namespace.scm")

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_dynamic_cast_module" (dynamic-link "./libdynamic_cast.so"))
(dynamic-call "scm_init_dynamic_cast_module" (dynamic-link "./libdynamic_cast"))
(load "../schemerunme/dynamic_cast.scm")

View file

@ -1,4 +1,4 @@
(dynamic-call "scm_init_guile_ext_test_module" (dynamic-link "./libguile_ext_test.so"))
(dynamic-call "scm_init_guile_ext_test_module" (dynamic-link "./libguile_ext_test"))
; This is a test for SF Bug 1573892
; If IsPointer is called before TypeQuery, the test-is-pointer will fail

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_import_nomodule_module" (dynamic-link "./libimport_nomodule.so"))
(dynamic-call "scm_init_import_nomodule_module" (dynamic-link "./libimport_nomodule"))
(load "../schemerunme/import_nomodule.scm")

View file

@ -6,6 +6,6 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_imports_a_module" (dynamic-link "./libimports_a.so"))
(dynamic-call "scm_init_imports_b_module" (dynamic-link "./libimports_b.so"))
(dynamic-call "scm_init_imports_a_module" (dynamic-link "./libimports_a"))
(dynamic-call "scm_init_imports_b_module" (dynamic-link "./libimports_b"))
(load "../schemerunme/imports.scm")

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_inherit_missing_module" (dynamic-link "./libinherit_missing.so"))
(dynamic-call "scm_init_inherit_missing_module" (dynamic-link "./libinherit_missing"))
(load "../schemerunme/inherit_missing.scm")

View file

@ -1,7 +1,7 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_integers_module" (dynamic-link "./libintegers.so"))
(dynamic-call "scm_init_integers_module" (dynamic-link "./libintegers"))
(define-macro (throws-exception? form)
`(catch #t

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string.so"))
(dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string"))
(load "../schemerunme/li_std_string.scm")

View file

@ -4,7 +4,7 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_li_typemaps_module" (dynamic-link "./libli_typemaps.so"))
(dynamic-call "scm_init_li_typemaps_module" (dynamic-link "./libli_typemaps"))
(load "../schemerunme/li_typemaps.scm")
(let ((lst (inoutr-int2 3 -2)))

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_list_vector_module" (dynamic-link "./liblist_vector.so"))
(dynamic-call "scm_init_list_vector_module" (dynamic-link "./liblist_vector"))
(load "../schemerunme/list_vector.scm")

View file

@ -3,5 +3,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_multivalue_module" (dynamic-link "./libmultivalue.so"))
(dynamic-call "scm_init_multivalue_module" (dynamic-link "./libmultivalue"))
(load "../schemerunme/multivalue.scm")

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_name_module" (dynamic-link "./libname.so"))
(dynamic-call "scm_init_name_module" (dynamic-link "./libname"))
(load "../schemerunme/name.scm")

View file

@ -1,7 +1,7 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_overload_complicated_module" (dynamic-link "./liboverload_complicated.so"))
(dynamic-call "scm_init_overload_complicated_module" (dynamic-link "./liboverload_complicated"))
(define-macro (check form)
`(if (not ,form)

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_overload_copy_module" (dynamic-link "./liboverload_copy.so"))
(dynamic-call "scm_init_overload_copy_module" (dynamic-link "./liboverload_copy"))
(load "../schemerunme/overload_copy.scm")

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_overload_extend_module" (dynamic-link "./liboverload_extend.so"))
(dynamic-call "scm_init_overload_extend_module" (dynamic-link "./liboverload_extend"))
(load "../schemerunme/overload_extend.scm")

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_overload_simple_module" (dynamic-link "./liboverload_simple.so"))
(dynamic-call "scm_init_overload_simple_module" (dynamic-link "./liboverload_simple"))
(load "../schemerunme/overload_simple.scm")

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_overload_subtype_module" (dynamic-link "./liboverload_subtype.so"))
(dynamic-call "scm_init_overload_subtype_module" (dynamic-link "./liboverload_subtype"))
(load "../schemerunme/overload_subtype.scm")

View file

@ -1,5 +1,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_pointer_in_out_module" (dynamic-link "./libpointer_in_out.so"))
(dynamic-call "scm_init_pointer_in_out_module" (dynamic-link "./libpointer_in_out"))
(load "../schemerunme/pointer_in_out.scm")

View file

@ -1,3 +1,3 @@
; copied from python runme_.py
(dynamic-call "scm_init_reference_global_vars_module" (dynamic-link "./libreference_global_vars.so"))
(dynamic-call "scm_init_reference_global_vars_module" (dynamic-link "./libreference_global_vars"))
(load "../schemerunme/reference_global_vars.scm")

View file

@ -1,7 +1,7 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_throw_exception_module" (dynamic-link "./libthrow_exception.so"))
(dynamic-call "scm_init_throw_exception_module" (dynamic-link "./libthrow_exception"))
(define-macro (check-throw form)
`(catch 'swig-exception

View file

@ -1,2 +1,2 @@
(dynamic-call "scm_init_typedef_inherit_module" (dynamic-link "./libtypedef_inherit.so"))
(dynamic-call "scm_init_typedef_inherit_module" (dynamic-link "./libtypedef_inherit"))
(load "../schemerunme/typedef_inherit.scm")

View file

@ -1,3 +1,3 @@
(dynamic-call "scm_init_typename_module" (dynamic-link "./libtypename.so"))
;;(dynamic-call "scm_init_types_module" (dynamic-link "./libtypes.so"))
(dynamic-call "scm_init_typename_module" (dynamic-link "./libtypename"))
;;(dynamic-call "scm_init_types_module" (dynamic-link "./libtypes"))
(load "../schemerunme/typename.scm")

View file

@ -4,5 +4,5 @@
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_unions_module" (dynamic-link "./libunions.so"))
(dynamic-call "scm_init_unions_module" (dynamic-link "./libunions"))
(load "../schemerunme/unions.scm")