diff --git a/.travis.yml b/.travis.yml index bcf231725..7bebfc9e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,16 @@ matrix: - compiler: clang os: linux env: SWIGLANG= + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG= + - compiler: gcc + os: linux + env: SWIGLANG= + sudo: required + dist: trusty - os: linux env: SWIGLANG= SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 sudo: required @@ -18,12 +25,18 @@ matrix: - compiler: gcc os: linux env: SWIGLANG=csharp + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=d + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=go + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=go VER=1.5 @@ -32,21 +45,31 @@ matrix: - compiler: gcc os: linux env: SWIGLANG=guile + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=java + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=node - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=jsc + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=javascript ENGINE=v8 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=lua + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=lua VER=5.3 @@ -64,69 +87,118 @@ matrix: - compiler: gcc os: linux env: SWIGLANG=perl5 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=php + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python VER=2.4 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python VER=2.5 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python VER=2.6 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python # 2.7 + sudo: required + dist: trusty - compiler: gcc os: linux - env: SWIGLANG=python PY3=3 # 3.2 + env: SWIGLANG=python PY3=3 VER=3.2 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python PY3=3 VER=3.3 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python PY3=3 VER=3.4 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python PY3=3 VER=3.5 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin VER=2.6 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin + sudo: required + dist: trusty - compiler: gcc os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 + env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.4 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 SWIGOPTPY3= + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-O + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-classic + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=r + sudo: required + dist: trusty - compiler: gcc os: linux - env: SWIGLANG=ruby + env: SWIGLANG=ruby VER=1.9.3 + sudo: required + dist: trusty + - compiler: gcc + os: linux + env: SWIGLANG=ruby VER=2.0.0 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=ruby VER=2.3.0 + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=scilab + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=tcl + sudo: required + dist: trusty - os: linux env: SWIGLANG=csharp SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 sudo: required @@ -151,8 +223,9 @@ matrix: env: SWIGLANG=python SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 sudo: required dist: trusty - - os: osx - env: SWIGLANG= SWIG_CC=gcc-4.2 SWIG_CXX=g++-4.2 + - compiler: gcc + os: osx + env: SWIGLANG= - compiler: clang os: osx env: SWIGLANG= @@ -162,6 +235,9 @@ matrix: - compiler: clang os: osx env: SWIGLANG=go + - compiler: clang + os: osx + env: SWIGLANG=guile - compiler: clang os: osx env: SWIGLANG=java @@ -192,14 +268,14 @@ matrix: - compiler: gcc os: linux env: SWIGLANG=ocaml + sudo: required + dist: trusty # Not quite working yet - compiler: gcc os: linux env: SWIGLANG=python SWIG_FEATURES=-O - # brew install guile fails on Travis as OSX 10.9 is too old now, default osx_image needs changing - - compiler: clang - os: osx - env: SWIGLANG=guile + sudo: required + dist: trusty before_install: - date -u - uname -a @@ -240,6 +316,3 @@ script: - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r' - make check-maintainer-clean && ../../configure $CONFIGOPTS - echo -en 'travis_fold:end:script.3\\r' -branches: - only: - - master diff --git a/CHANGES.current b/CHANGES.current index 148fd17af..afb4fa205 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,38 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.11 (in progress) ============================ +2016-10-30: myd7349 + [C#] Patch #740 Add std_array.i for C# for wrapping std::array. + + Patch also enhances std::vector C# wrappers with additional functions + (Contains, IndexOf, LastIndexOf and Remove). + +2016-10-30: tobilau + [Java] Fix wrappers for wstring parameters in director methods to cleanup local + ref after director callback has finished. + +2016-10-23: wsfulton + [C#] Add missing csdirectorin VOID_INT_PTR and csdirectorout VOID_INT_PTR typemaps. + +2016-10-23: jiulongw + Patch #781 - Fix wrapping of C compound expressions containing char constants + in quotes such as: + + #define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p') + + enum DifferentTypes { + typecharcompound='A'+1, + typecharcompound2='B' << 2 + }; + +2016-10-13: wsfulton + [Python] Issue #808 - fix Python pickling and metaclass for builtin wrappers. + + The metaclass (SwigPyObjectType) for SWIG objects was not defined in + a way that let importlib successfully import the Python wrappers. + The pickle module previously failed to pickle objects because it couldn't + determine what module the SWIG wrapped objects were in. + 2016-09-29: wsfulton [Allegrocl, CFFI, GO, Javascript, Ocaml, R, Scilab] Add missing support for the "ret" typemap in a few target languages. diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html index 4b6bad421..664e720c8 100644 --- a/Doc/Manual/Allegrocl.html +++ b/Doc/Manual/Allegrocl.html @@ -280,39 +280,39 @@ actual function.
example_wrap.i
-   ... lots of SWIG internals ...
+  ... lots of SWIG internals ...
 
 EXPORT int ACL___fact__SWIG_0 (char *larg1) {
-    int lresult = (int)0 ;
-    char *arg1 = (char *) 0 ;
-    int result;
-    
-    arg1 = larg1;
-    try {
-        result = (int)fact(arg1);
-        
-        lresult = result;
-        return lresult;
-    } catch (...) {
-        return (int)0;
-    }
+  int lresult = (int)0 ;
+  char *arg1 = (char *) 0 ;
+  int result;
+
+  arg1 = larg1;
+  try {
+    result = (int)fact(arg1);
+
+    lresult = result;
+    return lresult;
+  } catch (...) {
+    return (int)0;
+  }
 }
 
 
 EXPORT int ACL___fact__SWIG_1 (int larg1) {
-    int lresult = (int)0 ;
-    int arg1 ;
-    int result;
-    
-    arg1 = larg1;
-    try {
-        result = (int)fact(arg1);
-        
-        lresult = result;
-        return lresult;
-    } catch (...) {
-        return (int)0;
-    }
+  int lresult = (int)0 ;
+  int arg1 ;
+  int result;
+
+  arg1 = larg1;
+  try {
+    result = (int)fact(arg1);
+
+    lresult = result;
+    return lresult;
+  } catch (...) {
+    return (int)0;
+  }
 }
 
@@ -324,7 +324,7 @@ what is generated when parsing C code:
-   ...
+  ...
 
 (swig-in-package ())
 
@@ -688,10 +688,10 @@ char *xxx();
 %include "foo.h"
 
 namespace car {
-   ...
-   namespace tires {
-      int do_something(int n);
-   }
+  ...
+  namespace tires {
+    int do_something(int n);
+  }
 }
     
@@ -1209,8 +1209,8 @@ class schema.
synonyms.h
 class A { 
-   int x;
-   int y;
+  int x;
+  int y;
 };
 
 typedef A Foo;
@@ -1336,70 +1336,70 @@ float xxx(A *inst, int x);     /* return x + A->x + A->y */
     
overload_wrap.cxx
 EXPORT void ACL___delete_A__SWIG_0 (A *larg1) {
-    A *arg1 = (A *) 0 ;
-    
-    arg1 = larg1;
-    try {
-        delete arg1;
-        
-    } catch (...) {
-        
-    }
+  A *arg1 = (A *) 0 ;
+
+  arg1 = larg1;
+  try {
+    delete arg1;
+
+  } catch (...) {
+
+  }
 }
 
 
 EXPORT float ACL___xxx__SWIG_0 (int larg1, int larg2) {
-    float lresult = (float)0 ;
-    int arg1 ;
-    int arg2 ;
-    float result;
-    
-    arg1 = larg1;
-    arg2 = larg2;
-    try {
-        result = (float)xxx(arg1,arg2);
-        
-        lresult = result;
-        return lresult;
-    } catch (...) {
-        return (float)0;
-    }
+  float lresult = (float)0 ;
+  int arg1 ;
+  int arg2 ;
+  float result;
+
+  arg1 = larg1;
+  arg2 = larg2;
+  try {
+    result = (float)xxx(arg1,arg2);
+
+    lresult = result;
+    return lresult;
+  } catch (...) {
+    return (float)0;
+  }
 }
 
 
 EXPORT float ACL___xxx__SWIG_1 (int larg1) {
-    float lresult = (float)0 ;
-    int arg1 ;
-    float result;
-    
-    arg1 = larg1;
-    try {
-        result = (float)xxx(arg1);
-        
-        lresult = result;
-        return lresult;
-    } catch (...) {
-        return (float)0;
-    }
+  float lresult = (float)0 ;
+  int arg1 ;
+  float result;
+
+  arg1 = larg1;
+  try {
+    result = (float)xxx(arg1);
+
+    lresult = result;
+    return lresult;
+  } catch (...) {
+    return (float)0;
+  }
 }
 
 
 EXPORT float ACL___xxx__SWIG_2 (A *larg1, int larg2) {
-    float lresult = (float)0 ;
-    A *arg1 = (A *) 0 ;
-    int arg2 ;
-    float result;
-    
-    arg1 = larg1;
-    arg2 = larg2;
-    try {
-        result = (float)xxx(arg1,arg2);
-        
-        lresult = result;
-        return lresult;
-    } catch (...) {
-        return (float)0;
-    }
+  float lresult = (float)0 ;
+  A *arg1 = (A *) 0 ;
+  int arg2 ;
+  float result;
+
+  arg1 = larg1;
+  arg2 = larg2;
+  try {
+    result = (float)xxx(arg1,arg2);
+
+    lresult = result;
+    return lresult;
+  } catch (...) {
+    return (float)0;
+  }
 }
     
@@ -1675,21 +1675,21 @@ opoverload>
 return-val wrapper-name(parm0, parm1, ..., parmN)
 {
-   return-val lresult;   /* return value from wrapper */
-   <local-declaration>
-   ... results;          /* return value from function call */
+  return-val lresult;   /* return value from wrapper */
+  <local-declaration>
+  ... results;          /* return value from function call */
 
-   <binding locals to parameters>
+  <binding locals to parameters>
 
-   try {
-      result = function-name(local0, local1, ..., localN);
+  try {
+    result = function-name(local0, local1, ..., localN);
 
-      <convert and bind result to lresult>
+    <convert and bind result to lresult>
 
-      return lresult;
-   catch (...) {
-      return (int)0;
-   }
+    return lresult;
+  catch (...) {
+    return (int)0;
+  }
     
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index c825d8426..06c83c243 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -457,10 +457,10 @@ This kind of initialization is handled by SWIG.
 class SomeClass {
 public:
-    SomeClass() {}
-    explicit SomeClass(int new_value) : value(new_value) {}
+  SomeClass() {}
+  explicit SomeClass(int new_value) : value(new_value) {}
 
-    int value = 5;
+  int value = 5;
 };
 
@@ -688,7 +688,7 @@ initializers) with some limitations. The following code is correctly parsed:

 template <typename... BaseClasses> class ClassName : public BaseClasses... {
 public:
-   ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
+  ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
 }
 
@@ -818,7 +818,7 @@ reachable by the current thread can be defined as:

 struct A {
-   static thread_local int val;
+  static thread_local int val;
 };
 thread_local int global_val;
 
@@ -858,8 +858,8 @@ For example, the C++ compiler will not compile any code which attempts to use an
 struct NoInt {
-    void f(double i);
-    void f(int) = delete;
+  void f(double i);
+  void f(int) = delete;
 };
 
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 26f0c740e..03e039355 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -1021,18 +1021,18 @@ Now let's analyse the generated code to gain a fuller understanding of the typem
 SWIGEXPORT void SWIGSTDCALL CSharp_positivesonly(int jarg1) {
-    int arg1 ;
-    
-    arg1 = (int)jarg1; 
-    
-    if (arg1 < 0) {
-        SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException,
-                                               "only positive numbers accepted", "number");
-        return ;
-    }
-    
-    positivesonly(arg1);
-    
+  int arg1 ;
+
+  arg1 = (int)jarg1;
+
+  if (arg1 < 0) {
+    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException,
+      "only positive numbers accepted", "number");
+    return ;
+  }
+
+  positivesonly(arg1);
+
 }
 
@@ -1155,18 +1155,17 @@ The generated unmanaged code this time catches the C++ exception and converts it
 SWIGEXPORT void SWIGSTDCALL CSharp_negativesonly(int jarg1) {
-    int arg1 ;
-    
-    arg1 = (int)jarg1; 
-    
-    try {
-        negativesonly(arg1);
-        
-    } catch (std::out_of_range e) {
-        SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
-        return ;
-    }
-    
+  int arg1 ;
+
+  arg1 = (int)jarg1;
+
+  try {
+    negativesonly(arg1);
+
+  } catch (std::out_of_range e) {
+    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
+    return ;
+  }
 }
 
@@ -1221,19 +1220,18 @@ SWIG generates a try catch block with the throws typemap code in the catch handl
 SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) {
-    int arg1 ;
-    
-    arg1 = (int)jarg1; 
-    try {
-        evensonly(arg1);
+  int arg1 ;
+
+  arg1 = (int)jarg1;
+  try {
+    evensonly(arg1);
+  }
+  catch(std::out_of_range &_e) {
+    {
+      SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, (&_e)->what(), NULL);
+      return ;
     }
-    catch(std::out_of_range &_e) {
-      {
-          SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, (&_e)->what(), NULL);
-          return ;
-      }
-    }
-    
+  }
 }
 
@@ -1643,20 +1641,20 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Base_director_connect(void *objarg, class SwigDirector_Base : public Base, public Swig::Director { public: - SwigDirector_Base(); - virtual unsigned int UIntMethod(unsigned int x); - virtual ~SwigDirector_Base(); - virtual void BaseBoolMethod(Base const &b, bool flag); + SwigDirector_Base(); + virtual unsigned int UIntMethod(unsigned int x); + virtual ~SwigDirector_Base(); + virtual void BaseBoolMethod(Base const &b, bool flag); - typedef unsigned int (SWIGSTDCALL* SWIG_Callback0_t)(unsigned int); - typedef void (SWIGSTDCALL* SWIG_Callback1_t)(void *, unsigned int); - void swig_connect_director(SWIG_Callback0_t callbackUIntMethod, - SWIG_Callback1_t callbackBaseBoolMethod); + typedef unsigned int (SWIGSTDCALL* SWIG_Callback0_t)(unsigned int); + typedef void (SWIGSTDCALL* SWIG_Callback1_t)(void *, unsigned int); + void swig_connect_director(SWIG_Callback0_t callbackUIntMethod, + SWIG_Callback1_t callbackBaseBoolMethod); private: - SWIG_Callback0_t swig_callbackUIntMethod; - SWIG_Callback1_t swig_callbackBaseBoolMethod; - void swig_init_callbacks(); + SWIG_Callback0_t swig_callbackUIntMethod; + SWIG_Callback1_t swig_callbackBaseBoolMethod; + void swig_init_callbacks(); }; void SwigDirector_Base::swig_connect_director(SWIG_Callback0_t callbackUIntMethod, @@ -1940,10 +1938,10 @@ and usage from C++
-    Container container;
-    Element element(20);
-    container.setElement(&element);
-    cout << "element.value: " << container.getElement()->value << endl;
+  Container container;
+  Element element(20);
+  container.setElement(&element);
+  cout << "element.value: " << container.getElement()->value << endl;
 
diff --git a/Doc/Manual/Contract.html b/Doc/Manual/Contract.html index 4b4995819..c9bcd6f38 100644 --- a/Doc/Manual/Contract.html +++ b/Doc/Manual/Contract.html @@ -51,9 +51,9 @@ is a simple example:
 %contract sqrt(double x) {
 require:
-    x >= 0;
+  x >= 0;
 ensure:
-    sqrt >= 0;
+  sqrt >= 0;
 }
 
 ...
@@ -106,20 +106,20 @@ The %contract directive can also be applied to class methods and constr
 
 %contract Foo::bar(int x, int y) {
 require:
-   x > 0;
+  x > 0;
 ensure:
-   bar > 0;
+  bar > 0;
 }
 
 %contract Foo::Foo(int a) {
 require:
-   a > 0;
+  a > 0;
 }
 
 class Foo {
 public:
-    Foo(int);
-    int bar(int, int);
+  Foo(int);
+  int bar(int, int);
 };
 
@@ -133,7 +133,7 @@ Thus, any contract that you specified for a base class will also be attached to
 class Spam : public Foo {
 public:
-   int bar(int,int);    // Gets contract defined for Foo::bar(int,int)
+  int bar(int,int);    // Gets contract defined for Foo::bar(int,int)
 };
 
@@ -146,22 +146,22 @@ In addition to this, separate contracts can be applied to both the base class an
 %contract Foo::bar(int x, int) {
 require:
-    x > 0;
+  x > 0;
 }
 
 %contract Spam::bar(int, int y) {
 require:
-    y > 0;
+  y > 0;
 }
 
 class Foo {
 public:
-    int bar(int,int);   // Gets Foo::bar contract.
+  int bar(int,int);   // Gets Foo::bar contract.
 };
 
 class Spam : public Foo {
 public:
-     int bar(int,int);   // Gets Foo::bar and Spam::bar contract
+  int bar(int,int);   // Gets Foo::bar and Spam::bar contract
 };
 
@@ -225,7 +225,7 @@ function can be used in contracts. For example: %contract move(SomeObject *, int direction, in) { require: - check_direction(direction); + check_direction(direction); } #define UP 1 @@ -246,7 +246,7 @@ Alternatively, it can be used in typemaps and other directives. For example: %aggregate_check(int, check_direction, UP, DOWN, RIGHT, LEFT); %typemap(check) int direction { - if (!check_direction($1)) SWIG_exception(SWIG_ValueError, "Bad direction"); + if (!check_direction($1)) SWIG_exception(SWIG_ValueError, "Bad direction"); } #define UP 1 diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 8705534f9..014b1a3c2 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -56,12 +56,12 @@ handler. For example, you can specify the following:
 %exception {
-    try {
-        $action
-    }
-    catch (RangeError) {
-        ... handle error ...
-    }
+  try {
+    $action
+  }
+  catch (RangeError) {
+    ... handle error ...
+  }
 }
 
@@ -71,13 +71,13 @@ How the exception is handled depends on the target language, for example, Python
 %exception {
-    try {
-        $action
-    }
-    catch (RangeError) {
-        PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
-        SWIG_fail;
-    }
+  try {
+    $action
+  }
+  catch (RangeError) {
+    PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
+    SWIG_fail;
+  }
 }
 
@@ -341,12 +341,12 @@ to specific declaration name. For example:
 %exception allocate {
-    try {
-        $action
-    } 
-    catch (MemoryError) {
-        croak("Out of memory");
-    }
+  try {
+    $action
+  }
+  catch (MemoryError) {
+    croak("Out of memory");
+  }
 }
 
@@ -364,12 +364,12 @@ an exception handler for a specific class, you might write this:
 %exception Object::allocate {
-    try {
-        $action
-    } 
-    catch (MemoryError) {
-        croak("Out of memory");
-    }
+  try {
+    $action
+  }
+  catch (MemoryError) {
+    croak("Out of memory");
+  }
 }
 
@@ -386,12 +386,12 @@ in the specified class as well as for identically named functions appearing in d
 %exception Object::allocate(int) {
-    try {
-        $action
-    } 
-    catch (MemoryError) {
-        croak("Out of memory");
-    }
+  try {
+    $action
+  }
+  catch (MemoryError) {
+    croak("Out of memory");
+  }
 }
 
@@ -410,21 +410,21 @@ to attach exceptions to specific parts of a header file. For example: // Define a few exception handlers for specific declarations %exception Object::allocate(int) { - try { - $action - } - catch (MemoryError) { - croak("Out of memory"); - } + try { + $action + } + catch (MemoryError) { + croak("Out of memory"); + } } %exception Object::getitem { - try { - $action - } - catch (RangeError) { - croak("Index out of range"); - } + try { + $action + } + catch (RangeError) { + croak("Index out of range"); + } } ... // Read a raw header file @@ -560,17 +560,17 @@ common scripting language exceptions in a portable manner. For example :

%include exception.i %exception { - try { - $action - } catch(RangeError) { - SWIG_exception(SWIG_ValueError, "Range Error"); - } catch(DivisionByZero) { - SWIG_exception(SWIG_DivisionByZero, "Division by zero"); - } catch(OutOfMemory) { - SWIG_exception(SWIG_MemoryError, "Out of memory"); - } catch(...) { - SWIG_exception(SWIG_RuntimeError,"Unknown exception"); - } + try { + $action + } catch(RangeError) { + SWIG_exception(SWIG_ValueError, "Range Error"); + } catch(DivisionByZero) { + SWIG_exception(SWIG_DivisionByZero, "Division by zero"); + } catch(OutOfMemory) { + SWIG_exception(SWIG_MemoryError, "Out of memory"); + } catch(...) { + SWIG_exception(SWIG_RuntimeError,"Unknown exception"); + } }
@@ -611,8 +611,8 @@ example, consider a function like this:
 Foo *blah() {
-   Foo *f = new Foo();
-   return f;
+  Foo *f = new Foo();
+  return f;
 }
 
@@ -771,12 +771,12 @@ using the %feature directive. For example:
 %feature("except") Object::allocate {
-    try {
-        $action
-    } 
-    catch (MemoryError) {
-        croak("Out of memory");
-    }
+  try {
+    $action
+  }
+  catch (MemoryError) {
+    croak("Out of memory");
+  }
 }
 
 %feature("new","1") *::copy;
@@ -811,10 +811,10 @@ are defined.  For example:
 
 /* Define a global exception handler */
 %feature("except") {
-   try {
-     $action
-   }
-   ...
+  try {
+    $action
+  }
+  ...
 }
 
 ... bunch of declarations ...
@@ -867,11 +867,11 @@ In the following example, MyExceptionClass is the name of the Java clas
 
 %feature("except", throws="MyExceptionClass") Object::method { 
-   try {
-     $action
-   } catch (...) {
-     ... code to throw a MyExceptionClass Java exception ...
-   }
+  try {
+    $action
+  } catch (...) {
+    ... code to throw a MyExceptionClass Java exception ...
+  }
 };
 
@@ -993,21 +993,21 @@ To clarify, let's consider the except feature again (%exception // Define global exception handler %feature("except") { - try { - $action - } catch (...) { - croak("Unknown C++ exception"); - } + try { + $action + } catch (...) { + croak("Unknown C++ exception"); + } } // Define exception handler for all clone methods to log the method calls %feature("except") *::clone() { - try { - logger.info("$action"); - $action - } catch (...) { - croak("Unknown C++ exception"); - } + try { + logger.info("$action"); + $action + } catch (...) { + croak("Unknown C++ exception"); + } } ... initial set of class declarations with clone methods ... @@ -1165,14 +1165,14 @@ in the Python module. You might use %feature to rewrite proxy/shadow cl %feature("shadow") Foo::bar(int) %{ def bar(*args): if len(args) == 3: - return apply(examplec.Foo_bar_id,args) + return apply(examplec.Foo_bar_id,args) return apply(examplec.Foo_bar,args) %} class Foo { public: - int bar(int x); - int bar(int x, double y); + int bar(int x); + int bar(int x, double y); }
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html index 9e8e65358..318a9586f 100644 --- a/Doc/Manual/D.html +++ b/Doc/Manual/D.html @@ -229,8 +229,9 @@ void foo(SomeClass arg) { %newobject bar(); SomeClass *bar(); -%} -

The code generated for foo() and bar() looks like this:

+%} + +

The code generated for foo() and bar() looks like this:

 SomeClass foo() {
   return new SomeClass(example_im.foo(), false);
diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html
index e44d53084..798a1adb9 100644
--- a/Doc/Manual/Extending.html
+++ b/Doc/Manual/Extending.html
@@ -772,8 +772,8 @@ low-level %feature directive.  For example:
 ...
 class Foo {
 public:
-    Object *getitem(int index) throws(badindex);
-    ...
+  Object *getitem(int index) throws(badindex);
+  ...
 };
 
@@ -826,7 +826,7 @@ transformed. For example, suppose you are wrapping a class like this:
 class Foo {
 public:
-    virtual int *bar(int x);
+  virtual int *bar(int x);
 };
 
@@ -1381,14 +1381,14 @@ List *l = (some list); Iterator i; for (i = First(l); i.item; i = Next(i)) { - Printf(stdout,"%s\n", i.item); + Printf(stdout,"%s\n", i.item); } Hash *h = (some hash); Iterator j; for (j = First(j); j.item; j= Next(j)) { - Printf(stdout,"%s : %s\n", j.key, j.item); + Printf(stdout,"%s : %s\n", j.key, j.item); } @@ -1517,7 +1517,7 @@ common to see small code fragments of code generated using code like this: String *s = NewString(""); Printf(s,"Hello\n"); for (i = 0; i < 10; i++) { - Printf(s,"%d\n", i); + Printf(s,"%d\n", i); } ... /* Print string into a file */ @@ -1674,10 +1674,10 @@ Since parse tree nodes are just hash tables, attributes are accessed using the <
 int functionHandler(Node *n) {
-    String *name    = Getattr(n,"name");
-    String *symname = Getattr(n,"sym:name");
-    SwigType *type  = Getattr(n,"type");
-    ...
+  String *name    = Getattr(n,"name");
+  String *symname = Getattr(n,"sym:name");
+  SwigType *type  = Getattr(n,"type");
+  ...
 }
 
@@ -1703,8 +1703,8 @@ A quick way to check the value of an attribute is to use the checkAttribute(
 if (checkAttribute(n,"storage","virtual")) {
-   /* n is virtual */
-   ...
+  /* n is virtual */
+  ...
 }
 
@@ -1750,17 +1750,17 @@ Calls can be nested if necessary. Here is an example that shows how the functio
 int variableHandler(Node *n) {
-    Swig_save("variableHandler",n,"type","sym:name",NIL);
-    String *symname = Getattr(n,"sym:name");
-    SwigType *type  = Getattr(n,"type");
-    ...
-    Append(symname,"_global");         // Change symbol name
-    SwigType_add_pointer(type);        // Add pointer
-    ...
-    generate wrappers
-    ...
-    Swig_restore(n);                  // Restore original values
-    return SWIG_OK;
+  Swig_save("variableHandler",n,"type","sym:name",NIL);
+  String *symname = Getattr(n,"sym:name");
+  SwigType *type  = Getattr(n,"type");
+  ...
+  Append(symname,"_global");         // Change symbol name
+  SwigType_add_pointer(type);        // Add pointer
+  ...
+  generate wrappers
+  ...
+  Swig_restore(n);                  // Restore original values
+  return SWIG_OK;
 }
 
@@ -2375,10 +2375,10 @@ code like this: Parm *parms; Parm *p; for (p = parms; p; p = nextSibling(p)) { - SwigType *type = Getattr(p,"type"); - String *name = Getattr(p,"name"); - String *value = Getattr(p,"value"); - ... + SwigType *type = Getattr(p,"type"); + String *name = Getattr(p,"name"); + String *value = Getattr(p,"value"); + ... } @@ -2650,19 +2650,19 @@ insert some code like this:
 void main(int argc, char *argv[]) {
-   ... command line options ...
+  ... command line options ...
 
-   /* Set language-specific subdirectory in SWIG library */
-   SWIG_library_directory("python");
+  /* Set language-specific subdirectory in SWIG library */
+  SWIG_library_directory("python");
 
-   /* Set language-specific preprocessing symbol */
-   Preprocessor_define("SWIGPYTHON 1", 0);
+  /* Set language-specific preprocessing symbol */
+  Preprocessor_define("SWIGPYTHON 1", 0);
 
-   /* Set language-specific configuration file */
-   SWIG_config_file("python.swg");
+  /* Set language-specific configuration file */
+  SWIG_config_file("python.swg");
 
-   /* Set typemap language (historical) */
-   SWIG_typemap_lang("python");
+  /* Set typemap language (historical) */
+  SWIG_typemap_lang("python");
 }
 
@@ -2721,26 +2721,26 @@ An outline of top() might be as follows:
 int Python::top(Node *n) {
 
-   /* Get the module name */
-   String *module = Getattr(n,"name");
+  /* Get the module name */
+  String *module = Getattr(n,"name");
 
-   /* Get the output file name */
-   String *outfile = Getattr(n,"outfile");
+  /* Get the output file name */
+  String *outfile = Getattr(n,"outfile");
 
-   /* Initialize I/O (see next section) */
-   ...
+  /* Initialize I/O (see next section) */
+  ...
 
-   /* Output module initialization code */
-   ...
+  /* Output module initialization code */
+  ...
 
-   /* Emit code for children */
-   Language::top(n);
+  /* Emit code for children */
+  Language::top(n);
 
-   ...
-   /* Cleanup files */
-   ...
+  ...
+  /* Cleanup files */
+  ...
 
-   return SWIG_OK;
+  return SWIG_OK;
 }
 
@@ -2777,62 +2777,62 @@ such as:
 class PYTHON : public Language {
 protected:
-   /* General DOH objects used for holding the strings */
-   File *f_begin;
-   File *f_runtime;
-   File *f_header;
-   File *f_wrappers;
-   File *f_init;
+  /* General DOH objects used for holding the strings */
+  File *f_begin;
+  File *f_runtime;
+  File *f_header;
+  File *f_wrappers;
+  File *f_init;
 
 public:
-   ...
+  ...
 
 };
 
 int Python::top(Node *n) {
 
-   ...
+  ...
 
-   /* Initialize I/O */
-   f_begin = NewFile(outfile, "w", SWIG_output_files());
-   if (!f_begin) {
-      FileErrorDisplay(outfile);
-      SWIG_exit(EXIT_FAILURE);
-   }
-   f_runtime = NewString("");
-   f_init = NewString("");
-   f_header = NewString("");
-   f_wrappers = NewString("");
+  /* Initialize I/O */
+  f_begin = NewFile(outfile, "w", SWIG_output_files());
+  if (!f_begin) {
+    FileErrorDisplay(outfile);
+    SWIG_exit(EXIT_FAILURE);
+  }
+  f_runtime = NewString("");
+  f_init = NewString("");
+  f_header = NewString("");
+  f_wrappers = NewString("");
 
-   /* Register file targets with the SWIG file handler */
-   Swig_register_filebyname("begin", f_begin);
-   Swig_register_filebyname("header", f_header);
-   Swig_register_filebyname("wrapper", f_wrappers);
-   Swig_register_filebyname("runtime", f_runtime);
-   Swig_register_filebyname("init", f_init);
+  /* Register file targets with the SWIG file handler */
+  Swig_register_filebyname("begin", f_begin);
+  Swig_register_filebyname("header", f_header);
+  Swig_register_filebyname("wrapper", f_wrappers);
+  Swig_register_filebyname("runtime", f_runtime);
+  Swig_register_filebyname("init", f_init);
 
-   /* Output module initialization code */
-   Swig_banner(f_begin);
-   ...
+  /* Output module initialization code */
+  Swig_banner(f_begin);
+  ...
 
-   /* Emit code for children */
-   Language::top(n);
+  /* Emit code for children */
+  Language::top(n);
 
-   ...
-   /* Write all to the file */
-   Dump(f_runtime, f_begin);
-   Dump(f_header, f_begin);
-   Dump(f_wrappers, f_begin);
-   Wrapper_pretty_print(f_init, f_begin);
+  ...
+  /* Write all to the file */
+  Dump(f_runtime, f_begin);
+  Dump(f_header, f_begin);
+  Dump(f_wrappers, f_begin);
+  Wrapper_pretty_print(f_init, f_begin);
 
-   /* Cleanup files */
-   Delete(f_runtime);
-   Delete(f_header);
-   Delete(f_wrappers);
-   Delete(f_init);
-   Delete(f_begin);
+  /* Cleanup files */
+  Delete(f_runtime);
+  Delete(f_header);
+  Delete(f_wrappers);
+  Delete(f_init);
+  Delete(f_begin);
 
-   return SWIG_OK;
+  return SWIG_OK;
 }
 
diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 20ffb1a91..0877ea09d 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -1109,7 +1109,7 @@ Typesafe enums have their advantages over using plain integers in that they can However, there are limitations. For example, they cannot be used in switch statements and serialization is an issue. Please look at the following references for further information: - http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums +http://java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums Replace Enums with Classes in Effective Java Programming on the Sun website, Create enumerated constants in Java JavaWorld article, Java Tip 133: More on typesafe enums and @@ -1309,16 +1309,16 @@ example: %inline %{ /* C-style cast */ Bar *FooToBar(Foo *f) { - return (Bar *) f; + return (Bar *) f; } /* C++-style cast */ Foo *BarToFoo(Bar *b) { - return dynamic_cast<Foo*>(b); + return dynamic_cast<Foo*>(b); } Foo *IncrFoo(Foo *f, int i) { - return f+i; + return f+i; } %} @@ -1377,12 +1377,12 @@ can also be forced to be read-only using the %immutable directive. For
 struct Foo {
-   ...
-   %immutable;
-   int x;        /* Read-only members */
-   char *name;
-   %mutable;
-   ...
+  ...
+  %immutable;
+  int x;        /* Read-only members */
+  char *name;
+  %mutable;
+  ...
 };
 
@@ -1403,7 +1403,7 @@ example, consider this:
 struct Bar {
-    int  x[16];
+  int  x[16];
 };
 
@@ -1452,11 +1452,11 @@ pointer. For example, suppose you have two structures like this:
 struct Foo {
-   int a;
+  int a;
 };
 
 struct Bar {
-   Foo f;
+  Foo f;
 };
 
@@ -1544,8 +1544,8 @@ Static class members are unsurprisingly wrapped as static members of the Java cl
 class Spam {
 public:
-   static void foo();
-   static int bar;
+  static void foo();
+  static int bar;
 };
 
@@ -1738,9 +1738,9 @@ Similarly, if you have a class like this,
 class Foo {
 public:
-    Foo();
-    Foo(const Foo &);
-    ...
+  Foo();
+  Foo(const Foo &);
+  ...
 };
 
@@ -1876,10 +1876,10 @@ submodules or packages. For example, if you have a file like this, %module example namespace foo { - int fact(int n); - struct Vector { - double x,y,z; - }; + int fact(int n); + struct Vector { + double x,y,z; + }; }; @@ -1907,11 +1907,11 @@ For example: %rename(Bar_spam) Bar::spam; namespace Foo { - int spam(); + int spam(); } namespace Bar { - int spam(); + int spam(); } @@ -1969,12 +1969,12 @@ For example: template<class T1, class T2> struct pair { - typedef T1 first_type; - typedef T2 second_type; - T1 first; - T2 second; - pair(); - pair(const T1&, const T2&); + typedef T1 first_type; + typedef T2 second_type; + T1 first; + T2 second; + pair(); + pair(const T1&, const T2&); ~pair(); }; @@ -2025,9 +2025,9 @@ that implements operator->() like this:
 template<class T> class SmartPtr {
-   ...
-   T *operator->();
-   ...
+  ...
+  T *operator->();
+  ...
 }
 
@@ -2040,8 +2040,8 @@ Then, if you have a class like this,
 class Foo {
 public:
-     int x;
-     int bar();
+  int x;
+  int bar();
 };
 
@@ -2125,8 +2125,8 @@ have a global function and class like this
 class Foo {
 public:
-     int x;
-     int spam(int num, Foo* foo);
+  int x;
+  int spam(int num, Foo* foo);
 };
 void egg(Foo* chips);
 
@@ -2140,19 +2140,19 @@ These procedural wrappers essentially perform the equivalent of this C++ code:
 Foo *new_Foo() {
-    return new Foo();
+  return new Foo();
 }
 void delete_Foo(Foo *f) {
-    delete f;
+  delete f;
 }
 int Foo_x_get(Foo *f) {
-    return f->x;
+  return f->x;
 }
 void Foo_x_set(Foo *f, int value) {
-    f->x = value;
+  f->x = value;
 }
 int Foo_spam(Foo *f, int num, Foo* foo) {
-    return f->spam(num, foo);
+  return f->spam(num, foo);
 }
 
@@ -2494,10 +2494,10 @@ they came from. Therefore, the ownership is set to false. For example:
 class Foo {
 public:
-    Foo();
-    Foo bar1();
-    Foo &bar2();
-    Foo *bar2();
+  Foo();
+  Foo bar1();
+  Foo &bar2();
+  Foo *bar2();
 };
 
@@ -2532,9 +2532,9 @@ change the ownership of an object. For instance, consider code like this:
 class Obj {};
 class Node {
-   Obj *value;
+  Obj *value;
 public:
-   void set_value(Obj *v) { value = v; }
+  void set_value(Obj *v) { value = v; }
 };
 
@@ -2580,7 +2580,7 @@ However, you can tell the proxy class to manage the memory if you specify the @@ -2608,7 +2608,7 @@ Now add in the %newobject directive: class Obj {...}; class Factory { public: - static Obj *createObj() { return new Obj(); } + static Obj *createObj() { return new Obj(); } }; @@ -3656,13 +3656,13 @@ In the following, class Bar will get a director class that handles the methods o %feature("director") Foo; class Foo { public: - virtual void one(); - virtual void two(); + virtual void one(); + virtual void two(); }; class Bar: public Foo { public: - virtual void three(); + virtual void three(); }; @@ -3918,12 +3918,12 @@ is used in the feature code. Consider the following, which also happens to be th
 %feature("director:except") %{
-   jthrowable $error = jenv->ExceptionOccurred();
-   if ($error) {
-     jenv->ExceptionClear();
-     $directorthrowshandlers
-     throw Swig::DirectorException(jenv, $error);
-   }
+  jthrowable $error = jenv->ExceptionOccurred();
+  if ($error) {
+    jenv->ExceptionClear();
+    $directorthrowshandlers
+    throw Swig::DirectorException(jenv, $error);
+  }
 %}
 
@@ -3985,12 +3985,12 @@ unexpected exceptions, the default handling can be changed with:
 %feature("director:except") %{
-   jthrowable $error = jenv->ExceptionOccurred();
-   if ($error) {
-     jenv->ExceptionClear();
-     $directorthrowshandlers
-     return $null; // exception is ignored
-   }
+  jthrowable $error = jenv->ExceptionOccurred();
+  if ($error) {
+    jenv->ExceptionClear();
+    $directorthrowshandlers
+    return $null; // exception is ignored
+  }
 %}
 
@@ -4003,7 +4003,7 @@ the return $null; could be changed to:
-   throw std::runtime_error(Swig::JavaExceptionMessage(jenv, $error).message());
+  throw std::runtime_error(Swig::JavaExceptionMessage(jenv, $error).message());
 
@@ -4262,16 +4262,16 @@ functions. Just use the %inline directive. For example: %inline %{ /* Note: double[4][4] is equivalent to a pointer to an array double (*)[4] */ double (*new_mat44())[4] { - return (double (*)[4]) malloc(16*sizeof(double)); + return (double (*)[4]) malloc(16*sizeof(double)); } void free_mat44(double (*x)[4]) { - free(x); + free(x); } void mat44_set(double x[4][4], int i, int j, double v) { - x[i][j] = v; + x[i][j] = v; } double mat44_get(double x[4][4], int i, int j) { - return x[i][j]; + return x[i][j]; } %} @@ -4317,22 +4317,22 @@ Here is a simple example: %} struct Vector { - double x,y,z; + double x,y,z; }; %extend Vector { - char *toString() { - static char tmp[1024]; - sprintf(tmp,"Vector(%g,%g,%g)", $self->x,$self->y,$self->z); - return tmp; - } - Vector(double x, double y, double z) { - Vector *v = (Vector *) malloc(sizeof(Vector)); - v->x = x; - v->y = y; - v->z = z; - return v; - } + char *toString() { + static char tmp[1024]; + sprintf(tmp,"Vector(%g,%g,%g)", $self->x,$self->y,$self->z); + return tmp; + } + Vector(double x, double y, double z) { + Vector *v = (Vector *) malloc(sizeof(Vector)); + v->x = x; + v->y = y; + v->z = z; + return v; + } }; @@ -4451,18 +4451,18 @@ We can catch the C++ exception and rethrow it as a Java exception like this:

 %exception getitem {
   try {
-     $action
+    $action
   } catch (std::out_of_range &e) {
     jclass clazz = jenv->FindClass("java/lang/Exception");
     jenv->ThrowNew(clazz, "Range error");
     return $null;
-   }
+  }
 }
 
 class FooClass {
-public:
-     FooClass *getitem(int index);      // Might throw std::out_of_range exception
-     ...
+  public:
+    FooClass *getitem(int index);      // Might throw std::out_of_range exception
+    ...
 };
 
@@ -4480,18 +4480,18 @@ See Clearing featur
 %javaexception("java.lang.Exception") getitem {
   try {
-     $action
+    $action
   } catch (std::out_of_range &e) {
     jclass clazz = jenv->FindClass("java/lang/Exception");
     jenv->ThrowNew(clazz, "Range error");
     return $null;
-   }
+  }
 }
 
 class FooClass {
 public:
-     FooClass *getitem(int index);      // Might throw std::out_of_range exception
-     ...
+  FooClass *getitem(int index);      // Might throw std::out_of_range exception
+  ...
 };
 
