From 7e55b36764492403e02dfec919b53b1e9b377781 Mon Sep 17 00:00:00 2001
From: John Lenz
Date: Tue, 5 Apr 2005 17:48:31 +0000
Subject: [PATCH] Chicken: a few bug fixes, a new example and some new test
suite runme, and some doc updates
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7143 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 11 +
Doc/Manual/Chicken.html | 186 ++++++++++-----
Examples/chicken/README | 1 +
Examples/chicken/egg/Makefile | 39 ++++
Examples/chicken/egg/README | 19 ++
Examples/chicken/egg/mod1.i | 8 +
Examples/chicken/egg/mod2.i | 17 ++
Examples/chicken/egg/multi.setup | 2 +
Examples/chicken/egg/multi_init.scm | 2 +
Examples/chicken/egg/single.i | 8 +
Examples/chicken/egg/single.setup | 2 +
Examples/chicken/egg/test.scm | 18 ++
Examples/test-suite/chicken/Makefile.in | 23 ++
Examples/test-suite/chicken/README | 4 +
.../test-suite/chicken/newobject2_runme.ss | 21 +-
.../chicken/newobject2_runme_proxy.ss | 29 +++
Lib/cdata.i | 6 +
Lib/chicken/swigclosprefix.scm | 2 +-
Source/Modules/chicken.cxx | 217 ++++++++----------
19 files changed, 435 insertions(+), 180 deletions(-)
create mode 100644 Examples/chicken/egg/Makefile
create mode 100644 Examples/chicken/egg/README
create mode 100644 Examples/chicken/egg/mod1.i
create mode 100644 Examples/chicken/egg/mod2.i
create mode 100644 Examples/chicken/egg/multi.setup
create mode 100644 Examples/chicken/egg/multi_init.scm
create mode 100644 Examples/chicken/egg/single.i
create mode 100644 Examples/chicken/egg/single.setup
create mode 100644 Examples/chicken/egg/test.scm
create mode 100644 Examples/test-suite/chicken/newobject2_runme_proxy.ss
diff --git a/CHANGES.current b/CHANGES.current
index 3968e56ee..a4745716e 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -1,6 +1,17 @@
Version 1.3.25 (In progress)
============================
+04/05/2005: wuzzeb (John Lenz)
+ [Chicken]
+ + Added Examples/chicken/egg, an example on how to build a chicken
+ extension library in the form of an egg. Also updated the
+ documentation on the different linking options.
+
+ + chicken test-suite now has support to check SWIG with the -proxy
+ argument if there exists a _proxy_runme.ss file.
+
+ + More fixes for overloaded functions and -proxy
+
03/31/2005: wsfulton
Turned on extra template features for all languages which were
previously only available to Python.
diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html
index bf132b987..0ef9bc34d 100644
--- a/Doc/Manual/Chicken.html
+++ b/Doc/Manual/Chicken.html
@@ -104,11 +104,14 @@
generation improvements, part of the wrapper is direct CHICKEN
function calls (example_wrap.c) and part is CHICKEN
Scheme (example.scm). The basic Scheme code must
- be compiled to C using your system's CHICKEN compiler.
+ be compiled to C using your system's CHICKEN compiler or
+ both files can be compiled directly using the much simpler csc.
-
% chicken example.scm -output-file oexample.c
+
+% chicken example.scm -output-file oexample.c
+
@@ -132,7 +135,8 @@
This will generate example_wrap.cxx and
example.scm. The basic Scheme code must be
- compiled to C using your system's CHICKEN compiler.
+ compiled to C using your system's CHICKEN compiler or
+ both files can be compiled directly using the much simpler csc.
@@ -317,21 +321,7 @@
-
17.4 Compilation
-
-
-
- Please refer to CHICKEN - A practical and portable Scheme
- system - User's manual for detailed help on how to compile
- C code for use in a CHICKEN program. Briefly, to compile C
- code, be sure to add `chicken-config -cflags` or
- `chicken-config -shared -cflags` to your compiler
- options. Use the -shared option if you want to create
- a dynamically loadable module. You might also want to use the
- much simpler csc or csc.bat.
-
-
-
17.5 Linkage
+
17.4 Linkage
@@ -342,51 +332,139 @@
-extra-libs -libs` or `chicken-config -shared
-extra-libs -libs`to your linker options. Use the
-shared option if you want to create a dynamically
- loadable module.
+ loadable module. You might also want to use the much simpler
+ csc or csc.bat.
-
17.5.1 Shared library
+
Each scheme file that is generated
+ by SWIG contains (declare (uses modname)). This means that to load the
+ module from scheme code, the code must include (declare (uses modname)).
+
-
- The easiest way to use SWIG and CHICKEN is to use the csc compiler
- wrapper provided by CHICKEN. Assume you have a SWIG interface file
- in example.i and the C functions being wrapped are in example_impl.c.
-
+
17.4.1 Static binary or shared library linked at compile time
- You must be careful not to name the example_impl.c file example.c because
- when compiling example.scm, csc compiles that into example.c!
-
-
-
- The test_script.scm should have (load-library 'example "example.so")
- and (declare (uses example)). As well, the path to example.so should
- be accessable to the loader. You might need to set LD_LIBRARY_PATH.
-
Similar to the above, any number of module.scm files could be compiled
+into a shared library, and then that shared library linked when compiling the
+main application.
The exmaple.so file can then linked with test_script.scm when it
+is compiled, in which case test_script.scm must have (declare (uses example)).
+Multiple SWIG modules could have been linked into example.so and each
+one accessed with a (declare (uses ... )).
+
+
+
+
+$ csc -v test_script.scm -lexample
+
+
+
+
An alternative is the test_script.scm can have the code (load-library 'example "example.so"),
+in which case the test script does not need to be linked with example.so. The test_script.scm file can then
+be run with csi.
+
+
+
17.4.2 Building chicken extension libraries
+
+
+
Building a shared library like in the above section only works if the library
+is linked at compile time with a script containing (declare (uses ...)) or is
+loaded explictetly with (load-library 'example "example.so"). It is
+not the format that chicken expects for extension libraries and eggs. The problem is the
+(declare (unit modname)) inside the modname.scm file. There are
+two possible solutions to this.
+
+
First, SWIG accepts a -nounit argument, in which case the (declare (unit modname))
+is not generated. Then, the modname.scm and modname_wrap.c files must be compiled into
+their own shared library.
This library can then be loaded by scheme code with the (require 'modname) function.
+See
+Loading-extension-libraries in the eval unit inside the Chicken manual for more information.
+
+
Another alternative is to run SWIG normally and create a scheme file that contains (declare (uses modname))
+and then compile that file into the shared library as well. For example, inside the mod_load.scm file,
Then the extension library can be loaded with (require 'mod). As we can see here,
+mod_load.scm contains the code that gets exectued when the module is loaded. All this code
+does is load both mod1 and mod2. As we can see, this technique is more useful when you want to
+combine a few SWIG modules into one chicken extension library, especially if modules are related by
+%import
+
+
In either method, the files that are compiled into the shared library could also be
+packaged into an egg. The mod1_wrap.c and mod2_wrap.c files that are created by SWIG
+are stand alone and do not need SWIG to be installed to be compiled. Thus the egg could be
+distributed and used by anyone, even if SWIG is not installed.
+
+
See the Examples/chicken/egg directory in the SWIG source for an example that builds
+two eggs, one using the first method and one using the second method.
+
+
17.4.3 Linking multiple SWIG modules with TinyCLOS
+
+
Linking together multiple modules that share type information using the %import
+directive while also using -proxy is more complicated. For example, if mod2.i imports mod1.i, then the
+mod2.scm file contains references to symbols declared in mod1.scm,
+and thus a (declare (uses mod1)) or (require 'mod1) must be exported
+to the top of mod2.scm. By default, when SWIG encounters an %import "modname.i" directive,
+it exports (declare (uses modname)) into the scm file. This works fine unless mod1 was compiled with
+the -nounit argument or was compiled into an extension library with other modules under a different name.
+
+
One option is to override the automatic generation of (declare (uses mod1))
+by passing the -noclosuses option to SWIG when compiling mod2.i.
+SWIG then provides the %insert(closprefix) %{ %} directive. Any scheme code inside that directive is inserted into the
+generated .scm file, and if mod1 was compiled with -nounit, the directive should contain (require 'mod1).
+This option allows for mixed loading as well, where some modules are imported with (declare (uses modname))
+(which means they were compiled without -nounit) and some are imported with (require 'modname).
+
+
The other option is to use the second idea in the above section. Compile all the modules normally, without any
+%insert(closprefix), -nounit, or -noclosuses. Then the modules will import each other correctly
+with (declare (uses ...)).
+To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...))
+all the modules.