diff --git a/CHANGES.current b/CHANGES.current index 3fab761b8..5bd6e6910 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,384 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.5 (in progress) =========================== +2012-01-24: wsfulton + Fix crash with bad regex - bug #3474250. + +2012-01-24: wsfulton + [Python] Add Python stepped slicing support to the STL wrappers (std::vector, std::list). + Assigning to a slice, reading a slice and deleting a slice with steps now work. + For example: + + %template(vector_i) std::vector + + vi = vector_i(range(10)) + print list(vi) + vi[1:4:2] = [111, 333] + print list(vi) + del vi[3:10:3] + print list(vi) + print list(vi[::-1]) + + gives (same behaviour as native Python sequences such as list): + + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + [0, 111, 2, 333, 4, 5, 6, 7, 8, 9] + [0, 111, 2, 4, 5, 7, 8] + [8, 7, 5, 4, 2, 111, 0] + +2012-01-23: klickverbot + [D] Correctly annotate function pointers with C linkage. + [D] Exception and Error have become blessed names; removed d_exception_name test case. + +2012-01-20: wsfulton + [Python] Fix some indexing bugs in Python STL wrappers when the index is negative, eg: + + %template(vector_i) std::vector + + iv=vector_i([0,1,2,3,4,5]) + iv[-7:] + + now returns [0, 1, 2, 3, 4, 5] instead of [5]. + + vv[7:9] = [22,33] + + now returns [0, 1, 2, 3, 4, 5, 22, 33] instead of "index out range" error. + + Also fix some segfaults when replacing ranges, eg when il is a std::list wrapper: + + il[0:2] = [11] + +2012-01-17: wsfulton + [Go] Fix forward class declaration within a class when used as a base. + +2012-01-07: wsfulton + [C#] Add support for %nspace when using directors. + +2012-01-06: wsfulton + [Java] Patch #3452560 from Brant Kyser - add support for %nspace when using directors. + +2011-12-21: wsfulton + The 'directorin' typemap now accepts $1, $2 etc expansions instead of having to use workarounds - + $1_name, $2_name etc. + +2011-12-20: wsfulton + [Java] Add (char *STRING, size_t LENGTH) director typemaps. + +2011-12-20: wsfulton + [C#, Go, Java, D] Add support for the 'directorargout' typemap. + +2011-12-20: wsfulton + [Ocaml, Octave, PHP, Python, Ruby] Correct special variables in 'directorargout' typemap. + This change will break any 'directorargout' typemaps you may have written. Please change: + $result to $1 + $input to $result + + Also fix the named 'directorargout' DIRECTOROUT typemaps for these languages which didn't + previously compile and add in $1, $2 etc expansion. + + *** POTENTIAL INCOMPATIBILITY *** + +2011-12-10: talby + [perl5] SWIG_error() now gets decorated with perl source file/line number. + [perl5] error handling now conforms to public XS api (fixes perl v5.14 issue). + +2011-12-10: wsfulton + [Android/Java] Fix directors to compile on Android. + + Added documentation and examples for Android. + +2011-12-08: vadz + Bug fix: Handle methods renamed or ignored in the base class correctly in the derived classes + (they could be sometimes mysteriously not renamed or ignored there before). + +2011-12-03: klickverbot + [D] Fix exception glue code for newer DMD 2 versions. + [D] Do not default to 32 bit glue code for DMD anymore. + [D] Use stdc.config.c_long/c_ulong to represent C long types. + +2011-12-01: szager + [python] Fixed bug 3447426: memory leak in vector.__getitem__. + +2011-11-30: wsfulton + [R] Remove C++ comments from generated C code. + +2011-11-27: olly + [Python] Fix some warnings when compiling generated wrappers with + certain GCC warning options (Debian bug #650246). + +2011-11-28: wsfulton + Fix #3433541 %typemap(in, numinputs=0) with 10+ arguments. + +2011-11-28: olly + [Perl] Fix warnings when compiling generated wrappers with certain + GCC warning options (Debian bug #436711). + +2011-11-28: olly + [PHP] Update keyword list to include keywords added in PHP releases up to 5.3. + +2011-11-25: wsfulton + [C#] Provide an easy way to override the default visibility for the proxy class pointer + constructors and getCPtr() method. The visibility is 'internal' by default and if multiple + SWIG modules are being used and compiled into different assemblies, then they need to be + 'public' in order to use the constructor or getCPtr() method from a different assembly. + Use the following macros to change the visibilities in the proxy and type wrapper class: + + SWIG_CSBODY_PROXY(public, public, SWIGTYPE) + SWIG_CSBODY_TYPEWRAPPER(public, public, public, SWIGTYPE) + + [Java] Provide an easy way to override the default visibility for the proxy class pointer + constructors and getCPtr() method. The visibility is 'protected' by default and if multiple + SWIG modules are being used and compiled into different packages, then they need to be + 'public' in order to use the constructor or getCPtr() method from a different package. + Use the following macros to change the visibilities in the proxy and type wrapper class: + + SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) + SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) + + The default for Java has changed from public to protected for the proxy classes. Use the + SWIG_JAVABODY_PROXY macro above to restore to the previous visibilities. + + *** POTENTIAL INCOMPATIBILITY *** + +2011-11-22: szager + [python] Bug 3440044: #ifdef out SWIG_Python_NonDynamicSetAttr if -builtin + isn't being used, to avoid unnecessary binary incompatibilities between + python installations. + +2011-11-17: wsfulton + Bug fix: Remove root directory from directory search list in Windows. + +2011-11-13: wsfulton + [Ruby] Apply patch #3421876 from Robin Stocker to fix #3416818 - same class name in + different namespaces confusion when using multiple modules. + +2011-11-11: wsfulton + Fix pcre-build.sh to work with non-compressed tarballs - problem reported by Adrian Blakely. + +2011-11-04: szager + [python] Bug 3429388: python unsigned integer handling on 32-bit architectures. + +2011-11-03: wsfulton + Expand special variables in typemap warnings, eg: + + %typemap(in, warning="1000:Test warning for 'in' typemap for $1_type $1_name") int "..." + +2011-11-01: wsfulton + Fix named output typemaps not being used when the symbol uses a qualifier and contains + a number, eg: + + %typemap(out) double ABC::m1 "..." + +2011-10-24: talby + [perl5] SF bug #3423119 - overload dispatch stack corruption fix. Better, but more research + is needed on a stable path for tail calls in XS. + + Also, fix for large long longs in 32 bit perl. + +2011-10-13: xavier98 + [octave] Allow Octave modules to be re-loaded after a "clear all". + +2011-09-19: wsfulton + Fix regression introduced in swig-2.0.1 reported by Teemu Ikonone leading to uncompilable code + when using typedef and function pointer references, for example: + + typedef int FN(const int &a, int b); + void *typedef_call1(FN *& precallback, FN * postcallback); + +2011-09-14: wsfulton + [Lua] Patch #3408012 from Raman Gopalan - add support for embedded Lua (eLua) + including options for targeting Lua Tiny RAM (LTR). + +2011-09-14: wsfulton + [C#] Add boost_intrusive_ptr.i library contribution from patch #3401571. + +2011-09-13: wsfulton + Add warnings for badly named destructors, eg: + + struct KStruct { + ~NOT_KStruct() {} + }; + + cpp_extend_destructors.i:92: Warning 521: Illegal destructor name ~NOT_KStruct. Ignored. + +2011-09-13: wsfulton + Fix %extend and destructors for templates. The destructor in %extend was not always wrapped, + for example: + + %extend FooT { + ~FooT() { delete $self; } // was not wrapped as expected + }; + template class FooT {}; + %template(FooTi) FooT; + +2011-09-13: wsfulton + Fix special variables such as "$decl" and "$fulldecl" in destructors to include the ~ character. + +2011-09-10: talby + [perl5] SF bug #1481958 - Improve range checking for integer types. + Enhance li_typemaps_runme.pl + +2011-09-08: wsfulton + Fix %extend on typedef classes in a namespace using the typedef name, for example: + namespace Space { + %extend CStruct { + ... + } + typedef struct tagCStruct { ... } CStruct; + } + +2011-08-31: xavier98 + [octave] patches from Karl Wette: improvements to module loading behavior; + added example of friend operator to operator example; fixed octave panic/crash in 3.0.5; + documentation improvements + +2011-08-30: szager + [python] Bug 3400486, fix error signalling for built-in constructors. + +2011-08-26: wsfulton + [Go] Fix file/line number display for "gotype" when using typemap debugging options + -tmsearch and -tmused. + +2011-08-26: wsfulton + [C#, D] Fix %callback which was generating uncompileable code. + +2011-08-25: wsfulton + Fix constructors in named typedef class declarations as reported by Gregory Bronner: + + typedef struct A { + A(){} // Constructor which was not accepted by SWIG + B(){} // NOT a constructor --illegal, but was accepted by SWIG + } B; + + For C code, the fix now results in the use of 'struct A *' instead of just 'B *' in + the generated code when wrapping members in A, but ultimately this does not matter, as + they are the same thing. + +2011-08-23: wsfulton + Fix %newobject when used in conjunction with %feature("ref") as reported by Jan Becker. The + code from the "ref" feature was not always being generated for the function specified by %newobject. + Documentation for "ref" and "unref" moved from Python to the C++ chapter. + +2011-08-22: szager + [python] Fixed memory leak with --builtin option (bug 3385089). + +2011-08-22: wsfulton + [Lua] SF patch #3394339 from Torsten Landschoff - new option -nomoduleglobal to disable installing + the module table into the global namespace. Require call also returns the module table instead + of a string. + +2011-08-12: wsfulton + SF bug # 3333549 - %shared_ptr fixes when the type is a template using template parameters + that are typedef'd to another type. + + Also fixed %shared_ptr when template parameters have default values. + +2011-08-09: xavier98 + Fix bug 3387394; Octave patches for 3.4.0 compatibility, etc. (from Karl Wette) + +2011-08-04: wsfulton + Add in $symname expansion for director methods. + +2011-07-29: olly + [PHP] Don't generate "return $r;" in cases where $r hasn't been set. + This was basically harmless, except it generated a PHP E_NOTICE if + the calling code had enabled them. + +2011-07-26: wsfulton + Fix scoping of forward class declarations nested within a class (for C++). Previously the symbol + was incorrectly put into the outer namespace, eg + + namespace std { + template struct map { + class iterator; + } + } + + iterator was scoped as std::iterator, but now it is correctly std::map::iterator; + + Also fixed is %template and template parameters that are a typedef when the template contains + default template parameters, eg: + + namespace Std { + template struct Map { + typedef Key key_type; + typedef T mapped_type; + } + } + tyepdef double DOUBLE; + %typemap(MM) Std::Map; + + All symbols within Map will be resolved correctly, eg key_type and mapped_type no matter if the + wrapped code uses Std::Map or std::Map or Std::Map + + Also fixes bug #3378145 - regression introduced in 2.0.4 - %template using traits. + +2011-07-20 szager + [python] Fix closure for tp_call slot. + +2011-07-16: wsfulton + [python] Fix director typemap using PyObject *. + +2011-07-13: szager + [python] SF patch #3365908 - Add all template parameters to map support code in std_map.i + +2011-07-13: szager + [python] Fix for bug 3324753: %rename member variables with -builtin. + +2011-07-01: wsfulton + Fix some scope and symbol lookup problems when template default parameters are being + used with typedef. For example: + + template struct Foo { + typedef XX X; + typedef TT T; + }; + template struct UsesFoo { + void x(typename Foo::T, typename Foo::X); + }; + + Also fixes use of std::vector::size_type for Python as reported by Aubrey Barnard. + +2011-06-23: olly + [PHP] Fix director code to work when PHP is built with ZTS enabled, + which is the standard configuration on Microsoft Windows. + +2011-06-21: mutandiz + [allegrocl] + - various small tweaks and bug fixes. + - Avoid name conflicts between smart pointer wrappers and the wrappers for + the actual class. + - Fix default typemaps for C bindings, which were incorrectly attempting to + call non-existent destructors on user-defined types. + - New feature, feature:aclmixins, for adding superclass to the foreign class + wrappers. + - Improve longlong typemaps. + +2011-06-19: wsfulton + Fix incorrect typemaps being used for a symbol within a templated type, eg: + A::value_type would incorrectly use a typemap for type A. + +2011-06-18: olly + [Tcl] Fix variable declarations in middle of blocks which isn't + permitted in C90 (issue probably introduced in 2.0.3 by patch #3224663). + Reported by Paul Obermeier in SF#3288586. + +2011-06-17: wsfulton + [Java] SF #3312505 - slightly easier to wrap char[] or char[ANY] with a Java byte[] + using arrays_java.i. + +2011-06-13: wsfulton + [Ruby, Octave] SF #3310528 Autodoc fixes similar to those described below for Python. + +2011-06-10: wsfulton + [Python] Few subtle bugfixes in autodoc documentation generation, + - Unnamed argument names fix for autodoc levels > 0. + - Display of template types fixed for autodoc levels > 1. + - Fix SF #3310528 - display of typedef structs for autodoc levels > 1. + - Add missing type for self for autodoc levels 1 and 3. + - autodoc levels 2 and 3 documented. + - Minor tweaks to autodoc style to conform with PEP8. + 2011-05-30: olly [PHP] Fix handling of directors when -prefix is used. diff --git a/COPYRIGHT b/COPYRIGHT index 855425431..e86a994fa 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -54,6 +54,7 @@ Past SWIG developers and major contributors include: Duncan Temple Lang (R) Miklos Vajna (PHP directors) Mark Gossage (mark@gossage.cjb.net) (Lua) + Raman Gopalan (ramangopalan@gmail.com) (eLua) Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) John Lenz (Guile, MzScheme updates, Chicken module, runtime system) Baozeng Ding (Scilab) diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html new file mode 100644 index 000000000..443d77691 --- /dev/null +++ b/Doc/Manual/Android.html @@ -0,0 +1,749 @@ + + + +SWIG and Android + + + +

18 SWIG and Android

+ + + + + + +

+This chapter describes SWIG's support of Android. +

+ + + +

18.1 Overview

+ + +

+The Android chapter is fairly short as support for Android is the same as for Java, where the Java Native Interface (JNI) is +used to call from Android Java into C or C++ compiled code. +Everything in the Java chapter applies to generating code for access from Android Java code. +This chapter contains a few Android specific notes and examples. +

+ +

18.2 Android examples

+ + +

18.2.1 Examples introduction

+ + +

+The examples require the the Android SDK and Android NDK which can be installed as per instructions in the links. +The Eclipse version is not required for these examples as just the command line tools are used (shown for Linux as the host, but Windows will be very similar, if not identical in most places). +Add the SDK tools and NDK tools to your path and create a directory somewhere for your Android projects (adjust PATH as necessary to where you installed the tools): +

+ +
+
+$ export PATH=$HOME/android/android-sdk-linux_x86/tools:$HOME/android/android-sdk-linux_x86/platform-tools:$HOME/android/android-ndk-r6b:$PATH
+$ mkdir AndroidApps 
+$ cd AnrdoidApps
+
+
+ +

+The examples use a target id of 1. This might need changing depending on your setup. +After installation of the Android SDK, the available target ids can be viewed by running the command below. +Please adjust the id to suit your target device. +

+ +
+
+$ android list targets
+
+
+ +

+The following examples are shipped with SWIG under the Examples/android directory and include a Makefile to build and install each example. +

+ +

18.2.2 Simple C example

+ + +

+This simple C example shows how to call a C function as well as read and modify a global variable. +First we'll create and build a pure Java Android app. Afterwards the JNI code will be generated by SWIG and built into the app. +First create and build an app called SwigSimple in a subdirectory called simple using the commands below. +Adjust the --target id as mentioned earlier in the Examples introduction. +Managing Projects from the Command Line on the Android developer's site is a useful reference for these steps. +

+ +
+
+$ android create project --target 1 --name SwigSimple --path ./simple --activity SwigSimple --package org.swig.simple
+$ cd simple
+$ ant debug
+
+
+ +

+Modify src/org/swig/simple/SwigSimple.java from the default to: +

+ +
+
+package org.swig.simple;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.ScrollView;
+import android.text.method.ScrollingMovementMethod;
+
+public class SwigSimple extends Activity
+{
+    TextView outputText = null;
+    ScrollView scroller = null;
+
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState)
+    {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+
+        outputText = (TextView)findViewById(R.id.OutputText);
+        outputText.setText("Press 'Run' to start...\n");
+        outputText.setMovementMethod(new ScrollingMovementMethod());
+
+        scroller = (ScrollView)findViewById(R.id.Scroller);
+    }
+
+    public void onRunButtonClick(View view)
+    {
+      outputText.append("Started...\n");
+      nativeCall();
+      outputText.append("Finished!\n");
+      
+      // Ensure scroll to end of text
+      scroller.post(new Runnable() {
+        public void run() {
+          scroller.fullScroll(ScrollView.FOCUS_DOWN);
+        }
+      });
+    }
+
+    /** Calls into C/C++ code */
+    public void nativeCall()
+    {
+        // TODO
+    }
+}
+
+
+ +

+The above simply adds a Run button and scrollable text view as the GUI aspects of the program. +The associated resources need to be created, modify res/layout/main.xml as follows: +

+ +
+
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<Button
+    android:id="@+id/RunButton"  
+    android:layout_width="wrap_content"  
+    android:layout_height="wrap_content"  
+    android:text="Run..."  
+    android:onClick="onRunButtonClick"
+    />
+<ScrollView
+    android:id="@+id/Scroller"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<TextView
+    android:id="@+id/OutputText"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    />
+</ScrollView>
+</LinearLayout>
+
+
+ +

+Rebuild the project with your changes: +

+ +
+
+$ ant debug
+
+
+ +

+Although there are no native function calls in the code, yet, you may want to check that this simple pure +Java app runs before adding in the native calls. +First, set up your Android device for hardware debugging, see Using hardware devices on the Android developer's site. +When complete your device should be listed in those attached, something like: +

+ +
+
+$ adb devices
+List of devices attached 
+A32-6DBE0001-9FF80000-015D62C3-02018028	device
+
+
+ +

+This means you are now ready to install the application... +

+ +
+
+$ adb install bin/SwigSimple-debug.apk 
+95 KB/s (4834 bytes in 0.049s)
+	pkg: /data/local/tmp/SwigSimple-debug.apk
+Success
+
+
+ +

+The newly installed 'SwigSimple' app will be amongst all your other applications on the home screen. Run the app and it will show a Run button text box below it. +Press the Run button to see the simple text output. +

+ +

+The application can be uninstalled like any other application and in fact must be uninstalled before installing an updated version. Uninstalling is quite easy too from your host computer: +

+ +
+
+$ adb uninstall org.swig.simple
+Success
+
+
+ +

+Now that you have a pure Java Android app working, let's add some JNI code generated from SWIG. +

+ +

+First create a jni subdirectory and then create some C source code in jni/example.c: +

+ +
+
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+  int g;
+  g = y;
+  while (x > 0) {
+    g = x;
+    x = y % x;
+    y = g;
+  }
+  return g;
+}
+
+
+ +

+Create a SWIG interface file for this C code, jni/example.i: +

+ +
+
+/* File : example.i */
+%module example
+
+%inline %{
+extern int    gcd(int x, int y);
+extern double Foo;
+%}
+
+
+ +

+Invoke SWIG as follows: +

+ +
+
+$ swig -java -package org.swig.simple -outdir src/org/swig/simple -o jni/example_wrap.c jni/example.i
+
+
+ +

+SWIG generates the following files: +

+
    +
  • src/org/swig/simple/exampleJNI.java
  • +
  • src/org/swig/simple/example.java
  • +
  • jni/example_wrap.c
  • +
+ +

+Next we need to create a standard Android NDK build system file jni/Android.mk: +

+ +
+
+# File: Android.mk
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := example
+LOCAL_SRC_FILES := example_wrap.c example.c
+
+include $(BUILD_SHARED_LIBRARY)
+
+
+ +

+See the Android NDK documentation for more on the NDK build system and getting started with the NDK. +A simple invocation of ndk-build will compile the .c files and generate a shared object/system library. Output will be similar to: +

+ +
+
+$ ndk-build
+Compile thumb  : example <= example_wrap.c
+Compile thumb  : example <= example.c
+SharedLibrary  : libexample.so
+Install        : libexample.so => libs/armeabi/libexample.so
+
+
+ +

+Now that the C JNI layer has been built, we can write Java code to call into the this layer. +Modify the nativeCall method in src/org/swig/simple/SwigSimple.java to call the JNI code as follows and add the static constructor to load the system library containing the compiled JNI C code: +

+ +
+
+    /** Calls into C/C++ code */
+    public void nativeCall()
+    {
+      // Call our gcd() function
+      
+      int x = 42;
+      int y = 105;
+      int g = example.gcd(x,y);
+      outputText.append("The greatest common divisor of " + x + " and " + y + " is " + g + "\n");
+
+      // Manipulate the Foo global variable
+
+      // Output its current value
+      double foo = example.getFoo();
+      outputText.append("Foo = " + foo + "\n");
+
+      // Change its value
+      example.setFoo(3.1415926);
+
+      // See if the change took effect
+      outputText.append("Foo = " + example.getFoo() + "\n");
+
+      // Restore value
+      example.setFoo(foo);
+    }
+
+    /** static constructor */
+    static {
+        System.loadLibrary("example");
+    }
+
+
+ +

+Compile the Java code as usual, uninstall the old version of the app if still installed and re-install the new app: +

+ +
+
+$ ant debug
+$ adb uninstall org.swig.simple
+$ adb install bin/SwigSimple-debug.apk 
+
+
+ +

+Run the app again and this time you will see the output pictured below, showing the result of calls into the C code: +

+ +
Android screenshot of SwigSimple example
+ + +

18.2.3 C++ class example

+ + +

+The steps for calling C++ code are almost identical to those in the previous C code example. +All the steps required to compile and use a simple hierarchy of classes for shapes are shown in this example. +

+ +

+First create an Android project called SwigClass in a subdirectory called class. +The steps below create and build a the JNI C++ app. +Adjust the --target id as mentioned earlier in the Examples introduction. +

+ +
+
+$ android create project --target 1 --name SwigClass --path ./class --activity SwigClass --package org.swig.classexample
+$ cd class
+
+
+ +

+Now create a jni subdirectory and then create a C++ header file jni/example.h which defines our +hierarchy of shape classes: +

+ +
+
+/* File : example.h */
+
+class Shape {
+public:
+  Shape() {
+    nshapes++;
+  }
+  virtual ~Shape() {
+    nshapes--;
+  };
+  double  x, y;   
+  void    move(double dx, double dy);
+  virtual double area(void) = 0;
+  virtual double perimeter(void) = 0;
+  static  int nshapes;
+};
+
+class Circle : public Shape {
+private:
+  double radius;
+public:
+  Circle(double r) : radius(r) { };
+  virtual double area(void);
+  virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+  double width;
+public:
+  Square(double w) : width(w) { };
+  virtual double area(void);
+  virtual double perimeter(void);
+};
+
+
+ +

+and create the implementation in the jni/example.cpp file: +

+ +
+
+/* File : example.cpp */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+  x += dx;
+  y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+  return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+  return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+  return width*width;
+}
+
+double Square::perimeter(void) {
+  return 4*width;
+}
+
+
+ +

+Create a SWIG interface file for this C++ code in jni/example.i: +

+ +
+
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
+
+ +

+Invoke SWIG as follows, note that the -c++ option is required for C++ code: +

+ +
+
+$ swig -c++ -java -package org.swig.classexample -outdir src/org/swig/classexample -o jni/example_wrap.cpp jni/example.i
+
+
+ +

+SWIG generates the following files: +

+
    +
  • src/org/swig/classexample/Square.java
  • +
  • src/org/swig/classexample/exampleJNI.java
  • +
  • src/org/swig/classexample/example.java
  • +
  • src/org/swig/classexample/Circle.java
  • +
  • src/org/swig/classexample/Shape.java
  • +
  • jni/example_wrap.cpp
  • +
+ +

+Next we need to create an Android NDK build system file for compiling the C++ code jni/Android.mk. +The -frtti compiler flag isn't strictly needed for this example, but is needed for any code that uses C++ RTTI: +

+ +
+
+# File: Android.mk
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := example
+LOCAL_SRC_FILES := example_wrap.cpp example.cpp
+LOCAL_CFLAGS    := -frtti
+
+include $(BUILD_SHARED_LIBRARY)
+
+
+ + +

+A simple invocation of ndk-build will compile the .cpp files and generate a shared object/system library. Output will be similar to: +

+ +
+
+$ ndk-build
+Compile++ thumb  : example <= example_wrap.cpp
+Compile++ thumb  : example <= example.cpp
+StaticLibrary  : libstdc++.a
+SharedLibrary  : libexample.so
+Install        : libexample.so => libs/armeabi/libexample.so
+
+
+ +

+Now that the C JNI layer has been built, we can write Java code to call into this layer. +Modify src/org/swig/classexample/SwigClass.java from the default to: +

+ +
+
+package org.swig.classexample;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.ScrollView;
+import android.text.method.ScrollingMovementMethod;
+
+public class SwigClass extends Activity
+{
+    TextView outputText = null;
+    ScrollView scroller = null;
+
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState)
+    {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+
+        outputText = (TextView)findViewById(R.id.OutputText);
+        outputText.setText("Press 'Run' to start...\n");
+        outputText.setMovementMethod(new ScrollingMovementMethod());
+
+        scroller = (ScrollView)findViewById(R.id.Scroller);
+    }
+
+    public void onRunButtonClick(View view)
+    {
+      outputText.append("Started...\n");
+      nativeCall();
+      outputText.append("Finished!\n");
+      
+      // Ensure scroll to end of text
+      scroller.post(new Runnable() {
+        public void run() {
+          scroller.fullScroll(ScrollView.FOCUS_DOWN);
+        }
+      });
+    }
+
+    /** Calls into C/C++ code */
+    public void nativeCall()
+    {
+      // ----- Object creation -----
+
+      outputText.append( "Creating some objects:\n" );
+      Circle c = new Circle(10);
+      outputText.append( "    Created circle " + c + "\n");
+      Square s = new Square(10);
+      outputText.append( "    Created square " + s + "\n");
+
+      // ----- Access a static member -----
+
+      outputText.append( "\nA total of " + Shape.getNshapes() + " shapes were created\n" );
+
+      // ----- Member data access -----
+
+      // Notice how we can do this using functions specific to
+      // the 'Circle' class.
+      c.setX(20);
+      c.setY(30);
+
+      // Now use the same functions in the base class
+      Shape shape = s;
+      shape.setX(-10);
+      shape.setY(5);
+
+      outputText.append( "\nHere is their current position:\n" );
+      outputText.append( "    Circle = (" + c.getX() + " " + c.getY() + ")\n" );
+      outputText.append( "    Square = (" + s.getX() + " " + s.getY() + ")\n" );
+
+      // ----- Call some methods -----
+
+      outputText.append( "\nHere are some properties of the shapes:\n" );
+      Shape[] shapes = {c,s};
+      for (int i=0; i<shapes.length; i++)
+      {
+        outputText.append( "   " + shapes[i].toString() + "\n" );
+        outputText.append( "        area      = " + shapes[i].area() + "\n" );
+        outputText.append( "        perimeter = " + shapes[i].perimeter() + "\n" );
+      }
+
+      // Notice how the area() and perimeter() functions really
+      // invoke the appropriate virtual method on each object.
+
+      // ----- Delete everything -----
+
+      outputText.append( "\nGuess I'll clean up now\n" );
+
+      // Note: this invokes the virtual destructor
+      // You could leave this to the garbage collector
+      c.delete();
+      s.delete();
+
+      outputText.append( Shape.getNshapes() + " shapes remain\n" );
+      outputText.append( "Goodbye\n" );
+    }
+
+    /** static constructor */
+    static {
+        System.loadLibrary("example");
+    }
+}
+
+
+ +

+Note the static constructor and the interesting JNI code is in the nativeCall method. +The remaining code deals with the GUI aspects which are identical to the previous C simple example. Modify res/layout/main.xml to contain the xml for the 'Run' button and scrollable text view: +

+ +
+
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<Button
+    android:id="@+id/RunButton"  
+    android:layout_width="wrap_content"  
+    android:layout_height="wrap_content"  
+    android:text="Run..."  
+    android:onClick="onRunButtonClick"
+    />
+<ScrollView
+    android:id="@+id/Scroller"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<TextView
+    android:id="@+id/OutputText"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    />
+</ScrollView>
+</LinearLayout>
+
+
+ + +

+Compile the Java code as usual, uninstall the old version of the app if installed and re-install the new app: +

+ +
+
+$ ant debug
+$ adb uninstall org.swig.classexample
+$ adb install bin/SwigClass-debug.apk 
+
+
+ +

+Run the app to see the result of calling the C++ code from Java: +

+ +
Android screenshot of SwigClass example
+ + + + diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 6691400b7..b511dc126 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -5,12 +5,13 @@ -

18 SWIG and C#

+