@@ -4569,7 +4569,7 @@ example:
 void add(int x, int y, int *result) {
-   *result = x + y;
+  *result = x + y;
 }
 
@@ -4581,7 +4581,7 @@ or perhaps
 int sub(int *x, int *y) {
-   return *x-*y;
+  return *x-*y;
 }
 
@@ -4653,7 +4653,7 @@ If a function mutates one of its parameters like this,
 void negate(int *x) {
-   *x = -(*x);
+  *x = -(*x);
 }
 
@@ -4811,9 +4811,9 @@ Let's consider an example: %include "arrays_java.i"; int array[4]; void populate(int x[]) { - int i; - for (i=0; i<4; i++) - x[i] = 100 + i; + int i; + for (i=0; i<4; i++) + x[i] = 100 + i; } @@ -4829,7 +4829,7 @@ example.populate(array); System.out.print("array: "); for (int i=0; i<array.length; i++) - System.out.print(array[i] + " "); + System.out.print(array[i] + " "); example.setArray(array); @@ -4837,7 +4837,7 @@ int[] global_array = example.getArray(); System.out.print("\nglobal_array: "); for (int i=0; i<array.length; i++) - System.out.print(global_array[i] + " "); + System.out.print(global_array[i] + " "); @@ -4875,11 +4875,11 @@ Sometimes a C function expects an array to be passed as a pointer. For example,
 int sumitems(int *first, int nitems) {
-    int i, sum = 0;
-    for (i = 0; i < nitems; i++) {
-        sum += first[i];
-    }
-    return sum;
+  int i, sum = 0;
+  for (i = 0; i < nitems; i++) {
+    sum += first[i];
+  }
+  return sum;
 }
 
@@ -4960,7 +4960,7 @@ In Java, you would use the functions like this:
 SWIGTYPE_p_int array = example.new_intArray(10000000);  // Array of 10-million integers
 for (int i=0; i<10000; i++) {                           // Set some values
-    example.intArray_setitem(array,i,i);
+  example.intArray_setitem(array,i,i);
 }
 int sum = example.sumitems(array,10000);
 System.out.println("Sum = " + sum);
@@ -4989,7 +4989,7 @@ For instance, you will be able to do this in Java:
 
 intArray array = new intArray(10000000);  // Array of 10-million integers
 for (int i=0; i<10000; i++) {             // Set some values
-    array.setitem(i,i);
+  array.setitem(i,i);
 }
 int sum = example.sumitems(array.cast(),10000);
 System.out.println("Sum = " + sum);
@@ -5604,12 +5604,12 @@ The following code snippet might aid in understand aliasing rules better:
 

-    short a;
-    short* pa = 0;
-    int i = 0x1234;
+short a;
+short* pa = 0;
+int i = 0x1234;
 
-    a = (short)i;    /* okay */
-    a = *(short*)&i; /* breaks aliasing rules */
+a = (short)i;    /* okay */
+a = *(short*)&i; /* breaks aliasing rules */
 

@@ -5618,15 +5618,15 @@ In SWIG, the "in" and "out" typemaps for pointers are typically

-    %typemap(in) struct Foo * %{
-      $1 = *(struct Foo **)&$input; /* cast jlong into C ptr */
-    %}
-    %typemap(out) struct Bar * %{
-      *(struct Bar **)&$result = $1; /* cast C ptr into jlong */
-    %} 
-    struct Bar {...};
-    struct Foo {...};
-    struct Bar * FooBar(struct Foo *f);
+%typemap(in) struct Foo * %{
+  $1 = *(struct Foo **)&$input; /* cast jlong into C ptr */
+%}
+%typemap(out) struct Bar * %{
+  *(struct Bar **)&$result = $1; /* cast C ptr into jlong */
+%}
+struct Bar {...};
+struct Foo {...};
+struct Bar * FooBar(struct Foo *f);
 

@@ -5863,10 +5863,10 @@ If the typemap gets put into a function with void as return, $null will expand t

 SWIGEXPORT void JNICALL Java_jnifn(...) {
-    if (error) {
-      SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array element error");
-      return ;
-    }
+  if (error) {
+    SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array element error");
+    return ;
+  }
   ...
 }
 
@@ -5877,10 +5877,10 @@ otherwise $null expands to NULL
 SWIGEXPORT jobject JNICALL Java_jnifn(...) {
-    if (error) {
-      SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array element error");
-      return NULL;
-    }
+  if (error) {
+    SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array element error");
+    return NULL;
+  }
   ...
 }
 
@@ -5905,8 +5905,8 @@ Here is an example: } %inline %{ - class Class {...}; - Class * bar(Class cls, unsigned short ush) { return new Class(); }; + class Class {...}; + Class * bar(Class cls, unsigned short ush) { return new Class(); }; %}
@@ -6117,9 +6117,9 @@ Below shows an example modifying the finalizer, assuming the delete met
 %typemap(javafinalize) SWIGTYPE %{
-   protected void finalize() {
-     swig_delete();  // renamed to prevent conflict with existing delete method
-   }
+  protected void finalize() {
+    swig_delete();  // renamed to prevent conflict with existing delete method
+  }
 ]%
 
@@ -6965,45 +6965,45 @@ The following SWIG interface file allows a Java String array to be used as a
 %typemap(in) (int argc, char **argv) {
-    int i = 0;
-    $1 = (*jenv)->GetArrayLength(jenv, $input);
-    $2 = (char **) malloc(($1+1)*sizeof(char *));
-    /* make a copy of each string */
-    for (i = 0; i<$1; i++) {
-        jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, $input, i);
-        const char * c_string = (*jenv)->GetStringUTFChars(jenv, j_string, 0);
-        $2[i] = malloc((strlen(c_string)+1)*sizeof(char));
-        strcpy($2[i], c_string);
-        (*jenv)->ReleaseStringUTFChars(jenv, j_string, c_string);
-        (*jenv)->DeleteLocalRef(jenv, j_string);
-    }
-    $2[i] = 0;
+  int i = 0;
+  $1 = (*jenv)->GetArrayLength(jenv, $input);
+  $2 = (char **) malloc(($1+1)*sizeof(char *));
+  /* make a copy of each string */
+  for (i = 0; i<$1; i++) {
+    jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, $input, i);
+    const char * c_string = (*jenv)->GetStringUTFChars(jenv, j_string, 0);
+    $2[i] = malloc((strlen(c_string)+1)*sizeof(char));
+    strcpy($2[i], c_string);
+    (*jenv)->ReleaseStringUTFChars(jenv, j_string, c_string);
+    (*jenv)->DeleteLocalRef(jenv, j_string);
+  }
+  $2[i] = 0;
 }
 
 %typemap(freearg) (int argc, char **argv) {
-    int i;
-    for (i=0; i<$1-1; i++)
-      free($2[i]);
-    free($2);
+  int i;
+  for (i=0; i<$1-1; i++)
+    free($2[i]);
+  free($2);
 }
 
 %typemap(jni) (int argc, char **argv) "jobjectArray"
@@ -7211,7 +7211,7 @@ If we define a structure MyDouble containing a double member v
 /* Define a new structure to use instead of double * */
 %inline %{
 typedef struct {
-    double value;
+  double value;
 } MyDouble;
 %}
 
@@ -7232,12 +7232,12 @@ argument of MyDouble instead of double *. This will
 allow the calling function to read the double * value after returning from the function.
 */
 %typemap(in) double *OUTVALUE {
-    jclass clazz = jenv->FindClass("MyDouble");
-    jfieldID fid = jenv->GetFieldID(clazz, "swigCPtr", "J");
-    jlong cPtr = jenv->GetLongField($input, fid);
-    MyDouble *pMyDouble = NULL;
-    *(MyDouble **)&pMyDouble = *(MyDouble **)&cPtr;
-    $1 = &pMyDouble->value;
+  jclass clazz = jenv->FindClass("MyDouble");
+  jfieldID fid = jenv->GetFieldID(clazz, "swigCPtr", "J");
+  jlong cPtr = jenv->GetLongField($input, fid);
+  MyDouble *pMyDouble = NULL;
+  *(MyDouble **)&pMyDouble = *(MyDouble **)&cPtr;
+  $1 = &pMyDouble->value;
 }
 
 %typemap(jtype) double *OUTVALUE "MyDouble"
@@ -7310,25 +7310,25 @@ Let's examine this with the following code:
 using namespace std;
 class Vehicle {
 public:
-    virtual void start() = 0;
+  virtual void start() = 0;
 ...
 };
 
 class Ambulance : public Vehicle {
-    string vol;
+  string vol;
 public:
-    Ambulance(string volume) : vol(volume) {}
-    virtual void start() {
-        cout << "Ambulance started" << endl;
-    }
-    void sound_siren() {
-        cout << vol << " siren sounded!" << endl;
-    }
+  Ambulance(string volume) : vol(volume) {}
+  virtual void start() {
+    cout << "Ambulance started" << endl;
+  }
+  void sound_siren() {
+    cout << vol << " siren sounded!" << endl;
+  }
 ...
 };
 
 Vehicle *vehicle_factory() {
-    return new Ambulance("Very loud");
+  return new Ambulance("Very loud");
 }
 
@@ -7368,18 +7368,18 @@ The first is not to use a Java cast but a call to C++ to make the cast. Add this
 %exception Ambulance::dynamic_cast(Vehicle *vehicle) {
-    $action
+  $action
     if (!result) {
-        jclass excep = jenv->FindClass("java/lang/ClassCastException");
-        if (excep) {
-            jenv->ThrowNew(excep, "dynamic_cast exception");
-        }
+      jclass excep = jenv->FindClass("java/lang/ClassCastException");
+      if (excep) {
+        jenv->ThrowNew(excep, "dynamic_cast exception");
+      }
     }
 }
 %extend Ambulance {
-    static Ambulance *dynamic_cast(Vehicle *vehicle) {
-        return dynamic_cast<Ambulance *>(vehicle);
-    }
+  static Ambulance *dynamic_cast(Vehicle *vehicle) {
+    return dynamic_cast<Ambulance *>(vehicle);
+  }
 };
 
@@ -7400,8 +7400,8 @@ Add the following before the definition of vehicle_factory:
 %typemap(out) Vehicle * {
-    Ambulance *downcast = dynamic_cast<Ambulance *>($1);
-    *(Ambulance **)&$result = downcast;
+  Ambulance *downcast = dynamic_cast<Ambulance *>($1);
+  *(Ambulance **)&$result = downcast;
 }
 
 %typemap(javaout) Vehicle * {
@@ -7418,20 +7418,20 @@ Consider expanding our example with a new Vehicle type and a more flexible facto
 
 class FireEngine : public Vehicle {
 public:
-    FireEngine() {}
-    virtual void start() {
-        cout << "FireEngine started" << endl;
-    }
-    void roll_out_hose() {
-        cout << "Hose rolled out" << endl;
-    }
- ...
+  FireEngine() {}
+  virtual void start() {
+    cout << "FireEngine started" << endl;
+  }
+  void roll_out_hose() {
+    cout << "Hose rolled out" << endl;
+  }
+  ...
 };
 Vehicle *vehicle_factory(int vehicle_number) {
-    if (vehicle_number == 0)
-        return new Ambulance("Very loud");
-    else
-        return new FireEngine();
+  if (vehicle_number == 0)
+    return new Ambulance("Very loud");
+  else
+    return new FireEngine();
 }
 
@@ -7460,37 +7460,37 @@ Note that in this case, the Java class is constructed using JNI code rather than } %typemap(out) Vehicle *vehicle_factory { - Ambulance *ambulance = dynamic_cast<Ambulance *>($1); - FireEngine *fireengine = dynamic_cast<FireEngine *>($1); - if (ambulance) { - // call the Ambulance(long cPtr, boolean cMemoryOwn) constructor - jclass clazz = jenv->FindClass("Ambulance"); - if (clazz) { - jmethodID mid = jenv->GetMethodID(clazz, "<init>", "(JZ)V"); - if (mid) { - jlong cptr = 0; - *(Ambulance **)&cptr = ambulance; - $result = jenv->NewObject(clazz, mid, cptr, false); - } - } - } else if (fireengine) { - // call the FireEngine(long cPtr, boolean cMemoryOwn) constructor - jclass clazz = jenv->FindClass("FireEngine"); - if (clazz) { - jmethodID mid = jenv->GetMethodID(clazz, "<init>", "(JZ)V"); - if (mid) { - jlong cptr = 0; - *(FireEngine **)&cptr = fireengine; - $result = jenv->NewObject(clazz, mid, cptr, false); - } - } + Ambulance *ambulance = dynamic_cast<Ambulance *>($1); + FireEngine *fireengine = dynamic_cast<FireEngine *>($1); + if (ambulance) { + // call the Ambulance(long cPtr, boolean cMemoryOwn) constructor + jclass clazz = jenv->FindClass("Ambulance"); + if (clazz) { + jmethodID mid = jenv->GetMethodID(clazz, "<init>", "(JZ)V"); + if (mid) { + jlong cptr = 0; + *(Ambulance **)&cptr = ambulance; + $result = jenv->NewObject(clazz, mid, cptr, false); + } } - else { - cout << "Unexpected type " << endl; + } else if (fireengine) { + // call the FireEngine(long cPtr, boolean cMemoryOwn) constructor + jclass clazz = jenv->FindClass("FireEngine"); + if (clazz) { + jmethodID mid = jenv->GetMethodID(clazz, "<init>", "(JZ)V"); + if (mid) { + jlong cptr = 0; + *(FireEngine **)&cptr = fireengine; + $result = jenv->NewObject(clazz, mid, cptr, false); + } } + } + else { + cout << "Unexpected type " << endl; + } - if (!$result) - cout << "Failed to create new java object" << endl; + if (!$result) + cout << "Failed to create new java object" << endl; }
@@ -7523,7 +7523,7 @@ Pure Java code methods like these can be easily added: return equal; } public int hashCode() { - return (int)getPointer(); + return (int)getPointer(); } %} @@ -7656,11 +7656,11 @@ The following Java code shows how we intend the code to be used:
-    Butler jeeves = new Butler();
-    example.HireButler(jeeves);
-    System.out.println("Greeting:     " + jeeves.getGreeting());
-    System.out.println("Availability: " + jeeves.getHoursAvailable() + " hours per day");
-    example.FireButler(jeeves);
+Butler jeeves = new Butler();
+example.HireButler(jeeves);
+System.out.println("Greeting:     " + jeeves.getGreeting());
+System.out.println("Availability: " + jeeves.getHoursAvailable() + " hours per day");
+example.FireButler(jeeves);
 
@@ -7771,8 +7771,8 @@ To implement this, we use the above interface file code but remove the javac return pButler; } ~Butler() { - FireButler($self); - } + FireButler($self); + } }
@@ -7818,12 +7818,12 @@ and the following usage from Java after running the code through SWIG:
-    Wheel wheel = new Bike(10).getWheel();
-    System.out.println("wheel size: " + wheel.getSize());
-    // Simulate a garbage collection
-    System.gc();
-    System.runFinalization();
-    System.out.println("wheel size: " + wheel.getSize());
+Wheel wheel = new Bike(10).getWheel();
+System.out.println("wheel size: " + wheel.getSize());
+// Simulate a garbage collection
+System.gc();
+System.runFinalization();
+System.out.println("wheel size: " + wheel.getSize());
 
@@ -7861,13 +7861,13 @@ is called using the following typemaps. // of dangling C++ pointer. Intended for methods that return pointers or // references to a member variable. %typemap(javaout) Wheel& getWheel { - long cPtr = $jnicall; - $javaclassname ret = null; - if (cPtr != 0) { - ret = new $javaclassname(cPtr, $owner); - ret.addReference(this); - } - return ret; + long cPtr = $jnicall; + $javaclassname ret = null; + if (cPtr != 0) { + ret = new $javaclassname(cPtr, $owner); + ret.addReference(this); + } + return ret; } @@ -7938,10 +7938,10 @@ and usage from C++
-    Container container;
-    Element element(20);
-    container.setElement(&element);
-    cout << "element.value: " << container.getElement()->value << endl;
+Container container;
+Element element(20);
+container.setElement(&element);
+cout << "element.value: " << container.getElement()->value << endl;
 
@@ -7951,9 +7951,9 @@ and more or less equivalent usage from Java
-    Container container = new Container();
-    container.setElement(new Element(20));
-    System.out.println("element value: " + container.getElement().getValue());
+Container container = new Container();
+container.setElement(new Element(20));
+System.out.println("element value: " + container.getElement().getValue());
 
@@ -7964,12 +7964,12 @@ In order to understand why, consider a garbage collection occuring...
-    Container container = new Container();
-    container.setElement(new Element(20));
-    // Simulate a garbage collection
-    System.gc();
-    System.runFinalization();
-    System.out.println("element value: " + container.getElement().getValue());
+Container container = new Container();
+container.setElement(new Element(20));
+// Simulate a garbage collection
+System.gc();
+System.runFinalization();
+System.out.println("element value: " + container.getElement().getValue());
 
@@ -8095,7 +8095,7 @@ From Java, the intention is then to call into a modifed API with something like:
 java.util.GregorianCalendar calendarIn = 
-    new java.util.GregorianCalendar(2011, java.util.Calendar.APRIL, 13, 0, 0, 0);
+  new java.util.GregorianCalendar(2011, java.util.Calendar.APRIL, 13, 0, 0, 0);
 java.util.GregorianCalendar calendarOut = new java.util.GregorianCalendar();
 
 // Note in calls below, calendarIn remains unchanged and calendarOut 
@@ -8315,7 +8315,7 @@ public class FooDerived extends Foo {
   public static FooDerived downcastFooDerived(Foo foo_object)
   {
     try {
-     return (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object);
+      return foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object);
     }
 
     catch (ClassCastException exc) {
@@ -8366,10 +8366,8 @@ public abstract class UserVisibleFoo extends Foo {
   public static UserVisibleFoo downcastUserVisibleFoo(Foo foo_object)
   {
     try {
-     return (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null);
-    }
-
-    catch (ClassCastException exc) {
+      return foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null;
+    } catch (ClassCastException exc) {
       // Wasn't a FooDerived object, some other subclass of Foo
       return null;
     }
@@ -8457,8 +8455,8 @@ Consider the example we looked at when examining proxy classes:
 
 class Foo {
 public:
-     int x;
-     int spam(int num, Foo* foo);
+  int x;
+  int spam(int num, Foo* foo);
 };
 
diff --git a/Doc/Manual/Javascript.html b/Doc/Manual/Javascript.html index 16f674892..c133718d5 100644 --- a/Doc/Manual/Javascript.html +++ b/Doc/Manual/Javascript.html @@ -300,34 +300,34 @@ extern bool example_initialize(JSGlobalContextRef context); int main(int argc, char* argv[]) { - // Initialize GTK+ - gtk_init(&argc, &argv); + // Initialize GTK+ + gtk_init(&argc, &argv); - ... + ... - // Create a browser instance - WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); - WebFrame *webframe = webkit_web_view_get_main_frame(webView); - JSGlobalContextRef context = webkit_web_frame_get_global_context(webFrame); - JSObjectRef global = JSContextGetGlobalObject(context); + // Create a browser instance + WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + WebFrame *webframe = webkit_web_view_get_main_frame(webView); + JSGlobalContextRef context = webkit_web_frame_get_global_context(webFrame); + JSObjectRef global = JSContextGetGlobalObject(context); - JSObjectRef exampleModule; - example_initialize(context, &exampleModule); - JSStringRef jsName = JSStringCreateWithUTF8CString("example"); - JSObjectSetProperty(context, global, jsName, exampleModule, kJSPropertyAttributeReadOnly, NULL); - JSStringRelease(jsName); + JSObjectRef exampleModule; + example_initialize(context, &exampleModule); + JSStringRef jsName = JSStringCreateWithUTF8CString("example"); + JSObjectSetProperty(context, global, jsName, exampleModule, kJSPropertyAttributeReadOnly, NULL); + JSStringRelease(jsName); - ... + ... - // Load a web page into the browser instance - webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/"); + // Load a web page into the browser instance + webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/"); - ... + ... - // Run the main GTK+ event loop - gtk_main(); + // Run the main GTK+ event loop + gtk_main(); - return 0; + return 0; } diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 954de54f7..a9c827add 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -218,13 +218,13 @@ interface is as follows:
 struct name {
-   name();                            // Create pointer object
-  ~name();                            // Delete pointer object
-   void assign(type value);           // Assign value
-   type value();                      // Get value
-   type *cast();                      // Cast the pointer to original type
-   static name *frompointer(type *);  // Create class wrapper from existing
-                                      // pointer
+  name();                            // Create pointer object
+  ~name();                           // Delete pointer object
+  void assign(type value);           // Assign value
+  type value();                      // Get value
+  type *cast();                      // Cast the pointer to original type
+  static name *frompointer(type *);  // Create class wrapper from existing
+                                     // pointer
 };
 
@@ -384,10 +384,10 @@ function like this:
 void print_array(double x[10]) {
-   int i;
-   for (i = 0; i < 10; i++) {
-      printf("[%d] = %g\n", i, x[i]);
-   }
+  int i;
+  for (i = 0; i < 10; i++) {
+    printf("[%d] = %g\n", i, x[i]);
+  }
 }
 
@@ -436,13 +436,13 @@ interface is as follows:
 struct name {
-   name(int nelements);                  // Create an array
-  ~name();                               // Delete array
-   type getitem(int index);              // Return item
-   void setitem(int index, type value);  // Set item
-   type *cast();                         // Cast to original type
-   static name *frompointer(type *);     // Create class wrapper from
-                                         // existing pointer
+  name(int nelements);                  // Create an array
+  ~name();                              // Delete array
+  type getitem(int index);              // Return item
+  void setitem(int index, type value);  // Set item
+  type *cast();                         // Cast to original type
+  static name *frompointer(type *);     // Create class wrapper from
+                                        // existing pointer
 };
 
@@ -874,9 +874,9 @@ If you have a function that allocates memory like this,
 char *foo() {
-   char *result = (char *) malloc(...);
-   ...
-   return result;
+  char *result = (char *) malloc(...);
+  ...
+  return result;
 }
 
@@ -919,16 +919,16 @@ implementation:
 void get_path(char *s) {
-    // Potential buffer overflow---uh, oh.
-    sprintf(s,"%s/%s", base_directory, sub_directory);
+  // Potential buffer overflow---uh, oh.
+  sprintf(s,"%s/%s", base_directory, sub_directory);
 }
 ...
 // Somewhere else in the C program
 {
-    char path[1024];
-    ...
-    get_path(path);
-    ...
+  char path[1024];
+  ...
+  get_path(path);
+  ...
 }
 
@@ -1236,8 +1236,8 @@ returned in a parameter of type char **. For example:
 void foo(char **s) {
-    *s = (char *) malloc(64);
-    sprintf(*s, "Hello world\n");
+  *s = (char *) malloc(64);
+  sprintf(*s, "Hello world\n");
 }
 
@@ -1284,10 +1284,10 @@ returned in two parameters of type char ** and int *. For exa
 void foo(char **s, int *sz) {
-    *s = (char *) malloc(64);
-    *sz = 64;
-    // Write some binary data
-    ...
+  *s = (char *) malloc(64);
+  *sz = 64;
+  // Write some binary data
+  ...
 }
 
@@ -1337,7 +1337,7 @@ You could wrap it with a function like this:
 void my_get_data(char **result, int *len) {
-   *result = get_data(len);
+  *result = get_data(len);
 }
 
@@ -1503,8 +1503,8 @@ instantiate different versions of vector for the types that you want to %include "std_vector.i" namespace std { - %template(vectori) vector<int>; - %template(vectord) vector<double>; + %template(vectori) vector<int>; + %template(vectord) vector<double>; }; @@ -1554,19 +1554,19 @@ To illustrate the use of this library, consider the following functions: #include <numeric> double average(std::vector<int> v) { - return std::accumulate(v.begin(),v.end(),0.0)/v.size(); + return std::accumulate(v.begin(),v.end(),0.0)/v.size(); } std::vector<double> half(const std::vector<double>& v) { - std::vector<double> w(v); - for (unsigned int i=0; i<w.size(); i++) - w[i] /= 2.0; - return w; + std::vector<double> w(v); + for (unsigned int i=0; i<w.size(); i++) + w[i] /= 2.0; + return w; } void halve_in_place(std::vector<double>& v) { - std::transform(v.begin(),v.end(),v.begin(), - std::bind2nd(std::divides<double>(),2.0)); + std::transform(v.begin(),v.end(),v.begin(), + std::bind2nd(std::divides<double>(),2.0)); } @@ -1585,8 +1585,8 @@ To wrap with SWIG, you might write the following: %include "std_vector.i" // Instantiate templates used by example namespace std { - %template(IntVector) vector<int>; - %template(DoubleVector) vector<double>; + %template(IntVector) vector<int>; + %template(DoubleVector) vector<double>; } // Include the header file with above prototypes @@ -1645,7 +1645,7 @@ make sure you include the appropriate using or typedef directives. For %include "std_vector.i" namespace std { - %template(IntVector) vector<int>; + %template(IntVector) vector<int>; } using namespace std; @@ -2011,11 +2011,11 @@ For example:
 %include "exception.i"
 %exception std::vector::getitem {
-    try {
-        $action
-    } catch (std::out_of_range& e) {
-        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
-    }
+  try {
+    $action
+  } catch (std::out_of_range& e) {
+    SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
+  }
 }
 
diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 0867ba926..190e7bdfb 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -134,17 +134,16 @@ typedef int days; struct bar { short p, q; - char a, b; - int *z[1000]; - struct bar * n; + char a, b; + int *z[1000]; + struct bar * n; }; struct bar * my_struct; struct foo { - int a; - struct foo * b[100]; - + int a; + struct foo * b[100]; }; int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int p); @@ -436,44 +435,41 @@ Various features which were available for C headers can also be used
 namespace OpenDemo {
   class Test
-    {
+  {
     public:
-        float x;
-        // constructors
-        Test (void) {x = 0;}
-        Test (float X) {x = X;}
+      float x;
+      // constructors
+      Test (void) {x = 0;}
+      Test (float X) {x = X;}
 
-        // vector addition
-        Test operator+ (const Test& v) const {return Test (x+v.x);}
+      // vector addition
+      Test operator+ (const Test& v) const {return Test (x+v.x);}
 
       // length squared
-        float lengthSquared (void) const {return this->dot (*this);}
+      float lengthSquared (void) const {return this->dot (*this);}
 
-        static float distance (const Test& a, const Test& b){return(a-b).length();}
+      static float distance (const Test& a, const Test& b){return(a-b).length();}
 
-        inline Test parallelComponent (const Test& unitBasis) const {
-          return unitBasis * projection;
-        }
+      inline Test parallelComponent (const Test& unitBasis) const {
+        return unitBasis * projection;
+      }
 
-        Test setYtoZero (void) const {return Test (this->x);}
+      Test setYtoZero (void) const {return Test (this->x);}
 
-        static const Test zero;
-    };
+      static const Test zero;
+  };
 
+  inline Test operator* (float s, const Test& v) {return v*s;}
 
-   inline Test operator* (float s, const Test& v) {return v*s;}
+  inline std::ostream& operator<< (std::ostream& o, const Test& v)
+  {
+    return o << "(" << v.x << ")";
+  }
 
-
-    inline std::ostream& operator<< (std::ostream& o, const Test& v)
-    {
-        return o << "(" << v.x << ")";
-    }
-
-
-    inline Test RandomUnitVectorOnXZPlane (void)
-    {
-        return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();
-    }
+  inline Test RandomUnitVectorOnXZPlane (void)
+  {
+    return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();
+  }
 }
 

The interface used is:

@@ -778,10 +774,10 @@ The module also handles strutcures and #define constants as shown

 struct bar {
-    short x, y;
-    char a, b;
-    int *z[1000];
-    struct bar * n;
+  short x, y;
+  char a, b;
+  int *z[1000];
+  struct bar * n;
 };
 
 #define max 1000
diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html
index 004ca6f2b..131d92825 100644
--- a/Doc/Manual/Lua.html
+++ b/Doc/Manual/Lua.html
@@ -521,9 +521,9 @@ Enums are exported into a class table. For example, given some enums:
 
%module example
 enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
 struct Test {
-    enum { TEST1 = 10, TEST2 = 20 };
+  enum { TEST1 = 10, TEST2 = 20 };
 #ifdef __cplusplus // There are no static members in C
-    static const int ICONST = 12;
+  static const int ICONST = 12;
 #endif
 };
 
@@ -645,12 +645,12 @@ Like the pointer in the previous section, this is held as a userdata. However, a const members of a structure are read-only. Data members can also be forced to be read-only using the immutable directive. As with other immutables, setting attempts will be cause an error. For example:

struct Foo {
-   ...
-   %immutable;
-   int x;        // Read-only members
-   char *name;
-   %mutable;
-   ...
+  ...
+  %immutable;
+  int x;        // Read-only members
+  char *name;
+  %mutable;
+  ...
 };
 

@@ -661,11 +661,11 @@ When a member of a structure is itself a structure, it is handled as a pointer.

struct Foo {
-   int a;
+  int a;
 };
 
 struct Bar {
-   Foo f;
+  Foo f;
 };
 

@@ -695,8 +695,8 @@ Because the pointer points inside the structure, you can modify the contents and 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;
+  int x, y;
+  double z;
 };
 
 > --From eLua
@@ -749,8 +749,8 @@ Class data members are accessed in the same manner as C structures. Static class
 

class Spam {
 public:
-   static void foo();
-   static int bar;
+  static void foo();
+  static int bar;
 };
 

@@ -871,9 +871,9 @@ Similarly, if you have a class like this,

class Foo {
 public:
-    Foo();
-    Foo(const Foo &);
-    ...
+  Foo();
+  Foo(const Foo &);
+  ...
 };
 

@@ -1090,13 +1090,14 @@ public: Now we extend it with some new code

%extend Complex {
-   const char *__str__() {
-       static char tmp[1024];
-       sprintf(tmp,"Complex(%g,%g)", $self->re(),$self->im());
-       return tmp;
-   }
-   bool operator==(const Complex& c)
-   {    return ($self->re()==c.re() && $self->im()==c.im());}
+  const char *__str__() {
+    static char tmp[1024];
+    sprintf(tmp,"Complex(%g,%g)", $self->re(),$self->im());
+    return tmp;
+  }
+  bool operator==(const Complex& c) {
+    return ($self->re()==c.re() && $self->im()==c.im());
+  }
 };
 

@@ -1123,9 +1124,9 @@ Extend works with both C and C++ code, on classes and structs. It does not modif

If you have a function that allocates memory like this,

char *foo() {
-   char *result = (char *) malloc(...);
-   ...
-   return result;
+  char *result = (char *) malloc(...);
+  ...
+  return result;
 }
 
@@ -1154,12 +1155,12 @@ char *foo(); template<class T1, class T2> struct pair { - typedef T1 first_type; - typedef T2 second_type; - T1 first; - T2 second; - pair(); - pair(const T1&, const T2&); + typedef T1 first_type; + typedef T2 second_type; + T1 first; + T2 second; + pair(); + pair(const T1&, const T2&); ~pair(); }; @@ -1183,9 +1184,9 @@ Obviously, there is more to template wrapping than shown in this example. More d In certain C++ programs, it is common to use classes that have been wrapped by so-called "smart pointers." Generally, this involves the use of a template class that implements operator->() like this:

template<class T> class SmartPtr {
-   ...
-   T *operator->();
-   ...
+  ...
+  T *operator->();
+  ...
 }
 

@@ -1193,8 +1194,8 @@ Then, if you have a class like this,

class Foo {
 public:
-     int x;
-     int bar();
+  int x;
+  int bar();
 };
 

@@ -1564,17 +1565,17 @@ Received an integer : 6

However for more complex functions which use input/output parameters or arrays, you will need to make use of <typemaps.i>, which contains typemaps for these situations. For example, consider these functions:

void add(int x, int y, int *result) {
-   *result = x + y;
+  *result = x + y;
 }
 
 int sub(int *x1, int *y1) {
-   return *x1-*y1;
+  return *x1-*y1;
 }
 
 void swap(int *sx, int *sy) {
-   int t=*sx;
-   *sx=*sy;
-   *sy=t;
+  int t=*sx;
+  *sx=*sy;
+  *sy=t;
 }
 
@@ -1739,7 +1740,7 @@ ptr=nil -- the iMath* will be GC'ed as normal
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() +This returns a value which can be checked with the macro SWIG_IsOK()

void SWIG_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type,int own);

diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index c5c199262..08402b68c 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -36,12 +36,12 @@ Example interface file: /* define a macro for the struct creation */ %define handle_ptr(TYPE,NAME) %typemap(argout) TYPE *NAME{ - Scheme_Object *o = SWIG_NewStructFromPtr($1, $*1_mangle); - SWIG_APPEND_VALUE(o); + Scheme_Object *o = SWIG_NewStructFromPtr($1, $*1_mangle); + SWIG_APPEND_VALUE(o); } %typemap(in,numinputs=0) TYPE *NAME (TYPE temp) { - $1 = &temp; + $1 = &temp; } %enddef diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 9b9744f65..25ec933ff 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -56,7 +56,7 @@ More information can be found at
O

- This chapter is intended to give an introduction to using the module. You should also read the SWIG documentation that is not specific to Octave. +This chapter is intended to give an introduction to using the module. You should also read the SWIG documentation that is not specific to Octave. Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).

@@ -314,7 +314,7 @@ swigexample.SUNDAY=0

C/C++ pointers are fully supported by SWIG. Furthermore, SWIG has no problem working with incomplete type information. Given a wrapping of the <file.h> interface: - C/C++ pointers are fully supported by SWIG. Furthermore, SWIG has no problem working with incomplete type information. Given a wrapping of the <file.h> interface: + C/C++ pointers are fully supported by SWIG. Furthermore, SWIG has no problem working with incomplete type information. Given a wrapping of the <file.h> interface:

%module swigexample
@@ -663,10 +663,10 @@ For example, function templates can be instantiated as follows:
 
 
%module swigexample
 %inline {
- template<class __scalar>
-   __scalar mul(__scalar a,__scalar b) {
-   return a*b;
- }
+  template<class __scalar>
+    __scalar mul(__scalar a,__scalar b) {
+    return a*b;
+  }
 }
 %include <std_complex.i>
 %template(mul) mul<std::complex<double> >
diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html
index 8d7b866d6..4722a01ba 100644
--- a/Doc/Manual/Perl5.html
+++ b/Doc/Manual/Perl5.html
@@ -940,12 +940,12 @@ example:
 %inline %{
 /* C-style cast */
 Bar *FooToBar(Foo *f) {
-   return (Bar *) f;
+  return (Bar *) f;
 }
 
 /* C++-style cast */
 Foo *BarToFoo(Bar *b) {
-   return dynamic_cast<Foo*>(b);
+  return dynamic_cast<Foo*>(b);
 }
 
 Foo *IncrFoo(Foo *f, int i) {
@@ -1020,12 +1020,12 @@ can also be forced to be read-only using the %immutable directive. For
 
 struct Foo {
-   ...
-   %immutable;
-   int x;        /* Read-only members */
-   char *name;
-   %mutable;
-   ...
+  ...
+  %immutable;
+  int x;        /* Read-only members */
+  char *name;
+  %mutable;
+  ...
 };
 
@@ -1045,7 +1045,7 @@ Array members are normally wrapped as read-only. For example,
 struct Foo {
-   int  x[50];
+  int x[50];
 };
 
@@ -1076,11 +1076,11 @@ When structure members are wrapped, they are handled as pointers. For example,
 struct Foo {
-   ...
+  ...
 };
 
 struct Bar {
-   Foo f;
+  Foo f;
 };
 
@@ -1222,9 +1222,9 @@ void foo(char *c); // Stays 'foo' (not renamed) class Spam { public: - void foo(int); // Becomes 'foo_i' - void foo(double); // Becomes 'foo_d' - ... + void foo(int); // Becomes 'foo_i' + void foo(double); // Becomes 'foo_d' + ... };
@@ -1380,7 +1380,7 @@ example:
 void add(int x, int y, int *result) {
-   *result = x + y;
+  *result = x + y;
 }
 
@@ -1392,7 +1392,7 @@ or perhaps
 int sub(int *x, int *y) {
-   return *x+*y;
+  return *x+*y;
 }
 
@@ -1456,7 +1456,7 @@ If a function mutates one of its parameters like this,
 void negate(int *x) {
-   *x = -(*x);
+  *x = -(*x);
 }
 
@@ -1614,7 +1614,7 @@ class DoubleArray { } // Destroy an array ~DoubleArray() { - delete ptr; + delete ptr; } // Return the length of the array int length() { @@ -2173,11 +2173,11 @@ reference to be used as a char ** datatype. int i = 0,len = 0; /* Figure out how many elements we have */ while ($1[len]) - len++; + len++; svs = (SV **) malloc(len*sizeof(SV *)); for (i = 0; i < len ; i++) { - svs[i] = sv_newmortal(); - sv_setpv((SV*)svs[i],$1[i]); + svs[i] = sv_newmortal(); + sv_setpv((SV*)svs[i],$1[i]); }; myav = av_make(len,svs); free(svs); @@ -2188,20 +2188,20 @@ reference to be used as a char ** datatype. // Now a few test functions %inline %{ -int print_args(char **argv) { + int print_args(char **argv) { int i = 0; while (argv[i]) { - printf("argv[%d] = %s\n", i,argv[i]); - i++; + printf("argv[%d] = %s\n", i,argv[i]); + i++; } return i; -} + } -// Returns a char ** list -char **get_args() { + // Returns a char ** list + char **get_args() { static char *values[] = { "Dave", "Mike", "Susan", "John", "Michelle", 0}; return &values[0]; -} + } %}
@@ -2349,10 +2349,10 @@ For example:
 %typemap(memberin) int [ANY] {
-   int i;
-   for (i = 0; i < $1_dim0; i++) {
-      $1[i] = $input[i];
-   }
+  int i;
+  for (i = 0; i < $1_dim0; i++) {
+    $1[i] = $input[i];
+  }
 }
 
@@ -2477,7 +2477,9 @@ is usually accessed as follows:
 Foo *f;
-if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, 0) == -1) return NULL;
+if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, 0))) {
+  SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
+}
 
 SV *sv = sv_newmortal();
 SWIG_MakePtr(sv, f, SWIGTYPE_p_Foo, 0);
@@ -2492,7 +2494,9 @@ variable $1_descriptor.  For example:
 
 %typemap(in) Foo * {
-   if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) return NULL;
+  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
+    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
+  }
 }
 
@@ -2505,7 +2509,9 @@ For example:
 %typemap(in) Foo * {
-   if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 0)) == -1) return NULL;
+  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $descriptor(Foo *), 0))) {
+    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
+  }
 }
 
@@ -2997,9 +3003,9 @@ low-level helper functions. For example, this code now seems to work:
 my $a =
   [[1,0,0,0],
-   [0,1,0,0],
-   [0,0,1,0],
-   [0,0,0,1]];
+  [0,1,0,0],
+  [0,0,1,0],
+  [0,0,0,1]];
 set_transform($im, $a);
 
diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 8c483b7a0..56a6ba530 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -995,7 +995,7 @@ require("mymodule.php"); class MyFoo extends Foo { function one() { - print "one from php\n"; + print "one from php\n"; } }
diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html index 2538f8f18..8eaed7f4f 100644 --- a/Doc/Manual/Preprocessor.html +++ b/Doc/Manual/Preprocessor.html @@ -225,16 +225,16 @@ For example: %define ARRAYHELPER(type,name) %inline %{ type *new_ ## name (int nitems) { - return (type *) malloc(sizeof(type)*nitems); + return (type *) malloc(sizeof(type)*nitems); } void delete_ ## name(type *t) { - free(t); + free(t); } type name ## _get(type *t, int index) { - return t[index]; + return t[index]; } void name ## _set(type *t, int index, type val) { - t[index] = val; + t[index] = val; } %} %enddef @@ -334,7 +334,7 @@ if you write code like this, %{ #ifdef NEED_BLAH int blah() { - ... + ... } #endif %} @@ -358,11 +358,11 @@ file. For example:
 %extend Foo {
-   void bar() {
-      #ifdef DEBUG
-       printf("I'm in bar\n");
-      #endif
-   }
+  void bar() {
+    #ifdef DEBUG
+      printf("I'm in bar\n");
+    #endif
+  }
 }
 
@@ -375,11 +375,11 @@ to actually go into the wrapper file, prefix the preprocessor directives with
 %extend Foo {
-   void bar() {
-      %#ifdef DEBUG
-       printf("I'm in bar\n");
-      %#endif
-   }
+  void bar() {
+    %#ifdef DEBUG
+      printf("I'm in bar\n");
+    %#endif
+  }
 }
 
diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index cf0f86024..b6df0895f 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -1262,12 +1262,12 @@ consider writing some helper functions instead. For example: %inline %{ /* C-style cast */ Bar *FooToBar(Foo *f) { - return (Bar *) f; + return (Bar *) f; } /* C++-style cast */ Foo *BarToFoo(Bar *b) { - return dynamic_cast<Foo*>(b); + return dynamic_cast<Foo*>(b); } Foo *IncrFoo(Foo *f, int i) { @@ -1355,12 +1355,12 @@ can also be forced to be read-only using the %immutable directive. For
 struct Foo {
-   ...
-   %immutable;
-   int x;        /* Read-only members */
-   char *name;
-   %mutable;
-   ...
+  ...
+  %immutable;
+  int x;        /* Read-only members */
+  char *name;
+  %mutable;
+  ...
 };
 
@@ -1427,11 +1427,11 @@ pointer. For example, suppose you have two structures like this:
 struct Foo {
-   int a;
+  int a;
 };
 
 struct Bar {
-   Foo f;
+  Foo f;
 };
 
@@ -1525,9 +1525,8 @@ suppose you have a class like this:
 class Spam {
 public:
-   static void foo();
-   static int bar;
-
+  static void foo();
+  static int bar;
 };
 
@@ -1904,10 +1903,10 @@ submodules or packages. For example, if you have a file like this, %module example namespace foo { - int fact(int n); - struct Vector { - double x,y,z; - }; + int fact(int n); + struct Vector { + double x,y,z; + }; }; @@ -1976,13 +1975,13 @@ For example: template<class T1, class T2> struct pair { - typedef T1 first_type; - typedef T2 second_type; - T1 first; - T2 second; - pair(); - pair(const T1&, const T2&); - ~pair(); + typedef T1 first_type; + typedef T2 second_type; + T1 first; + T2 second; + pair(); + pair(const T1&, const T2&); + ~pair(); }; %template(pairii) pair<int,int>; @@ -2037,9 +2036,9 @@ that implements operator->() like this:
 template<class T> class SmartPtr {
-   ...
-   T *operator->();
-   ...
+  ...
+  T *operator->();
+  ...
 }
 
@@ -2052,8 +2051,8 @@ Then, if you have a class like this,
 class Foo {
 public:
-     int x;
-     int bar();
+  int x;
+  int bar();
 };
 
@@ -2154,9 +2153,9 @@ have a class like this
 class Foo {
 public:
-     int x;
-     int spam(int);
-     ...
+    int x;
+    int spam(int);
+    ...
 
@@ -2749,10 +2748,10 @@ change the ownership of an object. For instance, consider code like this:
 class Node {
-   Object *value;
+  Object *value;
 public:
-   void set_value(Object *v) { value = v; }
-   ...
+  void set_value(Object *v) { value = v; }
+  ...
 };
 
@@ -3319,16 +3318,16 @@ functions. Just use the %inline directive. For example: %inline %{ /* Note: double[4][4] is equivalent to a pointer to an array double (*)[4] */ double (*new_mat44())[4] { - return (double (*)[4]) malloc(16*sizeof(double)); + return (double (*)[4]) malloc(16*sizeof(double)); } void free_mat44(double (*x)[4]) { - free(x); + free(x); } void mat44_set(double x[4][4], int i, int j, double v) { - x[i][j] = v; + x[i][j] = v; } double mat44_get(double x[4][4], int i, int j) { - return x[i][j]; + return x[i][j]; } %} @@ -3374,12 +3373,12 @@ void set_transform(Image *im, double x[4][4]); /* Rewrite the high level interface to set_transform */ %pythoncode %{ def set_transform(im,x): - a = new_mat44() - for i in range(4): - for j in range(4): - mat44_set(a,i,j,x[i][j]) - _example.set_transform(im,a) - free_mat44(a) + a = new_mat44() + for i in range(4): + for j in range(4): + mat44_set(a,i,j,x[i][j]) + _example.set_transform(im,a) + free_mat44(a) %} @@ -3529,11 +3528,11 @@ proxy, just before the return statement. // Add python code to bar() %feature("pythonprepend") Foo::bar(int) %{ - #do something before C++ call + #do something before C++ call %} %feature("pythonappend") Foo::bar(int) %{ - #do something after C++ call + #do something after C++ call %} @@ -3558,11 +3557,11 @@ SWIG version 1.3.28 you can use the directive forms // Add python code to bar() %pythonprepend Foo::bar(int) %{ - #do something before C++ call + #do something before C++ call %} %pythonappend Foo::bar(int) %{ - #do something after C++ call + #do something after C++ call %} @@ -3587,11 +3586,11 @@ as it will then get attached to all the overloaded C++ methods. For example: // Add python code to bar() %pythonprepend Foo::bar %{ - #do something before C++ call + #do something before C++ call %} %pythonappend Foo::bar %{ - #do something after C++ call + #do something after C++ call %} @@ -3625,22 +3624,22 @@ Here is a simple example: %} struct Vector { - double x,y,z; + double x,y,z; }; %extend Vector { - char *__str__() { - static char tmp[1024]; - sprintf(tmp,"Vector(%g,%g,%g)", $self->x,$self->y,$self->z); - return tmp; - } - Vector(double x, double y, double z) { - Vector *v = (Vector *) malloc(sizeof(Vector)); - v->x = x; - v->y = y; - v->z = z; - return v; - } + char *__str__() { + static char tmp[1024]; + sprintf(tmp,"Vector(%g,%g,%g)", $self->x,$self->y,$self->z); + return tmp; + } + Vector(double x, double y, double z) { + Vector *v = (Vector *) malloc(sizeof(Vector)); + v->x = x; + v->y = y; + v->z = z; + return v; + } }; @@ -3666,13 +3665,13 @@ For example, if you wanted to overload a Python operator, you might do this:
 %extend Vector {
-    Vector __add__(Vector *other) {
-         Vector v;
-         v.x = $self->x + other->x;
-         v.y = $self->y + other->y;
-         v.z = $self->z + other->z;
-         return v;
-    }
+  Vector __add__(Vector *other) {
+    Vector v;
+    v.x = $self->x + other->x;
+    v.y = $self->y + other->y;
+    v.z = $self->z + other->z;
+    return v;
+  }
 };
 
@@ -3716,8 +3715,8 @@ or a NULL pointer perhaps). Here is a simple example of how you might handle th %exception malloc { $action if (!result) { - PyErr_SetString(PyExc_MemoryError,"Not enough memory"); - return NULL; + PyErr_SetString(PyExc_MemoryError,"Not enough memory"); + SWIG_fail; } } void *malloc(size_t nbytes); @@ -3746,11 +3745,11 @@ that. For example:
 %exception {
-   $action
-   if (err_occurred()) {
-      PyErr_SetString(PyExc_RuntimeError, err_message());
-      return NULL;
-   }
+  $action
+  if (err_occurred()) {
+    PyErr_SetString(PyExc_RuntimeError, err_message());
+    SWIG_fail;
+  }
 }
 
@@ -3766,25 +3765,26 @@ C++ exceptions are also easy to handle. For example, you can write code like th
 %exception getitem {
-   try {
-      $action
-   } catch (std::out_of_range &e) {
-      PyErr_SetString(PyExc_IndexError, const_cast<char*>(e.what()));
-      return NULL;
-   }
+  try {
+    $action
+  } catch (std::out_of_range &e) {
+    PyErr_SetString(PyExc_IndexError, const_cast<char*>(e.what()));
+    SWIG_fail;
+  }
 }
 
 class Base {
 public:
-     Foo *getitem(int index);      // Exception handled added
-     ...
+  Foo *getitem(int index);      // Exception handled added
+  ...
 };
 

When raising a Python exception from C, use the PyErr_SetString() -function as shown above. The following exception types can be used as the first argument. +function as shown above followed by SWIG_fail. +The following exception types can be used as the first argument.

@@ -3818,6 +3818,13 @@ PyExc_ZeroDivisionError
+

+SWIG_fail is a C macro which when called within the context of SWIG wrapper function, +will jump to the error handler code. This will call any cleanup code (freeing any temp variables) +and then return from the wrapper function so that the Python interpreter can raise the Python exception. +This macro should always be called after setting a Python error in code snippets, such as typemaps and %exception, that are ultimately generated into the wrapper function. +

+

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

 void add(int x, int y, int *result) {
-   *result = x + y;
+  *result = x + y;
 }
 
@@ -3856,7 +3863,7 @@ or perhaps
 int sub(int *x, int *y) {
-   return *x-*y;
+  return *x-*y;
 }
 
@@ -3921,7 +3928,7 @@ If a function mutates one of its parameters like this,
 void negate(int *x) {
-   *x = -(*x);
+  *x = -(*x);
 }
 
@@ -4417,7 +4424,7 @@ You can refine this by supplying an optional parameter name. For example: $1 = (int) PyLong_AsLong($input); if ($1 < 0) { PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value."); - return NULL; + SWIG_fail; } } %inline %{ @@ -4457,8 +4464,8 @@ Typemaps can also be defined for groups of consecutive arguments. For example:
 %typemap(in) (char *str, int len) {
-    $1 = PyString_AsString($input);
-    $2 = PyString_Size($input);
+  $1 = PyString_AsString($input);
+  $2 = PyString_Size($input);
 };
 
 int count(char c, char *str, int len);
@@ -4750,18 +4757,18 @@ object to be used as a char ** object.
     $1 = (char **) malloc((size+1)*sizeof(char *));
     for (i = 0; i < size; i++) {
       PyObject *o = PyList_GetItem($input,i);
-      if (PyString_Check(o))
+      if (PyString_Check(o)) {
         $1[i] = PyString_AsString(PyList_GetItem($input,i));
-      else {
-        PyErr_SetString(PyExc_TypeError,"list must contain strings");
+      } else {
         free($1);
-        return NULL;
+        PyErr_SetString(PyExc_TypeError,"list must contain strings");
+        SWIG_fail;
       }
     }
     $1[i] = 0;
   } else {
     PyErr_SetString(PyExc_TypeError,"not a list");
-    return NULL;
+    SWIG_fail;
   }
 }
 
@@ -4773,12 +4780,12 @@ object to be used as a char ** object.
 // Now a test function
 %inline %{
 int print_args(char **argv) {
-    int i = 0;
-    while (argv[i]) {
-         printf("argv[%d] = %s\n", i,argv[i]);
-         i++;
-    }
-    return i;
+  int i = 0;
+  while (argv[i]) {
+    printf("argv[%d] = %s\n", i,argv[i]);
+    i++;
+  }
+  return i;
 }
 %}
 
@@ -4849,18 +4856,18 @@ previous example:
     $2 = (char **) malloc(($1+1)*sizeof(char *));
     for (i = 0; i < $1; i++) {
       PyObject *o = PyList_GetItem($input,i);
-      if (PyString_Check(o))
+      if (PyString_Check(o)) {
         $2[i] = PyString_AsString(PyList_GetItem($input,i));
-      else {
-        PyErr_SetString(PyExc_TypeError,"list must contain strings");
+      } else {
         free($2);
-        return NULL;
+        PyErr_SetString(PyExc_TypeError,"list must contain strings");
+        SWIG_fail;
       }
     }
     $2[i] = 0;
   } else {
     PyErr_SetString(PyExc_TypeError,"not a list");
-    return NULL;
+    SWIG_fail;
   }
 }
 
@@ -4995,7 +5002,7 @@ no meaningful input value), an additional typemap can be written.  For example:
 
 
 %typemap(in,numinputs=0) double *OutValue(double temp) {
-    $1 = &temp;
+  $1 = &temp;
 }
 
 
@@ -5038,12 +5045,12 @@ This too, can be handled used typemaps as follows : if (PyTuple_Check($input)) { if (!PyArg_ParseTuple($input,"dddd",temp,temp+1,temp+2,temp+3)) { PyErr_SetString(PyExc_TypeError,"tuple must have 4 elements"); - return NULL; + SWIG_fail; } $1 = &temp[0]; } else { PyErr_SetString(PyExc_TypeError,"expected a tuple."); - return NULL; + SWIG_fail; } } @@ -5077,22 +5084,22 @@ arrays of different sizes. To do this, you might write a typemap as follows: %typemap(in) double[ANY](double temp[$1_dim0]) { int i; if (!PySequence_Check($input)) { - PyErr_SetString(PyExc_TypeError,"Expecting a sequence"); - return NULL; + PyErr_SetString(PyExc_TypeError,"Expecting a sequence"); + SWIG_fail; } if (PyObject_Length($input) != $1_dim0) { - PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements"); - return NULL; + PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements"); + SWIG_fail; } for (i =0; i < $1_dim0; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyFloat_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats"); - return NULL; - } - temp[i] = PyFloat_AsDouble(o); - Py_DECREF(o); + PyObject *o = PySequence_GetItem($input,i); + if (!PyFloat_Check(o)) { + Py_XDECREF(o); + PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats"); + SWIG_fail; + } + temp[i] = PyFloat_AsDouble(o); + Py_DECREF(o); } $1 = &temp[0]; } @@ -5123,32 +5130,32 @@ to use a helper function instead. This will greatly reduce the amount of wrappe static int convert_darray(PyObject *input, double *ptr, int size) { int i; if (!PySequence_Check(input)) { - PyErr_SetString(PyExc_TypeError,"Expecting a sequence"); - return 0; + PyErr_SetString(PyExc_TypeError,"Expecting a sequence"); + return 0; } if (PyObject_Length(input) != size) { - PyErr_SetString(PyExc_ValueError,"Sequence size mismatch"); - return 0; + PyErr_SetString(PyExc_ValueError,"Sequence size mismatch"); + return 0; } for (i =0; i < size; i++) { - PyObject *o = PySequence_GetItem(input,i); - if (!PyFloat_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats"); - return 0; - } - ptr[i] = PyFloat_AsDouble(o); - Py_DECREF(o); + PyObject *o = PySequence_GetItem(input,i); + if (!PyFloat_Check(o)) { + Py_XDECREF(o); + PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats"); + return 0; + } + ptr[i] = PyFloat_AsDouble(o); + Py_DECREF(o); } return 1; } %} %typemap(in) double [ANY](double temp[$1_dim0]) { - if (!convert_darray($input,temp,$1_dim0)) { - return NULL; - } - $1 = &temp[0]; + if (!convert_darray($input,temp,$1_dim0)) { + SWIG_fail; + } + $1 = &temp[0]; }
@@ -5201,8 +5208,9 @@ is usually accessed as follows:
 Foo *f;
-if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, SWIG_POINTER_EXCEPTION) == -1)
-  return NULL;
+if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, 0))) {
+  SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
+}
 
 PyObject *obj;
 obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
@@ -5217,8 +5225,9 @@ variable $1_descriptor.  For example:
 
 %typemap(in) Foo * {
-if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,SWIG_POINTER_EXCEPTION)) == -1)
-  return NULL;
+  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
+    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
+  }
 }
 
@@ -5231,9 +5240,9 @@ For example:
 %typemap(in) Foo * {
-if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 
-                                               SWIG_POINTER_EXCEPTION)) == -1)
-  return NULL;
+  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $descriptor(Foo *), 0))) {
+    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
+  }
 }
 
@@ -5442,7 +5451,7 @@ resulting in
 def function_name(*args, **kwargs):
-  """
+    """
     function_name(x, y, foo=None, bar=None) -> bool
 
     Parameters
diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html
index bf1705d20..ae489f574 100644
--- a/Doc/Manual/SWIG.html
+++ b/Doc/Manual/SWIG.html
@@ -1357,16 +1357,16 @@ SWIG generates the following code:
 
 /* C mode */
 void foo_set(char *value) {
-   if (foo) free(foo);
-   foo = (char *) malloc(strlen(value)+1);
-   strcpy(foo,value);
+  if (foo) free(foo);
+  foo = (char *) malloc(strlen(value)+1);
+  strcpy(foo,value);
 }
 
 /* C++ mode.  When -c++ option is used */
 void foo_set(char *value) {
-   if (foo) delete [] foo;
-   foo = new char[strlen(value)+1];
-   strcpy(foo,value);
+  if (foo) delete [] foo;
+  foo = new char[strlen(value)+1];
+  strcpy(foo,value);
 }
 
@@ -1381,8 +1381,8 @@ exactly like you want. For example:
 %inline %{
   void set_foo(char *value) {
-       strncpy(foo,value, 50);
-   }
+    strncpy(foo,value, 50);
+  }
 %}
 
@@ -1538,10 +1538,10 @@ a few simple assist functions like this:
 %inline %{
 void a_set(int i, int j, int val) {
-   a[i][j] = val;
+  a[i][j] = val;
 }
 int a_get(int i, int j) {
-   return a[i][j];
+  return a[i][j];
 }
 %}
 
@@ -1558,11 +1558,11 @@ some helper functions in your interface. For example: %inline %{ /* Create any sort of [size] array */ int *int_array(int size) { - return (int *) malloc(size*sizeof(int)); + return (int *) malloc(size*sizeof(int)); } /* Create a two-dimension array [size][10] */ int (*int_array_10(int size))[10] { - return (int (*)[10]) malloc(size*10*sizeof(int)); + return (int (*)[10]) malloc(size*10*sizeof(int)); } %} @@ -1587,10 +1587,10 @@ code:
 char *pathname_get() {
-   return pathname;
+  return pathname;
 }
 void pathname_set(char *value) {
-   strncpy(pathname,value,256);
+  strncpy(pathname,value,256);
 }
 
@@ -2521,12 +2521,12 @@ Occasionally, a structure will contain data members that are themselves structur
 typedef struct Foo {
-   int x;
+  int x;
 } Foo;
 
 typedef struct Bar {
-   int y;
-   Foo f;           /* struct member */
+  int y;
+  Foo f;           /* struct member */
 } Bar;
 
@@ -2540,10 +2540,10 @@ The accessors to the member variable as a pointer are effectively wrapped as fol
 Foo *Bar_f_get(Bar *b) {
-   return &b->f;
+  return &b->f;
 }
 void Bar_f_set(Bar *b, Foo *value) {
-   b->f = *value;
+  b->f = *value;
 }
 
@@ -2588,7 +2588,7 @@ is a structure or class. For instance, if you had a structure like this,
 struct Foo {
-   WORD   w;
+  WORD   w;
 };
 
@@ -2843,10 +2843,10 @@ double Vector_magnitude(Vector *v) { typedef struct Vector { double x,y,z; %extend { - Vector(int,int,int); // This calls new_Vector() - ~Vector(); // This calls delete_Vector() - double magnitude(); // This will call Vector_magnitude() - ... + Vector(int,int,int); // This calls new_Vector() + ~Vector(); // This calls delete_Vector() + double magnitude(); // This will call Vector_magnitude() + ... } } Vector; @@ -3083,7 +3083,7 @@ in terms of high-level accessor functions such as this,
 double Vector_x_get(Vector *v) {
-   return v->x;
+  return v->x;
 }
 
@@ -3100,15 +3100,15 @@ the following function is generated instead: static int _wrap_Vector_x_get(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct Vector *arg1 ; - double result ; - - if (SWIG_GetArgs(interp, objc, objv,"p:Vector_x_get self ",&arg0, - SWIGTYPE_p_Vector) == TCL_ERROR) - return TCL_ERROR; - result = (double ) (arg1->x); - Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) result)); - return TCL_OK; + struct Vector *arg1 ; + double result ; + + if (SWIG_GetArgs(interp, objc, objv,"p:Vector_x_get self ",&arg0, + SWIGTYPE_p_Vector) == TCL_ERROR) + return TCL_ERROR; + result = (double ) (arg1->x); + Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) result)); + return TCL_OK; } @@ -3183,23 +3183,23 @@ the wrapper file is as shown:
 %begin %{
-   ... code in begin section ...
+  ... code in begin section ...
 %}
 
 %runtime %{
-   ... code in runtime section ...
+  ... code in runtime section ...
 %}
 
 %header %{
-   ... code in header section ...
+  ... code in header section ...
 %}
 
 %wrapper %{
-   ... code in wrapper section ...
+  ... code in wrapper section ...
 %}
 
 %init %{
-   ... code in init section ...
+  ... code in init section ...
 %}
 
diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 73b242fa3..95a3d054b 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -256,11 +256,11 @@ C++ class like this:
 class Foo {
-public:
-      Foo();
-     ~Foo();
-      int  bar(int x);
-      int  x;
+  public:
+    Foo();
+    ~Foo();
+    int  bar(int x);
+    int  x;
 };
 
@@ -272,24 +272,24 @@ Using C++ as pseudocode, a proxy class looks something like this:
 class FooProxy {
-private:
-      Foo    *self;
-public:
-      FooProxy() {
-            self = new_Foo();
-      }
-     ~FooProxy() {
-            delete_Foo(self);
-      }
-      int bar(int x) {
-            return Foo_bar(self,x);
-      }
-      int x_get() {
-            return Foo_x_get(self);
-      }
-      void x_set(int x) {
-            Foo_x_set(self,x);
-      }
+  private:
+    Foo    *self;
+  public:
+    FooProxy() {
+      self = new_Foo();
+    }
+    ~FooProxy() {
+      delete_Foo(self);
+    }
+    int bar(int x) {
+      return Foo_bar(self,x);
+    }
+    int x_get() {
+      return Foo_x_get(self);
+    }
+    void x_set(int x) {
+      Foo_x_set(self,x);
+    }
 };
 
@@ -303,19 +303,19 @@ For example, in Python, the proxy might look roughly like this:
 class Foo:
     def __init__(self):
-         self.this = new_Foo()
+        self.this = new_Foo()
     def __del__(self):
-         delete_Foo(self.this)
+        delete_Foo(self.this)
     def bar(self,x):
-         return Foo_bar(self.this,x)
+        return Foo_bar(self.this,x)
     def __getattr__(self,name):
-         if name == 'x':
-              return Foo_x_get(self.this)
-         ...
+        if name == 'x':
+            return Foo_x_get(self.this)
+        ...
     def __setattr__(self,name,value):
-         if name == 'x':
-              Foo_x_set(self.this,value)
-         ...
+        if name == 'x':
+            Foo_x_set(self.this,value)
+        ...
 