19 SWIG and C#

  • Introduction
  • Differences to the Java module +
  • Void pointers
  • C# Arrays +
  • Multiples modules
  • C# Typemap examples
    • Memory management when returning references to member variables @@ -46,7 +48,7 @@ -

      18.1 Introduction

      +

      19.1 Introduction

      @@ -66,7 +68,7 @@ The Microsoft Developer Network (MSDN) h Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries.

      -

      18.2 Differences to the Java module

      +

      19.2 Differences to the Java module

      @@ -169,6 +171,14 @@ javadestruct_derived -> csdestruct_derived

    • +
    • +

      Typemap macros:

      +
      +SWIG_JAVABODY_PROXY         -> SWIG_CSBODY_PROXY
      +SWIG_JAVABODY_TYPEWRAPPER   -> SWIG_CSBODY_TYPEWRAPPER
      +
      +
    • +
    • Additional typemaps:

      @@ -455,7 +465,25 @@ Windows users can also get the examples working using a Cygwin or MinGW environment for automatic configuration of the example makefiles. Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path. -

      18.3 C# Arrays

      +

      19.3 Void pointers

      + + +

      +By default SWIG treats void * as any other pointer and hence marshalls it as a type wrapper class called SWIGTYPE_p_void. +If you want to marshall with the .NET System.IntPtr type instead, there is a simple set of named typemaps called +void *VOID_INT_PTR that can be used. +They can be applied like any other named typemaps: +

      + + +
      +
      +%apply void *VOID_INT_PTR { void * }
      +void * f(void *v);
      +
      +
      + +

      19.4 C# Arrays

      @@ -467,7 +495,7 @@ with one of the following three approaches; namely the SWIG C arrays library, P/ pinned arrays.

      -

      18.3.1 The SWIG C arrays library

      +

      19.4.1 The SWIG C arrays library

      @@ -504,7 +532,7 @@ example.print_array(c.cast()); // Pass to C

-

18.3.2 Managed arrays using P/Invoke default array marshalling

+

19.4.2 Managed arrays using P/Invoke default array marshalling

@@ -618,7 +646,7 @@ This results in the module class method

-and intermediate class method +and intermediary class method

@@ -631,7 +659,7 @@ and intermediate class method
-

18.3.3 Managed arrays using pinning

+

19.4.3 Managed arrays using pinning

@@ -713,7 +741,7 @@ marshalling is the "unsafe" quantifier, which is required because we are handlin

-Also the intermediate class method looks a little different from the default marshalling +Also the intermediary class method looks a little different from the default marshalling example - the method is expecting an IntPtr as the parameter type.

@@ -726,7 +754,7 @@ public static extern void myArrayCopy(IntPtr jarg1, IntPtr jarg2, int jarg3); -

18.4 C# Exceptions

+

19.5 C# Exceptions

@@ -823,7 +851,7 @@ set so should only be used when a C# exception is not created.

-

18.4.1 C# exception example using "check" typemap

+

19.5.1 C# exception example using "check" typemap

@@ -1005,7 +1033,7 @@ method and C# code does not handle pending exceptions via the canthrow attribute Actually it will issue this warning for any function beginning with SWIG_CSharpSetPendingException.

-

18.4.2 C# exception example using %exception

+

19.5.2 C# exception example using %exception

@@ -1070,7 +1098,7 @@ The managed code generated does check for the pending exception as mentioned ear -

18.4.3 C# exception example using exception specifications

+

19.5.3 C# exception example using exception specifications