@@ -338,10 +338,10 @@ C++ code:
 class Foo {
 public:
-      Foo();
-     ~Foo();
-      int bar(int x);
-      int x;
+  Foo();
+  ~Foo();
+  int bar(int x);
+  int x;
 };
 
 class Spam {
@@ -407,45 +407,45 @@ roughly like this:
 
 class FooProxy {
-public:
-      Foo    *self;
-      int     thisown;
+  public:
+    Foo    *self;
+    int     thisown;
 
-      FooProxy() {
-            self = new_Foo();
-            thisown = 1;       // Newly created object
-      }
-     ~FooProxy() {
-            if (thisown) delete_Foo(self);
-      }
-      ...
-      // Ownership control API
-      void disown() {
-           thisown = 0;
-      }
-      void acquire() {
-           thisown = 1;
-      }
+    FooProxy() {
+      self = new_Foo();
+      thisown = 1;       // Newly created object
+    }
+    ~FooProxy() {
+      if (thisown) delete_Foo(self);
+    }
+    ...
+    // Ownership control API
+    void disown() {
+      thisown = 0;
+    }
+    void acquire() {
+      thisown = 1;
+    }
 };
 
 class FooPtrProxy: public FooProxy {
 public:
-      FooPtrProxy(Foo *s) {
-          self = s;
-          thisown = 0;
-      }
+  FooPtrProxy(Foo *s) {
+    self = s;
+    thisown = 0;
+  }
 };
 
 class SpamProxy {
-     ...
-     FooProxy *value_get() {
-          return FooPtrProxy(Spam_value_get(self));
-     }
-     void value_set(FooProxy *v) {
-          Spam_value_set(self,v->self);
-          v->disown();
-     }
-     ...
+  ...
+  FooProxy *value_get() {
+    return FooPtrProxy(Spam_value_get(self));
+  }
+  void value_set(FooProxy *v) {
+    Spam_value_set(self,v->self);
+    v->disown();
+  }
+  ...
 };
 
@@ -704,9 +704,9 @@ First, SWIG won't generate wrappers for protected or private constructors. For
 class Foo {
 protected:
-     Foo();         // Not wrapped.
+  Foo();         // Not wrapped.
 public:
-      ...
+    ...
 };
 
@@ -720,8 +720,8 @@ pure virtual methods. Here are some examples:
 class Bar {
 public:
-     Bar();               // Not wrapped.  Bar is abstract.
-     virtual void spam(void) = 0; 
+  Bar();               // Not wrapped.  Bar is abstract.
+  virtual void spam(void) = 0;
 };
 
 class Grok : public Bar {
@@ -754,8 +754,8 @@ non-abstract using this:
 
 class Foo : public Bar {
 public:
-     Foo();    // Generated no matter what---not abstract. 
-     ...
+  Foo();    // Generated no matter what---not abstract.
+  ...
 };
 
@@ -948,9 +948,9 @@ Alternatively, you can specify an immutable member in advance like this: %immutable List::length; ... class List { - ... - int length; // Immutable by above directive - ... + ... + int length; // Immutable by above directive + ... };
@@ -1078,7 +1078,7 @@ like this
 struct Foo {
-   size_t  len;
+  size_t  len;
 };
 
@@ -1176,10 +1176,10 @@ The following example illustrates this:
 class Foo {
 private:
-   static const int spam;
+  static const int spam;
 public:
-   void bar(int x, int y = spam);   // Won't work with %feature("compactdefaultargs") -
-                                    // private default value
+  void bar(int x, int y = spam);   // Won't work with %feature("compactdefaultargs") -
+                                   // private default value
 };
 
@@ -1262,9 +1262,9 @@ you have this code:
 class Foo {
 public:
-     ...
-     friend void blah(Foo *f);
-     ...
+  ...
+  friend void blah(Foo *f);
+  ...
 };
 
@@ -1299,9 +1299,9 @@ namespace bar { class Foo { public: - ... - friend void blah(Foo *f); - ... + ... + friend void blah(Foo *f); + ... }; } @@ -1364,7 +1364,7 @@ For example:
 class Bar {
 public:
-     Foo &spam();
+  Foo &spam();
 };
 
@@ -1376,8 +1376,8 @@ Generates an accessor like this:
 Foo *Bar_spam(Bar *obj) {
-   Foo &result = obj->spam();
-   return &result;
+  Foo &result = obj->spam();
+  return &result;
 }
 
@@ -1433,10 +1433,10 @@ following:
 Vector *wrap_cross_product(Vector *a, Vector *b) {
-   Vector x = *a;
-   Vector y = *b;
-   Vector r = cross_product(x,y);
-   return new Vector(r);
+  Vector x = *a;
+  Vector y = *b;
+  Vector r = cross_product(x,y);
+  return new Vector(r);
 }
@@ -1455,10 +1455,10 @@ called the "Fulton Transform". This produces a wrapper that looks like this:
 Vector cross_product(Vector *a, Vector *b) {
-   SwigValueWrapper<Vector> x = *a;
-   SwigValueWrapper<Vector> y = *b;
-   SwigValueWrapper<Vector> r = cross_product(x,y);
-   return new Vector(r);
+  SwigValueWrapper<Vector> x = *a;
+  SwigValueWrapper<Vector> y = *b;
+  SwigValueWrapper<Vector> r = cross_product(x,y);
+  return new Vector(r);
 }
 
@@ -1672,7 +1672,7 @@ Similarly, typedef allows unnamed structures to be used as base classes
 typedef struct {
-   ...
+  ...
 } Foo;
 
 class Bar : public Foo {    // Ok. 
@@ -1741,23 +1741,23 @@ inheritance.  For example, suppose you had code like this:
 
 class A {
 public:
-   int x;
+  int x;
 };
 
 class B {
 public:
-   int y;
+  int y;
 };
 
 class C : public A, public B {
 };
 
 int A_function(A *a) {
-   return a->x;
+  return a->x;
 }
 
 int B_function(B *b) {
-   return b->y;
+  return b->y;
 }
 
@@ -1844,10 +1844,10 @@ constructors. For example, if you supply SWIG with overloaded functions like th
 void foo(int x) {
-   printf("x is %d\n", x);
+  printf("x is %d\n", x);
 }
 void foo(char *x) {
-   printf("x is '%s'\n", x);
+  printf("x is '%s'\n", x);
 }
 
@@ -1875,10 +1875,10 @@ this code,
 class Foo {
 public:
-     Foo();
-     Foo(const Foo &);   // Copy constructor
-     void bar(int x);
-     void bar(char *s, int y);
+  Foo();
+  Foo(const Foo &);   // Copy constructor
+  void bar(int x);
+  void bar(char *s, int y);
 };
 
@@ -2193,9 +2193,9 @@ void foo(char *c); // Stays 'foo' (not renamed) class Spam { public: - void foo(int); // Becomes 'foo_i' - void foo(double); // Becomes 'foo_d' - ... + void foo(int); // Becomes 'foo_i' + void foo(double); // Becomes 'foo_d' + ... }; @@ -2227,23 +2227,23 @@ an entire class hierarchy with only a few declarations. For example: class Spam { public: - virtual void foo(int); // Renamed to foo_i - virtual void foo(double); // Renamed to foo_d - ... + virtual void foo(int); // Renamed to foo_i + virtual void foo(double); // Renamed to foo_d + ... }; class Bar : public Spam { public: - virtual void foo(int); // Renamed to foo_i - virtual void foo(double); // Renamed to foo_d -... + virtual void foo(int); // Renamed to foo_i + virtual void foo(double); // Renamed to foo_d + ... }; class Grok : public Bar { public: - virtual void foo(int); // Renamed to foo_i - virtual void foo(double); // Renamed to foo_d -... + virtual void foo(int); // Renamed to foo_i + virtual void foo(double); // Renamed to foo_d + ... }; @@ -2256,18 +2256,18 @@ class definition itself. For example:
 class Spam {
-   %rename(foo_i) foo(int);
-   %rename(foo_d) foo(double);
+  %rename(foo_i) foo(int);
+  %rename(foo_d) foo(double);
 public:
-   virtual void foo(int);      // Renamed to foo_i
-   virtual void foo(double);   // Renamed to foo_d
-   ...
+  virtual void foo(int);      // Renamed to foo_i
+  virtual void foo(double);   // Renamed to foo_d
+  ...
 };
 
 class Bar : public Spam {
 public:
-   virtual void foo(int);      // Renamed to foo_i
-   virtual void foo(double);   // Renamed to foo_d
+  virtual void foo(int);      // Renamed to foo_i
+  virtual void foo(double);   // Renamed to foo_d
 ...
 };
 
@@ -2406,9 +2406,9 @@ For example, if you have a class like this:

 class Spam {
 public:
-   ...
-   void bar() const;
-   ...
+  ...
+  void bar() const;
+  ...
 };
 
@@ -2443,10 +2443,10 @@ that differ only in their qualifiers, like this:
 class Spam {
 public:
-   ...
-   void bar();         // Unqualified member
-   void bar() const;   // Qualified member
-   ...
+  ...
+  void bar();         // Unqualified member
+  void bar() const;   // Qualified member
+  ...
 };
 
@@ -2492,11 +2492,11 @@ typedef int Integer; class Spam { public: - void foo(Integer); // Stays 'foo' (not renamed) + void foo(Integer); // Stays 'foo' (not renamed) }; class Ham { public: - void foo(int); // Renamed to foo_i + void foo(int); // Renamed to foo_i }; @@ -2511,9 +2511,9 @@ Let's consider the following example class:

 class Spam {
 public:
-   ...
-   void bar(int i=-1, double d=0.0);
-   ...
+  ...
+  void bar(int i=-1, double d=0.0);
+  ...
 };
 
@@ -2660,9 +2660,9 @@ something like this pseudocode:
 _wrap_Complex___add__(args) {
-   ... get args ...
-   obj->operator+(args);
-   ...
+  ... get args ...
+  obj->operator+(args);
+  ...
 }
 
@@ -2763,8 +2763,28 @@ have to handle it like a normal function. For example:
  • Certain operators are ignored by default. For instance, new and delete operators -are ignored as well as conversion operators. -

  • +are ignored as well as conversion and index operators. A warning such as the one below is shown: +

    + +

    +

    +
    +example.i:12: Warning 503: Can't wrap 'operator []' unless renamed to a valid identifier.
    +
    +
    + + +
  • The index operator, operator[], is particularly difficult to overload due to differences in C++ +implementations. Specifically, the get and set operators in other languages typically are separated +into two methods such that additional logic can be packed into the operations; C# uses +this[type key] { get { ... } set { ... }}, Python uses +__getitem__ and __setitem__, etc. In C++ if the return +type of operator[] is a reference and the method is const, it is often indicative of the setter, +and and the getter is usually a const function return an object by value. +In the absence of any hard and fast rules and the fact that there may be multiple index operators, +it is up to the user to choose the getter and setter to use by using %rename as shown earlier. +

    +
  • The semantics of certain C++ operators may not match those in the target language.
  • @@ -3126,7 +3146,7 @@ For example, if you wrote code like this, %template(intList) List<int>; ... class UltraList : public List<int> { - ... + ... }; @@ -3314,8 +3334,8 @@ look like this:
     class Foo {
     public:
    -     template<class T> void bar(T x, T y) { ... };
    -     ...
    +  template<class T> void bar(T x, T y) { ... };
    +  ...
     };
     
    @@ -3328,10 +3348,10 @@ To expand the template, simply use %template inside the class.
     class Foo {
     public:
    -     template<class T> void bar(T x, T y) { ... };
    -     ...
    -     %template(barint)    bar<int>;
    -     %template(bardouble) bar<double>;
    +  template<class T> void bar(T x, T y) { ... };
    +  ...
    +  %template(barint)    bar<int>;
    +  %template(bardouble) bar<double>;
     };
     
    @@ -3344,13 +3364,13 @@ Or, if you want to leave the original class definition alone, just do this:
     class Foo {
     public:
    -     template<class T> void bar(T x, T y) { ... };
    -     ...
    +  template<class T> void bar(T x, T y) { ... };
    +  ...
     };
     ...
     %extend Foo {
    -     %template(barint)    bar<int>;
    -     %template(bardouble) bar<double>;
    +  %template(barint)    bar<int>;
    +  %template(bardouble) bar<double>;
     };
     
    @@ -3363,8 +3383,8 @@ or simply
     class Foo {
     public:
    -     template<class T> void bar(T x, T y) { ... };
    -     ...
    +  template<class T> void bar(T x, T y) { ... };
    +  ...
     };
     ...
     
    @@ -3413,9 +3433,9 @@ template class.  Here is a slightly perverse example:
     // A template
     template<class T> class Foo {
     public:
    -     // A member template
    -     template<class S> T bar(S x, S y) { ... };
    -     ...
    +  // A member template
    +  template<class S> T bar(S x, S y) { ... };
    +  ...
     };
     
     // Expand a few member templates
    @@ -3443,12 +3463,12 @@ and conversions. For example:
     
     template<class T1, class T2> struct pair {
    -   T1 first;
    -   T2 second;
    -   pair() : first(T1()), second(T2()) { }
    -   pair(const T1 &x, const T2 &y) : first(x), second(y) { }
    -   template<class U1, class U2> pair(const pair<U1,U2> &x) 
    -                                        : first(x.first),second(x.second) { }
    +  T1 first;
    +  T2 second;
    +  pair() : first(T1()), second(T2()) { }
    +  pair(const T1 &x, const T2 &y) : first(x), second(y) { }
    +  template<class U1, class U2> pair(const pair<U1,U2> &x)
    +                                       : first(x.first),second(x.second) { }
     };
     
    @@ -3462,7 +3482,7 @@ in the template class itself. For example:
     %extend pair {
    -   %template(pair) pair<T1,T2>;        // Generate default copy constructor
    +  %template(pair) pair<T1,T2>;        // Generate default copy constructor
     };
     
    @@ -3484,13 +3504,13 @@ Alternatively, you could expand the constructor template in selected instantiati // Create a default constructor only %extend pair<int,int> { - %template(paird) pair<int,int>; // Default constructor + %template(paird) pair<int,int>; // Default constructor }; // Create default and conversion constructors %extend pair<double,double> { - %template(paird) pair<double,dobule>; // Default constructor - %template(pairc) pair<int,int>; // Conversion constructor + %template(paird) pair<double,dobule>; // Default constructor + %template(pairc) pair<int,int>; // Conversion constructor };
    @@ -3504,8 +3524,8 @@ instead:
     // Create default and conversion constructors 
     %extend pair<double,double> {
    -   %template(pair) pair<double,dobule>;   // Default constructor
    -   %template(pair) pair<int,int>;         // Conversion constructor
    +  %template(pair) pair<double,dobule>;   // Default constructor
    +  %template(pair) pair<int,int>;         // Conversion constructor
     };
     
    @@ -3527,19 +3547,19 @@ included directly in template definitions. For example:
     // File : list.h
     template<class T> class List {
    -   ...
    +  ...
     public:
    -    %rename(__getitem__) get(int);
    -    List(int max);
    -    ~List();
    -    ...
    -    T get(int index);
    -    %extend {
    -        char *__str__() {
    -            /* Make a string representation */
    -            ...
    -        }
    +  %rename(__getitem__) get(int);
    +  List(int max);
    +  ~List();
    +  ...
    +  T get(int index);
    +  %extend {
    +    char *__str__() {
    +      /* Make a string representation */
    +      ...
         }
    +  }
     };
     
    @@ -3556,14 +3576,14 @@ It is also possible to separate these declarations from the template class. For
     %rename(__getitem__) List::get;
     %extend List {
    -    char *__str__() {
    -        /* Make a string representation */
    -        ...
    -    }
    -    /* Make a copy */
    -    T *__copy__() {
    -       return new List<T>(*$self);
    -    }
    +  char *__str__() {
    +    /* Make a string representation */
    +    ...
    +  }
    +  /* Make a copy */
    +  T *__copy__() {
    +    return new List<T>(*$self);
    +  }
     };
     
     ...
    @@ -3722,15 +3742,15 @@ encapsulate common functionality.  For example:
     
     namespace math {
    -   double sin(double);
    -   double cos(double);
    +  double sin(double);
    +  double cos(double);
     
    -   class Complex {
    -      double im,re;
    -   public:
    -      ...
    -   };
    -   ...
    +  class Complex {
    +    double im,re;
    +  public:
    +    ...
    +  };
    +  ...
     };
     
    @@ -3798,18 +3818,18 @@ namespace A { } namespace B { - namespace C { - using namespace A; - } - typedef C::Foo FooClass; + namespace C { + using namespace A; + } + typedef C::Foo FooClass; } namespace BIGB = B; namespace D { - using BIGB::FooClass; - class Bar : public FooClass { - } + using BIGB::FooClass; + class Bar : public FooClass { + } }; class Spam : public D::Bar { @@ -3843,12 +3863,12 @@ you have code like this,
     %module foo
     namespace foo {
    -   void bar(int);
    -   void spam();
    +  void bar(int);
    +  void spam();
     }
     
     namespace bar {
    -   void blah();
    +  void blah();
     }
     
     
    @@ -3882,10 +3902,10 @@ namespaces to generate a name conflict in the target language. For example:
     namespace A {
    -   void foo(int);
    +  void foo(int);
     }
     namespace B {
    -   void foo(double);
    +  void foo(double);
     }
     
    @@ -3910,10 +3930,10 @@ To resolve this error, simply use %rename to disambiguate the declarati %rename(B_foo) B::foo; ... namespace A { - void foo(int); + void foo(int); } namespace B { - void foo(double); // Gets renamed to B_foo + void foo(double); // Gets renamed to B_foo }
    @@ -3932,7 +3952,7 @@ system to track type-names. Therefore, if you have code like this:
     namespace A {
    -   typedef int Integer;
    +  typedef int Integer;
     }
     using namespace A;
     void foo(Integer x);
    @@ -3981,18 +4001,18 @@ typemaps, exception handlers, and so forth.  For example, consider the following
     
     namespace foo {
    -    typedef int Integer;
    -    class bar {
    +  typedef int Integer;
    +  class bar {
         public:
    -       ...
    -    };
    +      ...
    +  };
     }
     
     %extend foo::bar {
    -   Integer add(Integer x, Integer y) {
    -       Integer r = x + y;        // Error. Integer not defined in this scope
    -       return r;
    -   }
    +  Integer add(Integer x, Integer y) {
    +    Integer r = x + y;        // Error. Integer not defined in this scope
    +    return r;
    +  }
     };
     
    @@ -4007,10 +4027,10 @@ To fix the problem, make sure you use fully qualified names. For example:
     %extend foo::bar {
    -   Integer add(Integer x, Integer y) {
    -       foo::Integer r = x + y;        // Ok.
    -       return r;
    -   }
    +  Integer add(Integer x, Integer y) {
    +    foo::Integer r = x + y;        // Ok.
    +    return r;
    +  }
     };
     
    @@ -4037,17 +4057,17 @@ these directives, consider the following: // Good version %inline %{ namespace foo { - void bar(int) { ... } - ... + void bar(int) { ... } + ... } %} // Bad version. Emitted code not placed in namespace. namespace foo { %inline %{ - void bar(int) { ... } /* I'm bad */ - ... -%} + void bar(int) { ... } /* I'm bad */ + ... + %} }
    @@ -4060,12 +4080,12 @@ included in the generated functions. For example, if you have code like this,
     namespace foo {
    -   class bar {
    -   public:
    -        %extend {
    -           int blah(int x);
    -        };
    -   };
    +  class bar {
    +    public:
    +      %extend {
    +        int blah(int x);
    +      };
    +  };
     }
     
    @@ -4088,13 +4108,13 @@ conflicts in the input, there will be no conflicts in the generated code.
     namespace foo {
    -   class bar;
    -   class spam {
    -   public:
    -        ...
    -        operator bar();      // Conversion of spam -> bar
    -        ...
    -   };
    +  class bar;
    +  class spam {
    +    public:
    +    ...
    +    operator bar();      // Conversion of spam -> bar
    +    ...
    +  };
     }
     
    @@ -4128,13 +4148,13 @@ Note, however, that if the operator is defined using a qualifier in its name, th %rename(tofoo) foo::spam::operator bar(); // will not match %rename(tofoo) foo::spam::operator foo::bar(); // will match namespace foo { - class bar; - class spam { - public: - ... - operator foo::bar(); - ... - }; + class bar; + class spam { + public: + ... + operator foo::bar(); + ... + }; } @@ -4346,7 +4366,7 @@ f = Foo() try: f.blah() except Error,e: - # e is a wrapped instance of "Error" + # e is a wrapped instance of "Error" @@ -4550,13 +4570,13 @@ code produces wrappers like this:
     int Foo_x_get(Foo *f) {
    -   return (*f)->x;
    +  return (*f)->x;
     }
     void Foo_x_set(Foo *f, int value) {
    -   (*f)->x = value;
    +  (*f)->x = value;
     }
     void Foo_bar(Foo *f) {
    -   (*f)->bar();
    +  (*f)->bar();
     }
     
    @@ -4636,8 +4656,8 @@ class Foo { // Ignored class Bar { public: - Foo *operator->(); - ... + Foo *operator->(); + ... }; @@ -4785,14 +4805,14 @@ 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 = 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)
    +a = create_A()      # (count: 1)
    +exit                # 'a' is released, SWIG unref 'a' called in the destructor wrapper (count: 0)
     
    @@ -4976,14 +4996,14 @@ won't cause a conflict. For example:

     class Foo {
     public:
    -       int blah(int );
    -       double blah(double);
    +  int blah(int );
    +  double blah(double);
     };
     
     class Bar : public Foo {
     public:
    -       using Foo::blah;    // Only imports blah(double);
    -       int blah(int);
    +  using Foo::blah;    // Only imports blah(double);
    +  int blah(int);
     };
     
    @@ -4997,14 +5017,14 @@ imported by using. For example: %rename(blah_long) Foo::blah(long); class Foo { public: - int blah(int); - long blah(long); // Renamed to blah_long + int blah(int); + long blah(long); // Renamed to blah_long }; class Bar : public Foo { public: - using Foo::blah; // Only imports blah(int) - double blah(double x); + using Foo::blah; // Only imports blah(int) + double blah(double x); }; @@ -5101,7 +5121,7 @@ void bar(Object *); ... // C++ code void blah() { - bar(foo()); // Error: bar discards const + bar(foo()); // Error: bar discards const }; diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 0eaa61423..a1970e934 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -443,14 +443,15 @@ The example below shows this for a C function returning 2 values and a result: int divide(int n, int d, int *OUTPUT, int *OUTPUT); %{ -int divide(int n, int d, int q*, int *r) { - if (d != 0) { - *q = n / d; - *r = n % d; - return 1; - } - else return 0; -} + int divide(int n, int d, int q*, int *r) { + if (d != 0) { + *q = n / d; + *r = n % d; + return 1; + } else { + return 0; + } + } %} diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index 31fae0321..af4880217 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -837,8 +837,8 @@ access constants in procedure bodies. For example:
     proc blah {} {
    -   global FOO
    -   bar $FOO
    +  global FOO
    +  bar $FOO
     }
     
    @@ -865,7 +865,7 @@ its actual value or a symbolic identifier name. For example:
     proc blah {} {
    -   bar FOO
    +  bar FOO
     }
     
    @@ -949,12 +949,12 @@ example: %inline %{ /* C-style cast */ Bar *FooToBar(Foo *f) { - return (Bar *) f; + return (Bar *) f; } /* C++-style cast */ Foo *BarToFoo(Bar *b) { - return dynamic_cast<Foo*>(b); + return dynamic_cast<Foo*>(b); } Foo *IncrFoo(Foo *f, int i) { @@ -1028,12 +1028,12 @@ can also be forced to be read-only using the %immutable directive. For
     struct Foo {
    -   ...
    -   %immutable;
    -   int x;        /* Read-only members */
    -   char *name;
    -   %mutable;
    -   ...
    +  ...
    +  %immutable;
    +  int x;        /* Read-only members */
    +  char *name;
    +  %mutable;
    +  ...
     };
     
    @@ -1100,11 +1100,11 @@ pointer. For example, suppose you have two structures like this:
     struct Foo {
    -   int a;
    +  int a;
     };
     
     struct Bar {
    -   Foo f;
    +  Foo f;
     };
     
    @@ -1302,9 +1302,8 @@ To illustrate, suppose you have a class like this:
     class Spam {
     public:
    -   static void foo();
    -   static int bar;
    -
    +  static void foo();
    +  static int bar;
     };
     
    @@ -1662,10 +1661,10 @@ submodules or packages. For example, if you have a file like this, %module example namespace foo { - int fact(int n); - struct Vector { - double x,y,z; - }; + int fact(int n); + struct Vector { + double x,y,z; + }; }; @@ -1731,12 +1730,12 @@ For example: template<class T1, class T2> struct pair { - typedef T1 first_type; - typedef T2 second_type; - T1 first; - T2 second; - pair(); - pair(const T1&, const T2&); + typedef T1 first_type; + typedef T2 second_type; + T1 first; + T2 second; + pair(); + pair(const T1&, const T2&); ~pair(); }; @@ -1776,9 +1775,9 @@ that implements operator->() like this:
     template<class T> class SmartPtr {
    -   ...
    -   T *operator->();
    -   ...
    +  ...
    +  T *operator->();
    +  ...
     }
     
    @@ -1791,8 +1790,8 @@ Then, if you have a class like this,
     class Foo {
     public:
    -     int x;
    -     int bar();
    +  int x;
    +  int bar();
     };
     
    @@ -1874,9 +1873,9 @@ have a class like this
     class Foo {
     public:
    -     int x;
    -     int spam(int);
    -     ...
    +  int x;
    +  int spam(int);
    +  ...
     
    @@ -2065,10 +2064,10 @@ change the ownership of an object. For instance, consider code like this:
     class Node {
    -   Object *value;
    +  Object *value;
     public:
    -   void set_value(Object *v) { value = v; }
    -   ...
    +  void set_value(Object *v) { value = v; }
    +  ...
     };
     
    @@ -2125,7 +2124,7 @@ example:
     void add(int x, int y, int *result) {
    -   *result = x + y;
    +  *result = x + y;
     }
     
    @@ -2137,7 +2136,7 @@ or perhaps
     int sub(int *x, int *y) {
    -   return *x+*y;
    +  return *x+*y;
     }
     
    @@ -2198,7 +2197,7 @@ If a function mutates one of its parameters like this,
     void negate(int *x) {
    -   *x = -(*x);
    +  *x = -(*x);
     }
     
    @@ -2328,7 +2327,7 @@ class DoubleArray { } // Destroy an array ~DoubleArray() { - delete ptr; + delete ptr; } // Return the length of the array int length() { @@ -2797,36 +2796,36 @@ used as a char ** object. // This tells SWIG to treat char ** as a special case %typemap(in) char ** { - Tcl_Obj **listobjv; - int nitems; - int i; - if (Tcl_ListObjGetElements(interp, $input, &nitems, &listobjv) == TCL_ERROR) { - return TCL_ERROR; - } - $1 = (char **) malloc((nitems+1)*sizeof(char *)); - for (i = 0; i < nitems; i++) { - $1[i] = Tcl_GetStringFromObj(listobjv[i],0); - } - $1[i] = 0; + Tcl_Obj **listobjv; + int nitems; + int i; + if (Tcl_ListObjGetElements(interp, $input, &nitems, &listobjv) == TCL_ERROR) { + return TCL_ERROR; + } + $1 = (char **) malloc((nitems+1)*sizeof(char *)); + for (i = 0; i < nitems; i++) { + $1[i] = Tcl_GetStringFromObj(listobjv[i],0); + } + $1[i] = 0; } // This gives SWIG some cleanup code that will get called after the function call %typemap(freearg) char ** { - if ($1) { - free($1); - } + if ($1) { + free($1); + } } // Now a test functions %inline %{ -int print_args(char **argv) { + int print_args(char **argv) { int i = 0; while (argv[i]) { - printf("argv[%d] = %s\n", i,argv[i]); - i++; + printf("argv[%d] = %s\n", i,argv[i]); + i++; } return i; -} + } %} %include "tclsh.i" @@ -2855,21 +2854,21 @@ function argument. For example :
     // A typemap defining how to return an argument by appending it to the result
     %typemap(argout) double *outvalue {
    -     Tcl_Obj *o = Tcl_NewDoubleObj($1);
    -     Tcl_ListObjAppendElement(interp,$result,o);
    +  Tcl_Obj *o = Tcl_NewDoubleObj($1);
    +  Tcl_ListObjAppendElement(interp,$result,o);
     }
     
     // A typemap telling SWIG to ignore an argument for input
     // However, we still need to pass a pointer to the C function
     %typemap(in,numinputs=0) double *outvalue (double temp) {
    -     $1 = &temp;
    +  $1 = &temp;
     }
     
     // Now a function returning two values
     int mypow(double a, double b, double *outvalue) {
    -        if ((a < 0) || (b < 0)) return -1;
    -        *outvalue = pow(a,b);
    -        return 0;
    +  if ((a < 0) || (b < 0)) return -1;
    +  *outvalue = pow(a,b);
    +  return 0;
     };
     
    @@ -2992,7 +2991,7 @@ work)
     %typemap(out) int, short, long {
    -   Tcl_SetIntObj($result,(int) $1);
    +  Tcl_SetIntObj($result,(int) $1);
     }
     
    @@ -3004,10 +3003,10 @@ work)
     %typemap(in) float, double {
    -   double temp;
    -   if (Tcl_GetDoubleFromObj(interp, $input, &temp) == TCL_ERROR)
    -       return TCL_ERROR;
    -   $1 = ($1_ltype) temp;
    +  double temp;
    +  if (Tcl_GetDoubleFromObj(interp, $input, &temp) == TCL_ERROR)
    +    return TCL_ERROR;
    +  $1 = ($1_ltype) temp;
     }
     
    @@ -3017,7 +3016,7 @@ work)
     %typemap(out) float, double {
    -   Tcl_SetDoubleObj($result, $1);
    +  Tcl_SetDoubleObj($result, $1);
     }
     
    @@ -3029,9 +3028,8 @@ work)
     %typemap(in) char * {
    -   int len;
    -   $1 = Tcl_GetStringFromObj(interp, &len);
    -   }
    +  int len;
    +  $1 = Tcl_GetStringFromObj(interp, &len);
     }
     
    @@ -3090,7 +3088,9 @@ is usually accessed as follows:
     Foo *f;
    -if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, 0) == -1) return NULL;
    +if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, 0))) {
    +  SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
    +}
     
     Tcl_Obj *;
     obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
    @@ -3105,7 +3105,9 @@ variable $1_descriptor.  For example:
     
     %typemap(in) Foo * {
    -   if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) return NULL;
    +  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
    +    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
    +  }
     }
     
    @@ -3118,7 +3120,9 @@ For example:
     %typemap(in) Foo * {
    -   if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 0)) == -1) return NULL;
    +  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $descriptor(Foo *), 0))) {
    +    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
    +  }
     }
     
    diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 309984b50..8aa5abb3f 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -164,16 +164,16 @@ Inside the wrapper function, you might see these functions used like this:
     PyObject *wrap_factorial(PyObject *self, PyObject *args) {
    -    int       arg1;
    -    int       result;
    -    PyObject *obj1;
    -    PyObject *resultobj;
    +  int       arg1;
    +  int       result;
    +  PyObject *obj1;
    +  PyObject *resultobj;
     
    -    if (!PyArg_ParseTuple("O:factorial", &obj1)) return NULL;
    -    arg1 = PyInt_AsLong(obj1);
    -    result = factorial(arg1);
    -    resultobj = PyInt_FromLong(result);
    -    return resultobj;
    +  if (!PyArg_ParseTuple("O:factorial", &obj1)) return NULL;
    +  arg1 = PyInt_AsLong(obj1);
    +  result = factorial(arg1);
    +  resultobj = PyInt_FromLong(result);
    +  return resultobj;
     }
     
    @@ -222,12 +222,12 @@ a special %typemap directive is used. For example:
     /* Convert from Python --> C */
     %typemap(in) int {
    -    $1 = PyInt_AsLong($input);
    +  $1 = PyInt_AsLong($input);
     }
     
     /* Convert from C --> Python */
     %typemap(out) int {
    -    $result = PyInt_FromLong($1);
    +  $result = PyInt_FromLong($1);
     }
     
    @@ -270,33 +270,33 @@ A wrapper function would look approximately like this:
     PyObject *wrap_gcd(PyObject *self, PyObject *args) {
    -   int arg1;
    -   int arg2;
    -   int result;
    -   PyObject *obj1;
    -   PyObject *obj2;
    -   PyObject *resultobj;
    +  int arg1;
    +  int arg2;
    +  int result;
    +  PyObject *obj1;
    +  PyObject *obj2;
    +  PyObject *resultobj;
     
    -   if (!PyArg_ParseTuple("OO:gcd", &obj1, &obj2)) return NULL;
    +  if (!PyArg_ParseTuple("OO:gcd", &obj1, &obj2)) return NULL;
     
    -   /* "in" typemap, argument 1 */   
    -   {
    -      arg1 = PyInt_AsLong(obj1);
    -   }
    +  /* "in" typemap, argument 1 */
    +  {
    +    arg1 = PyInt_AsLong(obj1);
    +  }
     
    -   /* "in" typemap, argument 2 */
    -   {
    -      arg2 = PyInt_AsLong(obj2);
    -   }
    +  /* "in" typemap, argument 2 */
    +  {
    +    arg2 = PyInt_AsLong(obj2);
    +  }
     
    -   result = gcd(arg1,arg2);
    +  result = gcd(arg1,arg2);
     
    -   /* "out" typemap, return value */
    -   {
    -      resultobj = PyInt_FromLong(result);
    -   }
    +  /* "out" typemap, return value */
    +  {
    +    resultobj = PyInt_FromLong(result);
    +  }
     
    -   return resultobj;
    +  return resultobj;
     }
     
    @@ -323,7 +323,7 @@ it is applied to all future occurrences of that type in the input file. For exa
     /* Convert from Perl --> C */
     %typemap(in) int {
    -   $1 = SvIV($input);
    +  $1 = SvIV($input);
     }
     
     ...
    @@ -344,12 +344,12 @@ underlying type.  For example, you could have code like this:
     
     /* Convert from Ruby--> C */
     %typemap(in) int {
    -   $1 = NUM2INT($input);
    +  $1 = NUM2INT($input);
     }
     ...
     typedef int Integer;
     namespace foo {
    -    typedef Integer Number;
    +  typedef Integer Number;
     };
     
     int foo(int x);
    @@ -373,11 +373,11 @@ example, you could write a typemap like this:
     
     %typemap(in) double nonnegative {
    -   $1 = PyFloat_AsDouble($input);
    -   if ($1 < 0) {
    -        PyErr_SetString(PyExc_ValueError,"argument must be nonnegative.");
    -        return NULL;
    -   }
    +  $1 = PyFloat_AsDouble($input);
    +  if ($1 < 0) {
    +    PyErr_SetString(PyExc_ValueError,"argument must be nonnegative.");
    +    SWIG_fail;
    +  }
     }
     
     ...
    @@ -399,8 +399,8 @@ consecutive arguments.    For example:
     
     %typemap(in) (char *str, int len) {
    -    $1 = PyString_AsString($input);   /* char *str */
    -    $2 = PyString_Size($input);       /* int len   */
    +  $1 = PyString_AsString($input);   /* char *str */
    +  $2 = PyString_Size($input);       /* int len   */
     }
     ...
     int count(char *str, int len, char c);
    @@ -434,12 +434,12 @@ A more general form of copying is found in the %apply directive like th
     
     %typemap(in) int {
    -   /* Convert an integer argument */
    -   ...
    +  /* Convert an integer argument */
    +  ...
     }
     %typemap(out) int {
    -   /* Return an integer value */
    -   ...
    +  /* Return an integer value */
    +  ...
     }
     
     /* Apply all of the integer typemaps to size_t */
    @@ -489,7 +489,7 @@ int foo(int x, double y, char *s);
     
     
    • Input argument conversion ("in" typemap).
    • -
    • Input argument type checking ("typecheck" typemap).
    • +
    • Input argument type checking for types used in overloaded methods ("typecheck" typemap).
    • Output argument handling ("argout" typemap).
    • Input argument value checking ("check" typemap).
    • Input argument initialization ("arginit" typemap).
    • @@ -549,7 +549,7 @@ int foo(int x, double y, char *s);
       struct Foo {
      -    int x[20];
      +  int x[20];
       };
       
      @@ -637,7 +637,7 @@ function instead. For example: %rename(foo) wrap_foo; %inline %{ void wrap_foo(char *s, int x) { - foo(x,s); + foo(x,s); } %}
    @@ -759,21 +759,21 @@ Here are some examples of valid typemap specifications:
     /* Simple typemap declarations */
     %typemap(in) int {
    -   $1 = PyInt_AsLong($input);
    +  $1 = PyInt_AsLong($input);
     }
     %typemap(in) int "$1 = PyInt_AsLong($input);";
     %typemap(in) int %{ 
    -   $1 = PyInt_AsLong($input);
    +  $1 = PyInt_AsLong($input);
     %}
     
     /* Typemap with extra argument name */
     %typemap(in) int nonnegative {
    -   ...
    +  ...
     }
     
     /* Multiple types in one typemap */
     %typemap(in) int, short, long { 
    -   $1 = SvIV($input);
    +  $1 = SvIV($input);
     }
     
     /* Typemap with modifiers */
    @@ -783,15 +783,15 @@ Here are some examples of valid typemap specifications:
     %typemap(in) (char *str, int len),
                  (char *buffer, int size)
     {
    -   $1 = PyString_AsString($input);
    -   $2 = PyString_Size($input);
    +  $1 = PyString_AsString($input);
    +  $2 = PyString_Size($input);
     }
     
     /* Typemap with extra pattern parameters */
     %typemap(in, numinputs=0) int *output (int temp),
                               long *output (long temp)
     {
    -   $1 = &temp;
    +  $1 = &temp;
     }
     
    @@ -837,7 +837,7 @@ subject to the typemap rules that are in effect at the point where the class its
     class Foo {
    -   ...
    +  ...
     };
     
     %typemap(in) int {
    @@ -845,8 +845,8 @@ class Foo {
     }
     
     %extend Foo {
    -   int blah(int x);    // typemap has no effect.  Declaration is attached to Foo which 
    -                       // appears before the %typemap declaration.
    +  int blah(int x);    // typemap has no effect.  Declaration is attached to Foo which
    +                      // appears before the %typemap declaration.
     };
     
    @@ -953,22 +953,22 @@ example:
     %typemap(in) int {
    -   ...
    +  ...
     }
     
     namespace std {
    -    class string;
    -    %typemap(in) string {
    -        ...
    -    }
    +  class string;
    +  %typemap(in) string {
    +    ...
    +  }
     }
     
     class Bar {
     public:
    -    typedef const int & const_reference;
    -    %typemap(out) const_reference {
    -         ...
    -    }
    +  typedef const int & const_reference;
    +  %typemap(out) const_reference {
    +    ...
    +  }
     };
     
    @@ -982,10 +982,10 @@ code
     namespace std {
    -    class string;
    -    %typemap(in) string {
    -       ...
    -    }
    +  class string;
    +  %typemap(in) string {
    +    ...
    +  }
     }
     
    @@ -997,17 +997,17 @@ is really defining a typemap for the type std::string. You could have
     namespace std {
    -    class string;
    -    %typemap(in) string {          /* std::string */
    -       ...
    -    }
    +  class string;
    +  %typemap(in) string {          /* std::string */
    +    ...
    +  }
     }
     
     namespace Foo {
    -    class string;
    -    %typemap(in) string {          /* Foo::string */
    -       ...
    -    }
    +  class string;
    +  %typemap(in) string {          /* Foo::string */
    +    ...
    +  }
     }
     
    @@ -1096,23 +1096,23 @@ shows how some of the basic rules are applied:
     %typemap(in) int *x {
    -   ... typemap 1
    +  ... typemap 1
     }
     
     %typemap(in) int * {
    -   ... typemap 2
    +  ... typemap 2
     }
     
     %typemap(in) const int *z {
    -   ... typemap 3
    +  ... typemap 3
     }
     
     %typemap(in) int [4] {
    -   ... typemap 4
    +  ... typemap 4
     }
     
     %typemap(in) int [ANY] {
    -   ... typemap 5
    +  ... typemap 5
     }
     
     void A(int *x);        // int *x rule       (typemap 1)
    @@ -1141,7 +1141,7 @@ for the reduced type.   To illustrate, suppose you had code like this:
     
     %typemap(in) int {
    -   ... typemap 1
    +  ... typemap 1
     }
     
     typedef int Integer;
    @@ -1185,11 +1185,11 @@ typedef double  pdouble;     // Positive double
     
     // typemap 1
     %typemap(in) double {
    -   ... get a double ...
    +  ... get a double ...
     }
     // typemap 2
     %typemap(in) pdouble {
    -   ... get a positive double ...
    +  ... get a positive double ...
     }
     double sin(double x);           // typemap 1
     pdouble sqrt(pdouble x);        // typemap 2
    @@ -1453,11 +1453,11 @@ any typemaps specified for a single type.  For example:
     
     %typemap(in) (char *buffer, int len) {
    -   // typemap 1
    +  // typemap 1
     }
     
     %typemap(in) char *buffer {
    -   // typemap 2
    +  // typemap 2
     }
     
     void foo(char *buffer, int len, int count); // (char *buffer, int len)
    @@ -1804,7 +1804,7 @@ void set_value(const char* val) {}
     %typemap(check) const char* val = char* NON_NULL;
     
     %typemap(arginit, noblock=1) const char* val {
    -   $1 = "";
    +  $1 = "";
     }
     
     void set_value(const char* val);
    @@ -1862,7 +1862,7 @@ When a typemap is defined like this:
     
     %typemap(in) int {
    -   $1 = PyInt_AsLong($input);
    +  $1 = PyInt_AsLong($input);
     }
     
    @@ -1875,12 +1875,12 @@ wrapper code will look like this:
     wrap_whatever() {
    -    ...
    -    // Typemap code
    -    {                    
    -       arg1 = PyInt_AsLong(obj1);
    -    }
    -    ...
    +  ...
    +  // Typemap code
    +  {
    +    arg1 = PyInt_AsLong(obj1);
    +  }
    +  ...
     }
     
    @@ -1893,11 +1893,11 @@ for use during typemap execution. For example:
     %typemap(in) short {
    -   long temp;          /* Temporary value */
    -   if (Tcl_GetLongFromObj(interp, $input, &temp) != TCL_OK) {
    -      return TCL_ERROR;
    -   }
    -   $1 = (short) temp;
    +  long temp;          /* Temporary value */
    +  if (Tcl_GetLongFromObj(interp, $input, &temp) != TCL_OK) {
    +    return TCL_ERROR;
    +  }
    +  $1 = (short) temp;
     }
     
    @@ -1966,11 +1966,11 @@ then pass a pointer to the object. To do this, simply specify the typemap with
     %typemap(in) std::string * (std::string temp) {
    -    unsigned int len;
    -    char        *s;
    -    s = SvPV($input,len);         /* Extract string data */
    -    temp.assign(s,len);           /* Assign to temp */
    -    $1 = &temp;                   /* Set argument to point to temp */
    +  unsigned int len;
    +  char        *s;
    +  s = SvPV($input,len);         /* Extract string data */
    +  temp.assign(s,len);           /* Assign to temp */
    +  $1 = &temp;                   /* Set argument to point to temp */
     }
     
    @@ -1983,16 +1983,16 @@ the scope of the entire wrapper function. For example:
     wrap_foo() {
    -   std::string temp;    <--- Declaration of temp goes here
    -   ...
    +  std::string temp;    <--- Declaration of temp goes here
    +  ...
     
    -   /* Typemap code */
    -   {
    -      ...
    -      temp.assign(s,len);
    -      ...
    -   } 
    -   ...
    +  /* Typemap code */
    +  {
    +    ...
    +    temp.assign(s,len);
    +    ...
    +  }
    +  ...
     }
     
    @@ -2021,35 +2021,35 @@ generated code would actually look like this:
     wrap_foo() {
    -   int *arg1;    /* Actual arguments */
    -   int *arg2;
    -   int *arg3;
    -   std::string temp1;    /* Locals declared in the typemap */
    -   std::string temp2;
    -   std::string temp3;
    -   ...
    -   {
    -       char *s;
    -       unsigned int len;
    -       ...
    -       temp1.assign(s,len);
    -       arg1 = *temp1;
    -   }
    -   {
    -       char *s;
    -       unsigned int len;
    -       ...
    -       temp2.assign(s,len);
    -       arg2 = &temp2;
    -   }
    -   {
    -       char *s;
    -       unsigned int len;
    -       ...
    -       temp3.assign(s,len);
    -       arg3 = &temp3;
    -   }
    -   ...
    +  int *arg1;    /* Actual arguments */
    +  int *arg2;
    +  int *arg3;
    +  std::string temp1;    /* Locals declared in the typemap */
    +  std::string temp2;
    +  std::string temp3;
    +  ...
    +  {
    +    char *s;
    +    unsigned int len;
    +    ...
    +    temp1.assign(s,len);
    +    arg1 = *temp1;
    +  }
    +  {
    +    char *s;
    +    unsigned int len;
    +    ...
    +    temp2.assign(s,len);
    +    arg2 = &temp2;
    +  }
    +  {
    +    char *s;
    +    unsigned int len;
    +    ...
    +    temp3.assign(s,len);
    +    arg3 = &temp3;
    +  }
    +  ...
     }
     
    @@ -2237,7 +2237,7 @@ This is useful when a typemap might match multiple C datatype. For example:
     %typemap(in)  int, short, long {
    -   $1 = ($1_ltype) PyInt_AsLong($input);
    +  $1 = ($1_ltype) PyInt_AsLong($input);
     }
     
    @@ -2285,8 +2285,8 @@ If necessary, type related substitutions can also be used when declaring locals.
     %typemap(in) int * ($*1_type temp) {
    -    temp = PyInt_AsLong($input);
    -    $1 = &temp;
    +  temp = PyInt_AsLong($input);
    +  $1 = &temp;
     }
     
    @@ -2300,7 +2300,7 @@ kinds of pointers. For example, if you wrote this,
     %typemap(in) int [10][20] {
    -   $1_ltype temp;
    +  $1_ltype temp;
     }
     
    @@ -2326,10 +2326,10 @@ casts to get the correct type when needed. For example:
     %typemap(in) int [10][20] {
    -   void *temp;
    -   ...
    -   (($1_ltype) temp)[i][j] = x;    /* set a value */
    -   ...
    +  void *temp;
    +  ...
    +  (($1_ltype) temp)[i][j] = x;    /* set a value */
    +  ...
     }
     
    @@ -2341,10 +2341,10 @@ Another approach, which only works for arrays is to use the $1_basetype
     %typemap(in) int [10][20] {
    -   $1_basetype temp[10][20];
    -   ...
    -   temp[i][j] = x;    /* set a value */
    -   ...
    +  $1_basetype temp[10][20];
    +  ...
    +  temp[i][j] = x;    /* set a value */
    +  ...
     }
     
    @@ -2518,7 +2518,7 @@ to C. For example:
     %typemap(in) int {
    -   $1 = PyInt_AsLong($input);
    +  $1 = PyInt_AsLong($input);
     }
     
    @@ -2548,7 +2548,7 @@ specified. The numinputs attributes facilitates this. For example:
     // Ignored argument.
     %typemap(in, numinputs=0) int *out (int temp) {
    -    $1 = &temp;
    +  $1 = &temp;
     }
     
    @@ -2578,7 +2578,7 @@ to see whether or not it matches a specific type. For example:
     %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) int {
    -   $1 = PyInt_Check($input) ? 1 : 0;
    +  $1 = PyInt_Check($input) ? 1 : 0;
     }
     
    @@ -2586,6 +2586,7 @@ to see whether or not it matches a specific type. For example:

    For typechecking, the $1 variable is always a simple integer that is set to 1 or 0 depending on whether or not the input argument is the correct type. +Set to 1 if the input argument is the correct type otherwise set to 0.

    @@ -2604,7 +2605,7 @@ into the target language. For example:

     %typemap(out) int {
    -   $result = PyInt_FromLong($1);
    +  $result = PyInt_FromLong($1);
     }
     
    @@ -2638,7 +2639,7 @@ For example:
     // Set argument to NULL before any conversion occurs
     %typemap(arginit) int *data {
    -   $1 = NULL;
    +  $1 = NULL;
     }
     
    @@ -2654,7 +2655,7 @@ argument. For example:
     %typemap(default) int flags {
    -   $1 = DEFAULT_FLAGS;
    +  $1 = DEFAULT_FLAGS;
     }
     ...
     int foo(int x, int y, int flags);
    @@ -2688,9 +2689,9 @@ converted.  For example:
     
     %typemap(check) int positive {
    -   if ($1 <= 0) {
    -       SWIG_exception(SWIG_ValueError,"Expected positive value.");
    -   }
    +  if ($1 <= 0) {
    +    SWIG_exception(SWIG_ValueError,"Expected positive value.");
    +  }
     }
     
    @@ -2709,12 +2710,12 @@ with an "in" typemap---possibly to ignore the input value. For example:
     /* Set the input argument to point to a temporary variable */
     %typemap(in, numinputs=0) int *out (int temp) {
    -   $1 = &temp;
    +  $1 = &temp;
     }
     
     %typemap(argout) int *out {
    -   // Append output value $1 to $result
    -   ...
    +  // Append output value $1 to $result
    +  ...
     }
     
    @@ -2756,12 +2757,12 @@ For example:
     // Get a list of integers
     %typemap(in) int *items {
    -   int nitems = Length($input);    
    -   $1 = (int *) malloc(sizeof(int)*nitems);
    +  int nitems = Length($input);
    +  $1 = (int *) malloc(sizeof(int)*nitems);
     }
     // Free the list 
     %typemap(freearg) int *items {
    -   free($1);
    +  free($1);
     }
     
    @@ -2786,10 +2787,10 @@ of a function. For example:
     %typemap(newfree) string * {
    -   delete $1;
    +  delete $1;
     }
     %typemap(out) string * {
    -   $result = PyString_FromString($1->c_str());
    +  $result = PyString_FromString($1->c_str());
     }
     ...
     
    @@ -2854,7 +2855,7 @@ cases.  For example:
     
     %typemap(memberin) int [4] {
    -   memmove($1, $input, 4*sizeof(int));
    +  memmove($1, $input, 4*sizeof(int));
     }
     
    @@ -2910,12 +2911,11 @@ with the catch block comprising the "throws" typemap content.
     ...
     try {
    -    bar();
    +  bar();
     }
     catch(char const *_e) {
    -    PyErr_SetString(PyExc_RuntimeError, _e);
    -    SWIG_fail;
    -    
    +  PyErr_SetString(PyExc_RuntimeError, _e);
    +  SWIG_fail;
     }
     ...
     
    @@ -2964,11 +2964,11 @@ similar to this: int i; if (!PySequence_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a sequence"); - return NULL; + SWIG_fail; } if (PySequence_Length($input) != 4) { PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected 4 elements"); - return NULL; + SWIG_fail; } for (i = 0; i < 4; i++) { PyObject *o = PySequence_GetItem($input,i); @@ -2976,7 +2976,7 @@ similar to this: temp[i] = (float) PyFloat_AsDouble(o); } else { PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); - return NULL; + SWIG_fail; } } $1 = temp; @@ -3009,11 +3009,11 @@ If you wanted to generalize the typemap to apply to arrays of all dimensions you int i; if (!PySequence_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a sequence"); - return NULL; + SWIG_fail; } if (PySequence_Length($input) != $1_dim0) { PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements"); - return NULL; + SWIG_fail; } for (i = 0; i < $1_dim0; i++) { PyObject *o = PySequence_GetItem($input,i); @@ -3021,7 +3021,7 @@ If you wanted to generalize the typemap to apply to arrays of all dimensions you temp[i] = (float) PyFloat_AsDouble(o); } else { PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); - return NULL; + SWIG_fail; } } $1 = temp; @@ -3037,7 +3037,7 @@ array dimensions. Multidimensional arrays can be matched in a similar manner.
     %typemap(in) float matrix[ANY][ANY] (float temp[$1_dim0][$1_dim1]) {
    -   ... convert a 2d array ...
    +  ... convert a 2d array ...
     }
     
    @@ -3053,11 +3053,11 @@ as shown. To work with heap allocated data, the following technique can be use int i; if (!PySequence_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a sequence"); - return NULL; + SWIG_fail; } if (PySequence_Length($input) != $1_dim0) { PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements"); - return NULL; + SWIG_fail; } $1 = (float *) malloc($1_dim0*sizeof(float)); for (i = 0; i < $1_dim0; i++) { @@ -3065,14 +3065,14 @@ as shown. To work with heap allocated data, the following technique can be use if (PyNumber_Check(o)) { $1[i] = (float) PyFloat_AsDouble(o); } else { - PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); free($1); - return NULL; + PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); + SWIG_fail; } } } %typemap(freearg) float value[ANY] { - if ($1) free($1); + if ($1) free($1); }
    @@ -3227,10 +3227,10 @@ pointers. For example:

     %typemap(check) Vector * {
    -    if ($1 == 0) {
    -        PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed");
    -        return NULL;
    -   }
    +  if ($1 == 0) {
    +    PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed");
    +    SWIG_fail;
    +  }
     }
     
     
    @@ -3508,16 +3508,16 @@ maps perform the conversion described for the above example: int i; if (!PyList_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expecting a list"); - return NULL; + SWIG_fail; } $1 = PyList_Size($input); $2 = (char **) malloc(($1+1)*sizeof(char *)); for (i = 0; i < $1; i++) { PyObject *s = PyList_GetItem($input,i); if (!PyString_Check(s)) { - free($2); - PyErr_SetString(PyExc_ValueError, "List items must be strings"); - return NULL; + free($2); + PyErr_SetString(PyExc_ValueError, "List items must be strings"); + SWIG_fail; } $2[i] = PyString_AsString(s); } @@ -3525,7 +3525,7 @@ maps perform the conversion described for the above example: } %typemap(freearg) (int argc, char *argv[]) { - if ($2) free($2); + if ($2) free($2); } /* Required for C++ method overloading */ @@ -3631,38 +3631,38 @@ might write typemaps like this:
     // typemap for an outgoing buffer
     %typemap(in) (void *wbuffer, size_t len) {
    -   if (!PyString_Check($input)) {
    -       PyErr_SetString(PyExc_ValueError, "Expecting a string");
    -       return NULL;
    -   }
    -   $1 = (void *) PyString_AsString($input);
    -   $2 = PyString_Size($input);
    +  if (!PyString_Check($input)) {
    +    PyErr_SetString(PyExc_ValueError, "Expecting a string");
    +    SWIG_fail;
    +  }
    +  $1 = (void *) PyString_AsString($input);
    +  $2 = PyString_Size($input);
     }
     
     // typemap for an incoming buffer
     %typemap(in) (void *rbuffer, size_t len) {
    -   if (!PyInt_Check($input)) {
    -       PyErr_SetString(PyExc_ValueError, "Expecting an integer");
    -       return NULL;
    -   }
    -   $2 = PyInt_AsLong($input);
    -   if ($2 < 0) {
    -       PyErr_SetString(PyExc_ValueError, "Positive integer expected");
    -       return NULL;
    -   }
    -   $1 = (void *) malloc($2);
    +  if (!PyInt_Check($input)) {
    +    PyErr_SetString(PyExc_ValueError, "Expecting an integer");
    +    SWIG_fail;
    +  }
    +  $2 = PyInt_AsLong($input);
    +  if ($2 < 0) {
    +    PyErr_SetString(PyExc_ValueError, "Positive integer expected");
    +    SWIG_fail;
    +  }
    +  $1 = (void *) malloc($2);
     }
     
     // Return the buffer.  Discarding any previous return result
     %typemap(argout) (void *rbuffer, size_t len) {
    -   Py_XDECREF($result);   /* Blow away any previous result */
    -   if (result < 0) {      /* Check for I/O error */
    -       free($1);
    -       PyErr_SetFromErrno(PyExc_IOError);
    -       return NULL;
    -   }
    -   $result = PyString_FromStringAndSize($1,result);
    -   free($1);
    +  Py_XDECREF($result);   /* Blow away any previous result */
    +  if (result < 0) {      /* Check for I/O error */
    +    free($1);
    +    PyErr_SetFromErrno(PyExc_IOError);
    +    return NULL;
    +  }
    +  $result = PyString_FromStringAndSize($1,result);
    +  free($1);
     }
     
    @@ -3717,13 +3717,13 @@ this, you could write a multi-argument typemap like this:
     %typemap(in) (double *mat, int rows, int columns) {
    -    MatrixObject *a;
    -    a = GetMatrixFromObject($input);     /* Get matrix somehow */
    +  MatrixObject *a;
    +  a = GetMatrixFromObject($input);     /* Get matrix somehow */
     
    -    /* Get matrix properties */
    -    $1 = GetPointer(a);
    -    $2 = GetRows(a);
    -    $3 = GetColumns(a);
    +  /* Get matrix properties */
    +  $1 = GetPointer(a);
    +  $2 = GetRows(a);
    +  $3 = GetColumns(a);
     }
     
    @@ -3916,9 +3916,9 @@ A fragment can use one or more additional fragments, for example: ... some marshalling code ... if (ival < CHAR_MIN /*defined in <limits.h>*/) { - ... + ... } else { - ... + ... } ... return value; @@ -4026,7 +4026,7 @@ struct A { } %typemap(in, fragment="incode"{A<T>}) { - ... here we use the 'type specialized' fragment "incode"{A<T>} ... + ... here we use the 'type specialized' fragment "incode"{A<T>} ... } };
    @@ -4139,15 +4139,18 @@ For example:
     class Foo {
    -   int x;
    +public:
    +  int x;
     };
     
     class Bar {
    -   int y;
    +public:
    +  int y;
     };
     
     class FooBar : public Foo, public Bar {
    -   int z;
    +public:
    +  int z;
     };
     
    @@ -4181,12 +4184,15 @@ handling of pointer values (and to make adjustments when needed).

    In the wrapper code generated for each language, pointers are handled through the use of special type descriptors and conversion functions. For example, -if you look at the wrapper code for Python, you will see code like this: +if you look at the wrapper code for Python, you will see code similar to the following +(simplified for brevity):

    -if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Foo,1)) == -1) return NULL;
    +if (!SWIG_IsOK(SWIG_ConvertPtr(obj0, (void **) &arg1, SWIGTYPE_p_Foo, 0))) {
    +  SWIG_exception_fail(SWIG_TypeError, "in method 'GrabVal', expecting type Foo");
    +}
     
    @@ -4198,8 +4204,10 @@ target language, a list of equivalent typenames (via typedef or inheritance), and pointer value handling information (if applicable). The SWIG_ConvertPtr() function is simply a utility function that takes a pointer object in the target language and a -type-descriptor objects and uses this information to generate a C++ -pointer. However, the exact name and calling conventions of the conversion +type-descriptor object and uses this information to generate a C++ pointer. +The SWIG_IsOK macro checks the return value for errors and +SWIG_exception_fail can be called to raise an exception in the target language. +However, the exact name and calling conventions of the conversion function depends on the target language (see language specific chapters for details).

    @@ -4305,7 +4313,9 @@ similar to this:
     %typemap(in) Foo * {
    -  if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) return NULL;
    +  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
    +    SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
    +  }
     }
     
    @@ -4338,12 +4348,12 @@ descriptor name for any C datatype. For example:
     %typemap(in) Foo * {
    -  if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) {
    -     Bar *temp;
    -     if ((SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *)) == -1) {
    -         return NULL;
    -     }
    -     $1 = (Foo *) temp;
    +  if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
    +    Bar *temp;
    +    if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *), 0))) {
    +      SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo or Bar");
    +    }
    +    $1 = (Foo *)temp;
       }
     }
     
    @@ -4429,32 +4439,32 @@ For example, the above functions would produce something roughly like this:
     // wrapper pseudocode
     _wrap_foo_0(argc, args[]) {       // foo(int)
    -   int arg1;
    -   int result;
    -   ...
    -   arg1 = FromInteger(args[0]);
    -   result = foo(arg1);
    -   return ToInteger(result);
    +  int arg1;
    +  int result;
    +  ...
    +  arg1 = FromInteger(args[0]);
    +  result = foo(arg1);
    +  return ToInteger(result);
     }
     
     _wrap_foo_1(argc, args[]) {       // foo(double)
    -   double arg1;
    -   int result;
    -   ...
    -   arg1 = FromDouble(args[0]);
    -   result = foo(arg1);
    -   return ToInteger(result);
    +  double arg1;
    +  int result;
    +  ...
    +  arg1 = FromDouble(args[0]);
    +  result = foo(arg1);
    +  return ToInteger(result);
     }
     
     _wrap_foo_2(argc, args[]) {       // foo(char *, int)
    -   char *arg1;
    -   int   arg2;
    -   int result;
    -   ...
    -   arg1 = FromString(args[0]);
    -   arg2 = FromInteger(args[1]);
    -   result = foo(arg1,arg2);
    -   return ToInteger(result);
    +  char *arg1;
    +  int   arg2;
    +  int result;
    +  ...
    +  arg1 = FromString(args[0]);
    +  arg2 = FromInteger(args[1]);
    +  result = foo(arg1,arg2);
    +  return ToInteger(result);
     }
     
     
    @@ -4467,20 +4477,20 @@ Next, a dynamic dispatch function is generated:
     _wrap_foo(argc, args[]) {
    -   if (argc == 1) {
    -       if (IsInteger(args[0])) {
    -           return _wrap_foo_0(argc,args);
    -       } 
    -       if (IsDouble(args[0])) {
    -           return _wrap_foo_1(argc,args);
    -       }
    -   }
    -   if (argc == 2) {
    -       if (IsString(args[0]) && IsInteger(args[1])) {
    -          return _wrap_foo_2(argc,args);
    -       }
    -   }
    -   error("No matching function!\n");
    +  if (argc == 1) {
    +    if (IsInteger(args[0])) {
    +      return _wrap_foo_0(argc,args);
    +    }
    +    if (IsDouble(args[0])) {
    +      return _wrap_foo_1(argc,args);
    +    }
    +  }
    +  if (argc == 2) {
    +    if (IsString(args[0]) && IsInteger(args[1])) {
    +      return _wrap_foo_2(argc,args);
    +    }
    +  }
    +  error("No matching function!\n");
     }
     
    @@ -4589,38 +4599,13 @@ The following excerpt from the Python module illustrates this: $1 = PyString_Check($input) ? 1 : 0; } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { - void *ptr; - if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0) == -1) { - $1 = 0; - PyErr_Clear(); - } else { - $1 = 1; - } +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE * { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $1_descriptor, 0); + $1 = SWIG_IsOK(res) ? 1 : 0; } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { - void *ptr; - if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0) == -1) { - $1 = 0; - PyErr_Clear(); - } else { - $1 = 1; - } -} - -%typecheck(SWIG_TYPECHECK_VOIDPTR) void * { - void *ptr; - if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0) == -1) { - $1 = 0; - PyErr_Clear(); - } else { - $1 = 1; - } -} - -%typecheck(SWIG_TYPECHECK_POINTER) PyObject * -{ +%typecheck(SWIG_TYPECHECK_POINTER) PyObject * { $1 = ($input != 0); }
    @@ -4652,11 +4637,11 @@ Here is an example,
     // Typemap for a C++ string
     %typemap(in) std::string {
    -    if (PyString_Check($input)) {
    -         $1 = std::string(PyString_AsString($input));
    -     } else {
    -         SWIG_exception(SWIG_TypeError, "string expected");
    -     }
    +  if (PyString_Check($input)) {
    +    $1 = std::string(PyString_AsString($input));
    +  } else {
    +    SWIG_exception(SWIG_TypeError, "string expected");
    +  }
     }
     // Copy the typecheck code for "char *".  
     %typemap(typecheck) std::string = char *;
    @@ -4675,7 +4660,7 @@ If you write a typecheck typemap and omit the precedence level, for example comm
     
     %typemap(typecheck /*,precedence=SWIG_TYPECHECK_INTEGER*/) int {
    -   $1 = PyInt_Check($input) ? 1 : 0;
    +  $1 = PyInt_Check($input) ? 1 : 0;
     }
     
    @@ -4727,10 +4712,10 @@ a set of typemaps like this:
     %typemap(in,numinputs=0) int *OUTPUT (int temp) {
    -   $1 = &temp;
    +  $1 = &temp;
     }
     %typemap(argout) int *OUTPUT {
    -   // return value somehow
    +  // return value somehow
     }
     
    @@ -4771,15 +4756,15 @@ For example:
     %typemap(in) int *INPUT (int temp) {
    -   temp = ... get value from $input ...;
    -   $1 = &temp;
    +  temp = ... get value from $input ...;
    +  $1 = &temp;
     }
     
     %typemap(check) int *POSITIVE {
    -   if (*$1 <= 0) {
    -      SWIG_exception(SWIG_ValueError,"Expected a positive number!\n");
    -      return NULL;
    -   }
    +  if (*$1 <= 0) {
    +    SWIG_exception(SWIG_ValueError,"Expected a positive number!\n");
    +    return NULL;
    +  }
     }
     
     ...
    @@ -4817,13 +4802,13 @@ to them.  For example, you could do this:
     
     %typemap(in) int *(int temp) {
    -   temp = (int) PyInt_AsLong($input);
    -   $1 = &temp;
    +  temp = (int) PyInt_AsLong($input);
    +  $1 = &temp;
     }
     
     %typemap(argout) int * {
    -   PyObject *o = PyInt_FromLong(temp$argnum);
    -   ...
    +  PyObject *o = PyInt_FromLong(temp$argnum);
    +  ...
     }
     
    diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index 1c99804f1..7f15d6d27 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -126,16 +126,16 @@ example:
     List make_list(const char *s, ...) {
    -    va_list ap;
    -    List    x;
    -    ...
    -    va_start(ap, s);
    -    while (s) {
    -       x.append(s);
    -       s = va_arg(ap, const char *);
    -    }
    -    va_end(ap);
    -    return x;
    +  va_list ap;
    +  List    x;
    +  ...
    +  va_start(ap, s);
    +  while (s) {
    +    x.append(s);
    +    s = va_arg(ap, const char *);
    +  }
    +  va_end(ap);
    +  return x;
     }
     
    @@ -188,12 +188,12 @@ In contrast, suppose you attempted to make some kind of wrapper around
     int wrap_printf(const char *fmt, ...) {
    -   va_list ap;
    -   va_start(ap,fmt);
    -   ...
    -   printf(fmt,ap);
    -   ...
    -   va_end(ap);
    +  va_list ap;
    +  va_start(ap,fmt);
    +  ...
    +  printf(fmt,ap);
    +  ...
    +  va_end(ap);
     };
     
    @@ -471,15 +471,15 @@ like this:
     wrap_printf() {
    -   char *arg1;
    -   void *arg2;
    -   int   result;
    +  char *arg1;
    +  void *arg2;
    +  int   result;
     
    -   arg1 = "%s";
    -   arg2 = (void *) PyString_AsString(arg2obj);
    -   ...
    -   result = printf(arg1,arg2);
    -   ...
    +  arg1 = "%s";
    +  arg2 = (void *) PyString_AsString(arg2obj);
    +  ...
    +  result = printf(arg1,arg2);
    +  ...
     }
     
    @@ -517,7 +517,7 @@ like this: argc = PyTuple_Size(varargs); if (argc > 10) { PyErr_SetString(PyExc_ValueError, "Too many arguments"); - return NULL; + SWIG_fail; } for (i = 0; i < argc; i++) { PyObject *pyobj = PyTuple_GetItem(varargs, i); @@ -525,16 +525,16 @@ like this: %#if PY_VERSION_HEX>=0x03000000 PyObject *pystr; if (!PyUnicode_Check(pyobj)) { - PyErr_SetString(PyExc_ValueError, "Expected a string"); - return NULL; + PyErr_SetString(PyExc_ValueError, "Expected a string"); + SWIG_fail; } pystr = PyUnicode_AsUTF8String(pyobj); str = strdup(PyBytes_AsString(pystr)); Py_XDECREF(pystr); %#else if (!PyString_Check(pyobj)) { - PyErr_SetString(PyExc_ValueError, "Expected a string"); - return NULL; + PyErr_SetString(PyExc_ValueError, "Expected a string"); + SWIG_fail; } str = PyString_AsString(pyobj); %#endif @@ -626,23 +626,23 @@ example. For example: of strings */ %typemap(in) (...) { - char **argv; - int argc; - int i; + char **argv; + int argc; + int i; - argc = PyTuple_Size(varargs); - argv = (char **) malloc(sizeof(char *)*(argc+1)); - for (i = 0; i < argc; i++) { - PyObject *o = PyTuple_GetItem(varargs,i); - if (!PyString_Check(o)) { - PyErr_SetString(PyExc_ValueError,"Expected a string"); - free(argv); - return NULL; - } - argv[i] = PyString_AsString(o); - } - argv[i] = NULL; - $1 = (void *) argv; + argc = PyTuple_Size(varargs); + argv = (char **) malloc(sizeof(char *)*(argc+1)); + for (i = 0; i < argc; i++) { + PyObject *o = PyTuple_GetItem(varargs,i); + if (!PyString_Check(o)) { + free(argv); + PyErr_SetString(PyExc_ValueError,"Expected a string"); + SWIG_fail; + } + argv[i] = PyString_AsString(o); + } + argv[i] = NULL; + $1 = (void *) argv; } /* Rewrite the function call, using libffi */ @@ -676,11 +676,11 @@ example. For example: &ffi_type_uint, types) == FFI_OK) { ffi_call(&cif, (void (*)()) execlp, &result, values); } else { - PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!"); free(types); free(values); free(arg3); - return NULL; + PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!"); + SWIG_fail; } free(types); free(values); @@ -744,8 +744,8 @@ As a more extreme example of libffi, here is some code that attempts to wrap %rename directive. For exa class Foo { public: - virtual void bar(char *arg, ...); // gets varargs above + virtual void bar(char *arg, ...); // gets varargs above }; class Spam: public Foo { public: - virtual void bar(char *arg, ...); // gets varargs above + virtual void bar(char *arg, ...); // gets varargs above };
    @@ -952,9 +952,9 @@ are placed in arg2, arg3, and so forth. For example:
     %feature("action") Foo::bar {
    -   ...
    -   result = arg1->bar(arg2, arg3, etc.);
    -   ...
    +  ...
    +  result = arg1->bar(arg2, arg3, etc.);
    +  ...
     }
     
    @@ -987,10 +987,10 @@ you might structure your interface like this:
     %typemap(const char *fmt, ...) {
    -   ...
    +  ...
     }
     %feature("action") traceprintf {
    -   ...
    +  ...
     }
     
     /* Include some header file with traceprintf in it */
    @@ -1011,7 +1011,7 @@ to control this:
     
     #ifdef USE_LIBFFI
     %feature("action") printf {
    -   ...
    +  ...
     }
     #endif
     #ifdef USE_OTHERFFI
    diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html
    index 89a8375a5..e7b291f21 100644
    --- a/Doc/Manual/Warnings.html
    +++ b/Doc/Manual/Warnings.html
    @@ -112,16 +112,16 @@ suppress a warning for a method in a class hierarchy, you could do this:
     %warnfilter(501) Object::foo;
     class Object {
     public:
    -   int foo(int);
    -   int foo(double);      // Silently ignored
    -   ...
    +  int foo(int);
    +  int foo(double);      // Silently ignored
    +  ...
     };
     
     class Derived : public Object {
     public:
    -   int foo(int);
    -   int foo(double);      // Silently ignored
    -   ...
    +  int foo(int);
    +  int foo(double);      // Silently ignored
    +  ...
     };
     
    @@ -136,7 +136,7 @@ Warnings can be suppressed for an entire class by supplying a class name. For e class Object { public: - ... // All 501 warnings ignored in class + ... // All 501 warnings ignored in class };
    @@ -259,7 +259,7 @@ Warning messages can be associated with typemaps using the
     %typemap(in, warning="901:You are really going to regret this usage of $1_type $1_name") blah * {
    -   ...
    +  ...
     }
     
    diff --git a/Examples/python/libffi/example.i b/Examples/python/libffi/example.i index 9a29ec04e..3f5d766c5 100644 --- a/Examples/python/libffi/example.i +++ b/Examples/python/libffi/example.i @@ -20,7 +20,7 @@ PyObject *o = PyTuple_GetItem(varargs,i); if (!PyString_Check(o)) { PyErr_SetString(PyExc_ValueError,"Expected a string"); - return NULL; + SWIG_fail; } argv[i] = PyString_AsString(o); } @@ -58,11 +58,11 @@ &ffi_type_uint, types) == FFI_OK) { ffi_call(&cif, (void (*)()) execlp, &result, values); } else { - PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!"); free(types); free(values); free(arg3); - return NULL; + PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!"); + SWIG_fail; } free(types); free(values); @@ -107,9 +107,9 @@ int execlp(const char *path, const char *arg1, ...); argv[i].type = VT_POINTER; argv[i].val.pvalue = (void *) PyString_AsString(o); } else { - PyErr_SetString(PyExc_ValueError,"Unsupported argument type"); free(argv); - return NULL; + PyErr_SetString(PyExc_ValueError,"Unsupported argument type"); + SWIG_fail; } } @@ -157,11 +157,11 @@ int execlp(const char *path, const char *arg1, ...); &ffi_type_uint, types) == FFI_OK) { ffi_call(&cif, (void (*)()) printf, &result, values); } else { - PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!"); free(types); free(values); free(args); - return NULL; + PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!"); + SWIG_fail; } free(types); free(values); diff --git a/Examples/python/multimap/example.i b/Examples/python/multimap/example.i index 635f61c13..66c0f74c6 100644 --- a/Examples/python/multimap/example.i +++ b/Examples/python/multimap/example.i @@ -69,7 +69,7 @@ extern int gcdmain(int argc, char *argv[]); PyObject *utf8str; if (!PyUnicode_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a string"); - return NULL; + SWIG_fail; } utf8str = PyUnicode_AsUTF8String($input); PyBytes_AsStringAndSize(utf8str, &cstr, &len); @@ -79,7 +79,7 @@ extern int gcdmain(int argc, char *argv[]); %#else if (!PyString_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a string"); - return NULL; + SWIG_fail; } $1 = PyString_AsString($input); $2 = (int)PyString_Size($input); diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 6e4034cb1..c6a02f487 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -203,6 +203,7 @@ CPP_TEST_CASES += \ director_thread \ director_unroll \ director_using \ + director_void \ director_wombat \ disown \ dynamic_cast \ @@ -259,7 +260,6 @@ CPP_TEST_CASES += \ langobj \ li_attribute \ li_attribute_template \ - li_boost_array \ li_boost_shared_ptr \ li_boost_shared_ptr_bits \ li_boost_shared_ptr_template \ @@ -487,6 +487,7 @@ CPP_TEST_CASES += \ typemap_array_qualifiers \ typemap_delete \ typemap_directorout \ + typemap_documentation \ typemap_global_scope \ typemap_manyargs \ typemap_namespace \ diff --git a/Examples/test-suite/cpp11_li_std_array.i b/Examples/test-suite/cpp11_li_std_array.i index 19304d9e6..dedd6483a 100644 --- a/Examples/test-suite/cpp11_li_std_array.i +++ b/Examples/test-suite/cpp11_li_std_array.i @@ -1,6 +1,6 @@ %module cpp11_li_std_array -#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) +#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP) %{ #include diff --git a/Examples/test-suite/cpp_static.i b/Examples/test-suite/cpp_static.i index c68e986eb..1f8ca1282 100644 --- a/Examples/test-suite/cpp_static.i +++ b/Examples/test-suite/cpp_static.i @@ -22,5 +22,28 @@ public: %} %{ -int StaticMemberTest::static_int; +int StaticMemberTest::static_int = 99; +%} + +%inline %{ +struct StaticBase { + static int statty; + virtual ~StaticBase() {} +}; +struct StaticDerived : StaticBase { + static int statty; +}; +%} + +%{ +int StaticBase::statty = 11; +int StaticDerived::statty = 111; +%} + +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs b/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs new file mode 100644 index 000000000..d0c956ad3 --- /dev/null +++ b/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs @@ -0,0 +1,82 @@ +// This test tests all the methods in the C# collection wrapper +using System; +using cpp11_li_std_arrayNamespace; + +public class cpp11_li_std_array_runme +{ + private static ArrayInt6 ToArray6(int[] a) + { + if (a.Length != 6) + throw new Exception("a is incorrect size"); + return new ArrayInt6(a); + } + + private static void compareContainers(ArrayInt6 actual, int[] expected) + { + if (actual.Count != expected.Length) + throw new Exception("Sizes are different: " + actual.Count + " " + expected.Length); + for (int i=0; ivoidPtrIn(&num); + } + int callVirtualOut(DirectorVoidPointer *d) { + return *(int *)d->voidPtrOut(); + } + static int VoidToInt(void *p) { + return *(int *)p; + } +}; +%} + diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index fd5978102..3beefccc0 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -569,6 +569,17 @@ repeat repeatTest(repeat e) { return e; } } %} +%inline %{ +namespace EnumWithMacro { +#define PACK(C1,C2,C3,C4) ((C1<<24)|(C2<<16)|(C3<<8)|C4) +typedef enum { + ABCD = PACK('A','B','C','D'), + ABCD2 = ABCD +} enumWithMacro; +enumWithMacro enumWithMacroTest(enumWithMacro e) { return e; } +} +%} + %inline %{ namespace DifferentSpace { enum DifferentTypes { @@ -577,7 +588,9 @@ enum DifferentTypes { typebooltrue = true, typebooltwo, typechar = 'C', - typedefaultint + typedefaultint, + typecharcompound='A'+1, + typecharcompound2='B' << 2 }; DifferentTypes differentTypesTest(DifferentTypes n) { return n; } @@ -587,7 +600,9 @@ enum { global_typebooltrue = true, global_typebooltwo, global_typechar = 'C', - global_typedefaultint + global_typedefaultint, + global_typecharcompound='A'+1, + global_typecharcompound2='B' << 2 }; int globalDifferentTypesTest(int n) { return n; } } diff --git a/Examples/test-suite/exception_classname.i b/Examples/test-suite/exception_classname.i index 6900581cf..ed8c433eb 100644 --- a/Examples/test-suite/exception_classname.i +++ b/Examples/test-suite/exception_classname.i @@ -1,7 +1,7 @@ %module exception_classname %warnfilter(SWIGWARN_RUBY_WRONG_NAME); -#ifdef SWIGPHP +#if defined(SWIGPHP) || defined(SWIGD) %rename(ExceptionClass) Exception; #endif diff --git a/Examples/test-suite/java/smart_pointer_ignore_runme.java b/Examples/test-suite/java/smart_pointer_ignore_runme.java index f02bf536a..d6c90dd4e 100644 --- a/Examples/test-suite/java/smart_pointer_ignore_runme.java +++ b/Examples/test-suite/java/smart_pointer_ignore_runme.java @@ -13,7 +13,7 @@ public class smart_pointer_ignore_runme { public static void main(String argv[]) { DerivedPtr d = smart_pointer_ignore.makeDerived(); - d.base(); - d.derived(); + d.baseMethod(); + d.derivedMethod(); } } diff --git a/Examples/test-suite/li_boost_array.i b/Examples/test-suite/li_boost_array.i deleted file mode 100644 index e18140a50..000000000 --- a/Examples/test-suite/li_boost_array.i +++ /dev/null @@ -1,87 +0,0 @@ -%module li_boost_array - -#if defined(SWIGPYTHON) || defined(SWIGRUBY) - -// Hack to use the std::array support for boost::array. -// Is limited as it currently exposes some 'using' bugs in SWIG though. -// For example, the type system fails to see that pointers to std::array -// and pointers to boost::array are the same. - -%{ -#if __cplusplus >= 201103 || (defined(_MSC_VER) && _MSC_VER >= 1900) -// Use C++11 array as this is unfortunately sometimes included by -#include -namespace boost { - using std::array; -} -#else -#include -namespace std { - using boost::array; -} -#endif -%} -namespace boost { - using std::array; -} - -%ignore std::array::fill; // Some older versions of boost don't have this function - -%include - -%template(ArrayInt6) std::array; - -%inline %{ -boost::array arrayOutVal() { - const signed char carray[] = { -2, -1, 0, 0, 1, 2 }; - boost::array myarray; - for (size_t i=0; i<6; ++i) { - myarray[i] = carray[i]; - } - return myarray; -} - -boost::array & arrayOutRef() { - static boost::array a = { -2, -1, 0, 0, 1, 2 }; - return a; -} - -const boost::array & arrayOutConstRef() { - static boost::array a = { -2, -1, 0, 0, 1, 2 }; - return a; -} - -boost::array * arrayOutPtr() { - static boost::array a = { -2, -1, 0, 0, 1, 2 }; - return &a; -} - -boost::array arrayInVal(boost::array myarray) { - for (boost::array::iterator it = myarray.begin(); it!=myarray.end(); ++it) { - *it *= 10; - } - return myarray; -} - -const boost::array & arrayInConstRef(const boost::array & myarray) { - static boost::array a = myarray; - for (boost::array::iterator it = a.begin(); it!=a.end(); ++it) { - *it *= 10; - } - return a; -} - -void arrayInRef(boost::array & myarray) { - for (boost::array::iterator it = myarray.begin(); it!=myarray.end(); ++it) { - *it *= 10; - } -} - -void arrayInPtr(boost::array * myarray) { - for (boost::array::iterator it = myarray->begin(); it!=myarray->end(); ++it) { - *it *= 10; - } -} -%} - -#endif diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index 7f474bd9c..9c74715f0 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -50,7 +50,7 @@ namespace test { PyComplex_ImagAsDouble($input)); } else { PyErr_SetString(PyExc_TypeError,"Expected test_complex.\n"); - return NULL; + SWIG_fail; } } %typemap(freearg) test::test_complex * { @@ -242,7 +242,7 @@ namespace Split { $1 = PyInt_AsLong($input); if ($1 < 0) { PyErr_SetString(PyExc_ValueError,"domain error\n"); - return NULL; + SWIG_fail; } } #endif diff --git a/Examples/test-suite/php/cpp_static_runme.php b/Examples/test-suite/php/cpp_static_runme.php index e1cc3e733..9b436b87c 100644 --- a/Examples/test-suite/php/cpp_static_runme.php +++ b/Examples/test-suite/php/cpp_static_runme.php @@ -4,11 +4,11 @@ require "tests.php"; require "cpp_static.php"; // New functions -check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3)); +check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3,is_python_builtin)); // New classes -check::classes(array(StaticMemberTest,StaticFunctionTest)); +check::classes(array(StaticMemberTest,StaticFunctionTest,cpp_static,StaticBase,StaticDerived)); // New vars -check::globals(array(staticmembertest_static_int)); +check::globals(array(staticmembertest_static_int,staticbase_statty,staticderived_statty)); check::done(); ?> diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i index db71bd2d7..3a999ada3 100644 --- a/Examples/test-suite/preproc_constants.i +++ b/Examples/test-suite/preproc_constants.i @@ -51,7 +51,7 @@ // Expressions - runtime tests check the type for any necessary type promotions of the expressions #define INT_AND_BOOL 0xFF & true -//#define INT_AND_CHAR 0xFF & 'A' /* FIXME compile error */ +#define INT_AND_CHAR 0xFF & 'A' #define INT_AND_INT 0xFF & 2 #define INT_AND_UINT 0xFF & 2u #define INT_AND_LONG 0xFF & 2l @@ -60,8 +60,7 @@ #define INT_AND_ULLONG 0xFF & 2ull #define BOOL_AND_BOOL true & true // Note integral promotion to type int -//#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int -/* FIXME ABOVE */ +#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int #define EXPR_MULTIPLY 0xFF * 2 @@ -88,6 +87,9 @@ #define EXPR_LOR 0xFF || 1 #define EXPR_CONDITIONAL true ? 2 : 2.2 +#define EXPR_CHAR_COMPOUND_ADD 'A' + 12 +#define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6 +#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p') /// constant assignment in enum #if defined(SWIGCSHARP) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index bfc5450b0..033b83103 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -64,6 +64,7 @@ CPP_TEST_CASES += \ python_docstring \ python_nondynamic \ python_overload_simple_cast \ + python_pickle \ python_pythoncode \ python_richcompare \ python_strict_unicode \ diff --git a/Examples/test-suite/python/cpp_static_runme.py b/Examples/test-suite/python/cpp_static_runme.py index 1c7705f3e..ef31f88af 100644 --- a/Examples/test-suite/python/cpp_static_runme.py +++ b/Examples/test-suite/python/cpp_static_runme.py @@ -13,6 +13,31 @@ else: StaticFunctionTest().static_func() StaticFunctionTest().static_func_2(1) StaticFunctionTest().static_func_3(1, 2) -StaticMemberTest.static_int = 10 -if not StaticMemberTest.static_int == 10: - raise RuntimeError("static_int not 10") + +if is_python_builtin(): + if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99") + StaticMemberTest.static_int = 10 + if not StaticMemberTest.static_int == 10: raise RuntimeError("static_int not 10") + + if not StaticBase.statty == 11: raise RuntimeError("statty not 11") + if not StaticDerived.statty == 111: raise RuntimeError("statty not 111") + StaticBase.statty = 22 + StaticDerived.statty = 222 + if not StaticBase.statty == 22: raise RuntimeError("statty not 22") + if not StaticDerived.statty == 222: raise RuntimeError("statty not 222") + + # Restore + StaticMemberTest.static_int = 99 + StaticBase.statty = 11 + StaticDerived.statty = 111 + +if not cvar.StaticMemberTest_static_int == 99: raise RuntimeError("cvar static_int not 99") +cvar.StaticMemberTest_static_int = 10 +if not cvar.StaticMemberTest_static_int == 10: raise RuntimeError("cvar static_int not 10") + +if not cvar.StaticBase_statty == 11: raise RuntimeError("cvar statty not 11") +if not cvar.StaticDerived_statty == 111: raise RuntimeError("cvar statty not 111") +cvar.StaticBase_statty = 22 +cvar.StaticDerived_statty = 222 +if not cvar.StaticBase_statty == 22: raise RuntimeError("cvar statty not 22") +if not cvar.StaticDerived_statty == 222: raise RuntimeError("cvar statty not 222") diff --git a/Examples/test-suite/python/li_boost_array_runme.py b/Examples/test-suite/python/li_boost_array_runme.py deleted file mode 100644 index 4fa7eb882..000000000 --- a/Examples/test-suite/python/li_boost_array_runme.py +++ /dev/null @@ -1,55 +0,0 @@ -from li_boost_array import * -import sys - - -def failed(a, b, msg): - raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) - - -def compare_sequences(a, b): - if len(a) != len(b): - failed(a, b, "different sizes") - for i in range(len(a)): - if a[i] != b[i]: - failed(a, b, "elements are different") - -def compare_containers(pythonlist, swigarray): - compare_sequences(pythonlist, swigarray) - -ps = [0, 1, 2, 3, 4, 5] - -ai = ArrayInt6(ps) - -compare_containers(ps, ai) - -# Modify content -for i in range(len(ps)): - ps[i] = (ps[i] + 1) * 10 - ai[i] = (ai[i] + 1) * 10 -compare_containers(ps, ai) - -# Empty -ai = ArrayInt6() -compare_containers([0, 0, 0, 0, 0, 0], ai) - -# Check return -compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2]) -compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2]) -#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2]) -#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2]) - -# Check passing arguments -ai = arrayInVal([9, 8, 7, 6, 5, 4]) -compare_containers(ai, [90, 80, 70, 60, 50, 40]) - -ai = arrayInConstRef([9, 8, 7, 6, 5, 4]) -compare_containers(ai, [90, 80, 70, 60, 50, 40]) - -#ai = ArrayInt6([9, 8, 7, 6, 5, 4]) -#arrayInRef(ai) -#compare_containers(ai, [90, 80, 70, 60, 50, 40]) - -#ai = ArrayInt6([9, 8, 7, 6, 5, 4]) -#arrayInPtr(ai) -#compare_containers(ai, [90, 80, 70, 60, 50, 40]) - diff --git a/Examples/test-suite/python/python_pickle_runme.py b/Examples/test-suite/python/python_pickle_runme.py new file mode 100644 index 000000000..cf2847919 --- /dev/null +++ b/Examples/test-suite/python/python_pickle_runme.py @@ -0,0 +1,35 @@ +import python_pickle + +import pickle +import sys + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + +def check(p): + msg = p.msg + if msg != "hi there": + raise RuntimeError("Bad, got: " + msg) + +if not is_new_style_class(python_pickle.PickleMe): + sys.exit(0) + +python_pickle.cvar.debug = False + +p = python_pickle.PickleMe("hi there") +check(p) + +r = p.__reduce__() +if python_pickle.cvar.debug: + print "__reduce__ returned:", r +pickle_string = pickle.dumps(p) +newp = pickle.loads(pickle_string) +check(newp) + +# Not yet working... some crash and others are not producing a sensible "can't be pickled" error +#nfp = python_pickle.NotForPickling("no no") +#print nfp.__reduce__() +#pickle_string = pickle.dumps(nfp) +#print pickle_string +#newp = pickle.loads(pickle_string) +#print newp.msg diff --git a/Examples/test-suite/python/typemap_documentation_runme.py b/Examples/test-suite/python/typemap_documentation_runme.py new file mode 100644 index 000000000..3d1c6fa8c --- /dev/null +++ b/Examples/test-suite/python/typemap_documentation_runme.py @@ -0,0 +1,20 @@ +import typemap_documentation + +f = typemap_documentation.Foo() +f.x = 55 +b = typemap_documentation.Bar() +b.y = 44 + +if 55 != typemap_documentation.GrabVal(f): + raise RuntimeError("bad value") + +try: + typemap_documentation.GrabVal(b) + raise RuntimeError("unexpected exception") +except TypeError: + pass + +if 55 != typemap_documentation.GrabValFooBar(f): + raise RuntimeError("bad f value") +if 44 != typemap_documentation.GrabValFooBar(b): + raise RuntimeError("bad b value") diff --git a/Examples/test-suite/python_builtin.i b/Examples/test-suite/python_builtin.i index 45654a014..4108f6753 100644 --- a/Examples/test-suite/python_builtin.i +++ b/Examples/test-suite/python_builtin.i @@ -2,6 +2,12 @@ %module python_builtin +%{ +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif +%} + %inline %{ #ifdef SWIGPYTHON_BUILTIN bool is_python_builtin() { return true; } @@ -156,12 +162,12 @@ void Dealloc2Destroyer(PyObject *v) { %feature("python:slot", "sq_length", functype="lenfunc") SimpleArray::__len__; %inline %{ class SimpleArray { - size_t size; + Py_ssize_t size; int numbers[5]; public: - SimpleArray(size_t size) : size(size) { - for (size_t x = 0; x jj) throw std::invalid_argument("getitem i should not be larger than j"); SimpleArray n(jj-ii); - for (size_t x = 0; x + +%extend PickleMe { +#if 0 +// Note: %pythoncode can't be used with -builtin +%pythoncode %{ +def __reduce__(self): + print "In Python __reduce__" + return (type(self), (self.msg, )) +%} +#else + // Equivalent to Python code above + PyObject *__reduce__() { + if (debug) + std::cout << "In C++ __reduce__" << std::endl; + PyObject *args = PyTuple_New(1); + PyTuple_SetItem(args, 0, SWIG_From_std_string(self->msg)); + + swig_type_info *ty = SWIGTYPE_p_PickleMe; + SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; +#if defined(SWIGPYTHON_BUILTIN) + PyObject *callable = (PyObject *)data->pytype; +#else + PyObject *callable = data->klass; +#endif + Py_INCREF(callable); + + PyObject *ret = PyTuple_New(2); + PyTuple_SetItem(ret, 0, callable); + PyTuple_SetItem(ret, 1, args); + return ret; + } +#endif +} + +%inline %{ +#include + +bool debug = false; + +struct PickleMe { + std::string msg; + PickleMe(const std::string& msg) : msg(msg) { + if (debug) + std::cout << "In C++ constructor " << " [" << msg << "]" << std::endl; + } +}; + +struct NotForPickling { + std::string msg; + NotForPickling(const std::string& msg) : msg(msg) {} +}; +%} diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i index c7d8b83ec..f05fb98eb 100644 --- a/Examples/test-suite/python_varargs_typemap.i +++ b/Examples/test-suite/python_varargs_typemap.i @@ -11,7 +11,7 @@ argc = PyTuple_Size(varargs); if (argc > 10) { PyErr_SetString(PyExc_ValueError, "Too many arguments"); - return NULL; + SWIG_fail; } for (i = 0; i < argc; i++) { PyObject *pyobj = PyTuple_GetItem(varargs, i); @@ -20,7 +20,7 @@ PyObject *pystr; if (!PyUnicode_Check(pyobj)) { PyErr_SetString(PyExc_ValueError, "Expected a string"); - return NULL; + SWIG_fail; } pystr = PyUnicode_AsUTF8String(pyobj); str = strdup(PyBytes_AsString(pystr)); @@ -28,7 +28,7 @@ %#else if (!PyString_Check(pyobj)) { PyErr_SetString(PyExc_ValueError, "Expected a string"); - return NULL; + SWIG_fail; } str = PyString_AsString(pyobj); %#endif diff --git a/Examples/test-suite/ruby/li_boost_array_runme.rb b/Examples/test-suite/ruby/li_boost_array_runme.rb deleted file mode 100644 index a7b7720ea..000000000 --- a/Examples/test-suite/ruby/li_boost_array_runme.rb +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env ruby -# -# Put description here -# -# -# -# -# - -require 'swig_assert' - -require 'li_boost_array' - -include Li_boost_array - - -def failed(a, b, msg) - raise RuntimeError, "#{msg} #{a} #{b}" -end - -def compare_sequences(a, b) - if a.size != b.size - failed(a, b, "different sizes") - end - for i in 0..a.size-1 - failed(a, b, "elements are different:") if a[i] != b[i] - end -end - -def compare_containers(rubyarray, swigarray) - compare_sequences(rubyarray, swigarray) -end - -ps = [0, 1, 2, 3, 4, 5] - -ai = ArrayInt6.new(ps) - -compare_containers(ps, ai) - -# Modify content -for i in 0..ps.size-1 - ps[i] = ps[i] * 10 - ai[i] = ai[i] * 10 -end -compare_containers(ps, ai) - -# Empty -ai = ArrayInt6.new() - -# Check return -compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2]) -compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2]) -#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2]) -#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2]) - -# Check passing arguments -ai = arrayInVal([9, 8, 7, 6, 5, 4]) -compare_containers(ai, [90, 80, 70, 60, 50, 40]) - -ai = arrayInConstRef([9, 8, 7, 6, 5, 4]) -compare_containers(ai, [90, 80, 70, 60, 50, 40]) - -#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) -#arrayInRef(ai) -#compare_containers(ai, [90, 80, 70, 60, 50, 40]) - -#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4]) -#arrayInPtr(ai) -#compare_containers(ai, [90, 80, 70, 60, 50, 40]) - diff --git a/Examples/test-suite/smart_pointer_ignore.i b/Examples/test-suite/smart_pointer_ignore.i index f369de782..146a5e49e 100644 --- a/Examples/test-suite/smart_pointer_ignore.i +++ b/Examples/test-suite/smart_pointer_ignore.i @@ -6,12 +6,12 @@ %inline %{ class Base { public: - void base() {} + void baseMethod() {} }; class Derived : public Base { public: - void derived() {} + void derivedMethod() {} }; template diff --git a/Examples/test-suite/typemap_documentation.i b/Examples/test-suite/typemap_documentation.i new file mode 100644 index 000000000..b7c1ddd22 --- /dev/null +++ b/Examples/test-suite/typemap_documentation.i @@ -0,0 +1,50 @@ +%module typemap_documentation + +// A place for checking that documented typemaps are working. +// The UTL languages are the only ones that are consistent enough to support these generic typemap functions. +// These are in the Typemaps.html chapter. + +%inline %{ +class Foo { +public: + int x; +}; + +class Bar { +public: + int y; +}; +%} + +#if defined(SWIGUTL) +%typemap(in) Foo * { + if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) { + SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo"); + } +} +#endif + +%inline %{ +int GrabVal(Foo *f) { + return f->x; +} +%} + + +#if defined(SWIGUTL) +%typemap(in) Foo * { + if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) { + Bar *temp; + if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *), 0))) { + SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo or Bar"); + } + $1 = (Foo *)temp; + } +} +#endif + +%inline %{ +int GrabValFooBar(Foo *f) { + return f->x; +} +%} diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index d94336194..a703899d8 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -860,7 +860,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { global::System.IntPtr ret = $imcall;$excode return ret; } - +%typemap(csdirectorin) void *VOID_INT_PTR "$iminput" +%typemap(csdirectorout) void *VOID_INT_PTR "$cscall" /* Typemaps used for the generation of proxy and type wrapper class code */ %typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" diff --git a/Lib/csharp/std_array.i b/Lib/csharp/std_array.i new file mode 100644 index 000000000..c1fee124d --- /dev/null +++ b/Lib/csharp/std_array.i @@ -0,0 +1,227 @@ +/* ----------------------------------------------------------------------------- + * std_array.i + * + * SWIG typemaps for std::array + * C# implementation + * The C# wrapper is made to look and feel like a C# System.Collections.Generic.IReadOnlyList<> collection. + * ----------------------------------------------------------------------------- */ + +%{ +#include +#include +#include +%} + +%include + + +%define SWIG_STD_ARRAY_INTERNAL(T, N) +%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n"; +%typemap(cscode) std::array< T, N > %{ + public $csclassname(global::System.Collections.ICollection c) : this() { + if (c == null) + throw new global::System.ArgumentNullException("c"); + int end = global::System.Math.Min(this.Count, c.Count); + int i = 0; + foreach ($typemap(cstype, T) elem in c) { + if (i >= end) + break; + this[i++] = elem; + } + } + + public int Count { + get { + return (int)size(); + } + } + + public $typemap(cstype, T) this[int index] { + get { + return getitem(index); + } + set { + setitem(index, value); + } + } + + public bool IsEmpty { + get { + return empty(); + } + } + + public void CopyTo($typemap(cstype, T)[] array) + { + CopyTo(0, array, 0, this.Count); + } + + public void CopyTo($typemap(cstype, T)[] array, int arrayIndex) + { + CopyTo(0, array, arrayIndex, this.Count); + } + + public void CopyTo(int index, $typemap(cstype, T)[] array, int arrayIndex, int count) + { + if (array == null) + throw new global::System.ArgumentNullException("array"); + if (index < 0) + throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero"); + if (arrayIndex < 0) + throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); + if (count < 0) + throw new global::System.ArgumentOutOfRangeException("count", "Value is less than zero"); + if (array.Rank > 1) + throw new global::System.ArgumentException("Multi dimensional array.", "array"); + if (index+count > this.Count || arrayIndex+count > array.Length) + throw new global::System.ArgumentException("Number of elements to copy is too large."); + for (int i=0; i global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>.GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + public $csclassnameEnumerator GetEnumerator() { + return new $csclassnameEnumerator(this); + } + + // Type-safe enumerator + /// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown + /// whenever the collection is modified. This has been done for changes in the size of the + /// collection but not when one of the elements of the collection is modified as it is a bit + /// tricky to detect unmanaged code that modifies the collection under our feet. + public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator + , global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> + { + private $csclassname collectionRef; + private int currentIndex; + private object currentObject; + private int currentSize; + + public $csclassnameEnumerator($csclassname collection) { + collectionRef = collection; + currentIndex = -1; + currentObject = null; + currentSize = collectionRef.Count; + } + + // Type-safe iterator Current + public $typemap(cstype, T) Current { + get { + if (currentIndex == -1) + throw new global::System.InvalidOperationException("Enumeration not started."); + if (currentIndex > currentSize - 1) + throw new global::System.InvalidOperationException("Enumeration finished."); + if (currentObject == null) + throw new global::System.InvalidOperationException("Collection modified."); + return ($typemap(cstype, T))currentObject; + } + } + + // Type-unsafe IEnumerator.Current + object global::System.Collections.IEnumerator.Current { + get { + return Current; + } + } + + public bool MoveNext() { + int size = collectionRef.Count; + bool moveOkay = (currentIndex+1 < size) && (size == currentSize); + if (moveOkay) { + currentIndex++; + currentObject = collectionRef[currentIndex]; + } else { + currentObject = null; + } + return moveOkay; + } + + public void Reset() { + currentIndex = -1; + currentObject = null; + if (collectionRef.Count != currentSize) { + throw new global::System.InvalidOperationException("Collection modified."); + } + } + + public void Dispose() { + currentIndex = -1; + currentObject = null; + } + } +%} + + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + + array(); + array(const array &other); + + size_type size() const; + bool empty() const; + + %rename(Fill) fill; + void fill(const value_type& val); + + %rename(Swap) swap; + void swap(array& other); + + %extend { + T getitemcopy(int index) throw (std::out_of_range) { + if (index>=0 && index<(int)$self->size()) + return (*$self)[index]; + else + throw std::out_of_range("index"); + } + const_reference getitem(int index) throw (std::out_of_range) { + if (index>=0 && index<(int)$self->size()) + return (*$self)[index]; + else + throw std::out_of_range("index"); + } + void setitem(int index, const_reference val) throw (std::out_of_range) { + if (index>=0 && index<(int)$self->size()) + (*$self)[index] = val; + else + throw std::out_of_range("index"); + } + void Reverse() { + std::reverse($self->begin(), $self->end()); + } + void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) { + if (index < 0) + throw std::out_of_range("index"); + if (count < 0) + throw std::out_of_range("count"); + if (index >= (int)$self->size()+1 || index+count > (int)$self->size()) + throw std::invalid_argument("invalid range"); + std::reverse($self->begin()+index, $self->begin()+index+count); + } + } +%enddef + + +%csmethodmodifiers std::array::empty "private" +%csmethodmodifiers std::array::getitemcopy "private" +%csmethodmodifiers std::array::getitem "private" +%csmethodmodifiers std::array::setitem "private" +%csmethodmodifiers std::array::size "private" + +namespace std { + template class array { + SWIG_STD_ARRAY_INTERNAL(T, N) + }; +} diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 467a2ade8..fad729dff 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -398,4 +398,5 @@ SWIG_STD_VECTOR_ENHANCED(unsigned long long) SWIG_STD_VECTOR_ENHANCED(float) SWIG_STD_VECTOR_ENHANCED(double) SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include +SWIG_STD_VECTOR_ENHANCED(std::wstring) // also requires a %include diff --git a/Lib/java/std_wstring.i b/Lib/java/std_wstring.i index 0137a2da5..dd0b2f5ff 100644 --- a/Lib/java/std_wstring.i +++ b/Lib/java/std_wstring.i @@ -60,16 +60,15 @@ class wstring; %} %typemap(directorin,descriptor="Ljava/lang/String;") wstring %{ -{ jsize $1_len = $1.length(); - jchar *conv_buf = new jchar[$1_len]; + jchar *$1_conv_buf = new jchar[$1_len]; for (jsize i = 0; i < $1_len; ++i) { - conv_buf[i] = (jchar)$1[i]; + $1_conv_buf[i] = (jchar)$1[i]; } - $input = jenv->NewString(conv_buf, $1_len); - delete [] conv_buf; -} -Swig::LocalRefGuard $1_refguard(jenv, $input); %} + $input = jenv->NewString($1_conv_buf, $1_len); + Swig::LocalRefGuard $1_refguard(jenv, $input); + delete [] $1_conv_buf; +%} %typemap(out) wstring %{jsize $1_len = $1.length(); @@ -139,16 +138,15 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); %} jenv->ReleaseStringChars($input, $1_pstr); %} %typemap(directorin,descriptor="Ljava/lang/String;") const wstring & %{ -{ jsize $1_len = $1.length(); - jchar *conv_buf = new jchar[$1_len]; + jchar *$1_conv_buf = new jchar[$1_len]; for (jsize i = 0; i < $1_len; ++i) { - conv_buf[i] = (jchar)($1)[i]; + $1_conv_buf[i] = (jchar)($1)[i]; } - $input = jenv->NewString(conv_buf, $1_len); - delete [] conv_buf; -} -Swig::LocalRefGuard $1_refguard(jenv, $input); %} + $input = jenv->NewString($1_conv_buf, $1_len); + Swig::LocalRefGuard $1_refguard(jenv, $input); + delete [] $1_conv_buf; +%} %typemap(out) const wstring & %{jsize $1_len = $1->length(); diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i index 4f21c5cbf..a3e99f510 100644 --- a/Lib/php/globalvar.i +++ b/Lib/php/globalvar.i @@ -4,8 +4,7 @@ * Global variables - add the variable to PHP * ----------------------------------------------------------------------------- */ -%typemap(varinit) char *, - char [] +%typemap(varinit) char * { zval *z_var; MAKE_STD_ZVAL(z_var); @@ -20,6 +19,16 @@ zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL); } +%typemap(varinit) char [] +{ + zval *z_var; + MAKE_STD_ZVAL(z_var); + z_var->type = IS_STRING; + z_var->value.str.val = estrdup($1); + z_var->value.str.len = strlen($1); + zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL); +} + %typemap(varinit) int, unsigned int, unsigned short, @@ -95,10 +104,7 @@ zval *z_var; MAKE_STD_ZVAL(z_var); z_var->type = IS_STRING; - if ($1) { - /* varinit char [ANY] */ - ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1); - } + ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1); zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL); } diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 314d2b385..75b131333 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -164,9 +164,13 @@ SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) } SWIGINTERN int -SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { +SwigPyObjectType_setattro(PyObject *typeobject, PyObject *name, PyObject *value) { PyObject *attribute; + PyTypeObject *type; descrsetfunc local_set; + + assert(PyType_Check(typeobject)); + type = (PyTypeObject *)typeobject; attribute = _PyType_Lookup(type, name); if (attribute != NULL) { /* Implement descriptor functionality, if any */ @@ -276,6 +280,95 @@ SwigPyStaticVar_Type(void) { return &staticvar_type; } +SWIGINTERN PyTypeObject* +SwigPyObjectType(void) { + static char swigpyobjecttype_doc[] = "Metaclass for SWIG wrapped types"; + static PyTypeObject swigpyobjecttype_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(&PyType_Type) + 0, /* ob_size */ +#endif + "SwigPyObjectType", /* tp_name */ + PyType_Type.tp_basicsize, /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + SwigPyObjectType_setattro, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */ + swigpyobjecttype_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version_tag */ +#endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#ifdef COUNT_ALLOCS + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ +#endif + }; + swigpyobjecttype_type = tmp; + type_init = 1; + swigpyobjecttype_type.tp_base = &PyType_Type; +#if PY_VERSION_HEX < 0x02020000 + swigpyobjecttype_type.ob_type = &PyType_Type; +#else + if (PyType_Ready(&swigpyobjecttype_type) < 0) + return NULL; +#endif + } + return &swigpyobjecttype_type; +} + SWIGINTERN PyGetSetDescrObject * SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index e671731ac..2cc582841 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -374,13 +374,13 @@ SWIG_init(void) { static PyGetSetDef thisown_getset_def = { (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure }; - PyObject *metatype_args; PyTypeObject *builtin_pytype; int builtin_base_count; swig_type_info *builtin_basetype; PyObject *tuple; PyGetSetDescrObject *static_getset; PyTypeObject *metatype; + PyTypeObject *swigpyobject; SwigPyClientData *cd; PyObject *public_interface, *public_symbol; PyObject *this_descr; @@ -395,14 +395,9 @@ SWIG_init(void) { (void)static_getset; (void)self; - /* metatype is used to implement static member variables. */ - metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); - assert(metatype_args); - metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL); + /* Metaclass is used to implement static member variables */ + metatype = SwigPyObjectType(); assert(metatype); - Py_DECREF(metatype_args); - metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; - assert(PyType_Ready(metatype) >= 0); #endif /* Fix SwigMethods to carry the callback ptrs when needed */ @@ -420,13 +415,15 @@ SWIG_init(void) { SWIG_InitializeModule(0); #ifdef SWIGPYTHON_BUILTIN + swigpyobject = SwigPyObject_TypeOnce(); + SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); assert(SwigPyObject_stype); cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; if (!cd) { SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; - SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce(); - } else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) { + SwigPyObject_clientdata.pytype = swigpyobject; + } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) { PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); # if PY_VERSION_HEX >= 0x03000000 return NULL; diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index ab5f74b19..8079805e4 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -78,4 +78,7 @@ extern "C" { #define SWIG_WARN_NODE_END(Node) \ if (wrnfilter) Swig_warnfilter(wrnfilter,0); \ } + +#define COMPOUND_EXPR_VAL(dtype) \ + ((dtype).type == T_CHAR || (dtype).type == T_WCHAR ? (dtype).rawval : (dtype).val) #endif diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 784187c28..82608053e 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5828,7 +5828,7 @@ definetype : { /* scanner_check_typedef(); */ } expr { if ($$.type == T_STRING) { $$.rawval = NewStringf("\"%(escape)s\"",$$.val); } else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) { - $$.rawval = 0; + $$.rawval = NewStringf("%s", $$.val); } $$.qualifier = 0; $$.bitfield = 0; @@ -6095,81 +6095,81 @@ exprnum : NUM_INT { $$ = $1; } ; exprcompound : expr PLUS expr { - $$.val = NewStringf("%s+%s",$1.val,$3.val); + $$.val = NewStringf("%s+%s", COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr MINUS expr { - $$.val = NewStringf("%s-%s",$1.val,$3.val); + $$.val = NewStringf("%s-%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr STAR expr { - $$.val = NewStringf("%s*%s",$1.val,$3.val); + $$.val = NewStringf("%s*%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr SLASH expr { - $$.val = NewStringf("%s/%s",$1.val,$3.val); + $$.val = NewStringf("%s/%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr MODULO expr { - $$.val = NewStringf("%s%%%s",$1.val,$3.val); + $$.val = NewStringf("%s%%%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr AND expr { - $$.val = NewStringf("%s&%s",$1.val,$3.val); + $$.val = NewStringf("%s&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr OR expr { - $$.val = NewStringf("%s|%s",$1.val,$3.val); + $$.val = NewStringf("%s|%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr XOR expr { - $$.val = NewStringf("%s^%s",$1.val,$3.val); + $$.val = NewStringf("%s^%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr LSHIFT expr { - $$.val = NewStringf("%s << %s",$1.val,$3.val); + $$.val = NewStringf("%s << %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote_type($1.type); } | expr RSHIFT expr { - $$.val = NewStringf("%s >> %s",$1.val,$3.val); + $$.val = NewStringf("%s >> %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote_type($1.type); } | expr LAND expr { - $$.val = NewStringf("%s&&%s",$1.val,$3.val); + $$.val = NewStringf("%s&&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr LOR expr { - $$.val = NewStringf("%s||%s",$1.val,$3.val); + $$.val = NewStringf("%s||%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr EQUALTO expr { - $$.val = NewStringf("%s==%s",$1.val,$3.val); + $$.val = NewStringf("%s==%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr NOTEQUALTO expr { - $$.val = NewStringf("%s!=%s",$1.val,$3.val); + $$.val = NewStringf("%s!=%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } /* Sadly this causes 2 reduce-reduce conflicts with templates. FIXME resolve these. | expr GREATERTHAN expr { - $$.val = NewStringf("%s > %s", $1.val, $3.val); + $$.val = NewStringf("%s > %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr LESSTHAN expr { - $$.val = NewStringf("%s < %s", $1.val, $3.val); + $$.val = NewStringf("%s < %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } */ | expr GREATERTHANOREQUALTO expr { - $$.val = NewStringf("%s >= %s", $1.val, $3.val); + $$.val = NewStringf("%s >= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr LESSTHANOREQUALTO expr { - $$.val = NewStringf("%s <= %s", $1.val, $3.val); + $$.val = NewStringf("%s <= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr QUESTIONMARK expr COLON expr %prec QUESTIONMARK { - $$.val = NewStringf("%s?%s:%s", $1.val, $3.val, $5.val); + $$.val = NewStringf("%s?%s:%s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3), COMPOUND_EXPR_VAL($5)); /* This may not be exactly right, but is probably good enough * for the purposes of parsing constant expressions. */ $$.type = promote($3.type, $5.type); @@ -6187,7 +6187,7 @@ exprcompound : expr PLUS expr { $$.type = $2.type; } | LNOT expr { - $$.val = NewStringf("!%s",$2.val); + $$.val = NewStringf("!%s",COMPOUND_EXPR_VAL($2)); $$.type = T_INT; } | type LPAREN { diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index d370b886e..884ae906d 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2809,29 +2809,39 @@ private: String *get = NewString(""); Printv(get, Swig_cresult_name(), " = ", NULL); - char quote; - if (Getattr(n, "wrappedasconstant")) { - quote = '\0'; - } else if (SwigType_type(type) == T_CHAR) { - quote = '\''; - } else if (SwigType_type(type) == T_STRING) { - Printv(get, "(char *)", NULL); - quote = '"'; + String *rawval = Getattr(n, "rawval"); + if (rawval && Len(rawval)) { + if (SwigType_type(type) == T_STRING) { + Printv(get, "(char *)", NULL); + } + + Printv(get, rawval, NULL); } else { - quote = '\0'; - } + char quote; + if (Getattr(n, "wrappedasconstant")) { + quote = '\0'; + } else if (SwigType_type(type) == T_CHAR) { + quote = '\''; + } else if (SwigType_type(type) == T_STRING) { + Printv(get, "(char *)", NULL); + quote = '"'; + } else { + quote = '\0'; + } - if (quote != '\0') { - Printf(get, "%c", quote); - } + if (quote != '\0') { + Printf(get, "%c", quote); + } - Printv(get, Getattr(n, "value"), NULL); + Printv(get, Getattr(n, "value"), NULL); - if (quote != '\0') { - Printf(get, "%c", quote); + if (quote != '\0') { + Printf(get, "%c", quote); + } } Printv(get, ";\n", NULL); + Setattr(n, "wrap:action", get); String *sname = Copy(symname); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 380cd98d5..20ffeb4ae 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3339,6 +3339,8 @@ public: Printf(builtin_closures_code, "%s /* defines %s */\n\n", closure_decl, closure_name); SetFlag(builtin_closures, closure_name); Delete(closure_decl); + } else { + closure_name = Copy(wrapper_name); } if (func_type) { String *s = NewStringf("(%s) %s", func_type, closure_name); @@ -3923,8 +3925,14 @@ public: String *pmname = SwigType_manglestr(pname); String *templ = NewStringf("SwigPyBuiltin_%s", mname); int funpack = modernargs && fastunpack; + static String *tp_new = NewString("PyType_GenericNew"); Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL); + + // We can’t statically initialize a structure member with a function defined in another C module + // So this is done in the initialization function instead, see https://docs.python.org/2/extending/newtypes.html + Printf(f_init, " builtin_pytype->tp_new = %s;\n", getSlot(n, "feature:python:tp_new", tp_new)); + Printv(f_init, " builtin_base_count = 0;\n", NIL); List *baselist = Getattr(n, "bases"); if (baselist) { @@ -4062,7 +4070,6 @@ public: static String *tp_basicsize = NewStringf("sizeof(SwigPyObject)"); static String *tp_dictoffset_default = NewString("offsetof(SwigPyObject, dict)"); - static String *tp_new = NewString("PyType_GenericNew"); static String *tp_hash = NewString("SwigPyObject_hash"); String *tp_as_number = NewStringf("&%s_type.as_number", templ); String *tp_as_sequence = NewStringf("&%s_type.as_sequence", templ); @@ -4123,7 +4130,7 @@ public: printSlot(f, getSlot(n, "feature:python:tp_dictoffset", tp_dictoffset_default), "tp_dictoffset", "Py_ssize_t"); printSlot(f, getSlot(n, "feature:python:tp_init", tp_init), "tp_init", "initproc"); printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc"); - printSlot(f, getSlot(n, "feature:python:tp_new", tp_new), "tp_new", "newfunc"); + printSlot(f, getSlot(), "tp_new", "newfunc"); printSlot(f, getSlot(n, "feature:python:tp_free"), "tp_free", "freefunc"); printSlot(f, getSlot(n, "feature:python:tp_is_gc"), "tp_is_gc", "inquiry"); printSlot(f, getSlot(n, "feature:python:tp_bases"), "tp_bases", "PyObject *"); diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index 50ac5cd09..b1a61f932 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e # exit on failure +set -e # exit on failure (same as -o errexit) lsb_release -a sudo apt-get -qq update @@ -51,7 +51,7 @@ case "$SWIGLANG" in ;; "lua") if [[ -z "$VER" ]]; then - sudo apt-get -qq install lua5.1 liblua5.1-dev + sudo apt-get -qq install lua5.2 liblua5.2-dev else sudo add-apt-repository -y ppa:ubuntu-cloud-archive/mitaka-staging sudo apt-get -qq update @@ -72,16 +72,10 @@ case "$SWIGLANG" in fi ;; "php") - sudo apt-get install php5-cli php5-dev + sudo apt-get -qq install php5-cli php5-dev ;; "python") - git clone https://github.com/jcrocholl/pep8.git - ( - cd pep8 - git checkout tags/1.5.7 - python ./setup.py build - sudo python ./setup.py install - ) + sudo apt-get -qq install pep8 if [[ "$PY3" ]]; then sudo apt-get install -qq python3-dev fi @@ -105,6 +99,8 @@ case "$SWIGLANG" in sudo apt-get -qq install scilab ;; "tcl") - sudo apt-get -qq install tcl8.4-dev + sudo apt-get -qq install tcl-dev ;; esac + +set +e # turn off exit on failure (same as +o errexit) diff --git a/Tools/travis-osx-install.sh b/Tools/travis-osx-install.sh index 965deed42..85183722b 100755 --- a/Tools/travis-osx-install.sh +++ b/Tools/travis-osx-install.sh @@ -1,18 +1,18 @@ #!/bin/bash -set -e # exit on failure +set -e # exit on failure (same as -o errexit) sw_vers brew update brew list -brew install pcre +# brew install pcre # Travis Xcode-7.3 has pcre # brew install boost WITHLANG=$SWIGLANG case "$SWIGLANG" in "csharp") - brew install https://s3.amazonaws.com/travisbuilds.swig.org/mono.rb + brew install mono ;; "guile") Tools/brew-install guile @@ -28,3 +28,6 @@ case "$SWIGLANG" in fi ;; esac + +# Workaround for https://github.com/travis-ci/travis-ci/issues/6522 +set +e # turn off exit on failure (same as +o errexit) diff --git a/appveyor.yml b/appveyor.yml index 9f2068903..d7be4a3d5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,16 +5,16 @@ platform: environment: matrix: - SWIGLANG: csharp - VSVER: 14 + VSVER: 12 - SWIGLANG: csharp - VSVER: 12 + VSVER: 14 - SWIGLANG: java - VSVER: 12 + VSVER: 14 - SWIGLANG: python - VSVER: 12 + VSVER: 14 VER: 27 - SWIGLANG: python - VSVER: 12 + VSVER: 14 VER: 35 PY3: 1