@@ -1127,7 +1155,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) { Multiple catch handlers are generated should there be more than one exception specifications declared.

-

18.4.4 Custom C# ApplicationException example

+

19.5.4 Custom C# ApplicationException example

@@ -1261,7 +1289,7 @@ try { -

18.5 C# Directors

+

19.6 C# Directors

@@ -1274,7 +1302,7 @@ The following sections provide information on the C# director implementation and However, the Java directors section should also be read in order to gain more insight into directors.

-

18.5.1 Directors example

+

19.6.1 Directors example

@@ -1395,7 +1423,7 @@ CSharpDerived - UIntMethod(123) -

18.5.2 Directors implementation

+

19.6.2 Directors implementation

@@ -1581,7 +1609,7 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) { -

18.5.3 Director caveats

+

19.6.3 Director caveats

@@ -1629,7 +1657,42 @@ However, a call from C# to CSharpDefaults.DefaultMethod() will of cours should pass the call on to CSharpDefaults.DefaultMethod(int)using the C++ default value, as shown above.

-

18.6 C# Typemap examples

+

19.7 Multiples modules

+ + +

+When using multiple modules it is is possible to compile each SWIG generated wrapper +into a different assembly. +However, by default the generated code may not compile if +generated classes in one assembly use generated classes in another assembly. +The visibility of the +getCPtr() and pointer constructor generated from the csbody typemaps needs changing. +The default visibility is internal but it needs to be public for access from a different assembly. +Just changing 'internal' to 'public' in the typemap achieves this. +Two macros are available in csharp.swg to make this easier and using them is the preferred approach +over simply copying the typemaps and modifying as this is forward compatible with any changes in +the csbody typemap in future versions of SWIG. +The macros are for the proxy and typewrapper classes and can respectively be used to +to make the method and constructor public: +

+ +
+
+  SWIG_CSBODY_PROXY(public, public, SWIGTYPE)
+  SWIG_CSBODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
+
+
+ +

+Alternatively, instead of exposing these as public, consider +using the [assembly:InternalsVisibleTo("Name")] attribute available in the .NET framework when you +know which assemblies these can be exposed to. +Another approach would be to make these public, but also to hide them from intellisense by using +the [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] attribute +if you don't want users to easily stumble upon these so called 'internal workings' of the wrappers. +

+ +

19.8 C# Typemap examples

This section includes a few examples of typemaps. For more examples, you @@ -1637,7 +1700,7 @@ might look at the files "csharp.swg" and "typemaps.i" in the SWIG library. -

18.6.1 Memory management when returning references to member variables

+

19.8.1 Memory management when returning references to member variables

@@ -1761,7 +1824,7 @@ public class Bike : IDisposable { Note the addReference call.

-

18.6.2 Memory management for objects passed to the C++ layer

+

19.8.2 Memory management for objects passed to the C++ layer

@@ -1880,7 +1943,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class. -

18.6.3 Date marshalling using the csin typemap and associated attributes

+

19.8.3 Date marshalling using the csin typemap and associated attributes

@@ -2166,7 +2229,7 @@ public class example { -

18.6.4 A date example demonstrating marshalling of C# properties

+

19.8.4 A date example demonstrating marshalling of C# properties

@@ -2267,7 +2330,7 @@ Some points to note: -

18.6.5 Turning wrapped classes into partial classes

+

19.8.5 Turning wrapped classes into partial classes

@@ -2367,7 +2430,7 @@ demonstrating that the class contains methods calling both unmanaged code - The following example is an alternative approach to adding managed code to the generated proxy class.

-

18.6.6 Extending proxy classes with additional C# code

+

19.8.6 Extending proxy classes with additional C# code

@@ -2406,7 +2469,7 @@ public class ExtendMe : IDisposable { -

18.6.7 Underlying type for enums

+

19.8.7 Underlying type for enums

diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index 006b648d6..4e43b9b90 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -8,7 +8,7 @@ -

19 SWIG and Chicken

+

20 SWIG and Chicken

    @@ -72,7 +72,7 @@

    -

    19.1 Preliminaries

    +

    20.1 Preliminaries

    @@ -89,7 +89,7 @@ directory for the basic steps to run SWIG CHICKEN.

    -

    19.1.1 Running SWIG in C mode

    +

    20.1.1 Running SWIG in C mode

    @@ -122,7 +122,7 @@ object files and linked into your project.

    -

    19.1.2 Running SWIG in C++ mode

    +

    20.1.2 Running SWIG in C++ mode

    @@ -151,10 +151,10 @@ object files and linked into your project.

    -

    19.2 Code Generation

    +

    20.2 Code Generation

    -

    19.2.1 Naming Conventions

    +

    20.2.1 Naming Conventions

    @@ -170,7 +170,7 @@ %rename SWIG directive in the SWIG interface file.

    -

    19.2.2 Modules

    +

    20.2.2 Modules

    @@ -192,7 +192,7 @@ (uses modulename)) CHICKEN Scheme form.

    -

    19.2.3 Constants and Variables

    +

    20.2.3 Constants and Variables

    @@ -229,7 +229,7 @@ for info on how to apply the %feature.

    -

    19.2.4 Functions

    +

    20.2.4 Functions

    @@ -248,7 +248,7 @@ parameters). The return values can then be accessed with (call-with-values).

    -

    19.2.5 Exceptions

    +

    20.2.5 Exceptions

    The SWIG chicken module has support for exceptions thrown from @@ -290,7 +290,7 @@

-

19.3 TinyCLOS

+

20.3 TinyCLOS

@@ -333,7 +333,7 @@

-

19.4 Linkage

+

20.4 Linkage

@@ -354,7 +354,7 @@

-

19.4.1 Static binary or shared library linked at compile time

+

20.4.1 Static binary or shared library linked at compile time

We can easily use csc to build a static binary.

@@ -395,7 +395,7 @@ in which case the test script does not need to be linked with example.so. The t be run with csi.

-

19.4.2 Building chicken extension libraries

+

20.4.2 Building chicken extension libraries

Building a shared library like in the above section only works if the library @@ -453,7 +453,7 @@ 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.

-

19.4.3 Linking multiple SWIG modules with TinyCLOS

+

20.4.3 Linking multiple SWIG modules with TinyCLOS

Linking together multiple modules that share type information using the %import @@ -477,7 +477,7 @@ with (declare (uses ...)). To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...)) all the modules.

-

19.5 Typemaps

+

20.5 Typemaps

@@ -486,7 +486,7 @@ all the modules.

Lib/chicken/chicken.swg.

-

19.6 Pointers

+

20.6 Pointers

@@ -519,7 +519,7 @@ all the modules.

type. flags is either zero or SWIG_POINTER_DISOWN (see below).

-

19.6.1 Garbage collection

+

20.6.1 Garbage collection

If the owner flag passed to SWIG_NewPointerObj is 1, NewPointerObj will add a @@ -550,7 +550,7 @@ all the modules.

must be called manually.

-

19.7 Unsupported features and known problems

+

20.7 Unsupported features and known problems

-

19.7.1 TinyCLOS problems with Chicken version <= 1.92

+

20.7.1 TinyCLOS problems with Chicken version <= 1.92

In Chicken versions equal to or below 1.92, TinyCLOS has a limitation such that generic methods do not properly work on methods diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index b53923c17..7cae25e7f 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -242,6 +242,7 @@

  • Exception handling with %catches
  • Pointers to Members
  • Smart pointers and operator->() +
  • C++ reference counted objects - ref/unref feature
  • Using declarations and inheritance
  • Nested classes
  • A brief rant about const-correctness @@ -396,6 +397,7 @@
  • Typemaps for multiple target languages
  • Optimal code generation when returning by value
  • Multi-argument typemaps +
  • Typemap warnings
  • Typemap fragments -

    22 SWIG and Guile

    +

    23 SWIG and Guile

    @@ -806,7 +826,7 @@
    -

    23 SWIG and Java

    +

    24 SWIG and Java

    @@ -944,12 +964,12 @@
  • Performance concerns and hints
  • Debugging -
  • Examples +
  • Java Examples -

    24 SWIG and Common Lisp

    +

    25 SWIG and Common Lisp

    @@ -972,7 +992,7 @@
    -

    25 SWIG and Lua

    +

    26 SWIG and Lua

    @@ -980,6 +1000,7 @@
  • Preliminaries
  • Running SWIG -
  • Typemaps +
  • Typemaps -
  • Writing typemaps +
  • Writing typemaps -
  • Customization of your Bindings +
  • Customization of your Bindings -
  • Details on the Lua binding +
  • Details on the Lua binding -

    26 SWIG and Modula-3

    +

    27 SWIG and Modula-3

    @@ -1067,7 +1089,7 @@
    -

    27 SWIG and MzScheme/Racket

    +

    28 SWIG and MzScheme/Racket

    @@ -1079,7 +1101,7 @@
    -

    28 SWIG and Ocaml

    +

    29 SWIG and Ocaml

    @@ -1130,7 +1152,7 @@
    -

    29 SWIG and Octave

    +

    30 SWIG and Octave

    @@ -1138,6 +1160,7 @@
  • Preliminaries
  • Running SWIG @@ -1165,7 +1188,7 @@ -

    30 SWIG and Perl5

    +

    31 SWIG and Perl5

    @@ -1232,7 +1255,7 @@
    -

    31 SWIG and PHP

    +

    32 SWIG and PHP

    @@ -1272,7 +1295,7 @@
    -

    32 SWIG and Pike

    +

    33 SWIG and Pike

    @@ -1296,7 +1319,7 @@
    -

    33 SWIG and Python

    +

    34 SWIG and Python

    @@ -1329,7 +1352,7 @@
  • C++ namespaces
  • C++ templates
  • C++ Smart Pointers -
  • C++ Reference Counted Objects (ref/unref) +
  • C++ reference counted objects
  • Further details on the Python class interface
      @@ -1389,6 +1412,8 @@
    • %feature("docstring") @@ -1404,7 +1429,7 @@ -

      34 SWIG and R

      +

      35 SWIG and R

      @@ -1420,7 +1445,7 @@
      -

      35 SWIG and Ruby

      +

      36 SWIG and Ruby

      @@ -1554,7 +1579,7 @@
      -

      36 SWIG and Tcl

      +

      37 SWIG and Tcl

      @@ -1620,7 +1645,7 @@
      -

      37 Extending SWIG to support new languages

      +

      38 Extending SWIG to support new languages

      @@ -1691,3 +1716,4 @@ + diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 7f164ac57..b98fbfc88 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -704,6 +704,11 @@ depends on the target language on implementing the 'disown' mechanism properly.

      +

      +The use of %newobject is also integrated with reference counting and is covered in the +C++ reference counted objects section. +

      +

      Compatibility note: Previous versions of SWIG had a special %new directive. However, unlike %newobject, it only applied to the next declaration. For example: diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html index abcffa58e..43fa69196 100644 --- a/Doc/Manual/D.html +++ b/Doc/Manual/D.html @@ -6,7 +6,7 @@ -

      20 SWIG and D

      +

      21 SWIG and D

        @@ -41,10 +41,10 @@ -

        20.1 Introduction

        +

        21.1 Introduction

        -

        From the D Programming Language web site: »D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. [...] The D language is statically typed and compiles directly to machine code.« As such, it is not very surprising that D is able to directly interface with C libraries. Why would a SWIG module for D be needed then in the first place?

        +

        From the D Programming Language web site: D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. [...] The D language is statically typed and compiles directly to machine code. As such, it is not very surprising that D is able to directly interface with C libraries. Why would a SWIG module for D be needed then in the first place?

        Well, besides the obvious downside that the C header files have to be manually converted to D modules for this to work, there is one major inconvenience with this approach: D code usually is on a higher abstraction level than C, and many of the features that make D interesting are simply not available when dealing with C libraries, requiring you e.g. to manually convert strings between pointers to \0-terminated char arrays and D char arrays, making the algorithms from the D2 standard library unusable with C arrays and data structures, and so on.

        @@ -53,7 +53,7 @@

        To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on C# (and also on Java, since the C# module was in turn forked from it).

        -

        20.2 Command line invocation

        +

        21.2 Command line invocation

        To activate the D module, pass the -d option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:

        @@ -83,10 +83,10 @@ -

        20.3 Typemaps

        +

        21.3 Typemaps

        -

        20.3.1 C# <-> D name comparison

        +

        21.3.1 C# <-> D name comparison

        If you already know the SWIG C# module, you might find the following name comparison table useful:

        @@ -112,7 +112,7 @@
      -

      20.3.2 ctype, imtype, dtype

      +

      21.3.2 ctype, imtype, dtype

      Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.

      @@ -120,7 +120,7 @@

      The ctype typemap is used to determine the types to use in the C wrapper functions. The types from the imtype typemap are used in the extern(C) declarations of these functions in the intermediary D module. The dtype typemap contains the D types used in the D proxy module/class.

      -

      20.3.3 in, out, directorin, directorout

      +

      21.3.3 in, out, directorin, directorout

      Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).

      @@ -130,7 +130,7 @@

      The directorin typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by directorout (see below).

      -

      20.3.4 din, dout, ddirectorin, ddirectorout

      +

      21.3.4 din, dout, ddirectorin, ddirectorout

      Typemaps for code generation in D proxy and type wrapper classes.

      @@ -157,13 +157,13 @@ dtype DClass.method(dtype a)
      -

      20.3.5 typecheck typemaps

      +

      21.3.5 typecheck typemaps

      Because, unlike many scripting languages supported by SWIG, D does not need any dynamic dispatch helper to access an overloaded function, the purpose of these is merely to issue a warning for overloaded C++ functions that cannot be overloaded in D (as more than one C++ type maps to a single D type).

      -

      20.3.6 Code injection typemaps

      +

      21.3.6 Code injection typemaps

      These typemaps are used for generating the skeleton of proxy classes for C++ types.

      @@ -175,7 +175,7 @@

      dconstructor, ddestructor, ddispose and ddispose_derived are used to generate the class constructor, destructor and dispose() method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in dbody and dbody_derived. You can override them for specific types.

      -

      20.3.7 Special variable macros

      +

      21.3.7 Special variable macros

      The standard SWIG special variables are available for use within typemaps as described in the Typemaps documentation, for example $1, $input, $result etc.

      @@ -295,7 +295,7 @@ $importtype(AnotherInterface) -

      20.4 %features

      +

      21.4 %features

      The D module defines a number of directives which modify the SWIG features set globally or for a specific declaration:

      @@ -325,7 +325,7 @@ struct A { -

      20.5 Pragmas

      +

      21.5 Pragmas

      There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:

      @@ -364,7 +364,7 @@ struct A { -

      20.6 D Exceptions

      +

      21.6 D Exceptions

      Out of the box, C++ exceptions are fundamentally incompatible to their equivalent in the D world and cannot simply be propagated to a calling D method. There is, however, an easy way to solve this problem: Just catch the exception in the C/C++ wrapper layer, pass the contents to D, and make the wrapper code rethrow the exception in the D world.

      @@ -374,7 +374,7 @@ struct A {

      As this feature is implemented in exactly the same way it is for C#, please see the C# documentation for a more detailed explanation.

      -

      20.7 D Directors

      +

      21.7 D Directors

      When the directors feature is activated, SWIG generates extra code on both the C++ and the D side to enable cross-language polymorphism. Essentially, this means that if you subclass a proxy class in D, C++ code can access any overridden virtual methods just as if you created a derived class in C++.

      @@ -383,19 +383,19 @@ struct A {

      -

      20.8 Other features

      +

      21.8 Other features

      -

      20.8.1 Extended namespace support (nspace)

      +

      21.8.1 Extended namespace support (nspace)

      By default, SWIG flattens all C++ namespaces into a single target language namespace, but as for Java and C#, the nspace feature is supported for D. If it is active, C++ namespaces are mapped to D packages/modules. Note, however, that like for the other languages, free variables and functions are not supported yet; currently, they are all allows written to the main proxy D module.

      -

      20.8.2 Native pointer support

      +

      21.8.2 Native pointer support

      -

      Contrary to many of the scripting languages supported by SWIG, D fully supports C-style pointers. The D module thus includes a custom mechanism to wrap C pointers directly as D pointers where applicable, that is, if the type that is pointed to is represented the same in C and D (on the bit-level), dubbed a »primtive type« below.

      +

      Contrary to many of the scripting languages supported by SWIG, D fully supports C-style pointers. The D module thus includes a custom mechanism to wrap C pointers directly as D pointers where applicable, that is, if the type that is pointed to is represented the same in C and D (on the bit-level), dubbed a primitive type below.

      Central to this custom pointer handling scheme are two typemap attributes: the cprimitive attribute on the dtype typemap and the nativepointer attribute on all the typemaps which influence the D side of the code (dtype, din, dout, ...). When a D typemap is looked up, the following happens behind the scenes:

      @@ -404,7 +404,7 @@ struct A {

      To determine if a type should be considered primitive, the cprimitive attribute on its dtype attribute is used. For example, the dtype typemap for float has cprimitive="1", so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *).

      -

      20.8.3 Operator overloading

      +

      21.8.3 Operator overloading

      The D module comes with basic operator overloading support for both D1 and D2. There are, however, a few limitations arising from conceptual differences between C++ and D:

      @@ -416,7 +416,7 @@ struct A {

      There are also some cases where the operators can be translated to D, but the differences in the implementation details are big enough that a rather involved scheme would be required for automatic wrapping them, which has not been implemented yet. This affects, for example, the array subscript operator, [], in combination with assignments - while operator [] in C++ simply returns a reference which is then written to, D resorts to a separate opIndexAssign method -, or implicit casting (which was introduced in D2 via alias this). Despite the lack of automatic support, manually handling these cases should be perfectly possible.

      -

      20.8.4 Running the test-suite

      +

      21.8.4 Running the test-suite

      As with any other language, the SWIG test-suite can be built for D using the *-d-test-suite targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional D_VERSION variable, e.g. make check-d-test-suite D_VERSION=2.

      @@ -424,14 +424,14 @@ struct A {

      Note: If you want to use GDC on Linux or another platform which requires you to link libdl for dynamically loading the shared library, you might have to add -ldl manually to the d_compile target in Examples/Makefile, because GDC does not currently honor the pragma(lib,...) statement.

      -

      20.9 D Typemap examples

      +

      21.9 D Typemap examples

      There are no D-specific typemap examples yet. However, with the above name comparison table, you should be able to get an idea what can be done by looking at the corresponding C# section.

      -

      20.10 Work in progress and planned features

      +

      21.10 Work in progress and planned features

      There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:

      diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index ff666791c..c3b2740f4 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -6,7 +6,7 @@ -

      37 Extending SWIG to support new languages

      +

      38 Extending SWIG to support new languages

        @@ -75,7 +75,7 @@ -

        37.1 Introduction

        +

        38.1 Introduction

        @@ -91,7 +91,7 @@ Also, this chapter is not meant to be a hand-holding tutorial. As a starting po you should probably look at one of SWIG's existing modules.

        -

        37.2 Prerequisites

        +

        38.2 Prerequisites

        @@ -121,7 +121,7 @@ obvious, but almost all SWIG directives as well as the low-level generation of wrapper code are driven by C++ datatypes.

        -

        37.3 The Big Picture

        +

        38.3 The Big Picture

        @@ -158,7 +158,7 @@ role in making the system work. For example, both typemaps and declaration anno based on pattern matching and interact heavily with the underlying type system.

        -

        37.4 Execution Model

        +

        38.4 Execution Model

        @@ -203,7 +203,7 @@ latter stage of compilation. The next few sections briefly describe some of these stages.

        -

        37.4.1 Preprocessing

        +

        38.4.1 Preprocessing

        @@ -284,7 +284,7 @@ been expanded as well as everything else that goes into the low-level construction of the wrapper code.

        -

        37.4.2 Parsing

        +

        38.4.2 Parsing

        @@ -385,7 +385,7 @@ returning a foo and taking types a and b as arguments).

        -

        37.4.3 Parse Trees

        +

        38.4.3 Parse Trees

        @@ -640,7 +640,7 @@ $ swig -c++ -python -debug-module 4 example.i

      -

      37.4.4 Attribute namespaces

      +

      38.4.4 Attribute namespaces

      @@ -659,7 +659,7 @@ that matches the name of the target language. For example, python:foo perl:foo.

      -

      37.4.5 Symbol Tables

      +

      38.4.5 Symbol Tables

      @@ -750,7 +750,7 @@ example.i:5. Previous declaration is foo_i(int ) -

      37.4.6 The %feature directive

      +

      38.4.6 The %feature directive

      @@ -806,7 +806,7 @@ For example, the exception code above is simply stored without any modifications.

      -

      37.4.7 Code Generation

      +

      38.4.7 Code Generation

      @@ -928,7 +928,7 @@ public : The role of these functions is described shortly.

      -

      37.4.8 SWIG and XML

      +

      38.4.8 SWIG and XML

      @@ -941,7 +941,7 @@ internal data structures, it may be useful to keep XML in the back of your mind as a model.

      -

      37.5 Primitive Data Structures

      +

      38.5 Primitive Data Structures

      @@ -987,7 +987,7 @@ typedef Hash Typetab; -

      37.5.1 Strings

      +

      38.5.1 Strings

      @@ -1128,7 +1128,7 @@ Returns the number of replacements made (if any). -

      37.5.2 Hashes

      +

      38.5.2 Hashes

      @@ -1205,7 +1205,7 @@ Returns the list of hash table keys. -

      37.5.3 Lists

      +

      38.5.3 Lists

      @@ -1294,7 +1294,7 @@ If t is not a standard object, it is assumed to be a char * and is used to create a String object. -

      37.5.4 Common operations

      +

      38.5.4 Common operations

      The following operations are applicable to all datatypes. @@ -1349,7 +1349,7 @@ objects and report errors. Gets the line number associated with x. -

      37.5.5 Iterating over Lists and Hashes

      +

      38.5.5 Iterating over Lists and Hashes

      To iterate over the elements of a list or a hash table, the following functions are used: @@ -1394,7 +1394,7 @@ for (j = First(j); j.item; j= Next(j)) { -

      37.5.6 I/O

      +

      38.5.6 I/O

      Special I/O functions are used for all internal I/O. These operations @@ -1531,7 +1531,7 @@ Similarly, the preprocessor and parser all operate on string-files. -

      37.6 Navigating and manipulating parse trees

      +

      38.6 Navigating and manipulating parse trees

      Parse trees are built as collections of hash tables. Each node is a hash table in which @@ -1665,7 +1665,7 @@ Deletes a node from the parse tree. Deletion reconnects siblings and properly u the parent so that sibling nodes are unaffected. -

      37.7 Working with attributes

      +

      38.7 Working with attributes

      @@ -1782,7 +1782,7 @@ the attribute is optional. Swig_restore() must always be called after function. -

      37.8 Type system

      +

      38.8 Type system

      @@ -1791,7 +1791,7 @@ pointers, references, and pointers to members. A detailed discussion of type theory is impossible here. However, let's cover the highlights.

      -

      37.8.1 String encoding of types

      +

      38.8.1 String encoding of types

      @@ -1892,7 +1892,7 @@ make the final type, the two parts are just joined together using string concatenation.

      -

      37.8.2 Type construction

      +

      38.8.2 Type construction

      @@ -2061,7 +2061,7 @@ Returns the prefix of a type. For example, if ty is ty is unmodified. -

      37.8.3 Type tests

      +

      38.8.3 Type tests

      @@ -2148,7 +2148,7 @@ Checks if ty is a varargs type. Checks if ty is a templatized type. -

      37.8.4 Typedef and inheritance

      +

      38.8.4 Typedef and inheritance

      @@ -2250,7 +2250,7 @@ Fully reduces ty according to typedef rules. Resulting datatype will consist only of primitive typenames. -

      37.8.5 Lvalues

      +

      38.8.5 Lvalues

      @@ -2287,7 +2287,7 @@ Literal y; // type = 'Literal', ltype='p.char' -

      37.8.6 Output functions

      +

      38.8.6 Output functions

      @@ -2349,7 +2349,7 @@ SWIG, but is most commonly associated with type-descriptor objects that appear in wrappers (e.g., SWIGTYPE_p_double). -

      37.9 Parameters

      +

      38.9 Parameters

      @@ -2448,7 +2448,7 @@ included. Used to emit prototypes. Returns the number of required (non-optional) arguments in p. -

      37.10 Writing a Language Module

      +

      38.10 Writing a Language Module

      @@ -2463,7 +2463,7 @@ describes the creation of a minimal Python module. You should be able to extra this to other languages.

      -

      37.10.1 Execution model

      +

      38.10.1 Execution model

      @@ -2473,7 +2473,7 @@ the parsing of command line options, all aspects of code generation are controll different methods of the Language that must be defined by your module.

      -

      37.10.2 Starting out

      +

      38.10.2 Starting out

      @@ -2581,7 +2581,7 @@ that activates your module. For example, swig -python foo.i. The messages from your new module should appear.

      -

      37.10.3 Command line options

      +

      38.10.3 Command line options

      @@ -2640,7 +2640,7 @@ to mark the option as valid. If you forget to do this, SWIG will terminate wit unrecognized command line option error.

      -

      37.10.4 Configuration and preprocessing

      +

      38.10.4 Configuration and preprocessing

      @@ -2689,7 +2689,7 @@ an implementation file python.cxx and a configuration file python.swg.

      -

      37.10.5 Entry point to code generation

      +

      38.10.5 Entry point to code generation

      @@ -2747,7 +2747,7 @@ int Python::top(Node *n) { -

      37.10.6 Module I/O and wrapper skeleton

      +

      38.10.6 Module I/O and wrapper skeleton

      @@ -2896,7 +2896,7 @@ functionWrapper : void Shape_y_set(Shape *self,double y) -

      37.10.7 Low-level code generators

      +

      38.10.7 Low-level code generators

      @@ -3050,7 +3050,7 @@ but without the typemaps, there is still work to do.

      -

      37.10.8 Configuration files

      +

      38.10.8 Configuration files

      @@ -3194,7 +3194,7 @@ politely displays the ignoring language message. -

      37.10.9 Runtime support

      +

      38.10.9 Runtime support

      @@ -3203,7 +3203,7 @@ Discuss the kinds of functions typically needed for SWIG runtime support (e.g. the SWIG files that implement those functions.

      -

      37.10.10 Standard library files

      +

      38.10.10 Standard library files

      @@ -3222,7 +3222,7 @@ The following are the minimum that are usually supported: Please copy these and modify for any new language.

      -

      37.10.11 User examples

      +

      38.10.11 User examples

      @@ -3251,7 +3251,7 @@ during this process, see the section on .

      -

      37.10.12 Test driven development and the test-suite

      +

      38.10.12 Test driven development and the test-suite

      @@ -3310,7 +3310,7 @@ It is therefore essential that the runtime tests are written in a manner that di but error/exception out with an error message on stderr on failure.

      -

      37.10.12.1 Running the test-suite

      +

      38.10.12.1 Running the test-suite

      @@ -3496,7 +3496,7 @@ The syntax for setting environment variables varies from one shell to the next, make ret_by_value.ctest SWIG_FEATURES="-debug-tmsearch" -

      37.10.13 Documentation

      +

      38.10.13 Documentation

      @@ -3528,7 +3528,7 @@ Some topics that you'll want to be sure to address include: if available.

    -

    37.10.14 Prerequisites for adding a new language module to the SWIG distribution

    +

    38.10.14 Prerequisites for adding a new language module to the SWIG distribution

    @@ -3585,7 +3585,7 @@ should be added should there be an area not already covered by the existing tests.

    -

    37.10.15 Coding style guidelines

    +

    38.10.15 Coding style guidelines

    @@ -3609,7 +3609,7 @@ The generated C/C++ code should also follow this style as close as possible. How should be avoided as unlike the SWIG developers, users will never have consistent tab settings.

    -

    37.11 Debugging Options

    +

    38.11 Debugging Options

    @@ -3636,7 +3636,7 @@ There are various command line options which can aid debugging a SWIG interface The complete list of command line options for SWIG are available by running swig -help.

    -

    37.12 Guide to parse tree nodes

    +

    38.12 Guide to parse tree nodes

    @@ -4044,7 +4044,7 @@ extern "X" { ... } declaration. -

    37.13 Further Development Information

    +

    38.13 Further Development Information

    diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 8c072e00a..cd39d1fa1 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -5,7 +5,7 @@ -

    21 SWIG and Go

    +

    22 SWIG and Go

      @@ -43,7 +43,7 @@ the Go programming language see golang.org.

      -

      21.1 Overview

      +

      22.1 Overview

      @@ -67,7 +67,7 @@ checking and runtime library are not used with Go. This should be borne in mind when reading the rest of the SWIG documentation.

      -

      21.2 Running SWIG with Go

      +

      22.2 Running SWIG with Go

      @@ -76,7 +76,7 @@ default SWIG will generate code for the gc compilers. To generate code for gccgo, you should also use the -gccgo option.

      -

      21.2.1 Additional Commandline Options

      +

      22.2.1 Additional Commandline Options

      @@ -129,7 +129,7 @@ swig -go -help -

      21.2.2 Go Output Files

      +

      22.2.2 Go Output Files

      When generating Go code, SWIG will generate the following @@ -174,7 +174,7 @@ A typical command sequence would look like this: % 6l main.6

    -

    21.3 A tour of basic C/C++ wrapping

    +

    22.3 A tour of basic C/C++ wrapping

    @@ -184,7 +184,7 @@ modifications have to occur. This section briefly covers the essential aspects of this wrapping.

    -

    21.3.1 Go Package Name

    +

    22.3.1 Go Package Name

    @@ -194,7 +194,7 @@ directive. You may override this by using SWIG's -package command line option.

    -

    21.3.2 Go Names

    +

    22.3.2 Go Names

    @@ -226,7 +226,7 @@ followed by that name, and the destructor will be named Delete followed by that name.

    -

    21.3.3 Go Constants

    +

    22.3.3 Go Constants

    @@ -234,7 +234,7 @@ C/C++ constants created via #define or the %constant directive become Go constants, declared with a const declaration. -

    21.3.4 Go Enumerations

    +

    22.3.4 Go Enumerations

    @@ -244,7 +244,7 @@ usual). The values of the enumeration will become variables in Go; code should avoid modifying those variables.

    -

    21.3.5 Go Classes

    +

    22.3.5 Go Classes

    @@ -322,7 +322,7 @@ returns a go interface. If the returned pointer can be null, you can check for this by calling the Swigcptr() method.

    -

    21.3.5.1 Go Class Inheritance

    +

    22.3.5.1 Go Class Inheritance

    @@ -334,7 +334,7 @@ Doing the reverse will require an explicit type assertion, which will be checked dynamically.

    -

    21.3.6 Go Templates

    +

    22.3.6 Go Templates

    @@ -342,7 +342,7 @@ In order to use C++ templates in Go, you must tell SWIG to create wrappers for a particular template instantation. To do this, use the %template directive. -

    21.3.7 Go Director Classes

    +

    22.3.7 Go Director Classes

    @@ -385,7 +385,7 @@ method defined in Go. The Go code may of course call other methods on itself, and those methods may be defined either in Go or in C++.

    -

    21.3.8 Default Go primitive type mappings

    +

    22.3.8 Default Go primitive type mappings

    @@ -492,7 +492,7 @@ that typemap, or add new values, to control how C/C++ types are mapped into Go types.

    -

    21.3.9 Output arguments

    +

    22.3.9 Output arguments

    Because of limitations in the way output arguments are processed in swig, @@ -503,7 +503,7 @@ argument.

    For example, suppose you were trying to wrap the modf() function in the C math library which splits x into integral and fractional parts (and -returns the integer part in one of its parameters):

    +returns the integer part in one of its parameters):

     double modf(double x, double *ip);
    @@ -536,7 +536,7 @@ some additional functions written in go that
     hide the ugly details.

    There are no char *OUTPUT typemaps. However you can -apply the signed char * typemaps instead:

    +apply the signed char * typemaps instead:

     %include <typemaps.i>
    @@ -545,7 +545,8 @@ void f(char *output);
     
    -

    21.3.10 Adding additional go code

    +

    22.3.10 Adding additional go code

    +

    Often the APIs generated by swig are not very natural in go, especially if there are output arguments. You can diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index 111c48214..6f1300492 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -8,7 +8,7 @@ -

    22 SWIG and Guile

    +

    23 SWIG and Guile

      @@ -47,7 +47,7 @@

      This section details guile-specific support in SWIG. -

      22.1 Meaning of "Module"

      +

      23.1 Meaning of "Module"

      @@ -55,7 +55,7 @@ There are three different concepts of "module" involved, defined separately for SWIG, Guile, and Libtool. To avoid horrible confusion, we explicitly prefix the context, e.g., "guile-module". -

      22.2 Using the SCM or GH Guile API

      +

      23.2 Using the SCM or GH Guile API

      The guile module can currently export wrapper files that use the guile GH interface or the @@ -103,7 +103,7 @@ for the specific API. Currently only the guile language module has created a ma but there is no reason other languages (like mzscheme or chicken) couldn't also use this. If that happens, there is A LOT less code duplication in the standard typemaps.

      -

      22.3 Linkage

      +

      23.3 Linkage

      @@ -111,7 +111,7 @@ Guile support is complicated by a lack of user community cohesiveness, which manifests in multiple shared-library usage conventions. A set of policies implementing a usage convention is called a linkage. -

      22.3.1 Simple Linkage

      +

      23.3.1 Simple Linkage

      @@ -206,7 +206,7 @@ placed between the define-module form and the SWIG_init via a preprocessor define to avoid symbol clashes. For this case, however, passive linkage is available. -

      22.3.2 Passive Linkage

      +

      23.3.2 Passive Linkage

      Passive linkage is just like simple linkage, but it generates an @@ -216,7 +216,7 @@ package name (see below).

      You should use passive linkage rather than simple linkage when you are using multiple modules. -

      22.3.3 Native Guile Module Linkage

      +

      23.3.3 Native Guile Module Linkage

      SWIG can also generate wrapper code that does all the Guile module @@ -257,7 +257,7 @@ Newer Guile versions have a shorthand procedure for this:

    -

    22.3.4 Old Auto-Loading Guile Module Linkage

    +

    23.3.4 Old Auto-Loading Guile Module Linkage

    Guile used to support an autoloading facility for object-code @@ -283,7 +283,7 @@ option, SWIG generates an exported module initialization function with an appropriate name. -

    22.3.5 Hobbit4D Linkage

    +

    23.3.5 Hobbit4D Linkage

    @@ -308,7 +308,7 @@ my/lib/libfoo.so.X.Y.Z and friends. This scheme is still very experimental; the (hobbit4d link) conventions are not well understood.

    -

    22.4 Underscore Folding

    +

    23.4 Underscore Folding

    @@ -320,7 +320,7 @@ complained so far. %rename to specify the Guile name of the wrapped functions and variables (see CHANGES). -

    22.5 Typemaps

    +

    23.5 Typemaps

    @@ -412,7 +412,7 @@ constant will appear as a scheme variable. See Features and the %feature directive for info on how to apply the %feature.

    -

    22.6 Representation of pointers as smobs

    +

    23.6 Representation of pointers as smobs

    @@ -433,7 +433,7 @@ representing the expected pointer type. See also If the Scheme object passed was not a SWIG smob representing a compatible pointer, a wrong-type-arg exception is raised. -

    22.6.1 GH Smobs

    +

    23.6.1 GH Smobs

    @@ -462,7 +462,7 @@ that created them, so the first module we check will most likely be correct. Once we have a swig_type_info structure, we loop through the linked list of casts, using pointer comparisons.

    -

    22.6.2 SCM Smobs

    +

    23.6.2 SCM Smobs

    The SCM interface (using the "-scm" argument to swig) uses swigrun.swg. @@ -477,7 +477,7 @@ in the smob tag. If a generated GOOPS module has been loaded, smobs will be wra GOOPS class.

    -

    22.6.3 Garbage Collection

    +

    23.6.3 Garbage Collection

    Garbage collection is a feature of the new SCM interface, and it is automatically included @@ -491,7 +491,7 @@ is exactly like described in 22.7 Exception Handling +

    23.7 Exception Handling

    @@ -517,7 +517,7 @@ mapping: The default when not specified here is to use "swig-error". See Lib/exception.i for details. -

    22.8 Procedure documentation

    +

    23.8 Procedure documentation

    If invoked with the command-line option -procdoc @@ -553,7 +553,7 @@ like this: typemap argument doc. See Lib/guile/typemaps.i for details. -

    22.9 Procedures with setters

    +

    23.9 Procedures with setters

    For global variables, SWIG creates a single wrapper procedure @@ -581,7 +581,7 @@ struct members, the procedures (struct-member-get pointer) and (struct-member-set pointer value) are not generated. -

    22.10 GOOPS Proxy Classes

    +

    23.10 GOOPS Proxy Classes

    SWIG can also generate classes and generic functions for use with @@ -730,7 +730,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th %import "foo.h" before the %inline block.

    -

    22.10.1 Naming Issues

    +

    23.10.1 Naming Issues

    As you can see in the example above, there are potential naming conflicts. The default exported @@ -767,7 +767,7 @@ guile-modules. For example,

    (use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:)))
    -

    22.10.2 Linking

    +

    23.10.2 Linking

    The guile-modules generated above all need to be linked together. GOOPS support requires diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 2ae9f7b95..76e147be5 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5,7 +5,7 @@ -

    23 SWIG and Java

    +

    24 SWIG and Java

  • Examples +
  • Java Examples @@ -155,7 +155,7 @@ It covers most SWIG features, but certain low-level details are covered in less

    -

    23.1 Overview

    +

    24.1 Overview

    @@ -190,7 +190,7 @@ Various customisation tips and techniques using SWIG directives are covered. The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.

    -

    23.2 Preliminaries

    +

    24.2 Preliminaries

    @@ -206,7 +206,11 @@ Run make -k check from the SWIG root directory after installing SWIG on The Java module requires your system to support shared libraries and dynamic loading. This is the commonly used method to load JNI code so your system will more than likely support this.

    -

    23.2.1 Running SWIG

    +

    +Android uses Java JNI and also works with SWIG. Please read the Android chapter in conjunction with this one if you are targeting Android. +

    + +

    24.2.1 Running SWIG

    @@ -265,7 +269,7 @@ The following sections have further practical examples and details on how you mi compiling and using the generated files.

    -

    23.2.2 Additional Commandline Options

    +

    24.2.2 Additional Commandline Options

    @@ -302,7 +306,7 @@ swig -java -help Their use will become clearer by the time you have finished reading this section on SWIG and Java.

    -

    23.2.3 Getting the right header files

    +

    24.2.3 Getting the right header files

    @@ -317,7 +321,7 @@ They are usually in directories like this:

    The exact location may vary on your machine, but the above locations are typical.

    -

    23.2.4 Compiling a dynamic module

    +

    24.2.4 Compiling a dynamic module

    @@ -353,7 +357,7 @@ The name of the shared library output file is important. If the name of your SWIG module is "example", the name of the corresponding shared library file should be "libexample.so" (or equivalent depending on your machine, see Dynamic linking problems for more information). The name of the module is specified using the %module directive or -module command line option.

    -

    23.2.5 Using your module

    +

    24.2.5 Using your module

    @@ -364,7 +368,7 @@ To load your shared native library module in Java, simply use Java's System. public class runme { static { -  System.loadLibrary("example"); + System.loadLibrary("example"); } public static void main(String argv[]) { @@ -388,7 +392,7 @@ $ If it doesn't work have a look at the following section which discusses problems loading the shared library.

    -

    23.2.6 Dynamic linking problems

    +

    24.2.6 Dynamic linking problems

    @@ -475,7 +479,7 @@ The following section also contains some C++ specific linking problems and solut

    -

    23.2.7 Compilation problems and compiling with C++

    +

    24.2.7 Compilation problems and compiling with C++

    @@ -528,7 +532,7 @@ Finally make sure the version of JDK header files matches the version of Java th

    -

    23.2.8 Building on Windows

    +

    24.2.8 Building on Windows

    @@ -537,7 +541,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine. This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers. In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.

    -

    23.2.8.1 Running SWIG from Visual Studio

    +

    24.2.8.1 Running SWIG from Visual Studio

    @@ -576,7 +580,7 @@ To run the native code in the DLL (example.dll), make sure that it is in your pa If the library fails to load have a look at Dynamic linking problems.

    -

    23.2.8.2 Using NMAKE

    +

    24.2.8.2 Using NMAKE

    @@ -635,7 +639,7 @@ Of course you may want to make changes for it to work for C++ by adding in the -

    -

    23.3 A tour of basic C/C++ wrapping

    +

    24.3 A tour of basic C/C++ wrapping

    @@ -645,7 +649,7 @@ variables are wrapped with JavaBean type getters and setters and so forth. This section briefly covers the essential aspects of this wrapping.

    -

    23.3.1 Modules, packages and generated Java classes

    +

    24.3.1 Modules, packages and generated Java classes

    @@ -681,7 +685,7 @@ swig -java -package com.bloggs.swig -outdir com/bloggs/swig example.i SWIG won't create the directory, so make sure it exists beforehand.

    -

    23.3.2 Functions

    +

    24.3.2 Functions

    @@ -715,7 +719,7 @@ System.out.println(example.fact(4)); -

    23.3.3 Global variables

    +

    24.3.3 Global variables

    @@ -802,7 +806,7 @@ extern char *path; // Read-only (due to %immutable) -

    23.3.4 Constants

    +

    24.3.4 Constants

    @@ -942,7 +946,7 @@ Or if you decide this practice isn't so bad and your own class implements ex

    -

    23.3.5 Enumerations

    +

    24.3.5 Enumerations

    @@ -956,7 +960,7 @@ The final two approaches use simple integers for each enum item. Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.

    -

    23.3.5.1 Anonymous enums

    +

    24.3.5.1 Anonymous enums

    @@ -1019,7 +1023,7 @@ As in the case of constants, you can access them through either the module class

    -

    23.3.5.2 Typesafe enums

    +

    24.3.5.2 Typesafe enums

    @@ -1113,7 +1117,7 @@ When upgrading to JDK 1.5 or later, proper Java enums could be used instead, wit The following section details proper Java enum generation.

    -

    23.3.5.3 Proper Java enums

    +

    24.3.5.3 Proper Java enums

    @@ -1166,7 +1170,7 @@ The additional support methods need not be generated if none of the enum items h Simpler Java enums for enums without initializers section.

    -

    23.3.5.4 Type unsafe enums

    +

    24.3.5.4 Type unsafe enums

    @@ -1214,7 +1218,7 @@ Note that unlike typesafe enums, this approach requires users to mostly use diff Thus the upgrade path to proper enums provided in JDK 1.5 is more painful.

    -

    23.3.5.5 Simple enums

    +

    24.3.5.5 Simple enums

    @@ -1233,7 +1237,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

    -

    23.3.6 Pointers

    +

    24.3.6 Pointers

    @@ -1321,7 +1325,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return a NULL pointer if the conversion can't be performed.

    -

    23.3.7 Structures

    +

    24.3.7 Structures

    @@ -1489,7 +1493,7 @@ x.setA(3); // Modify x.a - this is the same as b.f.a -

    23.3.8 C++ classes

    +

    24.3.8 C++ classes

    @@ -1552,7 +1556,7 @@ int bar = Spam.getBar(); -

    23.3.9 C++ inheritance

    +

    24.3.9 C++ inheritance

    @@ -1613,7 +1617,7 @@ Note that Java does not support multiple inheritance so any multiple inheritance A warning is given when multiple inheritance is detected and only the first base class is used.

    -

    23.3.10 Pointers, references, arrays and pass by value

    +

    24.3.10 Pointers, references, arrays and pass by value

    @@ -1668,7 +1672,7 @@ to hold the result and a pointer is returned (Java will release this memory when the returned object's finalizer is run by the garbage collector).

    -

    23.3.10.1 Null pointers

    +

    24.3.10.1 Null pointers

    @@ -1692,7 +1696,7 @@ For spam1 and spam4 above the Java null gets translat The converse also occurs, that is, NULL pointers are translated into null Java objects when returned from a C/C++ function.

    -

    23.3.11 C++ overloaded functions

    +

    24.3.11 C++ overloaded functions

    @@ -1807,7 +1811,7 @@ void spam(unsigned short); // Ignored -

    23.3.12 C++ default arguments

    +

    24.3.12 C++ default arguments

    @@ -1850,7 +1854,7 @@ Further details on default arguments and how to restore this approach are given

    -

    23.3.13 C++ namespaces

    +

    24.3.13 C++ namespaces

    @@ -1930,7 +1934,12 @@ in an unnamed package. -

    23.3.14 C++ templates

    +

    +If the resulting use of the nspace feature and hence packages results in a proxy class in one package deriving or using a proxy class from another package, +you will need to open up the visibility for the pointer constructor and getCPtr method from the default 'protected' to 'public' with the SWIG_JAVABODY_PROXY macro. See Java code typemaps. +

    + +

    24.3.14 C++ templates

    @@ -1979,7 +1988,7 @@ Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter.

    -

    23.3.15 C++ Smart Pointers

    +

    24.3.15 C++ Smart Pointers

    @@ -2063,7 +2072,7 @@ Foo f = p.__deref__(); // Returns underlying Foo * -

    23.4 Further details on the generated Java classes

    +

    24.4 Further details on the generated Java classes

    @@ -2078,7 +2087,7 @@ Finally enum classes are covered. First, the crucial intermediary JNI class is considered.

    -

    23.4.1 The intermediary JNI class

    +

    24.4.1 The intermediary JNI class

    @@ -2198,7 +2207,7 @@ If name is the same as modulename then the module class name g from modulename to modulenameModule.

    -

    23.4.1.1 The intermediary JNI class pragmas

    +

    24.4.1.1 The intermediary JNI class pragmas

    @@ -2277,7 +2286,7 @@ For example, let's change the intermediary JNI class access to just the default All the methods in the intermediary JNI class will then not be callable outside of the package as the method modifiers have been changed from public access to default access. This is useful if you want to prevent users calling these low level functions.

    -

    23.4.2 The Java module class

    +

    24.4.2 The Java module class

    @@ -2308,7 +2317,7 @@ example.egg(new Foo()); The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.

    -

    23.4.2.1 The Java module class pragmas

    +

    24.4.2.1 The Java module class pragmas

    @@ -2359,7 +2368,7 @@ See The intermediary JNI class pragmas secti

    -

    23.4.3 Java proxy classes

    +

    24.4.3 Java proxy classes

    @@ -2379,7 +2388,7 @@ public class Foo { swigCPtr = cPtr; } - public static long getCPtr(Foo obj) { + protected static long getCPtr(Foo obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -2435,7 +2444,7 @@ int y = f.spam(5, new Foo()); -

    23.4.3.1 Memory management

    +

    24.4.3.1 Memory management

    @@ -2597,7 +2606,7 @@ and

    -

    23.4.3.2 Inheritance

    +

    24.4.3.2 Inheritance

    @@ -2630,7 +2639,7 @@ public class Base { swigCPtr = cPtr; } - public static long getCPtr(Base obj) { + protected static long getCPtr(Base obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -2670,7 +2679,7 @@ public class Derived extends Base { swigCPtr = cPtr; } - public static long getCPtr(Derived obj) { + protected static long getCPtr(Derived obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -2713,7 +2722,7 @@ However, true cross language polymorphism can be achieved using the 23.4.3.3 Proxy classes and garbage collection +

    24.4.3.3 Proxy classes and garbage collection

    @@ -2796,7 +2805,7 @@ The section on Java typemaps details how to specify See the How to Handle Java Finalization's Memory-Retention Issues article for alternative approaches to managing memory by avoiding finalizers altogether.

    -

    23.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    +

    24.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling

    @@ -2918,7 +2927,7 @@ For example: Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.

    -

    23.4.3.5 Single threaded applications and thread safety

    +

    24.4.3.5 Single threaded applications and thread safety

    @@ -2949,7 +2958,7 @@ public class Test { swigCPtr = cPtr; } - public static long getCPtr(Test obj) { + protected static long getCPtr(Test obj) { return (obj == null) ? 0 : obj.swigCPtr; } @@ -3006,7 +3015,7 @@ for (int i=0; i<100000; i++) { -

    23.4.4 Type wrapper classes

    +

    24.4.4 Type wrapper classes

    @@ -3093,7 +3102,7 @@ public static void spam(SWIGTYPE_p_int x, SWIGTYPE_p_int y, int z) { ... } -

    23.4.5 Enum classes

    +

    24.4.5 Enum classes

    @@ -3102,7 +3111,7 @@ The Enumerations section discussed these but om The following sub-sections detail the various types of enum classes that can be generated.

    -

    23.4.5.1 Typesafe enum classes

    +

    24.4.5.1 Typesafe enum classes

    @@ -3186,7 +3195,7 @@ The swigValue method is used for marshalling in the other direction. The toString method is overridden so that the enum name is available.

    -

    23.4.5.2 Proper Java enum classes

    +

    24.4.5.2 Proper Java enum classes

    @@ -3264,7 +3273,7 @@ These needn't be generated if the enum being wrapped does not have any initializ Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.

    -

    23.4.5.3 Type unsafe enum classes

    +

    24.4.5.3 Type unsafe enum classes

    @@ -3295,7 +3304,7 @@ public final class Beverage { -

    23.5 Cross language polymorphism using directors

    +

    24.5 Cross language polymorphism using directors

    @@ -3317,7 +3326,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.

    -

    23.5.1 Enabling directors

    +

    24.5.1 Enabling directors

    @@ -3388,7 +3397,7 @@ public: -

    23.5.2 Director classes

    +

    24.5.2 Director classes

    @@ -3415,7 +3424,7 @@ If the correct implementation is in Java, the Java API is used to call the metho

    -

    23.5.3 Overhead and code bloat

    +

    24.5.3 Overhead and code bloat

    @@ -3433,7 +3442,7 @@ This situation can be optimized by selectively enabling director methods (using

    -

    23.5.4 Simple directors example

    +

    24.5.4 Simple directors example

    @@ -3461,7 +3470,7 @@ void callup(DirectorBase *director) {

    The following DirectorDerived Java class is derived from the Java proxy class DirectorBase and overrides upcall_method(). When C++ code invokes upcall_method(), the SWIG-generated C++ code redirects the call via JNI to the Java DirectorDerived subclass. -Naturally, the SWIG generated C++ code and the generated Java intermediate class marshal and convert arguments between C++ and Java when needed. +Naturally, the SWIG generated C++ code and the generated Java intermediary class marshal and convert arguments between C++ and Java when needed.

    @@ -3498,7 +3507,7 @@ DirectorDerived::upcall_method() invoked.
    -

    23.5.5 Director threading issues

    +

    24.5.5 Director threading issues

    @@ -3518,7 +3527,7 @@ Macros can be defined on the commandline when compiling your C++ code, or altern -

    23.6 Accessing protected members

    +

    24.6 Accessing protected members

    @@ -3614,7 +3623,7 @@ class MyProtectedBase extends ProtectedBase -

    23.7 Common customization features

    +

    24.7 Common customization features

    @@ -3626,7 +3635,7 @@ be awkward. This section describes some common SWIG features that are used to improve the interface to existing C/C++ code.

    -

    23.7.1 C/C++ helper functions

    +

    24.7.1 C/C++ helper functions

    @@ -3692,7 +3701,7 @@ hard to implement. It is possible to improve on this using Java code, typemaps, customization features as covered in later sections, but sometimes helper functions are a quick and easy solution to difficult cases.

    -

    23.7.2 Class extension with %extend

    +

    24.7.2 Class extension with %extend

    @@ -3755,7 +3764,7 @@ Vector(2,3,4) in any way---the extensions only show up in the Java interface.

    -

    23.7.3 Exception handling with %exception and %javaexception

    +

    24.7.3 Exception handling with %exception and %javaexception

    @@ -3914,7 +3923,7 @@ to raise exceptions. See the SWIG Library ch The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities.

    -

    23.7.4 Method access with %javamethodmodifiers

    +

    24.7.4 Method access with %javamethodmodifiers

    @@ -3940,7 +3949,7 @@ protected static void protect_me() { -

    23.8 Tips and techniques

    +

    24.8 Tips and techniques

    @@ -3950,7 +3959,7 @@ strings and arrays. This chapter discusses the common techniques for solving these problems.

    -

    23.8.1 Input and output parameters using primitive pointers and references

    +

    24.8.1 Input and output parameters using primitive pointers and references

    @@ -4124,7 +4133,7 @@ void foo(Bar *OUTPUT); will not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

    -

    23.8.2 Simple pointers

    +

    24.8.2 Simple pointers

    @@ -4190,7 +4199,7 @@ System.out.println("3 + 4 = " + result); See the SWIG Library chapter for further details.

    -

    23.8.3 Wrapping C arrays with Java arrays

    +

    24.8.3 Wrapping C arrays with Java arrays

    @@ -4257,7 +4266,7 @@ Please be aware that the typemaps in this library are not efficient as all the e There is an alternative approach using the SWIG array library and this is covered in the next section.

    -

    23.8.4 Unbounded C Arrays

    +

    24.8.4 Unbounded C Arrays

    @@ -4402,7 +4411,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

    -

    23.8.5 Binary data vs Strings

    +

    24.8.5 Binary data vs Strings

    @@ -4446,7 +4455,7 @@ len: 5 data: 68 69 0 6a 6b -

    23.8.6 Overriding new and delete to allocate from Java heap

    +

    24.8.6 Overriding new and delete to allocate from Java heap

    @@ -4563,7 +4572,7 @@ model and use these functions in place of malloc and free in your own code.

    -

    23.9 Java typemaps

    +

    24.9 Java typemaps

    @@ -4584,7 +4593,7 @@ Before proceeding, it should be stressed that typemaps are not a required part of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the generated code. -

    23.9.1 Default primitive type mappings

    +

    24.9.1 Default primitive type mappings

    @@ -4736,7 +4745,7 @@ However, the mappings allow the full range of values for each C type from Java.

    -

    23.9.2 Default typemaps for non-primitive types

    +

    24.9.2 Default typemaps for non-primitive types

    @@ -4751,7 +4760,7 @@ So in summary, the C/C++ pointer to non-primitive types is cast into the 64 bit The Java type is either the proxy class or type wrapper class.

    -

    23.9.3 Sixty four bit JVMs

    +

    24.9.3 Sixty four bit JVMs

    @@ -4764,7 +4773,7 @@ Unfortunately it won't of course hold true for JNI code.

    -

    23.9.4 What is a typemap?

    +

    24.9.4 What is a typemap?

    @@ -4887,7 +4896,7 @@ int c = example.count('e',"Hello World"); -

    23.9.5 Typemaps for mapping C/C++ types to Java types

    +

    24.9.5 Typemaps for mapping C/C++ types to Java types

    @@ -5147,7 +5156,7 @@ These are listed below: -

    23.9.6 Java typemap attributes

    +

    24.9.6 Java typemap attributes

    @@ -5193,7 +5202,7 @@ The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes. Note that when the 'pre' or 'post' attributes are specified and the associated type is used in a constructor, a constructor helper function is generated. This is necessary as the Java proxy constructor wrapper makes a call to a support constructor using a this call. In Java the this call must be the first statement in the constructor body. The constructor body thus calls the helper function and the helper function instead makes the JNI call, ensuring the 'pre' code is called before the JNI call is made. There is a Date marshalling example showing 'pre', 'post' and 'pgcppname' attributes in action.

    -

    23.9.7 Java special variables

    +

    24.9.7 Java special variables

    @@ -5344,7 +5353,7 @@ This special variable expands to the intermediary class name. Usually this is th unless the jniclassname attribute is specified in the %module directive.

    -

    23.9.8 Typemaps for both C and C++ compilation

    +

    24.9.8 Typemaps for both C and C++ compilation

    @@ -5381,7 +5390,7 @@ If you do not intend your code to be targeting both C and C++ then your typemaps

    -

    23.9.9 Java code typemaps

    +

    24.9.9 Java code typemaps

    @@ -5453,7 +5462,7 @@ import statements for Java class: empty default

    %typemap(javainterfaces)

    -interfaces (extends) for Java class: empty default +interfaces (implements) for Java class: empty default

    %typemap(javafinalize)

    @@ -5550,15 +5559,8 @@ The typemap code is the same that is in "java.swg", barring the last tw Note that SWIGTYPE will target all proxy classes, but not the type wrapper classes. Also the above typemap is only used for proxy classes that are potential base classes. To target proxy classes that are derived from a wrapped class as well, the "javabody_derived" typemap should also be overridden. -There is a macro in java.swg that implements this and the above can instead be implemented using:

    -
    -
    -SWIG_JAVABODY_METHODS(protected, protected, SWIGTYPE)
    -
    -
    -

    For the typemap to be used in all type wrapper classes, all the different types that type wrapper classes could be used for should be targeted:

    @@ -5568,7 +5570,7 @@ For the typemap to be used in all type wrapper classes, all the different types %typemap(javabody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ private long swigCPtr; - public $javaclassname(long cPtr, boolean bFutureUse) { + protected $javaclassname(long cPtr, boolean bFutureUse) { swigCPtr = cPtr; } @@ -5576,7 +5578,7 @@ For the typemap to be used in all type wrapper classes, all the different types swigCPtr = 0; } - public static long getCPtr($javaclassname obj) { + protected static long getCPtr($javaclassname obj) { return (obj == null) ? 0 : obj.swigCPtr; } %} @@ -5587,7 +5589,30 @@ For the typemap to be used in all type wrapper classes, all the different types Again this is the same that is in "java.swg", barring the method modifier for getCPtr.

    -

    23.9.10 Director specific typemaps

    +

    +When using multiple modules or the nspace feature it is common to invoke SWIG with a different -package +command line option for each module. +However, by default the generated code may not compile if +generated classes in one package use generated classes in another package. +The visibility of the +getCPtr() and pointer constructor generated from the javabody typemaps needs changing. +The default visibility is protected but it needs to be public for access from a different package. +Just changing 'protected' to 'public' in the typemap achieves this. +Two macros are available in java.swg to make this easier and using them is the preferred approach +over simply copying the typemaps and modifying as this is forward compatible with any changes in +the javabody typemap in future versions of SWIG. +The macros are for the proxy and typewrapper classes and can respectively be used to +to make the method and constructor public: +

    + +
    +
    +  SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
    +  SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
    +
    +
    + +

    24.9.10 Director specific typemaps

    @@ -5812,7 +5837,7 @@ The basic strategy here is to provide a default package typemap for the majority -

    23.10 Typemap Examples

    +

    24.10 Typemap Examples

    @@ -5822,7 +5847,7 @@ the SWIG library.

    -

    23.10.1 Simpler Java enums for enums without initializers

    +

    24.10.1 Simpler Java enums for enums without initializers

    @@ -5901,7 +5926,7 @@ This would be done by using the original versions of these typemaps in "enums.sw

    -

    23.10.2 Handling C++ exception specifications as Java exceptions

    +

    24.10.2 Handling C++ exception specifications as Java exceptions

    @@ -6026,7 +6051,7 @@ We could alternatively have used %rename to rename what() into

    -

    23.10.3 NaN Exception - exception handling for a particular type

    +

    24.10.3 NaN Exception - exception handling for a particular type

    @@ -6181,7 +6206,7 @@ If we were a martyr to the JNI cause, we could replace the succinct code within If we had, we would have put it in the "in" typemap which, like all JNI and Java typemaps, also supports the 'throws' attribute.

    -

    23.10.4 Converting Java String arrays to char **

    +

    24.10.4 Converting Java String arrays to char **

    @@ -6281,7 +6306,7 @@ public class runme { static { try { -  System.loadLibrary("example"); + System.loadLibrary("example"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. " + e); System.exit(1); @@ -6325,7 +6350,7 @@ Lastly the "jni", "jtype" and "jstype" typemaps are also required to specify what Java types to use.

    -

    23.10.5 Expanding a Java object to multiple arguments

    +

    24.10.5 Expanding a Java object to multiple arguments

    @@ -6407,7 +6432,7 @@ example.foo(new String[]{"red", "green", "blue", "white"}); -

    23.10.6 Using typemaps to return arguments

    +

    24.10.6 Using typemaps to return arguments

    @@ -6500,7 +6525,7 @@ public class runme { static { try { -  System.loadLibrary("example"); + System.loadLibrary("example"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. " + e); System.exit(1); @@ -6525,7 +6550,7 @@ $ java runme 1 12.0 340.0 -

    23.10.7 Adding Java downcasts to polymorphic return types

    +

    24.10.7 Adding Java downcasts to polymorphic return types

    @@ -6731,7 +6756,7 @@ SWIG usually generates code which constructs the proxy classes using Java code a Note that the JNI code above uses a number of string lookups to call a constructor, whereas this would not occur using byte compiled Java code.

    -

    23.10.8 Adding an equals method to the Java classes

    +

    24.10.8 Adding an equals method to the Java classes

    @@ -6775,7 +6800,7 @@ System.out.println("foo1? " + foo1.equals(foo2)); -

    23.10.9 Void pointers and a common Java base class

    +

    24.10.9 Void pointers and a common Java base class

    @@ -6834,7 +6859,7 @@ This example contains some useful functionality which you may want in your code.

  • It also has a function which effectively implements a cast from the type of the proxy/type wrapper class to a void pointer. This is necessary for passing a proxy class or a type wrapper class to a function that takes a void pointer. -

    23.10.10 Struct pointer to pointer

    +

    24.10.10 Struct pointer to pointer

    @@ -7014,7 +7039,7 @@ The C functional interface has been completely morphed into an object-oriented i the Butler class would behave much like any pure Java class and feel more natural to Java users.

    -

    23.10.11 Memory management when returning references to member variables

    +

    24.10.11 Memory management when returning references to member variables

    @@ -7137,7 +7162,7 @@ public class Bike { Note the addReference call.

    -

    23.10.12 Memory management for objects passed to the C++ layer

    +

    24.10.12 Memory management for objects passed to the C++ layer

    @@ -7253,7 +7278,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla -

    23.10.13 Date marshalling using the javain typemap and associated attributes

    +

    24.10.13 Date marshalling using the javain typemap and associated attributes

    @@ -7430,7 +7455,7 @@ A few things to note: -

    23.11 Living with Java Directors

    +

    24.11 Living with Java Directors

    @@ -7611,10 +7636,10 @@ public abstract class UserVisibleFoo extends Foo {

  • -

    23.12 Odds and ends

    +

    24.12 Odds and ends

    -

    23.12.1 JavaDoc comments

    +

    24.12.1 JavaDoc comments

    @@ -7670,7 +7695,7 @@ public class Barmy { -

    23.12.2 Functional interface without proxy classes

    +

    24.12.2 Functional interface without proxy classes

    @@ -7731,7 +7756,7 @@ All destructors have to be called manually for example the delete_Foo(foo) -

    23.12.3 Using your own JNI functions

    +

    24.12.3 Using your own JNI functions

    @@ -7781,7 +7806,7 @@ This directive is only really useful if you want to mix your own hand crafted JN

    -

    23.12.4 Performance concerns and hints

    +

    24.12.4 Performance concerns and hints

    @@ -7802,7 +7827,7 @@ However, you will have to be careful about memory management and make sure that This method normally calls the C++ destructor or free() for C code.

    -

    23.12.5 Debugging

    +

    24.12.5 Debugging

    @@ -7824,7 +7849,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh

    -

    23.13 Examples

    +

    24.13 Java Examples

    diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 02b8e53bd..dcec21c90 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -682,8 +682,12 @@ pointer.

    Copies all of the string data in s into the memory pointed to by -ptr. The string may contain embedded NULL bytes. The length of -the string is implicitly determined in the underlying wrapper code. +ptr. The string may contain embedded NULL bytes. +This is actually a wrapper to the standard C library memmove function, which is +declared as +void memmove(void *ptr, const void *src, size_t n). +The src and length n parameters are +extracted from the language specific string s in the underlying wrapper code.

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 92af4e6c9..01ff3a3ec 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,7 +6,7 @@ -

    24 SWIG and Common Lisp

    +

    25 SWIG and Common Lisp

      @@ -41,7 +41,7 @@ Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI foreign function interfaces.

      -

      24.1 Allegro Common Lisp

      +

      25.1 Allegro Common Lisp

      @@ -50,7 +50,7 @@ here

      -

      24.2 Common Foreign Function Interface(CFFI)

      +

      25.2 Common Foreign Function Interface(CFFI)

      @@ -77,7 +77,7 @@ swig -cffi -module module-name file-name files and the various things which you can do with them.

      -

      24.2.1 Additional Commandline Options

      +

      25.2.1 Additional Commandline Options

      @@ -118,7 +118,7 @@ swig -cffi -help -

      24.2.2 Generating CFFI bindings

      +

      25.2.2 Generating CFFI bindings

      As we mentioned earlier the ideal way to use SWIG is to use interface @@ -392,7 +392,7 @@ The feature intern_function ensures that all C names are
    -

    24.2.3 Generating CFFI bindings for C++ code

    +

    25.2.3 Generating CFFI bindings for C++ code

    This feature to SWIG (for CFFI) is very new and still far from @@ -568,7 +568,7 @@ If you have any questions, suggestions, patches, etc., related to CFFI module feel free to contact us on the SWIG mailing list, and also please add a "[CFFI]" tag in the subject line. -

    24.2.4 Inserting user code into generated files

    +

    25.2.4 Inserting user code into generated files

    @@ -608,7 +608,7 @@ Note that the block %{ ... %} is effectively a shortcut for

    -

    24.3 CLISP

    +

    25.3 CLISP

    @@ -638,7 +638,7 @@ swig -clisp -module module-name file-name interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.

    -

    24.3.1 Additional Commandline Options

    +

    25.3.1 Additional Commandline Options

    @@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for
    -

    24.3.2 Details on CLISP bindings

    +

    25.3.2 Details on CLISP bindings

    @@ -795,7 +795,7 @@ struct bar { -

    24.4 UFFI

    +

    25.4 UFFI

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index 04f96f2f3..9bbb3891d 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -6,13 +6,14 @@ -

    25 SWIG and Lua

    +

    26 SWIG and Lua

    @@ -67,13 +69,17 @@

    Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight configuration language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). Its also a really tiny language, less than 6000 lines of code, which compiles to <100 kilobytes of binary code. It can be found at http://www.lua.org

    -

    25.1 Preliminaries

    +

    +eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: http://www.eluaproject.net +

    + +

    26.1 Preliminaries

    -The current SWIG implementation is designed to work with Lua 5.0.x and Lua 5.1.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. ((Currently SWIG generated code has only been tested on Windows with MingW, though given the nature of Lua, is should not have problems on other OS's)). It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). +The current SWIG implementation is designed to work with Lua 5.0.x and Lua 5.1.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. ((Currently SWIG generated code has only been tested on Windows with MingW, though given the nature of Lua, is should not have problems on other OS's)). It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also supports eLua and works with eLua 0.8. SWIG generated code for eLua has been tested on Stellaris ARM Cortex-M3 LM3S and Infineon TriCore.

    -

    25.2 Running SWIG

    +

    26.2 Running SWIG

    @@ -105,7 +111,56 @@ This creates a C/C++ source file example_wrap.c or example_wrap.cxx

    The name of the wrapper file is derived from the name of the input file. For example, if the input file is example.i, the name of the wrapper file is example_wrap.c. To change this, you can use the -o option. The wrappered module will export one function "int luaopen_example(lua_State* L)" which must be called to register the module with the Lua interpreter. The name "luaopen_example" depends upon the name of the module.

    -

    25.2.1 Compiling and Linking and Interpreter

    +

    +To build an eLua module, run SWIG using -lua and add either -elua or -eluac. +

    +
    +$ swig -lua -elua example.i
    +
    +

    +or +

    +
    +$ swig -lua -eluac example.i
    +
    +

    +The -elua option puts all the C function wrappers and variable get/set wrappers in rotables. It also generates a metatable which will control the access to these variables from eLua. It also offers a significant amount of module size compression. On the other hand, the -eluac option puts all the wrappers in a single rotable. With this option, no matter how huge the module, it will consume no additional microcontroller SRAM (crass compression). There is a catch though: Metatables are not generated with -eluac. To access any value from eLua, one must directly call the wrapper function associated with that value. +

    + +

    26.2.1 Additional command line options

    + + +

    +The following table list the additional commandline options available for the Lua module. They can also be seen by using: +

    + +
    +swig -lua -help 
    +
    + + + + + + + + + + + + + + + + + + + + + +
    Lua specific options
    -eluaGenerates LTR compatible wrappers for smaller devices running elua.
    -eluacLTR compatible wrappers in "crass compress" mode for elua.
    -nomoduleglobalDo not register the module name as a global variable but return the module table from calls to require.
    + +

    26.2.2 Compiling and Linking and Interpreter

    @@ -151,8 +206,33 @@ $ gcc -I/usr/include/lua -c example_wrap.c -o example_wrap.o $ gcc -c example.c -o example.o $ gcc -I/usr/include/lua -L/usr/lib/lua min.o example_wrap.o example.o -o my_lua +

    +For eLua, the source must be built along with the wrappers generated by SWIG. Make sure the eLua source files platform_conf.h and auxmods.h are updated with the entries of your new module. Please note: "mod" is the module name. +

    +
    +/* Sample platform_conf.h */
    +#define LUA_PLATFORM_LIBS_ROM\
    +  _ROM( AUXLIB_PIO, luaopen_pio, pio_map )\
    +  _ROM( AUXLIB_TMR, luaopen_tmr, tmr_map )\
    +  _ROM( AUXLIB_MOD, luaopen_mod, mod_map )\
    +  ....
    +
    +

    +

    +
    +/* Sample auxmods.h */
    +#define AUXLIB_PIO       "pio"
    +LUALIB_API int ( luaopen_pio )(lua_State *L );
     
    -

    25.2.2 Compiling a dynamic module

    +#define AUXLIB_MOD "mod" +LUALIB_API int ( luaopen_mod )(lua_State *L ); +.... +
    +

    +More information on building and configuring eLua can be found here: http://www.eluaproject.net/doc/v0.8/en_building.html +

    + +

    26.2.3 Compiling a dynamic module

    @@ -220,7 +300,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib -

    25.2.3 Using your module

    +

    26.2.4 Using your module

    @@ -238,19 +318,19 @@ $ ./my_lua > -

    25.3 A tour of basic C/C++ wrapping

    +

    26.3 A tour of basic C/C++ wrapping

    By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.

    -

    25.3.1 Modules

    +

    26.3.1 Modules

    The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.

    -

    25.3.2 Functions

    +

    26.3.2 Functions

    @@ -288,7 +368,7 @@ It is also possible to rename the module with an assignment. 24 -

    25.3.3 Global variables

    +

    26.3.3 Global variables

    @@ -361,8 +441,22 @@ nil > print(example.PI) 3.142 +

    +If you have used the -eluac option for your eLua module, you will have to follow a different approach while manipulating global variables. (This is not applicable for wrappers generated with -elua) +

    +
    +> -- Applicable only with -eluac. (num is defined)
    +> print(example.num_get())
    +20
    +> example.num_set(50) -- new value added
    +> print(example.num_get())
    +50
    +
    +

    +In general, functions of the form "variable_get()" and "variable_set()" are automatically generated by SWIG for use with -eluac. +

    -

    25.3.4 Constants and enums

    +

    26.3.4 Constants and enums

    @@ -385,7 +479,18 @@ example.SUNDAY=0

    Constants are not guaranteed to remain constant in Lua. The name of the constant could be accidentally reassigned to refer to some other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

    -

    25.3.5 Pointers

    +

    +If you're using eLua and have used -elua or -eluac to generate your wrapper, macro constants and enums should be accessed through a rotable called "const". In eLua, macro constants and enums are guaranteed to remain constants since they are all contained within a rotable. A regular C constant is accessed from eLua just as if it were a regular global variable, just that the property of value immutability is demonstrated if an attempt at modifying a C constant is made. +

    +
    +> print(example.ICONST)
    +10
    +> print(example.const.SUNDAY)
    +0
    +> print(example.const.SCONST)
    +Hello World
    +
    +

    26.3.5 Pointers

    @@ -423,7 +528,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor nil -

    25.3.6 Structures

    +

    26.3.6 Structures

    @@ -508,8 +613,26 @@ Because the pointer points inside the structure, you can modify the contents and > x = b.f > x.a = 3 -- Modifies the same structure +

    +For eLua with the -eluac option, structure manipulation has to be performed with specific structure functions generated by SWIG. Let's say you have the following structure definition: +

    +
    struct data {
    +   int x, y;
    +   double z;
    +};
     
    -

    25.3.7 C++ classes

    +> --From eLua +> a = example.new_data() +> example.data_x_set(a, 10) +> example.data_y_set(a, 20) +> print(example.data_x_get(a), example.data_y_get(a)) +10 20 +
    +

    +In general, functions of the form "new_struct()", "struct_member_get()", "struct_member_set()" and "free_struct()" are automatically generated by SWIG for each structure defined in C. (Please note: This doesn't apply for modules generated with the -elua option) +

    + +

    26.3.7 C++ classes

    @@ -570,7 +693,7 @@ It is not (currently) possible to access static members of an instance: -- does NOT work -

    25.3.8 C++ inheritance

    +

    26.3.8 C++ inheritance

    @@ -595,7 +718,7 @@ then the function spam() accepts a Foo pointer or a pointer to any clas

    It is safe to use multiple inheritance with SWIG.

    -

    25.3.9 Pointers, references, values, and arrays

    +

    26.3.9 Pointers, references, values, and arrays

    @@ -626,7 +749,7 @@ Foo spam7();

    then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.

    -

    25.3.10 C++ overloaded functions

    +

    26.3.10 C++ overloaded functions

    @@ -712,7 +835,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin

    Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.

    -

    25.3.11 C++ operators

    +

    26.3.11 C++ operators

    @@ -824,7 +947,7 @@ It is also possible to overload the operator[], but currently this cann }; -

    25.3.12 Class extension with %extend

    +

    26.3.12 Class extension with %extend

    @@ -879,7 +1002,32 @@ true

    Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the '$self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).

    -

    25.3.13 C++ templates

    + +

    26.3.13 Using %newobject to release memory

    + + +

    If you have a function that allocates memory like this,

    +
    +
    char *foo() {
    +   char *result = (char *) malloc(...);
    +   ...
    +   return result;
    +}
    +
    +
    +

    then the SWIG generated wrappers will have a memory leak--the + returned data will be copied into a string object and the old contents + ignored.

    +

    To fix the memory leak, use the %newobject directive.

    +
    +
    %newobject foo;
    +...
    +char *foo();
    +
    +
    +

    This will release the allocated memory.

    + +

    26.3.14 C++ templates

    @@ -914,7 +1062,7 @@ In Lua:

    Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.

    -

    25.3.14 C++ Smart Pointers

    +

    26.3.15 C++ Smart Pointers

    @@ -966,7 +1114,7 @@ If you ever need to access the underlying pointer returned by operator->( > f = p:__deref__() -- Returns underlying Foo * -

    25.3.15 C++ Exceptions

    +

    26.3.16 C++ Exceptions

    @@ -985,13 +1133,13 @@ SWIG will automatically convert this to a Lua error.

    -> message()
    +> message()
     I died.
     stack traceback:
             [C]: in function 'message'
             stdin:1: in main chunk
             [C]: ?
    ->
    +>
     

    @@ -1000,13 +1148,13 @@ Using xpcall will allow you to obtain additional debug information (such as a st

    -> function a() b() end -- function a() calls function b()
    -> function b() message() end -- function b() calls C++ function message(), which throws 
    -> ok,res=pcall(a)  -- call the function
    -> print(ok,res)
    +> function a() b() end -- function a() calls function b()
    +> function b() message() end -- function b() calls C++ function message(), which throws 
    +> ok,res=pcall(a)  -- call the function
    +> print(ok,res)
     false   I died.
    -> ok,res=xpcall(a,debug.traceback)  -- call the function
    -> print(ok,res)
    +> ok,res=xpcall(a,debug.traceback)  -- call the function
    +> print(ok,res)
     false   I died.
     stack traceback:
             [C]: in function 'message'
    @@ -1018,7 +1166,7 @@ stack traceback:
     

    -SWIG is able to throw numeric types, enums, chars, char*'s and std::string's without problem. It has also written typemaps for std::exception and its derived classes, which convert the exception into and error string.

    +SWIG is able to throw numeric types, enums, chars, char*'s and std::string's without problem. It has also written typemaps for std::exception and its derived classes, which convert the exception into an error string.

    However its not so simple for to throw other types of objects. Thrown objects are not valid outside the 'catch' block. Therefore they cannot be @@ -1041,13 +1189,13 @@ SWIG will just convert it (poorly) to a string and use that as its error. (Yes i

    -> throw_A()
    +> throw_A()
     object exception:A *
     stack traceback:
             [C]: in function 'unknown'
             stdin:1: in main chunk
             [C]: ?
    ->
    +>
     

    To get a more useful behaviour out of SWIG you must either: provide a way to convert your exceptions into strings, or @@ -1088,14 +1236,14 @@ void throw_exc() throw(Exc) { Then the following code can be used (note: we use pcall to catch the error so we can process the exception).

    -> ok,res=pcall(throw_exc)
    -> print(ok)
    +> ok,res=pcall(throw_exc)
    +> print(ok)
     false
    -> print(res)
    +> print(res)
     userdata: 0003D880
    -> print(res.code,res.msg)
    +> print(res.code,res.msg)
     42      Hosed
    ->
    +>
     

    @@ -1110,12 +1258,12 @@ add exception specification to functions or globally (respectively).

    -

    25.4 Typemaps

    +

    26.4 Typemaps

    -

    This section explains what typemaps are and the usage of them. The default wrappering behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrappering. This section will be explaining how to use typemaps to best effect

    +

    This section explains what typemaps are and the usage of them. The default wrapping behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrapping. This section will be explaining how to use typemaps to best effect

    -

    25.4.1 What is a typemap?

    +

    26.4.1 What is a typemap?

    A typemap is nothing more than a code generation rule that is attached to a specific C datatype. For example, to convert integers from Lua to C, you might define a typemap like this:

    @@ -1143,7 +1291,7 @@ Received an integer : 6 720 -

    25.4.2 Using typemaps

    +

    26.4.2 Using typemaps

    There are many ready written typemaps built into SWIG for all common types (int, float, short, long, char*, enum and more), which SWIG uses automatically, with no effort required on your part.

    @@ -1196,7 +1344,7 @@ void swap(int *sx, int *sy);

    Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a const int& as an input parameter (since that it obviously input).

    -

    25.4.3 Typemaps and arrays

    +

    26.4.3 Typemaps and arrays

    Arrays present a challenge for SWIG, because like pointers SWIG does not know whether these are input or output values, nor @@ -1260,7 +1408,7 @@ and Lua tables to be 1..N, (the indexing follows the norm for the language). In

    Note: SWIG also can support arrays of pointers in a similar manner.

    -

    25.4.4 Typemaps and pointer-pointer functions

    +

    26.4.4 Typemaps and pointer-pointer functions

    Several C++ libraries use a pointer-pointer functions to create its objects. These functions require a pointer to a pointer which is then filled with the pointer to the new object. Microsoft's COM and DirectX as well as many other libraries have this kind of function. An example is given below:

    @@ -1279,7 +1427,7 @@ ok=Create_Math(&ptr); free(ptr); // dispose of iMath -

    SWIG has a ready written typemap to deal with such a kind of function in <typemaps.i>. It provides the correct wrappering as well as setting the flag to inform Lua that the object in question should be garbage collected. Therefore the code is simply:

    +

    SWIG has a ready written typemap to deal with such a kind of function in <typemaps.i>. It provides the correct wrapping as well as setting the flag to inform Lua that the object in question should be garbage collected. Therefore the code is simply:

    %include <typemaps.i>
     %apply SWIGTYPE** OUTPUT{iMath **pptr }; // tell SWIG its an output
    @@ -1294,16 +1442,16 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs)
     ptr=nil -- the iMath* will be GC'ed as normal
     
    -

    25.5 Writing typemaps

    +

    26.5 Writing typemaps

    This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the %typemap directive. This is an advanced topic that assumes familiarity with the Lua C API as well as the material in the "Typemaps" chapter.

    -

    Before proceeding, it should be stressed that writing typemaps is rarely needed unless you want to change some aspect of the wrappering, or to achieve an effect which in not available with the default bindings.

    +

    Before proceeding, it should be stressed that writing typemaps is rarely needed unless you want to change some aspect of the wrapping, or to achieve an effect which in not available with the default bindings.

    Before proceeding, you should read the previous section on using typemaps, as well as read the ready written typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you a idea to base your worn on).

    -

    25.5.1 Typemaps you can write

    +

    26.5.1 Typemaps you can write

    There are many different types of typemap that can be written, the full list can be found in the "Typemaps" chapter. However the following are the most commonly used ones.

    @@ -1316,7 +1464,7 @@ ptr=nil -- the iMath* will be GC'ed as normal (the syntax for the typecheck is different from the typemap, see typemaps for details). -

    25.5.2 SWIG's Lua-C API

    +

    26.5.2 SWIG's Lua-C API

    This section explains the SWIG specific Lua-C API. It does not cover the main Lua-C api, as this is well documented and not worth covering.

    @@ -1324,7 +1472,7 @@ ptr=nil -- the iMath* will be GC'ed as normal

    int SWIG_ConvertPtr(lua_State* L,int index,void** ptr,swig_type_info *type,int flags);

    -This is the standard function used for converting a Lua userdata to a void*. It takes the value at the given index in the Lua state and converts it to a userdata. It will then provide the neccesary type checks, confirming that the pointer is compatible with the type given in 'type'. Then finally setting '*ptr' to the pointer. +This is the standard function used for converting a Lua userdata to a void*. It takes the value at the given index in the Lua state and converts it to a userdata. It will then provide the necessary type checks, confirming that the pointer is compatible with the type given in 'type'. Then finally setting '*ptr' to the pointer. If flags is set to SWIG_POINTER_DISOWN, this is will clear any ownership flag set on the object.
    The returns a value which can be checked with the macro SWIG_IsOK()
    @@ -1345,7 +1493,7 @@ This function is a version of SWIG_ConvertPtr(), except that it will either work

    SWIG_fail

    -This macro, when called within the context of a SWIG wrappered function, will jump to the error handler code. This will call any cleanup code (freeing any temp variables) and then triggers a lua_error.
    +This macro, when called within the context of a SWIG wrapped function, will jump to the error handler code. This will call any cleanup code (freeing any temp variables) and then triggers a lua_error.
    A common use for this code is:
     if (!SWIG_IsOK(SWIG_ConvertPtr( .....)){
      lua_pushstring(L,"something bad happened");
    @@ -1355,7 +1503,7 @@ if (!SWIG_IsOK(SWIG_ConvertPtr( .....)){
     

    SWIG_fail_arg(char* func_name,int argnum,char* type)

    -This macro, when called within the context of a SWIG wrappered function, will display the error message and jump to the error handler code. The error message is of the form +This macro, when called within the context of a SWIG wrapped function, will display the error message and jump to the error handler code. The error message is of the form
     "Error in func_name (arg argnum), expected 'type' got 'whatever the type was'"
     
    @@ -1365,7 +1513,7 @@ This macro, when called within the context of a SWIG wrappered function, will di
    Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.
    -

    25.6 Customization of your Bindings

    +

    26.6 Customization of your Bindings

    @@ -1374,11 +1522,11 @@ This section covers adding of some small extra bits to your module to add the la -

    25.6.1 Writing your own custom wrappers

    +

    26.6.1 Writing your own custom wrappers

    -Sometimes, it may be neccesary to add your own special functions, which bypass the normal SWIG wrappering method, and just use the native Lua API calls. These 'native' functions allow direct adding of your own code into the module. This is performed with the %native directive as follows: +Sometimes, it may be necessary to add your own special functions, which bypass the normal SWIG wrapper method, and just use the native Lua API calls. These 'native' functions allow direct adding of your own code into the module. This is performed with the %native directive as follows:

    %native(my_func) int native_function(lua_State*L);  // registers native_function() with SWIG
     ...
    @@ -1390,10 +1538,10 @@ int native_function(lua_State*L) // my native code
     %}
     

    -The %native directive in the above example, tells SWIG that there is a function int native_function(lua_State*L); which is to be added into the module under the name 'my_func'. SWIG will not add any wrappering for this function, beyond adding it into the function table. How you write your code is entirely up to you. +The %native directive in the above example, tells SWIG that there is a function int native_function(lua_State*L); which is to be added into the module under the name 'my_func'. SWIG will not add any wrapper for this function, beyond adding it into the function table. How you write your code is entirely up to you.

    -

    25.6.2 Adding additional Lua code

    +

    26.6.2 Adding additional Lua code

    @@ -1431,18 +1579,18 @@ Good uses for this feature is adding of new code, or writing helper functions to See Examples/lua/arrays for an example of this code.

    -

    25.7 Details on the Lua binding

    +

    26.7 Details on the Lua binding

    In the previous section, a high-level view of Lua wrapping was presented. Obviously a lot of stuff happens behind the scenes to make this happen. This section will explain some of the low-level details on how this is achieved.

    - If you just want to use SWIG and don't care how it works, then stop reading here. This is going into the guts of the code and how it works. Its mainly for people who need to know whats going on within the code. + If you just want to use SWIG and don't care how it works, then stop reading here. This is going into the guts of the code and how it works. It's mainly for people who need to know what's going on within the code.

    -

    25.7.1 Binding global data into the module.

    +

    26.7.1 Binding global data into the module.

    @@ -1502,7 +1650,7 @@ end

    That way when you call 'a=example.Foo', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code 'example.Foo=10', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.

    -

    25.7.2 Userdata and Metatables

    +

    26.7.2 Userdata and Metatables

    @@ -1577,16 +1725,16 @@ So when 'p:Print()' is called, the __index looks on the object metatable for a ' In theory, you can play with this usertable & add new features, but remember that it is a shared table between all instances of one class, and you could very easily corrupt the functions in all the instances.

    -Note: Both the opaque structures (like the FILE*) and normal wrappered classes/structs use the same 'swig_lua_userdata' structure. Though the opaque structures has do not have a metatable attached, or any information on how to dispose of them when the interpreter has finished with them. +Note: Both the opaque structures (like the FILE*) and normal wrapped classes/structs use the same 'swig_lua_userdata' structure. Though the opaque structures has do not have a metatable attached, or any information on how to dispose of them when the interpreter has finished with them.

    Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__call' to the classes metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.

    -

    25.7.3 Memory management

    +

    26.7.3 Memory management

    -Lua is very helpful with the memory management. The 'swig_lua_userdata' is fully managed by the interpreter itself. This means that neither the C code nor the Lua code can damage it. Once a piece of userdata has no references to it, it is not instantly collected, but will be collected when Lua deems is necessary. (You can force collection by calling the Lua function collectgarbage()). Once the userdata is about to be free'ed, the interpreter will check the userdata for a metatable and for a function '__gc'. If this exists this is called. For all complete types (ie normal wrappered classes & structs) this should exist. The '__gc' function will check the 'swig_lua_userdata' to check for the 'own' field and if this is true (which is will be for all owned data's) it will then call the destructor on the pointer. +Lua is very helpful with the memory management. The 'swig_lua_userdata' is fully managed by the interpreter itself. This means that neither the C code nor the Lua code can damage it. Once a piece of userdata has no references to it, it is not instantly collected, but will be collected when Lua deems is necessary. (You can force collection by calling the Lua function collectgarbage()). Once the userdata is about to be free'ed, the interpreter will check the userdata for a metatable and for a function '__gc'. If this exists this is called. For all complete types (ie normal wrapped classes & structs) this should exist. The '__gc' function will check the 'swig_lua_userdata' to check for the 'own' field and if this is true (which is will be for all owned data) it will then call the destructor on the pointer.

    It is currently not recommended to edit this field or add some user code, to change the behaviour. Though for those who wish to try, here is where to look. diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index f9400abee..065313fa2 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -5,7 +5,7 @@ -

    26 SWIG and Modula-3

    +

    27 SWIG and Modula-3

      @@ -54,7 +54,7 @@ especially typemaps.

      -

      26.1 Overview

      +

      27.1 Overview

      @@ -84,7 +84,7 @@ FFTW -

      26.1.1 Motivation

      +

      27.1.1 Motivation

      @@ -131,10 +131,10 @@ functions), but it doesn't allow you to easily integrate a Module-3 module into a C/C++ project.

      -

      26.2 Conception

      +

      27.2 Conception

      -

      26.2.1 Interfaces to C libraries

      +

      27.2.1 Interfaces to C libraries

      @@ -283,7 +283,7 @@ and the principal type must be renamed (%typemap).

      -

      26.2.2 Interfaces to C++ libraries

      +

      27.2.2 Interfaces to C++ libraries

      @@ -384,10 +384,10 @@ There is no C++ library I wrote a SWIG interface for, so I'm not sure if this is possible or sensible, yet.

      -

      26.3 Preliminaries

      +

      27.3 Preliminaries

      -

      26.3.1 Compilers

      +

      27.3.1 Compilers

      @@ -400,7 +400,7 @@ For testing examples I use Critical Mass cm3.

      -

      26.3.2 Additional Commandline Options

      +

      27.3.2 Additional Commandline Options

      @@ -477,10 +477,10 @@ Instead generate templates for some basic typemaps. -

      26.4 Modula-3 typemaps

      +

      27.4 Modula-3 typemaps

      -

      26.4.1 Inputs and outputs

      +

      27.4.1 Inputs and outputs

      @@ -694,7 +694,7 @@ consist of the following parts: -

      26.4.2 Subranges, Enumerations, Sets

      +

      27.4.2 Subranges, Enumerations, Sets

      @@ -746,7 +746,7 @@ that I'd like to automate.

      -

      26.4.3 Objects

      +

      27.4.3 Objects

      @@ -759,7 +759,7 @@ is not really useful, yet.

      -

      26.4.4 Imports

      +

      27.4.4 Imports

      @@ -792,7 +792,7 @@ IMPORT M3toC;

    -

    26.4.5 Exceptions

    +

    27.4.5 Exceptions

    @@ -816,7 +816,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    26.4.6 Example

    +

    27.4.6 Example

    @@ -863,10 +863,10 @@ where almost everything is generated by a typemap: -

    26.5 More hints to the generator

    +

    27.5 More hints to the generator

    -

    26.5.1 Features

    +

    27.5.1 Features

    @@ -903,7 +903,7 @@ where almost everything is generated by a typemap:
    -

    26.5.2 Pragmas

    +

    27.5.2 Pragmas

    @@ -926,7 +926,7 @@ where almost everything is generated by a typemap:
    -

    26.6 Remarks

    +

    27.6 Remarks

      diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index 984b2dded..3b49a2974 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@ -

      27 SWIG and MzScheme/Racket

      +

      28 SWIG and MzScheme/Racket

        @@ -24,7 +24,7 @@

        This section contains information on SWIG's support of Racket, formally known as MzScheme. -

        27.1 Creating native structures

        +

        28.1 Creating native structures

        @@ -65,7 +65,7 @@ Then in scheme, you can use regular struct access procedures like

      -

      27.2 Simple example

      +

      28.2 Simple example

      @@ -166,7 +166,7 @@ Some points of interest:

    • The above requests mzc to create an extension using the CGC garbage-collector. The alternative -- the 3m collector -- has generally better performance, but work is still required for SWIG to emit code which is compatible with it.
    -

    27.3 External documentation

    +

    28.3 External documentation

    diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index 56c3db142..ba8aa5fa9 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -6,7 +6,7 @@ -

    28 SWIG and Ocaml

    +

    29 SWIG and Ocaml

      @@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit The Ocaml Website.

      -

      28.1 Preliminaries

      +

      29.1 Preliminaries

      @@ -99,7 +99,7 @@ file Examples/Makefile illustrate how to compile and link SWIG modules that will be loaded dynamically. This has only been tested on Linux so far.

      -

      28.1.1 Running SWIG

      +

      29.1.1 Running SWIG

      @@ -122,7 +122,7 @@ you will compile the file example_wrap.c with ocamlc or the resulting .ml and .mli files as well, and do the final link with -custom (not needed for native link).

      -

      28.1.2 Compiling the code

      +

      29.1.2 Compiling the code

      @@ -158,7 +158,7 @@ the user more freedom with respect to custom typing.

    -

    28.1.3 The camlp4 module

    +

    29.1.3 The camlp4 module

    @@ -234,7 +234,7 @@ let b = C_string (getenv "PATH") -

    28.1.4 Using your module

    +

    29.1.4 Using your module

    @@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom option is not needed when you build native code.

    -

    28.1.5 Compilation problems and compiling with C++

    +

    29.1.5 Compilation problems and compiling with C++

    @@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler. Most code meant to be compiled as C++ will not have problems.

    -

    28.2 The low-level Ocaml/C interface

    +

    29.2 The low-level Ocaml/C interface

    @@ -360,7 +360,7 @@ is that you must append them to the return list with swig_result = caml_list_a signature for a function that uses value in this way.

    -

    28.2.1 The generated module

    +

    29.2.1 The generated module

    @@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions. -

    28.2.2 Enums

    +

    29.2.2 Enums

    @@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a -

    28.2.2.1 Enum typing in Ocaml

    +

    29.2.2.1 Enum typing in Ocaml

    @@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master values using the swig_val function before sharing them with another module.

    -

    28.2.3 Arrays

    +

    29.2.3 Arrays

    -

    28.2.3.1 Simple types of bounded arrays

    +

    29.2.3.1 Simple types of bounded arrays

    @@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works for arrays whose bounds are completely specified.

    -

    28.2.3.2 Complex and unbounded arrays

    +

    29.2.3.2 Complex and unbounded arrays

    @@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array, so you have to specify it for yourself in the form of a typemap.

    -

    28.2.3.3 Using an object

    +

    29.2.3.3 Using an object

    @@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex, such as using a required sentinel, etc.

    -

    28.2.3.4 Example typemap for a function taking float * and int

    +

    29.2.3.4 Example typemap for a function taking float * and int

    @@ -572,7 +572,7 @@ void printfloats( float *tab, int len ); -

    28.2.4 C++ Classes

    +

    29.2.4 C++ Classes

    @@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the returned value for the same object.

    -

    28.2.4.1 STL vector and string Example

    +

    29.2.4.1 STL vector and string Example

    @@ -695,7 +695,7 @@ baz # -

    28.2.4.2 C++ Class Example

    +

    29.2.4.2 C++ Class Example

    @@ -725,7 +725,7 @@ public: }; -

    28.2.4.3 Compiling the example

    +

    29.2.4.3 Compiling the example

    @@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
       -L$QTPATH/lib -cclib -lqt
     
    -

    28.2.4.4 Sample Session

    +

    29.2.4.4 Sample Session

    @@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
     containing the string "hi" in a button.  
     

    -

    28.2.5 Director Classes

    +

    29.2.5 Director Classes

    -

    28.2.5.1 Director Introduction

    +

    29.2.5.1 Director Introduction

    @@ -800,7 +800,7 @@ class foo { };

    -

    28.2.5.2 Overriding Methods in Ocaml

    +

    29.2.5.2 Overriding Methods in Ocaml

    @@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing an overloaded class. This example is contained in Examples/ocaml/shapes.

    -

    28.2.5.3 Director Usage Example

    +

    29.2.5.3 Director Usage Example

    @@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the program in C++.

    -

    28.2.5.4 Creating director objects

    +

    29.2.5.4 Creating director objects

    @@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed properly.

    -

    28.2.5.5 Typemaps for directors, directorin, directorout, directorargout

    +

    29.2.5.5 Typemaps for directors, directorin, directorout, directorargout

    @@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments, and to receive arguments the same way you normally receive function returns.

    -

    28.2.5.6 directorin typemap

    +

    29.2.5.6 directorin typemap

    @@ -950,7 +950,7 @@ code receives when you are called. In general, a simple directorin typ can use the same body as a simple out typemap.

    -

    28.2.5.7 directorout typemap

    +

    29.2.5.7 directorout typemap

    @@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object ownership, etc.

    -

    28.2.5.8 directorargout typemap

    +

    29.2.5.8 directorargout typemap

    @@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral values will read zero, and struct or object returns have undefined results.

    -

    28.2.6 Exceptions

    +

    29.2.6 Exceptions

    diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 3c08d849b..8a01e7c76 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -8,13 +8,14 @@ -

    29 SWIG and Octave

    +

    30 SWIG and Octave

    To build an Octave module when wrapping C code, run SWIG using the -octave option:

    -
    $ swig -octave example.i 
    +
    $ swig -octave -o example_wrap.cpp example.i 

    The -c++ option is also required when wrapping C++ code:

    -
    $ swig -octave -c++ example.i 
    +
    $ swig -octave -c++ -o example_wrap.cpp example.i 

    -This creates a C++ source file example_wrap.cxx. A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module. +This creates a C++ source file example_wrap.cpp. A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module.

    +

    30.2.1 Command-line options

    + +

    -The swig command line has a number of options you can use, like to redirect it's output. Use swig --help to learn about these. +The swig command line has a number of options you can use, like to redirect its output. Use swig -help to learn about these. +Options specific to the Octave module are:

    -

    29.2.1 Compiling a dynamic module

    +
    +
    $ swig -octave -help
    +...
    +Octave Options (available with -octave)
    +     -global       - Load all symbols into the global namespace [default]
    +     -globals name - Set name used to access C global variables [default: 'cvar']
    +     -noglobal     - Do not load all symbols into the global namespace
    +     -opprefix str - Prefix str for global operator functions [default: 'op_']
    +
    + +

    +The -global and -noglobal options determine whether the Octave module will load all symbols into the global namespace in addition to the global namespace. +The -globals option sets the name of the variable which is the namespace for C global variables exported by the module. +The -opprefix options sets the prefix of the names of global/friend operator functions. +

    + +

    30.2.2 Compiling a dynamic module

    @@ -106,8 +131,8 @@ Building an oct file is usually done with the mkoctfile command (either within O

    -$ swig -octave -c++ example.i -o example_wrap.cxx
    -$ mkoctfile example_wrap.cxx example.c
    +$ swig -octave -c++ -o example_wrap.cpp example.i
    +$ mkoctfile example_wrap.cpp example.c
     

    @@ -124,7 +149,7 @@ $ mkoctfile example_wrap.cxx example.c

    octave:1> example
    -

    29.2.2 Using your module

    +

    30.2.3 Using your module

    @@ -142,10 +167,10 @@ octave:4> example.cvar.Foo=4; octave:5> example.cvar.Foo ans = 4 -

    29.3 A tour of basic C/C++ wrapping

    +

    30.3 A tour of basic C/C++ wrapping

    -

    29.3.1 Modules

    +

    30.3.1 Modules

    @@ -157,37 +182,73 @@ When Octave is asked to invoke example, it will try to find the .m or .

    -Giving this function a parameter "global" will cause it to load all symbols into the global namespace in addition to the example namespace. For example: +An Octave module takes three options, -global, -noglobal, and -globals, which behave the same as the corresponding swig command-line options. +Here are some example usages:

    -
    $ octave -q
    -octave:1> example("global")
    -octave:2> gcd(4,6)
    +    
    +octave:1> example -help
    +usage: example [-global|-noglobal] [-globals <name>]
    +octave:2> example -global
    +octave:3> gcd(4,6)
     ans =  2
    -octave:3> cvar.Foo
    +octave:4> cvar.Foo
     ans =  3
    -octave:4> cvar.Foo=4;
    -octave:5> cvar.Foo
    -ans =  4 
    +octave:5> cvar.Foo=4;
    +octave:6> cvar.Foo
    +ans =  4
     
    +
    +
    +octave:1> example -noglobal
    +octave:2> gcd(6,9)
    +ans =  3
    +octave:3> cvar.Foo
    +error: `cvar' undefined near line 3 column 1
    +octave:3> example.cvar.Foo
    +ans =  3
    +
    +
    +
    +octave:1> example -globals mycvar
    +octave:2> cvar.Foo
    +error: `cvar' undefined near line 2 column 1
    +octave:2> mycvar.Foo
    +ans =  3
    +
    +

    - It is also possible to rename the module namespace with an assignment, as in:
    -

    octave:1> example;
    +     It is also possible to rename the module / global variables namespaces with an assignment, as in: 
    +
    +octave:1> example
     octave:2> c=example;
     octave:3> c.gcd(10,4)
    -ans =  2 
    - -

    -All global variables are put into the cvar namespace object. This is accessible either as my_module.cvar, or just cvar (if the module is imported into the global namespace). -

    -

    -One can also rename it by simple assignment, e.g., -

    -
    -octave:1> some_vars = cvar;
    +ans =  2
    +octave:4> some_vars = cvar;
    +octave:5> some_vars.Foo
    +ans =  3
     
    -

    29.3.2 Functions

    +

    +Modules can also be loaded from within functions, even before being loaded in the base context. +If the module is also used in the base context, however, it must first be loaded again: +

    + +
    +octave:1> function l = my_lcm(a,b)
    +> example
    +> l = abs(a*b)/example.gcd(a,b);
    +> endfunction
    +octave:2> my_lcm(4,6)
    +ans =  12
    +octave:3> example.gcd(4,6)
    +error: can't perform indexing operations for <unknown type> type
    +octave:3> example;
    +octave:4> example.gcd(4,6)
    +ans =  2
    +
    + +

    30.3.2 Functions

    @@ -204,7 +265,7 @@ int fact(int n);

    octave:1> example.fact(4)
     24 
    -

    29.3.3 Global variables

    +

    30.3.3 Global variables

    @@ -257,7 +318,7 @@ octave:2> example.PI=3.142; octave:3> example.PI ans = 3.1420

    -

    29.3.4 Constants and enums

    +

    30.3.4 Constants and enums

    @@ -279,7 +340,7 @@ example.SCONST="Hello World" example.SUNDAY=0 .... -

    29.3.5 Pointers

    +

    30.3.5 Pointers

    @@ -326,7 +387,7 @@ octave:2> f=example.fopen("not there","r"); error: value on right hand side of assignment is undefined error: evaluating assignment expression near line 2, column 2 -

    29.3.6 Structures and C++ classes

    +

    30.3.6 Structures and C++ classes

    @@ -461,7 +522,7 @@ ans = 1 Depending on the ownership setting of a swig_ref, it may call C++ destructors when its reference count goes to zero. See the section on memory management below for details.

    -

    29.3.7 C++ inheritance

    +

    30.3.7 C++ inheritance

    @@ -470,7 +531,7 @@ This information contains the full class hierarchy. When an indexing operation ( the tree is walked to find a match in the current class as well as any of its bases. The lookup is then cached in the swig_ref.

    -

    29.3.8 C++ overloaded functions

    +

    30.3.8 C++ overloaded functions

    @@ -480,7 +541,7 @@ The dispatch function selects which overload to call (if any) based on the passe typecheck typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.

    -

    29.3.9 C++ operators

    +

    30.3.9 C++ operators

    @@ -580,7 +641,11 @@ On the C++ side, the default mappings are as follows: %rename(__brace) *::operator[]; -

    29.3.10 Class extension with %extend

    +

    +Octave can also utilise friend (i.e. non-member) operators with a simple %rename: see the example in the Examples/octave/operator directory. +

    + +

    30.3.10 Class extension with %extend

    @@ -610,7 +675,7 @@ octave:3> printf("%s\n",a); octave:4> a.__str() 4 -

    29.3.11 C++ templates

    +

    30.3.11 C++ templates

    @@ -687,14 +752,14 @@ ans = -

    29.3.12 C++ Smart Pointers

    +

    30.3.12 C++ Smart Pointers

    C++ smart pointers are fully supported as in other modules.

    -

    29.3.13 Directors (calling Octave from C++ code)

    +

    30.3.13 Directors (calling Octave from C++ code)

    @@ -775,14 +840,14 @@ c-side routine called octave-side routine called -

    29.3.14 Threads

    +

    30.3.14 Threads

    The use of threads in wrapped Director code is not supported; i.e., an Octave-side implementation of a C++ class must be called from the Octave interpreter's thread. Anything fancier (apartment/queue model, whatever) is left to the user. Without anything fancier, this amounts to the limitation that Octave must drive the module... like, for example, an optimization package that calls Octave to evaluate an objective function.

    -

    29.3.15 Memory management

    +

    30.3.15 Memory management

    @@ -816,14 +881,14 @@ The %newobject directive may be used to control this behavior for pointers retur In the case where one wishes for the C++ side to own an object that was created in Octave (especially a Director object), one can use the __disown() method to invert this logic. Then letting the Octave reference count go to zero will not destroy the object, but destroying the object will invalidate the Octave-side object if it still exists (and call destructors of other C++ bases in the case of multiple inheritance/subclass()'ing).

    -

    29.3.16 STL support

    +

    30.3.16 STL support

    Various STL library files are provided for wrapping STL containers.

    -

    29.3.17 Matrix typemaps

    +

    30.3.17 Matrix typemaps

    diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 5aae51888..da2344759 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -6,7 +6,7 @@ -

    30 SWIG and Perl5

    +

    31 SWIG and Perl5

      @@ -82,12 +82,12 @@ This chapter describes SWIG's support of Perl5. Although the Perl5 module is one of the earliest SWIG modules, it has continued to evolve and has been improved greatly with the help of SWIG users. For the -best results, it is recommended that SWIG be used with Perl5.003 or -later. Earlier versions are problematic and SWIG generated extensions -may not compile or run correctly. +best results, it is recommended that SWIG be used with Perl 5.8 or +later. We're no longer testing regularly with older versions, but +Perl 5.6 seems to mostly work, while older versions don't.

      -

      30.1 Overview

      +

      31.1 Overview

      @@ -108,7 +108,7 @@ described. Advanced customization features, typemaps, and other options are found near the end of the chapter.

      -

      30.2 Preliminaries

      +

      31.2 Preliminaries

      @@ -133,7 +133,7 @@ To build the module, you will need to compile the file example_wrap.c and link it with the rest of your program.

      -

      30.2.1 Getting the right header files

      +

      31.2.1 Getting the right header files

      @@ -165,7 +165,7 @@ loaded, an easy way to find out is to run Perl itself.

    -

    30.2.2 Compiling a dynamic module

    +

    31.2.2 Compiling a dynamic module

    @@ -198,7 +198,7 @@ the target should be named `example.so', `example.sl', or the appropriate dynamic module name on your system.

    -

    30.2.3 Building a dynamic module with MakeMaker

    +

    31.2.3 Building a dynamic module with MakeMaker

    @@ -232,7 +232,7 @@ the preferred approach to compilation. More information about MakeMaker can be found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.

    -

    30.2.4 Building a static version of Perl

    +

    31.2.4 Building a static version of Perl

    @@ -301,7 +301,7 @@ added to it. Depending on your machine, you may need to link with additional libraries such as -lsocket, -lnsl, -ldl, etc.

    -

    30.2.5 Using the module

    +

    31.2.5 Using the module

    @@ -456,7 +456,7 @@ system configuration (this requires root access and you will need to read the man pages).

    -

    30.2.6 Compilation problems and compiling with C++

    +

    31.2.6 Compilation problems and compiling with C++

    @@ -599,7 +599,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas any conflicting macros you find to swig-user mailing list.

    -

    30.2.7 Compiling for 64-bit platforms

    +

    31.2.7 Compiling for 64-bit platforms

    @@ -626,7 +626,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

    -

    30.3 Building Perl Extensions under Windows

    +

    31.3 Building Perl Extensions under Windows

    @@ -637,7 +637,7 @@ section assumes you are using SWIG with Microsoft Visual C++ although the procedure may be similar with other compilers.

    -

    30.3.1 Running SWIG from Developer Studio

    +

    31.3.1 Running SWIG from Developer Studio

    @@ -700,7 +700,7 @@ print "$a\n"; -

    30.3.2 Using other compilers

    +

    31.3.2 Using other compilers

    @@ -708,7 +708,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows. For general hints and suggestions refer to the Windows chapter.

    -

    30.4 The low-level interface

    +

    31.4 The low-level interface

    @@ -718,7 +718,7 @@ can be used to control your application. However, it is also used to construct more user-friendly proxy classes as described in the next section.

    -

    30.4.1 Functions

    +

    31.4.1 Functions

    @@ -741,7 +741,7 @@ use example; $a = &example::fact(2); -

    30.4.2 Global variables

    +

    31.4.2 Global variables

    @@ -811,7 +811,7 @@ extern char *path; // Declared later in the input -

    30.4.3 Constants

    +

    31.4.3 Constants

    @@ -851,7 +851,7 @@ print example::FOO,"\n"; -

    30.4.4 Pointers

    +

    31.4.4 Pointers

    @@ -960,7 +960,7 @@ as XS and xsubpp. Given the advancement of the SWIG typesystem and the SWIG and XS, this is no longer supported.

    -

    30.4.5 Structures

    +

    31.4.5 Structures

    @@ -1094,7 +1094,7 @@ void Bar_f_set(Bar *b, Foo *val) { -

    30.4.6 C++ classes

    +

    31.4.6 C++ classes

    @@ -1159,7 +1159,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox can be built using these low-level accessors. This is described shortly.

    -

    30.4.7 C++ classes and type-checking

    +

    31.4.7 C++ classes and type-checking

    @@ -1195,7 +1195,7 @@ If necessary, the type-checker also adjusts the value of the pointer (as is nece multiple inheritance is used).

    -

    30.4.8 C++ overloaded functions

    +

    31.4.8 C++ overloaded functions

    @@ -1239,7 +1239,7 @@ example::Spam_foo_d($s,3.14); Please refer to the "SWIG Basics" chapter for more information.

    -

    30.4.9 Operators

    +

    31.4.9 Operators

    @@ -1266,7 +1266,7 @@ The following C++ operators are currently supported by the Perl module:

  • operator or
  • -

    30.4.10 Modules and packages

    +

    31.4.10 Modules and packages

    @@ -1361,7 +1361,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar --> -

    30.5 Input and output parameters

    +

    31.5 Input and output parameters

    @@ -1580,7 +1580,7 @@ print "$c\n"; Note: The REFERENCE feature is only currently supported for numeric types (integers and floating point).

    -

    30.6 Exception handling

    +

    31.6 Exception handling

    @@ -1745,7 +1745,7 @@ This is still supported, but it is deprecated. The newer %exception di functionality, but it has additional capabilities that make it more powerful.

    -

    30.7 Remapping datatypes with typemaps

    +

    31.7 Remapping datatypes with typemaps

    @@ -1762,7 +1762,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Perl interface.

    -

    30.7.1 A simple typemap example

    +

    31.7.1 A simple typemap example

    @@ -1866,7 +1866,7 @@ example::count("e","Hello World"); -

    30.7.2 Perl5 typemaps

    +

    31.7.2 Perl5 typemaps

    @@ -1971,7 +1971,7 @@ Return of C++ member data (all languages). Check value of input parameter. -

    30.7.3 Typemap variables

    +

    31.7.3 Typemap variables

    @@ -2042,7 +2042,7 @@ properly assigned. The Perl name of the wrapper function being created. -

    30.7.4 Useful functions

    +

    31.7.4 Useful functions

    @@ -2111,7 +2111,7 @@ int sv_isa(SV *, char *0; -

    30.8 Typemap Examples

    +

    31.8 Typemap Examples

    @@ -2120,7 +2120,7 @@ might look at the files "perl5.swg" and "typemaps.i" in the SWIG library.

    -

    30.8.1 Converting a Perl5 array to a char **

    +

    31.8.1 Converting a Perl5 array to a char **

    @@ -2212,7 +2212,7 @@ print @$b,"\n"; # Print it out -

    30.8.2 Return values

    +

    31.8.2 Return values

    @@ -2241,7 +2241,7 @@ can be done using the EXTEND() macro as in : } -

    30.8.3 Returning values from arguments

    +

    31.8.3 Returning values from arguments

    @@ -2295,7 +2295,7 @@ print "multout(7,13) = @r\n"; ($x,$y) = multout(7,13); -

    30.8.4 Accessing array structure members

    +

    31.8.4 Accessing array structure members

    @@ -2358,7 +2358,7 @@ the "in" typemap in the previous section would be used to convert an to copy the converted array into a C data structure.

    -

    30.8.5 Turning Perl references into C pointers

    +

    31.8.5 Turning Perl references into C pointers

    @@ -2423,7 +2423,7 @@ print "$c\n"; -

    30.8.6 Pointer handling

    +

    31.8.6 Pointer handling

    @@ -2502,7 +2502,7 @@ For example: -

    30.9 Proxy classes

    +

    31.9 Proxy classes

    @@ -2518,7 +2518,7 @@ to the underlying code. This section describes the implementation details of the proxy interface.

    -

    30.9.1 Preliminaries

    +

    31.9.1 Preliminaries

    @@ -2540,7 +2540,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil high level wrappers. The wrappers, in turn, interact with the low-level procedural module.

    -

    30.9.2 Structure and class wrappers

    +

    31.9.2 Structure and class wrappers

    @@ -2666,7 +2666,7 @@ $v->DESTROY(); -

    30.9.3 Object Ownership

    +

    31.9.3 Object Ownership

    @@ -2753,7 +2753,7 @@ counting, garbage collection, or advanced features one might find in sophisticated languages.

    -

    30.9.4 Nested Objects

    +

    31.9.4 Nested Objects

    @@ -2806,7 +2806,7 @@ $p->{f}->{x} = 0.0; %${$p->{v}} = ( x=>0, y=>0, z=>0); -

    30.9.5 Proxy Functions

    +

    31.9.5 Proxy Functions

    @@ -2840,7 +2840,7 @@ This function replaces the original function, but operates in an identical manner.

    -

    30.9.6 Inheritance

    +

    31.9.6 Inheritance

    @@ -2916,7 +2916,7 @@ particular, inheritance of data members is extremely tricky (and I'm not even sure if it really works).

    -

    30.9.7 Modifying the proxy methods

    +

    31.9.7 Modifying the proxy methods

    @@ -2944,7 +2944,7 @@ public: }; -

    30.10 Adding additional Perl code

    +

    31.10 Adding additional Perl code

    diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 797cb058e..19ace7192 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -7,7 +7,7 @@ -

    31 SWIG and PHP

    +

    32 SWIG and PHP

      @@ -49,19 +49,23 @@

      -SWIG supports generating wrappers for PHP5. Support for PHP4 has been removed -as of SWIG 1.3.37. The PHP developers are no longer making new PHP4 releases, +SWIG supports generating wrappers for PHP5. Support for PHP4 was removed +in SWIG 1.3.37. The PHP developers are no longer making new PHP4 releases, and won't even be patching critical security issues after 2008-08-08, so it -doesn't make much sense for SWIG to continue to support PHP4 at this point. -If you need to continue to use PHP4, stick with SWIG 1.3.36. +doesn't make much sense for SWIG to continue to support PHP4 now. If you +really need to continue to use PHP4, just stick with SWIG 1.3.36. +

      + +

      +Currently any PHP5 release should work, but we don't regularly test with +PHP < 5.3.

      In this chapter, we discuss SWIG's support of PHP. The PHP module was extensively rewritten in release 1.3.26, and support for generating -OO wrappers for PHP5 was added in 1.3.30. The PHP module works fairly -well, but currently does not implement all the -features available in some of the other languages. +OO wrappers for PHP5 was added in 1.3.30. The PHP module now supports most +of the features available in some of the other languages.

      @@ -75,7 +79,7 @@ your extension into php directly, you will need the complete PHP source tree available.

      -

      31.1 Generating PHP Extensions

      +

      32.1 Generating PHP Extensions

      @@ -122,7 +126,7 @@ and it doesn't play nicely with package system. We don't recommend this approach, or provide explicit support for it.

      -

      31.1.1 Building a loadable extension

      +

      32.1.1 Building a loadable extension

      @@ -137,7 +141,7 @@ least work for Linux though): gcc -shared example_wrap.o -o example.so

    -

    31.1.2 Using PHP Extensions

    +

    32.1.2 Using PHP Extensions

    @@ -168,21 +172,22 @@ attempts to do the dl() call for you: include("example.php"); -

    31.2 Basic PHP interface

    +

    32.2 Basic PHP interface

    It is important to understand that PHP uses a single global namespace into which all symbols from extension modules are loaded. It is quite possible for names of symbols in one extension module to clash with -other symbols unless care is taken to %rename them. +other symbols unless care is taken to %rename them. At present +SWIG doesn't have support for the namespace feature added in PHP 5.3.

    -

    31.2.1 Constants

    +

    32.2.1 Constants

    -These work in much the same way as in C/C++, constants can be defined +These work in much the same way as in C/C++. Constants can be defined by using either the normal C pre-processor declarations, or the %constant SWIG directive. These will then be available from your PHP script as a PHP constant, (i.e. no dollar sign is needed to @@ -199,7 +204,7 @@ access them.) For example, with a swig interface file like this,

    -you can access the constants in your php script like this, +you can access the constants in your PHP script like this,

    @@ -213,9 +218,16 @@ echo "E = " . E . "\n";
     

    -There are two peculiarities with using constants in PHP. The first is that -if you try to use an undeclared constant, it will evaluate to a string -set to the constant's name. For example, +There's one peculiarity of how constants work in PHP which it is useful +to note (this is not specific to SWIG though) - if you try to use an undeclared +constant, PHP will issue a warning and then expand the constant to a string +version of the constant's name. The warning will often be missed though as +if you're using PHP in a webserver, it will probably end up in error.log or +similar. +

    + +

    +For example,

    @@ -243,67 +255,12 @@ if(EASY_TO_MISPEL) {
     

    -will issue a warning about the undeclared constant, but will then -evaluate it and turn it into a string ('EASY_TO_MISPEL'), which -evaluates to true, rather than the value of the constant which would -be false. This is a feature! +The mis-spelled constant will become the string 'EASY_TO_MISPEL', which +is treated as true by the if test, when the value of the intended constant +would be treated as false!

    -

    -The second 'feature' is that although constants are case sensitive (by -default), you cannot declare a constant twice with alternative -cases. E.g., -

    - -
    -
    -%module example
    -
    -#define TEST	Hello
    -#define Test	World
    -
    -
    - -

    -accessed from PHP, -

    - -
    -
    -include("example.php");
    -
    -echo TEST, Test;
    -
    -
    - -

    -will output "Hello Test" rather than "Hello World". This is because -internally, all constants are stored in a hash table by their lower -case name, so 'TEST' and 'Test' will map to the same hash element -('Test'). But, because we declared them case sensitive, the Zend -engine will test if the case matches with the case the constant was -declared with first. -

    - -

    -So, in the example above, the TEST constant was declared first, and -will be stored under the hash element 'test'. The 'Test' constant will -also map to the same hash element 'test', but will not overwrite -it. When called from the script, the TEST constant will again be -mapped to the hash element 'test' so the constant will be -retrieved. The case will then be checked, and will match up, so the -value ('Hello') will be returned. When 'Test' is evaluated, it will -also map to the same hash element 'test'. The same constant will be -retrieved, this time though the case check will fail as 'Test' != -'TEST'. So PHP will assume that Test is a undeclared constant, and as -explained above, will return it as a string set to the constant name -('Test'). Hence the script above will print 'Hello Test'. If they were -declared non-case sensitive, the output would be 'Hello Hello', as -both point to the same value, without the case test taking place. ( -Apologies, this paragraph needs rewriting to make some sense. ) -

    - -

    31.2.2 Global Variables

    +

    32.2.2 Global Variables

    @@ -352,7 +309,7 @@ undefined. At this time SWIG does not support custom accessor methods.

    -

    31.2.3 Functions

    +

    32.2.3 Functions

    @@ -405,7 +362,7 @@ print $s; # The value of $s was not changed. --> -

    31.2.4 Overloading

    +

    32.2.4 Overloading

    @@ -461,7 +418,7 @@ taking the integer argument.

    --> -

    31.2.5 Pointers and References

    +

    32.2.5 Pointers and References

    @@ -593,13 +550,15 @@ PHP in a number of ways: by using unset on an existing variable, or assigning NULL to a variable.

    -

    31.2.6 Structures and C++ classes

    +

    32.2.6 Structures and C++ classes

    -SWIG defaults to wrapping C++ structs and classes with PHP classes -unless "-noproxy" is specified. For PHP5, a PHP wrapper -class is generated which calls a set of flat functions wrapping the C++ class. +SWIG defaults to wrapping C++ structs and classes with PHP classes - this +is done by generating a PHP wrapper script which defines proxy classes +which calls a set of flat functions which actually wrap the C++ class. +You can disable this wrapper layer by passing the command-line option +"-noproxy" in which case you'll just get the flat functions.

    @@ -652,7 +611,7 @@ Would be used in the following way from PHP5: Member variables and methods are accessed using the -> operator.

    -

    31.2.6.1 Using -noproxy

    +

    32.2.6.1 Using -noproxy

    @@ -678,7 +637,7 @@ Complex_im_set($obj,$d); Complex_im_get($obj); -

    31.2.6.2 Constructors and Destructors

    +

    32.2.6.2 Constructors and Destructors

    @@ -719,7 +678,7 @@ the programmer can either reassign the variable or call unset($v)

    -

    31.2.6.3 Static Member Variables

    +

    32.2.6.3 Static Member Variables

    @@ -762,7 +721,7 @@ Ko::threats(10); echo "There has now been " . Ko::threats() . " threats\n"; -

    31.2.6.4 Static Member Functions

    +

    32.2.6.4 Static Member Functions

    @@ -784,7 +743,7 @@ Ko::threats(); -

    31.2.7 PHP Pragmas, Startup and Shutdown code

    +

    32.2.7 PHP Pragmas, Startup and Shutdown code

    @@ -872,7 +831,7 @@ The %rinit and %rshutdown statements are very similar but inse into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.

    -

    31.3 Cross language polymorphism

    +

    32.3 Cross language polymorphism

    @@ -907,7 +866,7 @@ wrapper functions takes care of all the cross-language method routing transparently.

    -

    31.3.1 Enabling directors

    +

    32.3.1 Enabling directors

    @@ -999,7 +958,7 @@ class MyFoo extends Foo { -

    31.3.2 Director classes

    +

    32.3.2 Director classes

    @@ -1079,7 +1038,7 @@ so there is no need for the extra overhead involved with routing the calls through PHP.

    -

    31.3.3 Ownership and object destruction

    +

    32.3.3 Ownership and object destruction

    @@ -1135,7 +1094,7 @@ In this example, we are assuming that FooContainer will take care of deleting all the Foo pointers it contains at some point.

    -

    31.3.4 Exception unrolling

    +

    32.3.4 Exception unrolling

    @@ -1194,7 +1153,7 @@ Swig::DirectorMethodException is thrown, PHP will register the exception as soon as the C wrapper function returns.

    -

    31.3.5 Overhead and code bloat

    +

    32.3.5 Overhead and code bloat

    @@ -1227,7 +1186,7 @@ optimized by selectively enabling director methods (using the %feature directive) for only those methods that are likely to be extended in PHP.

    -

    31.3.6 Typemaps

    +

    32.3.6 Typemaps

    @@ -1241,7 +1200,7 @@ need to be supported.

    -

    31.3.7 Miscellaneous

    +

    32.3.7 Miscellaneous

    Director typemaps for STL classes are mostly in place, and hence you diff --git a/Doc/Manual/Pike.html b/Doc/Manual/Pike.html index 8bd6b410f..8c1eb2d36 100644 --- a/Doc/Manual/Pike.html +++ b/Doc/Manual/Pike.html @@ -6,7 +6,7 @@ -

    32 SWIG and Pike

    +

    33 SWIG and Pike

      @@ -46,10 +46,10 @@ least, make sure you read the "SWIG Basics" chapter.

      -

      32.1 Preliminaries

      +

      33.1 Preliminaries

      -

      32.1.1 Running SWIG

      +

      33.1.1 Running SWIG

      @@ -94,7 +94,7 @@ can use the -o option:

      $ swig -pike -o pseudonym.c example.i
      -

      32.1.2 Getting the right header files

      +

      33.1.2 Getting the right header files

      @@ -114,7 +114,7 @@ You're looking for files with the names global.h, program.h and so on.

      -

      32.1.3 Using your module

      +

      33.1.3 Using your module

      @@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend) (1) Result: 24

    -

    32.2 Basic C/C++ Mapping

    +

    33.2 Basic C/C++ Mapping

    -

    32.2.1 Modules

    +

    33.2.1 Modules

    @@ -143,7 +143,7 @@ concerned), SWIG's %module directive doesn't really have any significance.

    -

    32.2.2 Functions

    +

    33.2.2 Functions

    @@ -168,7 +168,7 @@ exactly as you'd expect it to: (1) Result: 24 -

    32.2.3 Global variables

    +

    33.2.3 Global variables

    @@ -197,7 +197,7 @@ will result in two functions, Foo_get() and Foo_set(): (3) Result: 3.141590 -

    32.2.4 Constants and enumerated types

    +

    33.2.4 Constants and enumerated types

    @@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants, not as Pike enums.

    -

    32.2.5 Constructors and Destructors

    +

    33.2.5 Constructors and Destructors

    @@ -213,7 +213,7 @@ Constructors are wrapped as create() methods, and destructors are wrapped as destroy() methods, for Pike classes.

    -

    32.2.6 Static Members

    +

    33.2.6 Static Members

    diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 07f9e87d7..a9a9bc44e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -6,7 +6,7 @@ -

    33 SWIG and Python

    +

    34 SWIG and Python

  • Further details on the Python class interface
      @@ -98,6 +98,8 @@
    • %feature("docstring") @@ -133,7 +135,7 @@ very least, make sure you read the "SWIG Basics" chapter.

      -

      33.1 Overview

      +

      34.1 Overview

      @@ -160,10 +162,10 @@ described followed by a discussion of low-level implementation details.

      -

      33.2 Preliminaries

      +

      34.2 Preliminaries

      -

      33.2.1 Running SWIG

      +

      34.2.1 Running SWIG

      @@ -261,7 +263,7 @@ The following sections have further practical examples and details on how you might go about compiling and using the generated files.

      -

      33.2.2 Using distutils

      +

      34.2.2 Using distutils

      @@ -353,7 +355,7 @@ This same approach works on all platforms if the appropriate compiler is install can even build extensions to the standard Windows Python using MingGW)

      -

      33.2.3 Hand compiling a dynamic module

      +

      34.2.3 Hand compiling a dynamic module

      @@ -401,7 +403,7 @@ module actually consists of two files; socket.py and

      -

      33.2.4 Static linking

      +

      34.2.4 Static linking

      @@ -480,7 +482,7 @@ If using static linking, you might want to rely on a different approach (perhaps using distutils).

      -

      33.2.5 Using your module

      +

      34.2.5 Using your module

      @@ -637,7 +639,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      33.2.6 Compilation of C++ extensions

      +

      34.2.6 Compilation of C++ extensions

      @@ -729,7 +731,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

      -

      33.2.7 Compiling for 64-bit platforms

      +

      34.2.7 Compiling for 64-bit platforms

      @@ -766,7 +768,7 @@ and -m64 allow you to choose the desired binary format for your python extension.

      -

      33.2.8 Building Python Extensions under Windows

      +

      34.2.8 Building Python Extensions under Windows

      @@ -875,7 +877,7 @@ SWIG Wiki.

      -

      33.3 A tour of basic C/C++ wrapping

      +

      34.3 A tour of basic C/C++ wrapping

      @@ -884,7 +886,7 @@ to your C/C++ code. Functions are wrapped as functions, classes are wrapped as This section briefly covers the essential aspects of this wrapping.

      -

      33.3.1 Modules

      +

      34.3.1 Modules

      @@ -897,7 +899,7 @@ module name, make sure you don't use the same name as a built-in Python command or standard module name.

      -

      33.3.2 Functions

      +

      34.3.2 Functions

      @@ -921,7 +923,7 @@ like you think it does: >>>

  • -

    33.3.3 Global variables

    +

    34.3.3 Global variables

    @@ -1059,7 +1061,7 @@ that starts with a leading underscore. SWIG does not create cvar if there are no global variables in a module.

    -

    33.3.4 Constants and enums

    +

    34.3.4 Constants and enums

    @@ -1099,7 +1101,7 @@ other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

    -

    33.3.5 Pointers

    +

    34.3.5 Pointers

    @@ -1240,7 +1242,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

    -

    33.3.6 Structures

    +

    34.3.6 Structures

    @@ -1429,7 +1431,7 @@ everything works just like you would expect. For example: -

    33.3.7 C++ classes

    +

    34.3.7 C++ classes

    @@ -1518,7 +1520,7 @@ they are accessed through cvar like this: -

    33.3.8 C++ inheritance

    +

    34.3.8 C++ inheritance

    @@ -1573,7 +1575,7 @@ then the function spam() accepts Foo * or a pointer to any cla It is safe to use multiple inheritance with SWIG.

    -

    33.3.9 Pointers, references, values, and arrays

    +

    34.3.9 Pointers, references, values, and arrays

    @@ -1634,7 +1636,7 @@ treated as a returning value, and it will follow the same allocation/deallocation process.

    -

    33.3.10 C++ overloaded functions

    +

    34.3.10 C++ overloaded functions

    @@ -1757,7 +1759,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

    -

    33.3.11 C++ operators

    +

    34.3.11 C++ operators

    @@ -1846,7 +1848,7 @@ Also, be aware that certain operators don't map cleanly to Python. For instance overloaded assignment operators don't map to Python semantics and will be ignored.

    -

    33.3.12 C++ namespaces

    +

    34.3.12 C++ namespaces

    @@ -1913,7 +1915,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

    -

    33.3.13 C++ templates

    +

    34.3.13 C++ templates

    @@ -1967,7 +1969,7 @@ Some more complicated examples will appear later.

    -

    33.3.14 C++ Smart Pointers

    +

    34.3.14 C++ Smart Pointers

    @@ -2051,151 +2053,16 @@ simply use the __deref__() method. For example: - -

    33.3.15 C++ Reference Counted Objects (ref/unref)

    +

    34.3.15 C++ reference counted objects

    -Another usual idiom in C++ is the use of reference counted -objects. Consider for example: - -

    -
    -class RCObj  {
    -  // implement the ref counting mechanism
    -  int add_ref();
    -  int del_ref();
    -  int ref_count();
    -
    -public:
    -  virtual ~RCObj() = 0;
    -
    -  int ref() const {
    -    return add_ref();
    -  }
    -
    -  int unref() const   {
    -    if (ref_count() == 0 || del_ref() == 0 ) {
    -	delete this;
    -	return 0;
    -      } 
    -    return ref_count();
    -  }
    -};
    -
    -
    -class A : RCObj {
    -public:
    -  A();
    -  int foo();
    -};
    -
    -
    -class B {
    -  A *_a;
    -
    -public:
    -  B(A *a) : _a(a) { 
    -    a->ref(); 
    -  }
    -
    -  ~B() { 
    -    a->unref(); 
    -  }
    -};
    -
    -int main() {
    -  A *a  = new A();
    -  a->ref();           // 'a' is ref here
    -
    -  B *b1 = new B(a);   // 'a' is ref here
    -  if (1 + 1 == 2) {
    -    B *b2 = new B(a); // 'a' is ref here
    -    delete b2;        // 'a' is unref, but not deleted   
    -  }
    -
    -  delete b1;          // 'a' is unref, but not deleted   
    -  a->unref();         // 'a' is unref and deleted
    -}
    -
    -
    - -

    -In the example above, the 'A' class instance 'a' is a reference counted -object, which can't be deleted arbitrarily since it is shared between -the objects 'b1' and 'b2'. 'A' is derived from an Reference Counted -Object 'RCObj', which implements the ref/unref idiom. -

    - -

    -To tell SWIG that 'RCObj' and all its derived classes are reference -counted objects, you use the "ref" and "unref" features. -For example: +The C++ reference counted objects section contains +Python examples of memory management using referencing counting.

    -
    -
    -%module example
    -...
    -
    -%feature("ref")   RCObj "$this->ref();"
    -%feature("unref") RCObj "$this->unref();"
    -
    -%include "rcobj.h"
    -%include "A.h"
    -...
    -
    -
    - -

    -where the code passed to the "ref" and "unref" features will be -executed as needed whenever a new object is passed to python, or when -python tries to release the shadow object instance, respectively. -

    - -

    -In the python side, the use of a reference counted object is not -different than any other regular instance: -

    - -
    -
    -def create_A():
    -  a = A()         # SWIG ref 'a' (new object is passed to python)
    -  b1 = B(a)       # C++  ref 'a'
    -  if 1 + 1 == 2:
    -     b2 = B(a)    # C++ ref 'a'
    -  return a        # 'b1' and 'b2' are released, C++ unref 'a' twice
    -
    -a = create_A()   
    -exit              # 'a' is released, SWIG unref 'a'
    -
    -
    - -

    -Note that the user doesn't explicitly need to call 'a->ref()' nor 'a->unref()' -(as neither 'delete a'). Instead, SWIG take cares of executing the "ref" -and "unref" codes as needed. If the user doesn't specify the -"ref/unref" features, SWIG will produce a code equivalent to define -them as: -

    - -
    -
    -%feature("ref")   ""
    -%feature("unref") "delete $this;"
    -
    -
    - -

    -In other words, SWIG will not do anything special when a new object -is passed to python, and it will always 'delete' the object when -python releases the proxy instance. -

    - - -

    33.4 Further details on the Python class interface

    +

    34.4 Further details on the Python class interface

    @@ -2218,7 +2085,7 @@ the -builtin option are in the Built-in section.

    -

    33.4.1 Proxy classes

    +

    34.4.1 Proxy classes

    @@ -2307,7 +2174,7 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

    -

    33.4.2 Built-in Types

    +

    34.4.2 Built-in Types

    @@ -2351,7 +2218,7 @@ please refer to the python documentation:

    http://docs.python.org/extending/newtypes.html

    -

    33.4.2.1 Limitations

    +

    34.4.2.1 Limitations

    Use of the -builtin option implies a couple of limitations: @@ -2519,7 +2386,7 @@ assert(issubclass(B.Derived, A.Base)) -

    33.4.2.2 Operator overloads -- use them!

    +

    34.4.2.2 Operator overloads -- use them!

    The entire justification for the -builtin option is improved @@ -2620,7 +2487,7 @@ structs.

    -

    33.4.3 Memory management

    +

    34.4.3 Memory management

    NOTE: Although this section refers to proxy objects, everything here also applies @@ -2815,7 +2682,7 @@ It is also possible to deal with situations like this using typemaps--an advanced topic discussed later.

    -

    33.4.4 Python 2.2 and classic classes

    +

    34.4.4 Python 2.2 and classic classes

    @@ -2852,7 +2719,7 @@ class itself. In Python-2.1 and earlier, they have to be accessed as a global function or through an instance (see the earlier section).

    -

    33.5 Cross language polymorphism

    +

    34.5 Cross language polymorphism

    @@ -2886,7 +2753,7 @@ proxy classes, director classes, and C wrapper functions takes care of all the cross-language method routing transparently.

    -

    33.5.1 Enabling directors

    +

    34.5.1 Enabling directors

    @@ -2979,7 +2846,7 @@ class MyFoo(mymodule.Foo): -

    33.5.2 Director classes

    +

    34.5.2 Director classes

    @@ -3061,7 +2928,7 @@ so there is no need for the extra overhead involved with routing the calls through Python.

    -

    33.5.3 Ownership and object destruction

    +

    34.5.3 Ownership and object destruction

    @@ -3128,7 +2995,7 @@ deleting all the Foo pointers it contains at some point. Note that no hard references to the Foo objects remain in Python.

    -

    33.5.4 Exception unrolling

    +

    34.5.4 Exception unrolling

    @@ -3187,7 +3054,7 @@ Swig::DirectorMethodException is thrown, Python will register the exception as soon as the C wrapper function returns.

    -

    33.5.5 Overhead and code bloat

    +

    34.5.5 Overhead and code bloat

    @@ -3221,7 +3088,7 @@ directive) for only those methods that are likely to be extended in Python.

    -

    33.5.6 Typemaps

    +

    34.5.6 Typemaps

    @@ -3235,7 +3102,7 @@ need to be supported.

    -

    33.5.7 Miscellaneous

    +

    34.5.7 Miscellaneous

    @@ -3282,7 +3149,7 @@ methods that return const references.

    -

    33.6 Common customization features

    +

    34.6 Common customization features

    @@ -3295,7 +3162,7 @@ This section describes some common SWIG features that are used to improve your the interface to an extension module.

    -

    33.6.1 C/C++ helper functions

    +

    34.6.1 C/C++ helper functions

    @@ -3376,7 +3243,7 @@ hard to implement. It is possible to clean this up using Python code, typemaps, customization features as covered in later sections.

    -

    33.6.2 Adding additional Python code

    +

    34.6.2 Adding additional Python code

    @@ -3525,7 +3392,7 @@ public: -

    33.6.3 Class extension with %extend

    +

    34.6.3 Class extension with %extend

    @@ -3614,7 +3481,7 @@ Vector(12,14,16) in any way---the extensions only show up in the Python interface.

    -

    33.6.4 Exception handling with %exception

    +

    34.6.4 Exception handling with %exception

    @@ -3740,7 +3607,7 @@ The language-independent exception.i library file can also be used to raise exceptions. See the SWIG Library chapter.

    -

    33.7 Tips and techniques

    +

    34.7 Tips and techniques

    @@ -3750,7 +3617,7 @@ strings, binary data, and arrays. This chapter discusses the common techniques solving these problems.

    -

    33.7.1 Input and output parameters

    +

    34.7.1 Input and output parameters

    @@ -3963,7 +3830,7 @@ void foo(Bar *OUTPUT); may not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

    -

    33.7.2 Simple pointers

    +

    34.7.2 Simple pointers

    @@ -4032,7 +3899,7 @@ If you replace %pointer_functions() by %pointer_class(type,name)SWIG Library chapter for further details.

    -

    33.7.3 Unbounded C Arrays

    +

    34.7.3 Unbounded C Arrays

    @@ -4094,7 +3961,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

    -

    33.7.4 String handling

    +

    34.7.4 String handling

    @@ -4163,7 +4030,7 @@ If you need to return binary data, you might use the also be used to extra binary data from arbitrary pointers.

    -

    33.8 Typemaps

    +

    34.8 Typemaps

    @@ -4180,7 +4047,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Python interface or if you want to elevate your guru status.

    -

    33.8.1 What is a typemap?

    +

    34.8.1 What is a typemap?

    @@ -4296,7 +4163,7 @@ parameter is omitted): -

    33.8.2 Python typemaps

    +

    34.8.2 Python typemaps

    @@ -4337,7 +4204,7 @@ a look at the SWIG library version 1.3.20 or so.

    -

    33.8.3 Typemap variables

    +

    34.8.3 Typemap variables

    @@ -4408,7 +4275,7 @@ properly assigned. The Python name of the wrapper function being created. -

    33.8.4 Useful Python Functions

    +

    34.8.4 Useful Python Functions

    @@ -4536,7 +4403,7 @@ write me -

    33.9 Typemap Examples

    +

    34.9 Typemap Examples

    @@ -4545,7 +4412,7 @@ might look at the files "python.swg" and "typemaps.i" in the SWIG library.

    -

    33.9.1 Converting Python list to a char **

    +

    34.9.1 Converting Python list to a char **

    @@ -4625,7 +4492,7 @@ memory allocation is used to allocate memory for the array, the the C function.

    -

    33.9.2 Expanding a Python object into multiple arguments

    +

    34.9.2 Expanding a Python object into multiple arguments

    @@ -4704,7 +4571,7 @@ to supply the argument count. This is automatically set by the typemap code. F -

    33.9.3 Using typemaps to return arguments

    +

    34.9.3 Using typemaps to return arguments

    @@ -4793,7 +4660,7 @@ function can now be used as follows: >>> -

    33.9.4 Mapping Python tuples into small arrays

    +

    34.9.4 Mapping Python tuples into small arrays

    @@ -4842,7 +4709,7 @@ array, such an approach would not be recommended for huge arrays, but for small structures, this approach works fine.

    -

    33.9.5 Mapping sequences to C arrays

    +

    34.9.5 Mapping sequences to C arrays

    @@ -4931,7 +4798,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) { -

    33.9.6 Pointer handling

    +

    34.9.6 Pointer handling

    @@ -5028,7 +4895,7 @@ class object (if applicable). -

    33.10 Docstring Features

    +

    34.10 Docstring Features

    @@ -5056,7 +4923,7 @@ of your users much simpler.

    -

    33.10.1 Module docstring

    +

    34.10.1 Module docstring

    @@ -5090,7 +4957,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." -

    33.10.2 %feature("autodoc")

    +

    34.10.2 %feature("autodoc")

    @@ -5114,14 +4981,15 @@ introspection, then life is good once more. which when attached to a node in the parse tree will cause a docstring to be generated that includes the name of the function, parameter names, default values if any, and return type if any. There are also -three options for autodoc controlled by the value given to the -feature, described below. +four levels for autodoc controlled by the value given to the +feature, %feature("autodoc", "level"). +The four values for level are covered in the following sub-sections. -

    33.10.2.1 %feature("autodoc", "0")

    +

    34.10.2.1 %feature("autodoc", "0")

    -When the "0" option is given then the types of the parameters will +When level "0" is used then the types of the parameters will not be included in the autodoc string. For example, given this function prototype:

    @@ -5146,18 +5014,19 @@ def function_name(*args, **kwargs): -

    33.10.2.2 %feature("autodoc", "1")

    +

    34.10.2.2 %feature("autodoc", "1")

    -When the "1" option is used then the parameter types will be +When level "1" is used then the parameter types will be used in the autodoc string. In addition, an attempt is made to simplify the type name such that it makes more sense to the Python -user. Pointer, reference and const info is removed, -%rename's are evaluated, etc. (This is not always -successful, but works most of the time. See the next section for what -to do when it doesn't.) Given the example above, then turning on the -parameter types with the "1" option will result in Python code like +user. Pointer, reference and const info is removed if the associated type +is has an associated Python type (%rename's are thus shown correctly). +This works most of the time, otherwise a C/C++ type will be used. +See the next section for the "docstring" feature for tweaking the docstrings to your liking. +Given the example above, then turning on the +parameter types with level "1" will result in Python code like this:

    @@ -5170,8 +5039,92 @@ def function_name(*args, **kwargs): +

    34.10.2.3 %feature("autodoc", "2")

    -

    33.10.2.3 %feature("autodoc", "docstring")

    + +

    +Level "2" results in the function prototype as per level "0". In addition, a line of +documentation is generated for each parameter. Using the previous example, the generated +code will be: +

    + +
    +
    +def function_name(*args, **kwargs):
    +    """
    +    function_name(x, y, foo=None, bar=None) -> bool
    +
    +    Parameters:
    +        x: int
    +        y: int
    +        foo: Foo *
    +        bar: Bar *
    +
    +    """
    +    ...
    +
    +
    + +

    +Note that the documentation for each parameter is sourced from the "doc" typemap which by default shows the +C/C++ type rather than the simplified Python type name described earlier for level "1". +Typemaps can of course change the output for any particular type, for example the int x parameter: +

    + +
    +
    +%feature("autodoc", "2");
    +%typemap("doc") int x "$1_name (C++ type: $1_type) -- Input $1_name dimension"
    +bool function_name(int x, int y, Foo* foo=NULL, Bar* bar=NULL);
    +
    +
    + +

    +resulting in +

    + +
    +
    +def function_name(*args, **kwargs):
    +  """
    +    function_name(x, y, foo=None, bar=None) -> bool
    +
    +    Parameters:
    +        x (C++ type: int) -- Input x dimension
    +        y: int
    +        foo: Foo *
    +        bar: Bar *
    +
    +    """
    +
    +
    + +

    34.10.2.4 %feature("autodoc", "3")

    + + +

    +Level "3" results in the function prototype as per level "1" but also contains the same additional line of documentation for each parameter as per level "2". Using our earlier example again, the generated code will be: +

    + +
    +
    +def function_name(*args, **kwargs):
    +    """
    +    function_name(int x, int y, Foo foo=None, Bar bar=None) -> bool
    +
    +    Parameters:
    +        x: int
    +        y: int
    +        foo: Foo *
    +        bar: Bar *
    +
    +    """
    +    ...
    +
    +
    + + +

    34.10.2.5 %feature("autodoc", "docstring")

    @@ -5190,7 +5143,7 @@ void GetPosition(int* OUTPUT, int* OUTPUT); -

    33.10.3 %feature("docstring")

    +

    34.10.3 %feature("docstring")

    @@ -5222,7 +5175,7 @@ with more than one line. -

    33.11 Python Packages

    +

    34.11 Python Packages

    @@ -5249,7 +5202,7 @@ and also in base class declarations, etc. if the package name is different than its own.

    -

    33.12 Python 3 Support

    +

    34.12 Python 3 Support

    @@ -5276,7 +5229,7 @@ The following are Python 3.0 new features that are currently supported by SWIG.

    -

    33.12.1 Function annotation

    +

    34.12.1 Function annotation

    @@ -5285,7 +5238,7 @@ SWIG is able to generate proxy method definitions like this:

    -  def foo(self, bar : "int" = 0) -> "void" : ...
    +  def foo(self, bar : "int"=0) -> "void" : ...
     

    @@ -5294,7 +5247,7 @@ still could be generated:

    -  def foo(self, bar = 0): ...
    +  def foo(self, bar=0): ...
     

    @@ -5309,7 +5262,7 @@ For detailed usage of function annotation, see PEP 3107.

    -

    33.12.2 Buffer interface

    +

    34.12.2 Buffer interface

    @@ -5461,7 +5414,7 @@ modify the buffer. -

    33.12.3 Abstract base classes

    +

    34.12.3 Abstract base classes

    diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index e8cee6448..ceea32146 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -6,7 +6,7 @@ -

    34 SWIG and R

    +

    35 SWIG and R

      @@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux with gcc. The R bindings also work on Microsoft Windows using Visual C++.

      -

      34.1 Bugs

      +

      35.1 Bugs

      @@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:

    • C Array wrappings
    -

    34.2 Using R and SWIG

    +

    35.2 Using R and SWIG

    @@ -119,7 +119,7 @@ Without it, inheritance of wrapped objects may fail. These two files can be loaded in any order

    -

    34.3 Precompiling large R files

    +

    35.3 Precompiling large R files

    In cases where the R file is large, one make save a lot of loading @@ -137,7 +137,7 @@ will save a large amount of loading time. -

    34.4 General policy

    +

    35.4 General policy

    @@ -146,7 +146,7 @@ wrapping over the underlying functions and rely on the R type system to provide R syntax.

    -

    34.5 Language conventions

    +

    35.5 Language conventions

    @@ -155,7 +155,7 @@ and [ are overloaded to allow for R syntax (one based indices and slices)

    -

    34.6 C++ classes

    +

    35.6 C++ classes

    @@ -167,7 +167,7 @@ keep track of the pointer object which removes the necessity for a lot of the proxy class baggage you see in other languages.

    -

    34.7 Enumerations

    +

    35.7 Enumerations

    diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index f21e353ce..69005c731 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -7,7 +7,7 @@ -

    35 SWIG and Ruby

    +

    36 SWIG and Ruby

      @@ -148,7 +148,7 @@ -

      35.1 Preliminaries

      +

      36.1 Preliminaries

      SWIG 1.3 is known to work with Ruby versions 1.6 and later. @@ -171,7 +171,7 @@ of Ruby.

      -

      35.1.1 Running SWIG

      +

      36.1.1 Running SWIG

      To build a Ruby module, run SWIG using the -ruby @@ -225,7 +225,7 @@ to compile this file and link it with the rest of your program.

      -

      35.1.2 Getting the right header files

      +

      36.1.2 Getting the right header files

      In order to compile the wrapper code, the compiler needs the ruby.h @@ -274,7 +274,7 @@ installed, you can run Ruby to find out. For example:

      -

      35.1.3 Compiling a dynamic module

      +

      36.1.3 Compiling a dynamic module

      Ruby extension modules are typically compiled into shared @@ -428,7 +428,7 @@ manual pages for your compiler and linker to determine the correct set of options. You might also check the SWIG Wiki for additional information.

      -

      35.1.4 Using your module

      +

      36.1.4 Using your module

      Ruby module names must be capitalized, @@ -488,7 +488,7 @@ begins with:

      -

      35.1.5 Static linking

      +

      36.1.5 Static linking

      An alternative approach to dynamic linking is to rebuild the @@ -509,7 +509,7 @@ finally rebuilding Ruby.

      -

      35.1.6 Compilation of C++ extensions

      +

      36.1.6 Compilation of C++ extensions

      On most machines, C++ extension modules should be linked @@ -561,7 +561,7 @@ extension, e.g.

      -

      35.2 Building Ruby Extensions under Windows 95/NT

      +

      36.2 Building Ruby Extensions under Windows 95/NT

      Building a SWIG extension to Ruby under Windows 95/NT is @@ -600,7 +600,7 @@ files.

      -

      35.2.1 Running SWIG from Developer Studio

      +

      36.2.1 Running SWIG from Developer Studio

      If you are developing your application within Microsoft @@ -742,7 +742,7 @@ directory, then run the Ruby script from the DOS/Command prompt:

      -

      35.3 The Ruby-to-C/C++ Mapping

      +

      36.3 The Ruby-to-C/C++ Mapping

      This section describes the basics of how SWIG maps C or C++ @@ -752,7 +752,7 @@ declarations in your SWIG interface files to Ruby constructs.

      -

      35.3.1 Modules

      +

      36.3.1 Modules

      The SWIG %module directive specifies @@ -921,7 +921,7 @@ Ruby's built-in names.

      -

      35.3.2 Functions

      +

      36.3.2 Functions

      Global functions are wrapped as Ruby module methods. For @@ -984,7 +984,7 @@ module that can be used like so:

      -

      35.3.3 Variable Linking

      +

      36.3.3 Variable Linking

      C/C++ global variables are wrapped as a pair of singleton @@ -1084,7 +1084,7 @@ effect until it is explicitly disabled using %mutable. -

      35.3.4 Constants

      +

      36.3.4 Constants

      C/C++ constants are wrapped as module constants initialized @@ -1128,7 +1128,7 @@ constant values, e.g.

      -

      35.3.5 Pointers

      +

      36.3.5 Pointers

      "Opaque" pointers to arbitrary C/C++ types (i.e. types that @@ -1180,7 +1180,7 @@ the Ruby nil object.

      -

      35.3.6 Structures

      +

      36.3.6 Structures

      C/C++ structs are wrapped as Ruby classes, with accessor @@ -1355,7 +1355,7 @@ pointers. For example,

      -

      35.3.7 C++ classes

      +

      36.3.7 C++ classes

      Like structs, C++ classes are wrapped by creating a new Ruby @@ -1441,7 +1441,7 @@ class. -

      35.3.8 C++ Inheritance

      +

      36.3.8 C++ Inheritance

      The SWIG type-checker is fully aware of C++ inheritance. @@ -1672,7 +1672,7 @@ Typing").

      -

      35.3.9 C++ Overloaded Functions

      +

      36.3.9 C++ Overloaded Functions

      C++ overloaded functions, methods, and constructors are @@ -1872,7 +1872,7 @@ and C++" chapter for more information about overloading.

      -

      35.3.10 C++ Operators

      +

      36.3.10 C++ Operators

      For the most part, overloaded operators are handled @@ -1953,7 +1953,7 @@ on operator overloading.

      -

      35.3.11 C++ namespaces

      +

      36.3.11 C++ namespaces

      SWIG is aware of C++ namespaces, but namespace names do not @@ -2029,7 +2029,7 @@ identical symbol names, well, then you get what you deserve.

      -

      35.3.12 C++ templates

      +

      36.3.12 C++ templates

      C++ templates don't present a huge problem for SWIG. However, @@ -2073,7 +2073,7 @@ directive. For example:

      -

      35.3.13 C++ Standard Template Library (STL)

      +

      36.3.13 C++ Standard Template Library (STL)

      On a related note, the standard SWIG library contains a @@ -2326,7 +2326,7 @@ chapter.

      -

      35.3.14 C++ STL Functors

      +

      36.3.14 C++ STL Functors

      Some containers in the STL allow you to modify their default @@ -2526,7 +2526,7 @@ b
      -

      35.3.15 C++ STL Iterators

      +

      36.3.15 C++ STL Iterators

      The STL is well known for the use of iterators.  There @@ -2737,7 +2737,7 @@ i
      -

      35.3.16 C++ Smart Pointers

      +

      36.3.16 C++ Smart Pointers

      In certain C++ programs, it is common to use classes that @@ -2862,7 +2862,7 @@ method. For example:

      -

      35.3.17 Cross-Language Polymorphism

      +

      36.3.17 Cross-Language Polymorphism

      SWIG's Ruby module supports cross-language polymorphism @@ -2875,7 +2875,7 @@ using this feature with Ruby.

      -

      35.3.17.1 Exception Unrolling

      +

      36.3.17.1 Exception Unrolling

      Whenever a C++ director class routes one of its virtual @@ -2913,7 +2913,7 @@ caught here and a C++ exception is raised in its place.

      -

      35.4 Naming

      +

      36.4 Naming

      Ruby has several common naming conventions. Constants are @@ -3009,7 +3009,7 @@ planned to become the default option in future releases.

      -

      35.4.1 Defining Aliases

      +

      36.4.1 Defining Aliases

      It's a fairly common practice in the Ruby built-ins and @@ -3101,7 +3101,7 @@ Features") for more details).

      -

      35.4.2 Predicate Methods

      +

      36.4.2 Predicate Methods

      Ruby methods that return a boolean value and end in a @@ -3190,7 +3190,7 @@ Features") for more details).

      -

      35.4.3 Bang Methods

      +

      36.4.3 Bang Methods

      Ruby methods that modify an object in-place and end in an @@ -3254,7 +3254,7 @@ Features") for more details).

      -

      35.4.4 Getters and Setters

      +

      36.4.4 Getters and Setters

      Often times a C++ library will expose properties through @@ -3324,7 +3324,7 @@ methods to be exposed in Ruby as value and value=. -

      35.5 Input and output parameters

      +

      36.5 Input and output parameters

      A common problem in some C programs is handling parameters @@ -3575,10 +3575,10 @@ of %apply

      -

      35.6 Exception handling

      +

      36.6 Exception handling

      -

      35.6.1 Using the %exception directive

      +

      36.6.1 Using the %exception directive

      The SWIG %exception directive can be @@ -3673,7 +3673,7 @@ Features for more examples.

      -

      35.6.2 Handling Ruby Blocks

      +

      36.6.2 Handling Ruby Blocks

      One of the highlights of Ruby and most of its standard library @@ -3854,7 +3854,7 @@ RUBY_YIELD_SELF );

      For more information on typemaps, see Typemaps.

      -

      35.6.3 Raising exceptions

      +

      36.6.3 Raising exceptions

      There are three ways to raise exceptions from C++ code to @@ -4615,7 +4615,7 @@ the built-in Ruby exception types.

      -

      35.6.4 Exception classes

      +

      36.6.4 Exception classes

      Starting with SWIG 1.3.28, the Ruby module supports the %exceptionclass @@ -4673,7 +4673,7 @@ providing for a more natural integration between C++ code and Ruby code.

      -

      35.7 Typemaps

      +

      36.7 Typemaps

      This section describes how you can modify SWIG's default @@ -4696,7 +4696,7 @@ of the primitive C-Ruby interface.

      -

      35.7.1 What is a typemap?

      +

      36.7.1 What is a typemap?

      A typemap is nothing more than a code generation rule that is @@ -4958,7 +4958,7 @@ to be used as follows (notice how the length parameter is omitted):

      -

      35.7.2 Typemap scope

      +

      36.7.2 Typemap scope

      Once defined, a typemap remains in effect for all of the @@ -5006,7 +5006,7 @@ where the class itself is defined. For example:

      -

      35.7.3 Copying a typemap

      +

      36.7.3 Copying a typemap

      A typemap is copied by using assignment. For example:

      @@ -5108,7 +5108,7 @@ rules as for -

      35.7.4 Deleting a typemap

      +

      36.7.4 Deleting a typemap

      A typemap can be deleted by simply defining no code. For @@ -5160,7 +5160,7 @@ typemaps immediately after the clear operation.

      -

      35.7.5 Placement of typemaps

      +

      36.7.5 Placement of typemaps

      Typemap declarations can be declared in the global scope, @@ -5244,7 +5244,7 @@ string -

      35.7.6 Ruby typemaps

      +

      36.7.6 Ruby typemaps

      The following list details all of the typemap methods that @@ -5254,7 +5254,7 @@ can be used by the Ruby module:

      -

      35.7.6.1  "in" typemap

      +

      36.7.6.1  "in" typemap

      Converts Ruby objects to input @@ -5497,7 +5497,7 @@ arguments to be specified. For example:

      -

      35.7.6.2 "typecheck" typemap

      +

      36.7.6.2 "typecheck" typemap

      The "typecheck" typemap is used to support overloaded @@ -5538,7 +5538,7 @@ on "Typemaps and Overloading."

      -

      35.7.6.3  "out" typemap

      +

      36.7.6.3  "out" typemap

      Converts return value of a C function @@ -5770,7 +5770,7 @@ version of the C datatype matched by the typemap. -

      35.7.6.4 "arginit" typemap

      +

      36.7.6.4 "arginit" typemap

      The "arginit" typemap is used to set the initial value of a @@ -5795,7 +5795,7 @@ applications. For example:

      -

      35.7.6.5 "default" typemap

      +

      36.7.6.5 "default" typemap

      The "default" typemap is used to turn an argument into a @@ -5837,7 +5837,7 @@ default argument wrapping.

      -

      35.7.6.6 "check" typemap

      +

      36.7.6.6 "check" typemap

      The "check" typemap is used to supply value checking code @@ -5861,7 +5861,7 @@ arguments have been converted. For example:

      -

      35.7.6.7 "argout" typemap

      +

      36.7.6.7 "argout" typemap

      The "argout" typemap is used to return values from arguments. @@ -6019,7 +6019,7 @@ some function like SWIG_Ruby_AppendOutput.

      -

      35.7.6.8 "freearg" typemap

      +

      36.7.6.8 "freearg" typemap

      The "freearg" typemap is used to cleanup argument data. It is @@ -6055,7 +6055,7 @@ abort prematurely.

      -

      35.7.6.9 "newfree" typemap

      +

      36.7.6.9 "newfree" typemap

      The "newfree" typemap is used in conjunction with the %newobject @@ -6086,7 +6086,7 @@ ownership and %newobject for further details.

      -

      35.7.6.10 "memberin" typemap

      +

      36.7.6.10 "memberin" typemap

      The "memberin" typemap is used to copy data from an @@ -6119,7 +6119,7 @@ other objects.

      -

      35.7.6.11 "varin" typemap

      +

      36.7.6.11 "varin" typemap

      The "varin" typemap is used to convert objects in the target @@ -6130,7 +6130,7 @@ This is implementation specific.

      -

      35.7.6.12 "varout" typemap

      +

      36.7.6.12 "varout" typemap

      The "varout" typemap is used to convert a C/C++ object to an @@ -6141,7 +6141,7 @@ This is implementation specific.

      -

      35.7.6.13 "throws" typemap

      +

      36.7.6.13 "throws" typemap

      The "throws" typemap is only used when SWIG parses a C++ @@ -6200,7 +6200,7 @@ handling with %exception section.

      -

      35.7.6.14 directorin typemap

      +

      36.7.6.14 directorin typemap

      Converts C++ objects in director @@ -6454,7 +6454,7 @@ referring to the class itself. -

      35.7.6.15 directorout typemap

      +

      36.7.6.15 directorout typemap

      Converts Ruby objects in director @@ -6517,49 +6517,16 @@ typemap.

    - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - + @@ -6714,7 +6681,7 @@ exception.
    -

    35.7.6.16 directorargout typemap

    +

    36.7.6.16 directorargout typemap

    Output argument processing in director @@ -6763,80 +6730,21 @@ $result = output_helper( $result, NUM2INT($1) );

    - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - @@ -6954,7 +6862,7 @@ referring to the instance of the class itself -

    35.7.6.17 ret typemap

    +

    36.7.6.17 ret typemap

    Cleanup of function return values @@ -6964,7 +6872,7 @@ referring to the instance of the class itself -

    35.7.6.18 globalin typemap

    +

    36.7.6.18 globalin typemap

    Setting of C global variables @@ -6974,7 +6882,7 @@ referring to the instance of the class itself -

    35.7.7 Typemap variables

    +

    36.7.7 Typemap variables

    @@ -7084,7 +6992,7 @@ being created. -

    35.7.8 Useful Functions

    +

    36.7.8 Useful Functions

    When you write a typemap, you usually have to work directly @@ -7108,7 +7016,7 @@ across multiple languages.

    -

    35.7.8.1 C Datatypes to Ruby Objects

    +

    36.7.8.1 C Datatypes to Ruby Objects

    @@ -7164,7 +7072,7 @@ SWIG_From_float(float) -

    35.7.8.2 Ruby Objects to C Datatypes

    +

    36.7.8.2 Ruby Objects to C Datatypes

    Here, while the Ruby versions return the value directly, the SWIG @@ -7253,7 +7161,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -

    35.7.8.3 Macros for VALUE

    +

    36.7.8.3 Macros for VALUE

    RSTRING_LEN(str)

    @@ -7316,7 +7224,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -

    35.7.8.4 Exceptions

    +

    36.7.8.4 Exceptions

    void rb_raise(VALUE exception, const char *fmt, @@ -7483,7 +7391,7 @@ arguments are interpreted as with printf().

    -

    35.7.8.5 Iterators

    +

    36.7.8.5 Iterators

    void rb_iter_break()

    @@ -7585,7 +7493,7 @@ VALUE), VALUE value)

    -

    35.7.9 Typemap Examples

    +

    36.7.9 Typemap Examples

    This section includes a few examples of typemaps. For more @@ -7596,7 +7504,7 @@ directory.

    -

    35.7.10 Converting a Ruby array to a char **

    +

    36.7.10 Converting a Ruby array to a char **

    A common problem in many C programs is the processing of @@ -7651,7 +7559,7 @@ after the execution of the C function.

    -

    35.7.11 Collecting arguments in a hash

    +

    36.7.11 Collecting arguments in a hash

    Ruby's solution to the "keyword arguments" capability of some @@ -7930,7 +7838,7 @@ directory of the SWIG distribution.

    -

    35.7.12 Pointer handling

    +

    36.7.12 Pointer handling

    Occasionally, it might be necessary to convert pointer values @@ -8029,7 +7937,7 @@ For example:

    -

    35.7.12.1 Ruby Datatype Wrapping

    +

    36.7.12.1 Ruby Datatype Wrapping

    VALUE Data_Wrap_Struct(VALUE class, void @@ -8080,7 +7988,7 @@ and assigns that pointer to ptr. -

    35.7.13 Example: STL Vector to Ruby Array

    +

    36.7.13 Example: STL Vector to Ruby Array

    Another use for macros and type maps is to create a Ruby array @@ -8189,7 +8097,7 @@ the C++ Standard Template Library.
    -

    35.8 Docstring Features

    +

    36.8 Docstring Features

    @@ -8250,7 +8158,7 @@ generate ri documentation from a c wrap file, you could do:

    -

    35.8.1 Module docstring

    +

    36.8.1 Module docstring

    @@ -8301,7 +8209,7 @@ macro. For example: -

    35.8.2 %feature("autodoc")

    +

    36.8.2 %feature("autodoc")

    Since SWIG does know everything about the function it wraps, @@ -8330,7 +8238,7 @@ feature, described below. -

    35.8.2.1 %feature("autodoc", "0")

    +

    36.8.2.1 %feature("autodoc", "0")

    @@ -8378,7 +8286,7 @@ Then Ruby code like this will be generated: -

    35.8.2.2 %feature("autodoc", "1")

    +

    36.8.2.2 %feature("autodoc", "1")

    @@ -8410,7 +8318,7 @@ this: -

    35.8.2.3 %feature("autodoc", "2")

    +

    36.8.2.3 %feature("autodoc", "2")

    @@ -8426,7 +8334,7 @@ this: -

    35.8.2.4 %feature("autodoc", "3")

    +

    36.8.2.4 %feature("autodoc", "3")

    @@ -8454,7 +8362,7 @@ this: -

    35.8.2.5 %feature("autodoc", "docstring")

    +

    36.8.2.5 %feature("autodoc", "docstring")

    @@ -8482,7 +8390,7 @@ generated string. For example: -

    35.8.3 %feature("docstring")

    +

    36.8.3 %feature("docstring")

    @@ -8497,10 +8405,10 @@ docstring and they are output together.

    -

    35.9 Advanced Topics

    +

    36.9 Advanced Topics

    -

    35.9.1 Operator overloading

    +

    36.9.1 Operator overloading

    SWIG allows operator overloading with, by using the %extend @@ -9517,7 +9425,7 @@ parses the expression a != b as !(a == b). -

    35.9.2 Creating Multi-Module Packages

    +

    36.9.2 Creating Multi-Module Packages

    The chapter on Working @@ -9698,7 +9606,7 @@ initialized:

    -

    35.9.3 Specifying Mixin Modules

    +

    36.9.3 Specifying Mixin Modules

    The Ruby language doesn't support multiple inheritance, but @@ -9796,7 +9704,7 @@ Features") for more details).

    -

    35.10 Memory Management

    +

    36.10 Memory Management

    One of the most common issues in generating SWIG bindings for @@ -9843,7 +9751,7 @@ understanding of how the underlying library manages memory.

    -

    35.10.1 Mark and Sweep Garbage Collector

    +

    36.10.1 Mark and Sweep Garbage Collector

    Ruby uses a mark and sweep garbage collector. When the garbage @@ -9891,7 +9799,7 @@ this memory.

    -

    35.10.2 Object Ownership

    +

    36.10.2 Object Ownership

    As described above, memory management depends on clearly @@ -10149,7 +10057,7 @@ public: -

    35.10.3 Object Tracking

    +

    36.10.3 Object Tracking

    The remaining parts of this section will use the class library @@ -10400,7 +10308,7 @@ methods.

    -

    35.10.4 Mark Functions

    +

    36.10.4 Mark Functions

    With a bit more testing, we see that our class library still @@ -10518,7 +10426,7 @@ test suite.

    -

    35.10.5 Free Functions

    +

    36.10.5 Free Functions

    By default, SWIG creates a "free" function that is called when @@ -10768,7 +10676,7 @@ been freed, and thus raises a runtime exception.

    -

    35.10.6 Embedded Ruby and the C++ Stack

    +

    36.10.6 Embedded Ruby and the C++ Stack

    As has been said, the Ruby GC runs and marks objects before diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index c8e5ee870..b4baca6ae 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -57,6 +57,7 @@

  • Exception handling with %catches
  • Pointers to Members
  • Smart pointers and operator->() +
  • C++ reference counted objects - ref/unref feature
  • Using declarations and inheritance
  • Nested classes
  • A brief rant about const-correctness @@ -3356,7 +3357,7 @@ public:

    In this case, the %extend directive is not needed, and -%template does the exactly same job, i.e., it adds two new +%template does exactly the same job, i.e., it adds two new methods to the Foo class.

    @@ -4618,8 +4619,179 @@ p = f.__deref__() # Raw pointer from operator-> Note: Smart pointer support was first added in SWIG-1.3.14.

    +

    6.25 C++ reference counted objects - ref/unref feature

    -

    6.25 Using declarations and inheritance

    + +

    +Another similar idiom in C++ is the use of reference counted objects. Consider for example: + +

    +
    +class RCObj  {
    +  // implement the ref counting mechanism
    +  int add_ref();
    +  int del_ref();
    +  int ref_count();
    +
    +public:
    +  virtual ~RCObj() = 0;
    +
    +  int ref() const {
    +    return add_ref();
    +  }
    +
    +  int unref() const   {
    +    if (ref_count() == 0 || del_ref() == 0 ) {
    +	delete this;
    +	return 0;
    +      } 
    +    return ref_count();
    +  }
    +};
    +
    +
    +class A : RCObj {
    +public:
    +  A();
    +  int foo();
    +};
    +
    +
    +class B {
    +  A *_a;
    +
    +public:
    +  B(A *a) : _a(a) { 
    +    a->ref(); 
    +  }
    +
    +  ~B() { 
    +    a->unref(); 
    +  }
    +};
    +
    +int main() {
    +  A *a  = new A();       // (count: 0)
    +  a->ref();           // 'a' ref here (count: 1)
    +
    +  B *b1 = new B(a);   // 'a' ref here (count: 2)
    +  if (1 + 1 == 2) {
    +    B *b2 = new B(a); // 'a' ref here (count: 3)
    +    delete b2;        // 'a' unref, but not deleted (count: 2)
    +  }
    +
    +  delete b1;          // 'a' unref, but not deleted (count: 1)
    +  a->unref();         // 'a' unref and deleted (count: 0)
    +}
    +
    +
    + +

    +In the example above, the 'A' class instance 'a' is a reference counted +object, which can't be deleted arbitrarily since it is shared between +the objects 'b1' and 'b2'. 'A' is derived from a Reference Counted + Object 'RCObj', which implements the ref/unref idiom. +

    + +

    +To tell SWIG that 'RCObj' and all its derived classes are reference +counted objects, use the "ref" and "unref" features. +These are also available as %refobject and %unrefobject, respectively. +For example: +

    + + +
    +
    +%module example
    +...
    +
    +%feature("ref")   RCObj "$this->ref();"
    +%feature("unref") RCObj "$this->unref();"
    +
    +%include "rcobj.h"
    +%include "A.h"
    +...
    +
    +
    + +

    +where the code passed to the "ref" and "unref" features will be +executed as needed whenever a new object is passed to python, or when +python tries to release the proxy object instance, respectively. +

    + +

    +On the python side, the use of a reference counted object is no +different to any other regular instance: +

    + +
    +
    +def create_A():
    +  a = A()         # SWIG ref 'a' - new object is passed to python (count: 1)
    +  b1 = B(a)       # C++ ref 'a (count: 2)
    +  if 1 + 1 == 2:
    +     b2 = B(a)    # C++ ref 'a' (count: 3)
    +  return a        # 'b1' and 'b2' are released and deleted, C++ unref 'a' twice (count: 1)
    +
    +a = create_A()    # (count: 1)
    +exit              # 'a' is released, SWIG unref 'a' called in the destructor wrapper (count: 0)
    +
    +
    + +

    +Note that the user doesn't explicitly need to call 'a->ref()' nor 'a->unref()' +(and neither 'delete a'). Instead, SWIG takes cares of executing the "ref" +and "unref" calls as needed. If the user doesn't specify the +"ref/unref" feature for a type, SWIG will produce code equivalent to defining these +features: +

    + +
    +
    +%feature("ref")   ""
    +%feature("unref") "delete $this;"
    +
    +
    + +

    +In other words, SWIG will not do anything special when a new object +is passed to python, and it will always 'delete' the underlying object when +python releases the proxy instance. +

    + +

    +The %newobject feature is designed to indicate to +the target language that it should take ownership of the returned object. +When used in conjunction with a type that has the "ref" feature associated with it, it additionally emits the +code in the "ref" feature into the C++ wrapper. +Consider wrapping the following factory function in addition to the above: +

    + +
    +
    +%newobject AFactory;
    +A *AFactory() {
    +  return new A();
    +}
    +
    +
    + +

    +The AFactory function now acts much like a call to the A constructor with respect to memory handling: +

    + +
    +
    +a = AFactory()    # SWIG ref 'a' due to %newobject (count: 1)
    +exit              # 'a' is released, SWIG unref 'a' called in the destructor wrapper (count: 0)
    +
    +
    + + + +

    6.26 Using declarations and inheritance

    @@ -4782,7 +4954,7 @@ public: -

    6.26 Nested classes

    +

    6.27 Nested classes

    @@ -4926,7 +5098,7 @@ Nested class warnings could also not be suppressed using %warnfilter.

    -

    6.27 A brief rant about const-correctness

    +

    6.28 A brief rant about const-correctness

    @@ -4984,7 +5156,7 @@ using another tool if maintaining constness is the most important part of your project.

    -

    6.28 Where to go for more information

    +

    6.29 Where to go for more information

    diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 6f6f18bed..ebe6fa476 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -33,7 +33,8 @@ Last update : SWIG-2.0.5 (in progress)

    Language Module Documentation

      -
    • Allegro CL support
    • +
    • Allegro Common Lisp support
    • +
    • Android support
    • C# support
    • Chicken support
    • D support
    • @@ -43,7 +44,7 @@ Last update : SWIG-2.0.5 (in progress)
    • Common Lisp support
    • Lua support
    • Modula3 support
    • -
    • MzScheme support
    • +
    • MzScheme/Racket support
    • Ocaml support
    • Octave support
    • Perl5 support
    • diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index c677f6eed..f55a7f139 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -6,7 +6,7 @@ -

      36 SWIG and Tcl

      +

      37 SWIG and Tcl

        @@ -83,7 +83,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but this is no longer supported.

        -

        36.1 Preliminaries

        +

        37.1 Preliminaries

        @@ -109,7 +109,7 @@ build a Tcl extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

        -

        36.1.1 Getting the right header files

        +

        37.1.1 Getting the right header files

        @@ -127,7 +127,7 @@ this is the case, you should probably make a symbolic link so that tcl.h -

        36.1.2 Compiling a dynamic module

        +

        37.1.2 Compiling a dynamic module

        @@ -162,7 +162,7 @@ The name of the module is specified using the %module directive or the -module command line option.

        -

        36.1.3 Static linking

        +

        37.1.3 Static linking

        @@ -228,7 +228,7 @@ minimal in most situations (and quite frankly not worth the extra hassle in the opinion of this author).

        -

        36.1.4 Using your module

        +

        37.1.4 Using your module

        @@ -356,7 +356,7 @@ to the default system configuration (this requires root access and you will need the man pages).

        -

        36.1.5 Compilation of C++ extensions

        +

        37.1.5 Compilation of C++ extensions

        @@ -439,7 +439,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

        -

        36.1.6 Compiling for 64-bit platforms

        +

        37.1.6 Compiling for 64-bit platforms

        @@ -466,7 +466,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

        -

        36.1.7 Setting a package prefix

        +

        37.1.7 Setting a package prefix

        @@ -485,7 +485,7 @@ option will append the prefix to the name when creating a command and call it "Foo_bar".

        -

        36.1.8 Using namespaces

        +

        37.1.8 Using namespaces

        @@ -507,7 +507,7 @@ When the -namespace option is used, objects in the module are always accessed with the namespace name such as Foo::bar.

        -

        36.2 Building Tcl/Tk Extensions under Windows 95/NT

        +

        37.2 Building Tcl/Tk Extensions under Windows 95/NT

        @@ -518,7 +518,7 @@ covers the process of using SWIG with Microsoft Visual C++. although the procedure may be similar with other compilers.

        -

        36.2.1 Running SWIG from Developer Studio

        +

        37.2.1 Running SWIG from Developer Studio

        @@ -576,7 +576,7 @@ MSDOS > tclsh80 %

      -

      36.2.2 Using NMAKE

      +

      37.2.2 Using NMAKE

      @@ -639,7 +639,7 @@ to get you started. With a little practice, you'll be making lots of Tcl extensions.

      -

      36.3 A tour of basic C/C++ wrapping

      +

      37.3 A tour of basic C/C++ wrapping

      @@ -650,7 +650,7 @@ classes. This section briefly covers the essential aspects of this wrapping.

      -

      36.3.1 Modules

      +

      37.3.1 Modules

      @@ -684,7 +684,7 @@ To fix this, supply an extra argument to load like this: -

      36.3.2 Functions

      +

      37.3.2 Functions

      @@ -709,7 +709,7 @@ like you think it does: % -

      36.3.3 Global variables

      +

      37.3.3 Global variables

      @@ -789,7 +789,7 @@ extern char *path; // Read-only (due to %immutable) -

      36.3.4 Constants and enums

      +

      37.3.4 Constants and enums

      @@ -873,7 +873,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l conversion. This allows the global statement to be omitted.

      -

      36.3.5 Pointers

      +

      37.3.5 Pointers

      @@ -969,7 +969,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

      -

      36.3.6 Structures

      +

      37.3.6 Structures

      @@ -1251,7 +1251,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the memory management section that appears shortly.

      -

      36.3.7 C++ classes

      +

      37.3.7 C++ classes

      @@ -1318,7 +1318,7 @@ In Tcl, the static member is accessed as follows: -

      36.3.8 C++ inheritance

      +

      37.3.8 C++ inheritance

      @@ -1367,7 +1367,7 @@ For instance: It is safe to use multiple inheritance with SWIG.

      -

      36.3.9 Pointers, references, values, and arrays

      +

      37.3.9 Pointers, references, values, and arrays

      @@ -1421,7 +1421,7 @@ to hold the result and a pointer is returned (Tcl will release this memory when the return value is garbage collected).

      -

      36.3.10 C++ overloaded functions

      +

      37.3.10 C++ overloaded functions

      @@ -1544,7 +1544,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      36.3.11 C++ operators

      +

      37.3.11 C++ operators

      @@ -1646,7 +1646,7 @@ There are ways to make this operator appear as part of the class using the % Keep reading.

      -

      36.3.12 C++ namespaces

      +

      37.3.12 C++ namespaces

      @@ -1710,7 +1710,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      36.3.13 C++ templates

      +

      37.3.13 C++ templates

      @@ -1762,7 +1762,7 @@ More details can be found in the SWIG and C++ -

      36.3.14 C++ Smart Pointers

      +

      37.3.14 C++ Smart Pointers

      @@ -1846,7 +1846,7 @@ simply use the __deref__() method. For example: -

      36.4 Further details on the Tcl class interface

      +

      37.4 Further details on the Tcl class interface

      @@ -1859,7 +1859,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

      -

      36.4.1 Proxy classes

      +

      37.4.1 Proxy classes

      @@ -1924,7 +1924,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.

      -

      36.4.2 Memory management

      +

      37.4.2 Memory management

      @@ -2112,7 +2112,7 @@ typemaps--an advanced topic discussed later.

      -

      36.5 Input and output parameters

      +

      37.5 Input and output parameters

      @@ -2300,7 +2300,7 @@ set c [lindex $dim 1] -

      36.6 Exception handling

      +

      37.6 Exception handling

      @@ -2434,7 +2434,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.

      -

      36.7 Typemaps

      +

      37.7 Typemaps

      @@ -2451,7 +2451,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.

      -

      36.7.1 What is a typemap?

      +

      37.7.1 What is a typemap?

      @@ -2568,7 +2568,7 @@ parameter is omitted): -

      36.7.2 Tcl typemaps

      +

      37.7.2 Tcl typemaps

      @@ -2706,7 +2706,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.

      -

      36.7.3 Typemap variables

      +

      37.7.3 Typemap variables

      @@ -2777,7 +2777,7 @@ properly assigned. The Tcl name of the wrapper function being created. -

      36.7.4 Converting a Tcl list to a char **

      +

      37.7.4 Converting a Tcl list to a char **

      @@ -2839,7 +2839,7 @@ argv[2] = Larry 3 -

      36.7.5 Returning values in arguments

      +

      37.7.5 Returning values in arguments

      @@ -2881,7 +2881,7 @@ result, a Tcl function using these typemaps will work like this : % -

      36.7.6 Useful functions

      +

      37.7.6 Useful functions

      @@ -2958,7 +2958,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -

      36.7.7 Standard typemaps

      +

      37.7.7 Standard typemaps

      @@ -3042,7 +3042,7 @@ work) -

      36.7.8 Pointer handling

      +

      37.7.8 Pointer handling

      @@ -3118,7 +3118,7 @@ For example: -

      36.8 Turning a SWIG module into a Tcl Package.

      +

      37.8 Turning a SWIG module into a Tcl Package.

      @@ -3190,7 +3190,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.

      -

      36.9 Building new kinds of Tcl interfaces (in Tcl)

      +

      37.9 Building new kinds of Tcl interfaces (in Tcl)

      @@ -3289,7 +3289,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).

      -

      36.9.1 Proxy classes

      +

      37.9.1 Proxy classes

      @@ -3410,7 +3410,7 @@ short, but clever Tcl script can be combined with SWIG to do many interesting things.

      -

      36.10 Tcl/Tk Stubs

      +

      37.10 Tcl/Tk Stubs

      diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 6331aa1ac..b6e8cf3ce 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -73,6 +73,7 @@

    • Typemaps for multiple target languages
    • Optimal code generation when returning by value
    • Multi-argument typemaps +
    • Typemap warnings
    • Typemap fragments
      • Fragment type specialization @@ -3597,7 +3598,16 @@ with non-consecutive C/C++ arguments; a workaround such as a helper function re- the arguments to make them consecutive will need to be written.

        -

        10.10 Typemap fragments

        +

        10.10 Typemap warnings

        + + +

        +Warnings can be added to typemaps so that SWIG generates a warning message whenever the typemap is used. +See the information in the issuing warnings section. +

        + + +

        10.11 Typemap fragments

        @@ -3846,7 +3856,7 @@ fragment usage unless a desire to really get to grips with some powerful but tricky macro and fragment usage that is used in parts of the SWIG typemap library.

        -

        10.10.1 Fragment type specialization

        +

        10.11.1 Fragment type specialization

        @@ -3879,7 +3889,7 @@ struct A { -

        10.10.2 Fragments and automatic typemap specialization

        +

        10.11.2 Fragments and automatic typemap specialization

        @@ -3925,7 +3935,7 @@ The interested (or very brave) reader can take a look at the fragments.swg file

        -

        10.11 The run-time type checker

        +

        10.12 The run-time type checker

        @@ -3951,7 +3961,7 @@ language modules.

      • Modules can be unloaded from the type system.
      -

      10.11.1 Implementation

      +

      10.12.1 Implementation

      @@ -4137,7 +4147,7 @@ structures rather than creating new ones. These swig_module_info structures are chained together in a circularly linked list.

      -

      10.11.2 Usage

      +

      10.12.2 Usage

      This section covers how to use these functions from typemaps. To learn how to @@ -4231,7 +4241,7 @@ probably just look at the output of SWIG to get a better sense for how types are managed.

      -

      10.12 Typemaps and overloading

      +

      10.13 Typemaps and overloading

      @@ -4542,7 +4552,7 @@ Subsequent "in" typemaps would then perform more extensive type-checking.

    -

    10.13 More about %apply and %clear

    +

    10.14 More about %apply and %clear

    @@ -4628,7 +4638,7 @@ example: -

    10.14 Passing data between typemaps

    +

    10.15 Passing data between typemaps

    @@ -4665,7 +4675,7 @@ sure that the typemaps sharing information have exactly the same types and names

    -

    10.15 C++ "this" pointer

    +

    10.16 C++ "this" pointer

    @@ -4725,7 +4735,7 @@ will also match the typemap. One work around is to create an interface file tha the method, but gives the argument a name other than self.

    -

    10.16 Where to go for more information?

    +

    10.17 Where to go for more information?

    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 60552b97a..2a3ce560d 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -257,16 +257,23 @@ Warning messages can be associated with typemaps using the

    -%typemap(in, warning="901:You are really going to regret this") blah * {
    +%typemap(in, warning="901:You are really going to regret this usage of $1_type $1_name") blah * {
        ...
     }
     

    -In this case, the warning message will be printed whenever the typemap is actually used. +In this case, the warning message will be printed whenever the typemap is actually used and the special variables will be expanded as appropriate, for example:

    +
    +
    +example.i:23: Warning 901: You are really going to regret this usage of blah * self
    +example.i:24: Warning 901: You are really going to regret this usage of blah * stuff
    +
    +
    +

    14.5 Symbolic symbols

    @@ -501,7 +508,7 @@ example.i(4) : Syntax error in input.
  • 501. Overloaded declaration ignored. decl. Previous declaration is decl.
  • 502. Overloaded constructor ignored. decl. Previous declaration is decl.
  • 503. Can't wrap 'identifier' unless renamed to a valid identifier. -
  • 504. Function name must have a return type. +
  • 504. Function name must have a return type. Ignored.
  • 505. Variable length arguments discarded.
  • 506. Can't wrap varargs with keyword arguments enabled.
  • 507. Adding native function name not supported (ignored). @@ -518,6 +525,7 @@ example.i(4) : Syntax error in input.
  • 518. Portability warning: File file1 will be overwritten by file2 on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed.
  • 519. %template() contains no name. Template method ignored: declaration
  • 520. Base/Derived class 'classname1' of 'classname2' is not similarly marked as a smart pointer. +
  • 521. Illegal destructor name name. Ignored.

    14.9.6 Language module specific (700-899)

    diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index da8a5d6bf..6349f355a 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -313,6 +313,18 @@ If you want to check out SWIG to a different folder to the proposed the autotools will fail miserably on those.
  • +
  • +The PCRE third party library needs to be built next. +Download the latest PCRE source tarball, such as pcre-8.10.tar.bz2, from +PCRE and place in the /usr/src/swig directory. +Build PCRE as a static library using the Tools/pcre-build.sh script as follows: + +
    +cd /usr/src/swig
    +Tools/pcre-build.sh
    +
    +
  • +
  • You are now ready to build SWIG. Execute the following commands to build swig.exe:
    diff --git a/Doc/Manual/android-class.png b/Doc/Manual/android-class.png
    new file mode 100644
    index 000000000..f7061cb3a
    Binary files /dev/null and b/Doc/Manual/android-class.png differ
    diff --git a/Doc/Manual/android-simple.png b/Doc/Manual/android-simple.png
    new file mode 100644
    index 000000000..234674cba
    Binary files /dev/null and b/Doc/Manual/android-simple.png differ
    diff --git a/Doc/Manual/ch11.1.png b/Doc/Manual/ch11.1.png
    deleted file mode 100644
    index 2cc2becd4..000000000
    Binary files a/Doc/Manual/ch11.1.png and /dev/null differ
    diff --git a/Doc/Manual/ch11.2.png b/Doc/Manual/ch11.2.png
    deleted file mode 100644
    index e6d1b55ea..000000000
    Binary files a/Doc/Manual/ch11.2.png and /dev/null differ
    diff --git a/Doc/Manual/ch11.3.png b/Doc/Manual/ch11.3.png
    deleted file mode 100644
    index 54ee72442..000000000
    Binary files a/Doc/Manual/ch11.3.png and /dev/null differ
    diff --git a/Doc/Manual/ch12.1.png b/Doc/Manual/ch12.1.png
    deleted file mode 100644
    index 2072f06a4..000000000
    Binary files a/Doc/Manual/ch12.1.png and /dev/null differ
    diff --git a/Doc/Manual/ch9.table.2.png b/Doc/Manual/ch9.table.2.png
    deleted file mode 100644
    index ac6647e17..000000000
    Binary files a/Doc/Manual/ch9.table.2.png and /dev/null differ
    diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters
    index 924c8cfde..40e227164 100644
    --- a/Doc/Manual/chapters
    +++ b/Doc/Manual/chapters
    @@ -15,6 +15,7 @@ Warnings.html
     Modules.html
     CCache.html
     Allegrocl.html
    +Android.html
     CSharp.html
     Chicken.html
     D.html
    diff --git a/Examples/Makefile.in b/Examples/Makefile.in
    index 180ab90ed..2530c2c20 100644
    --- a/Examples/Makefile.in
    +++ b/Examples/Makefile.in
    @@ -12,7 +12,7 @@
     #      certain packages have been installed.   Set the prefixes
     #      accordingly.
     #
    -# 2.   To use this makefile, set required varibles, eg SRCS, INTERFACE, 
    +# 2.   To use this makefile, set required variables, eg SRCS, INTERFACE,
     #      INTERFACEDIR, INCLUDES, LIBS, TARGET, and do a
     #           $(MAKE) -f Makefile.template.in SRCS='$(SRCS)' \
     #           INCLUDES='$(INCLUDES) LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' \
    @@ -333,6 +333,7 @@ python_clean:
     # Make sure these locate your Octave installation
     OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@
     OCTAVE_LIB    =
    +OCTAVE        = @OCTAVE@ -qf
     
     # Extra Octave specific dynamic linking options
     OCTAVE_DLNK   = @OCTAVEDYNAMICLINKING@
    @@ -358,6 +359,17 @@ octave_cpp: $(SRCS)
     	$(CXX) -g -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) -I$(OCTAVE_INCLUDE)
     	$(CXXSHARED) -g $(CFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO)
     
    +# -----------------------------------------------------------------
    +# Running an Octave example
    +# -----------------------------------------------------------------
    +
    +OCTSCRIPT = runme.m
    +
    +octave_run: $(OCTSCRIPT)
    +	for file in $(OCTSCRIPT); do \
    +	   env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVEPATH=$(srcdir):$$OCTAVEPATH $(OCTAVE) $$file >/dev/null || break; \
    +	done
    +
     # -----------------------------------------------------------------
     # Cleaning the octave examples
     # -----------------------------------------------------------------
    @@ -1298,11 +1310,6 @@ else
       DCOMPILER = @D1COMPILER@
     endif
     
    -ifeq (dmd,$(DCOMPILER))
    -  # DMD is 32bit only by now
    -  DCFLAGS = -m32
    -endif
    -
     # ----------------------------------------------------------------
     # Build a dynamically loadable D wrapper for a C module
     # ----------------------------------------------------------------
    diff --git a/Examples/android/check.list b/Examples/android/check.list
    new file mode 100644
    index 000000000..69d56a4f6
    --- /dev/null
    +++ b/Examples/android/check.list
    @@ -0,0 +1,3 @@
    +# see top-level Makefile.in
    +class
    +simple
    diff --git a/Examples/android/class/AndroidManifest.xml b/Examples/android/class/AndroidManifest.xml
    new file mode 100644
    index 000000000..45c1fb1c7
    --- /dev/null
    +++ b/Examples/android/class/AndroidManifest.xml
    @@ -0,0 +1,15 @@
    +
    +
    +    
    +        
    +            
    +                
    +                
    +            
    +        
    +    
    + 
    diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile
    new file mode 100644
    index 000000000..7de95f559
    --- /dev/null
    +++ b/Examples/android/class/Makefile
    @@ -0,0 +1,29 @@
    +TOP        = ../..
    +SWIG       = $(TOP)/../preinst-swig
    +TARGET     = example
    +INTERFACE  = example.i
    +PACKAGEDIR = src/org/swig
    +PACKAGENAME= org.swig.classexample
    +SWIGOPT    = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample 
    +PROJECTNAME= SwigClass
    +TARGETID  = 1
    +
    +all::	android
    +
    +android::
    +	android update project --target $(TARGETID) --name $(PROJECTNAME) --path .
    +	$(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE)
    +	ndk-build
    +	ant debug
    +
    +install::
    +	-adb uninstall $(PACKAGENAME)
    +	adb install bin/$(PROJECTNAME)-debug.apk
    +
    +clean::
    +	ant clean
    +	rm -f jni/$(TARGET)_wrap.cpp
    +	rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
    +	
    +
    +check: all
    diff --git a/Examples/android/class/ant.properties b/Examples/android/class/ant.properties
    new file mode 100644
    index 000000000..ee52d86d9
    --- /dev/null
    +++ b/Examples/android/class/ant.properties
    @@ -0,0 +1,17 @@
    +# This file is used to override default values used by the Ant build system.
    +#
    +# This file must be checked in Version Control Systems, as it is
    +# integral to the build system of your project.
    +
    +# This file is only used by the Ant script.
    +
    +# You can use this to override default values such as
    +#  'source.dir' for the location of your java source folder and
    +#  'out.dir' for the location of your output folder.
    +
    +# You can also use it define how the release builds are signed by declaring
    +# the following properties:
    +#  'key.store' for the location of your keystore and
    +#  'key.alias' for the name of the key to use.
    +# The password will be asked during the build when you use the 'release' target.
    +
    diff --git a/Examples/android/class/build.xml b/Examples/android/class/build.xml
    new file mode 100644
    index 000000000..fe06943a9
    --- /dev/null
    +++ b/Examples/android/class/build.xml
    @@ -0,0 +1,85 @@
    +
    +
    +
    +    
    +    
    +
    +    
    +    
    +
    +    
    +    
    +
    +    
    +    
    +
    +
    +
    +
    +
    +    
    +    
    +    
    +
    +
    diff --git a/Examples/android/class/jni/Android.mk b/Examples/android/class/jni/Android.mk
    new file mode 100644
    index 000000000..25d42b541
    --- /dev/null
    +++ b/Examples/android/class/jni/Android.mk
    @@ -0,0 +1,10 @@
    +# File: Android.mk
    +LOCAL_PATH := $(call my-dir)
    +
    +include $(CLEAR_VARS)
    +
    +LOCAL_MODULE    := example
    +LOCAL_SRC_FILES := example_wrap.cpp example.cpp
    +LOCAL_CFLAGS    := -frtti
    +
    +include $(BUILD_SHARED_LIBRARY)
    diff --git a/Examples/android/class/jni/example.cpp b/Examples/android/class/jni/example.cpp
    new file mode 100644
    index 000000000..d59cc7c32
    --- /dev/null
    +++ b/Examples/android/class/jni/example.cpp
    @@ -0,0 +1,28 @@
    +/* File : example.cpp */
    +
    +#include "example.h"
    +#define M_PI 3.14159265358979323846
    +
    +/* Move the shape to a new location */
    +void Shape::move(double dx, double dy) {
    +  x += dx;
    +  y += dy;
    +}
    +
    +int Shape::nshapes = 0;
    +
    +double Circle::area(void) {
    +  return M_PI*radius*radius;
    +}
    +
    +double Circle::perimeter(void) {
    +  return 2*M_PI*radius;
    +}
    +
    +double Square::area(void) {
    +  return width*width;
    +}
    +
    +double Square::perimeter(void) {
    +  return 4*width;
    +}
    diff --git a/Examples/android/class/jni/example.h b/Examples/android/class/jni/example.h
    new file mode 100644
    index 000000000..64b7684fa
    --- /dev/null
    +++ b/Examples/android/class/jni/example.h
    @@ -0,0 +1,34 @@
    +/* File : example.h */
    +
    +class Shape {
    +public:
    +  Shape() {
    +    nshapes++;
    +  }
    +  virtual ~Shape() {
    +    nshapes--;
    +  };
    +  double  x, y;   
    +  void    move(double dx, double dy);
    +  virtual double area(void) = 0;
    +  virtual double perimeter(void) = 0;
    +  static  int nshapes;
    +};
    +
    +class Circle : public Shape {
    +private:
    +  double radius;
    +public:
    +  Circle(double r) : radius(r) { };
    +  virtual double area(void);
    +  virtual double perimeter(void);
    +};
    +
    +class Square : public Shape {
    +private:
    +  double width;
    +public:
    +  Square(double w) : width(w) { };
    +  virtual double area(void);
    +  virtual double perimeter(void);
    +};
    diff --git a/Examples/android/class/jni/example.i b/Examples/android/class/jni/example.i
    new file mode 100644
    index 000000000..fbdf7249f
    --- /dev/null
    +++ b/Examples/android/class/jni/example.i
    @@ -0,0 +1,9 @@
    +/* File : example.i */
    +%module example
    +
    +%{
    +#include "example.h"
    +%}
    +
    +/* Let's just grab the original header file here */
    +%include "example.h"
    diff --git a/Examples/android/class/local.properties b/Examples/android/class/local.properties
    new file mode 100644
    index 000000000..14b8d63b4
    --- /dev/null
    +++ b/Examples/android/class/local.properties
    @@ -0,0 +1,10 @@
    +# This file is automatically generated by Android Tools.
    +# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
    +#
    +# This file must *NOT* be checked in Version Control Systems,
    +# as it contains information specific to your local configuration.
    +
    +# location of the SDK. This is only used by Ant
    +# For customization when using a Version Control System, please read the
    +# header note.
    +sdk.dir=/home/william/android/android-sdk-linux_x86
    diff --git a/Examples/android/class/proguard.cfg b/Examples/android/class/proguard.cfg
    new file mode 100644
    index 000000000..b1cdf17b5
    --- /dev/null
    +++ b/Examples/android/class/proguard.cfg
    @@ -0,0 +1,40 @@
    +-optimizationpasses 5
    +-dontusemixedcaseclassnames
    +-dontskipnonpubliclibraryclasses
    +-dontpreverify
    +-verbose
    +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
    +
    +-keep public class * extends android.app.Activity
    +-keep public class * extends android.app.Application
    +-keep public class * extends android.app.Service
    +-keep public class * extends android.content.BroadcastReceiver
    +-keep public class * extends android.content.ContentProvider
    +-keep public class * extends android.app.backup.BackupAgentHelper
    +-keep public class * extends android.preference.Preference
    +-keep public class com.android.vending.licensing.ILicensingService
    +
    +-keepclasseswithmembernames class * {
    +    native ;
    +}
    +
    +-keepclasseswithmembers class * {
    +    public (android.content.Context, android.util.AttributeSet);
    +}
    +
    +-keepclasseswithmembers class * {
    +    public (android.content.Context, android.util.AttributeSet, int);
    +}
    +
    +-keepclassmembers class * extends android.app.Activity {
    +   public void *(android.view.View);
    +}
    +
    +-keepclassmembers enum * {
    +    public static **[] values();
    +    public static ** valueOf(java.lang.String);
    +}
    +
    +-keep class * implements android.os.Parcelable {
    +  public static final android.os.Parcelable$Creator *;
    +}
    diff --git a/Examples/android/class/project.properties b/Examples/android/class/project.properties
    new file mode 100644
    index 000000000..ea89160e0
    --- /dev/null
    +++ b/Examples/android/class/project.properties
    @@ -0,0 +1,11 @@
    +# This file is automatically generated by Android Tools.
    +# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
    +#
    +# This file must be checked in Version Control Systems.
    +#
    +# To customize properties used by the Ant build system use,
    +# "ant.properties", and override values to adapt the script to your
    +# project structure.
    +
    +# Project target.
    +target=android-8
    diff --git a/Examples/android/class/res/layout/main.xml b/Examples/android/class/res/layout/main.xml
    new file mode 100644
    index 000000000..d4e5d7fe8
    --- /dev/null
    +++ b/Examples/android/class/res/layout/main.xml
    @@ -0,0 +1,25 @@
    +
    +
    +
  • $symname Name of -function/method being wrapped$inputRuby object being sent to the function
    $symname Name of function/method being wrapped
    $1...n Argument being -sent to the functionArgument being sent to the function
    $resultResult that the -director function returnsResult that the director function returns
    $inputRuby object being sent to the function
    $symnamename of the -function/method being wrappedname of the function/method being wrapped
    $1...nArgument being -sent to the functionArgument being sent to the function