From 46791437a4ed30d330ee3e4f0b7a4d6ccdca0ae0 Mon Sep 17 00:00:00 2001
From: myd7349
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.
+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.
@@ -4417,7 +4425,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 %{
@@ -4750,18 +4758,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;
}
}
@@ -4849,18 +4857,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;
}
}
@@ -5038,12 +5046,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;
}
}
@@ -5078,18 +5086,18 @@ arrays of different sizes. To do this, you might write a typemap as follows:
int i;
if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
- return NULL;
+ SWIG_fail;
}
if (PyObject_Length($input) != $1_dim0) {
PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements");
- return NULL;
+ 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;
+ SWIG_fail;
}
temp[i] = PyFloat_AsDouble(o);
Py_DECREF(o);
@@ -5146,7 +5154,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
%typemap(in) double [ANY](double temp[$1_dim0]) {
if (!convert_darray($input,temp,$1_dim0)) {
- return NULL;
+ SWIG_fail;
}
$1 = &temp[0];
}
diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html
index 309984b50..d7226e33f 100644
--- a/Doc/Manual/Typemaps.html
+++ b/Doc/Manual/Typemaps.html
@@ -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;
+ }
}
...
@@ -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;
@@ -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,9 +3065,9 @@ 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;
}
}
}
@@ -3229,7 +3229,7 @@ pointers. For example:
%typemap(check) Vector * {
if ($1 == 0) {
PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed");
- return NULL;
+ SWIG_fail;
}
}
@@ -3508,7 +3508,7 @@ 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 *));
@@ -3517,7 +3517,7 @@ maps perform the conversion described for the above example:
if (!PyString_Check(s)) {
free($2);
PyErr_SetString(PyExc_ValueError, "List items must be strings");
- return NULL;
+ SWIG_fail;
}
$2[i] = PyString_AsString(s);
}
@@ -3633,7 +3633,7 @@ might write typemaps like this:
%typemap(in) (void *wbuffer, size_t len) {
if (!PyString_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting a string");
- return NULL;
+ SWIG_fail;
}
$1 = (void *) PyString_AsString($input);
$2 = PyString_Size($input);
@@ -3643,12 +3643,12 @@ might write typemaps like this:
%typemap(in) (void *rbuffer, size_t len) {
if (!PyInt_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting an integer");
- return NULL;
+ SWIG_fail;
}
$2 = PyInt_AsLong($input);
if ($2 < 0) {
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
- return NULL;
+ SWIG_fail;
}
$1 = (void *) malloc($2);
}
diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html
index 1c99804f1..21a41948e 100644
--- a/Doc/Manual/Varargs.html
+++ b/Doc/Manual/Varargs.html
@@ -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);
@@ -526,7 +526,7 @@ like this:
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));
@@ -534,7 +534,7 @@ like this:
%#else
if (!PyString_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");
- return NULL;
+ SWIG_fail;
}
str = PyString_AsString(pyobj);
%#endif
@@ -635,9 +635,9 @@ example. For example:
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;
+ PyErr_SetString(PyExc_ValueError,"Expected a string");
+ SWIG_fail;
}
argv[i] = PyString_AsString(o);
}
@@ -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 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
From 268b942865b42fb942723b177d160453abb7e6a4 Mon Sep 17 00:00:00 2001
From: William S Fulton
- ... 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;
+ }
}
- ...
+ ...
(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);
+ }
}
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 */
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;
+ }
}
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;
+ }
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;
};
template <typename... BaseClasses> class ClassName : public BaseClasses... {
public:
- ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
+ ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
}
struct A {
- static thread_local int val;
+ static thread_local int val;
};
thread_local int global_val;
struct NoInt {
- void f(double i);
- void f(int) = delete;
+ void f(double i);
+ void f(int) = delete;
};
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);
+
}
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 ;
+ }
}
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 ;
- }
- }
-
+ }
}
- 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;
%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);
};
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 ...
+ }
}
%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;
+ }
}
%exception allocate {
- try {
- $action
- }
- catch (MemoryError) {
- croak("Out of memory");
- }
+ try {
+ $action
+ }
+ catch (MemoryError) {
+ croak("Out of memory");
+ }
}
%exception Object::allocate {
- try {
- $action
- }
- catch (MemoryError) {
- croak("Out of memory");
- }
+ try {
+ $action
+ }
+ catch (MemoryError) {
+ croak("Out of memory");
+ }
}
%exception Object::allocate(int) {
- try {
- $action
- }
- catch (MemoryError) {
- croak("Out of memory");
- }
+ try {
+ $action
+ }
+ catch (MemoryError) {
+ croak("Out of memory");
+ }
}
Foo *blah() {
- Foo *f = new Foo();
- return f;
+ Foo *f = new Foo();
+ return f;
}
%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);
}
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);
+ ...
};
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");
+ ...
}
if (checkAttribute(n,"storage","virtual")) {
- /* n is virtual */
- ...
+ /* n is virtual */
+ ...
}
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;
}
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");
}
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;
+ ...
};
struct Bar {
- int x[16];
+ int x[16];
};
struct Foo {
- int a;
+ int a;
};
struct Bar {
- Foo f;
+ Foo f;
};
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->();
+ ...
}
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);
}
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
%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);
+ }
%}
%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
+ }
%}
return $null; could be changed to:
- throw std::runtime_error(Swig::JavaExceptionMessage(jenv, $error).message()); + throw std::runtime_error(Swig::JavaExceptionMessage(jenv, $error).message());
%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;
}
int sub(int *x, int *y) {
- return *x-*y;
+ return *x-*y;
}
void negate(int *x) {
- *x = -(*x);
+ *x = -(*x);
}
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;
}
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());
- 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;
- 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());
- 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());
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);
};
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
};
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]);
+ }
}
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
};
char *foo() {
- char *result = (char *) malloc(...);
- ...
- return result;
+ char *result = (char *) malloc(...);
+ ...
+ return result;
}
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);
+ ...
}
void foo(char **s) {
- *s = (char *) malloc(64);
- sprintf(*s, "Hello world\n");
+ *s = (char *) malloc(64);
+ sprintf(*s, "Hello world\n");
}
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
+ ...
}
void my_get_data(char **result, int *len) {
- *result = get_data(len);
+ *result = get_data(len);
}
%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..032d05dba 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;
}
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..19747c3dc 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];
+ }
}
@@ -2492,7 +2492,7 @@ variable $1_descriptor. For example:
%typemap(in) Foo * {
- if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) return NULL;
+ if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) return NULL;
}
@@ -2505,7 +2505,7 @@ For example:
%typemap(in) Foo * {
- if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 0)) == -1) return NULL;
+ if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 0)) == -1) return NULL;
}
@@ -2997,9 +2997,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
+ }
}
%extend Foo {
- void bar() {
- %#ifdef DEBUG
- printf("I'm in bar\n");
- %#endif
- }
+ void bar() {
+ %#ifdef DEBUG
+ printf("I'm in bar\n");
+ %#endif
+ }
}
struct Foo {
- ...
- %immutable;
- int x; /* Read-only members */
- char *name;
- %mutable;
- ...
+ ...
+ %immutable;
+ int x; /* Read-only members */
+ char *name;
+ %mutable;
+ ...
};
struct Foo {
- int a;
+ int a;
};
struct Bar {
- Foo f;
+ Foo f;
};
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->();
+ ...
}
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; }
+ ...
};
%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;
+ }
};
%exception {
- $action
- if (err_occurred()) {
- PyErr_SetString(PyExc_RuntimeError, err_message());
- SWIG_fail;
- }
+ $action
+ if (err_occurred()) {
+ PyErr_SetString(PyExc_RuntimeError, err_message());
+ SWIG_fail;
+ }
}
%exception getitem {
- try {
- $action
- } catch (std::out_of_range &e) {
- PyErr_SetString(PyExc_IndexError, const_cast<char*>(e.what()));
- SWIG_fail;
- }
+ 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
+ ...
};
void add(int x, int y, int *result) {
- *result = x + y;
+ *result = x + y;
}
int sub(int *x, int *y) {
- return *x-*y;
+ return *x-*y;
}
void negate(int *x) {
- *x = -(*x);
+ *x = -(*x);
}
%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);
@@ -4781,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;
}
%}
@@ -5003,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;
}
@@ -5085,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");
- SWIG_fail;
+ 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");
- SWIG_fail;
+ 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");
- SWIG_fail;
- }
- 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];
}
@@ -5131,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)) {
- SWIG_fail;
- }
- $1 = &temp[0];
+ if (!convert_darray($input,temp,$1_dim0)) {
+ SWIG_fail;
+ }
+ $1 = &temp[0];
}
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);
}
%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);
}
typedef struct Foo {
- int x;
+ int x;
} Foo;
typedef struct Bar {
- int y;
- Foo f; /* struct member */
+ int y;
+ Foo f; /* struct member */
} Bar;
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;
}
struct Foo {
- WORD w;
+ WORD w;
};
double Vector_x_get(Vector *v) {
- return v->x;
+ return v->x;
}
%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 ...
%}
class Foo {
-public:
- Foo();
- ~Foo();
- int bar(int x);
- int x;
+ public:
+ Foo();
+ ~Foo();
+ int bar(int x);
+ int x;
};
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);
+ }
};
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;
};
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();
};
Foo *Bar_spam(Bar *obj) {
- Foo &result = obj->spam();
- return &result;
+ Foo &result = obj->spam();
+ return &result;
}
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);
}
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);
}
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;
}
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);
}
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;
+ ...
};
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);
+ ...
}
class Foo {
public:
- template<class T> void bar(T x, T y) { ... };
- ...
+ template<class T> void bar(T x, T y) { ... };
+ ...
};
@@ -3328,10 +3328,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 +3344,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 +3363,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 +3413,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 +3443,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 +3462,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 +3484,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 +3504,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 +3527,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 */
+ ...
}
+ }
};
%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 +3722,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 +3798,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 +3843,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 +3882,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 +3910,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 +3932,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 +3981,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 +4007,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 +4037,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 */
+ ...
+ %}
}
namespace foo {
- class bar {
- public:
- %extend {
- int blah(int x);
- };
- };
+ class bar {
+ public:
+ %extend {
+ int blah(int x);
+ };
+ };
}
namespace foo {
- class bar;
- class spam {
- public:
- ...
- operator bar(); // Conversion of spam -> bar
- ...
- };
+ class bar;
+ class spam {
+ public:
+ ...
+ operator bar(); // Conversion of spam -> bar
+ ...
+ };
}
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();
}
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)
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 +4997,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 +5101,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..b07f99b69 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
}
proc blah {} {
- bar FOO
+ bar FOO
}
struct Foo {
- ...
- %immutable;
- int x; /* Read-only members */
- char *name;
- %mutable;
- ...
+ ...
+ %immutable;
+ int x; /* Read-only members */
+ char *name;
+ %mutable;
+ ...
};
struct Foo {
- int a;
+ int a;
};
struct Bar {
- Foo f;
+ Foo f;
};
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->();
+ ...
}
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; }
+ ...
};
void add(int x, int y, int *result) {
- *result = x + y;
+ *result = x + y;
}
int sub(int *x, int *y) {
- return *x+*y;
+ return *x+*y;
}
void negate(int *x) {
- *x = -(*x);
+ *x = -(*x);
}
// 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;
};
%typemap(out) int, short, long {
- Tcl_SetIntObj($result,(int) $1);
+ Tcl_SetIntObj($result,(int) $1);
}
%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;
}
%typemap(out) float, double {
- Tcl_SetDoubleObj($result, $1);
+ Tcl_SetDoubleObj($result, $1);
}
%typemap(in) char * {
- int len;
- $1 = Tcl_GetStringFromObj(interp, &len);
- }
+ int len;
+ $1 = Tcl_GetStringFromObj(interp, &len);
}
%typemap(in) Foo * {
- if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) return NULL;
+ if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) return NULL;
}
%typemap(in) Foo * {
- if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 0)) == -1) return NULL;
+ if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), 0)) == -1) return NULL;
}
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;
}
/* 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;
}
/* 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);
@@ -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 */
@@ -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;
}
@@ -2604,7 +2604,7 @@ into the target language. For example:
%typemap(out) int {
- $result = PyInt_FromLong($1);
+ $result = PyInt_FromLong($1);
}
@@ -2638,7 +2638,7 @@ For example:
// Set argument to NULL before any conversion occurs
%typemap(arginit) int *data {
- $1 = NULL;
+ $1 = NULL;
}
@@ -2654,7 +2654,7 @@ argument. For example:
%typemap(default) int flags {
- $1 = DEFAULT_FLAGS;
+ $1 = DEFAULT_FLAGS;
}
...
int foo(int x, int y, int flags);
@@ -2688,9 +2688,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 +2709,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 +2756,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 +2786,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 +2854,7 @@ cases. For example:
%typemap(memberin) int [4] {
- memmove($1, $input, 4*sizeof(int));
+ memmove($1, $input, 4*sizeof(int));
}
@@ -2910,12 +2910,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;
}
...
@@ -3037,7 +3036,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 ...
}
@@ -3072,7 +3071,7 @@ as shown. To work with heap allocated data, the following technique can be use
}
}
%typemap(freearg) float value[ANY] {
- if ($1) free($1);
+ if ($1) free($1);
}
@@ -3227,10 +3226,10 @@ pointers. For example:
%typemap(check) Vector * {
- if ($1 == 0) {
- PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed");
- SWIG_fail;
- }
+ if ($1 == 0) {
+ PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed");
+ SWIG_fail;
+ }
}
@@ -3515,9 +3514,9 @@ maps perform the conversion described for the above example:
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");
- SWIG_fail;
+ free($2);
+ PyErr_SetString(PyExc_ValueError, "List items must be strings");
+ SWIG_fail;
}
$2[i] = PyString_AsString(s);
}
@@ -3525,7 +3524,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 +3630,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");
- SWIG_fail;
- }
- $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");
- SWIG_fail;
- }
- $2 = PyInt_AsLong($input);
- if ($2 < 0) {
- PyErr_SetString(PyExc_ValueError, "Positive integer expected");
- SWIG_fail;
- }
- $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 +3716,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 +3915,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 +4025,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 +4138,15 @@ For example:
class Foo {
- int x;
+ int x;
};
class Bar {
- int y;
+ int y;
};
class FooBar : public Foo, public Bar {
- int z;
+ int z;
};
@@ -4339,11 +4338,11 @@ 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;
+ Bar *temp;
+ if ((SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *)) == -1) {
+ return NULL;
+ }
+ $1 = (Foo *) temp;
}
}
@@ -4429,32 +4428,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 +4466,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");
}
@@ -4652,11 +4651,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 +4674,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 +4726,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 +4770,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 +4816,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 21a41948e..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);
+ ...
}
@@ -525,16 +525,16 @@ like this:
%#if PY_VERSION_HEX>=0x03000000
PyObject *pystr;
if (!PyUnicode_Check(pyobj)) {
- PyErr_SetString(PyExc_ValueError, "Expected a string");
- SWIG_fail;
+ 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");
- SWIG_fail;
+ 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)) {
- free(argv);
- PyErr_SetString(PyExc_ValueError,"Expected a string");
- SWIG_fail;
- }
- 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 */
@@ -912,12 +912,12 @@ and it fully supports classes much like the %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 * {
- ...
+ ...
}
From 96015de0dd600da5ec0431d04a7eb2f2c5dd9a96 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Sat, 22 Oct 2016 20:55:37 +0100
Subject: [PATCH 37/43] Update documentation for using SWIG_ConvertPtr example
usage
Add a test case to test the example documentation typemaps
---
Doc/Manual/Lua.html | 2 +-
Doc/Manual/Perl5.html | 12 +++-
Doc/Manual/Python.html | 16 +++--
Doc/Manual/Tcl.html | 12 +++-
Doc/Manual/Typemaps.html | 66 ++++++++-----------
Examples/test-suite/common.mk | 1 +
.../python/typemap_documentation_runme.py | 20 ++++++
Examples/test-suite/typemap_documentation.i | 50 ++++++++++++++
8 files changed, 125 insertions(+), 54 deletions(-)
create mode 100644 Examples/test-suite/python/typemap_documentation_runme.py
create mode 100644 Examples/test-suite/typemap_documentation.i
diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html
index 032d05dba..131d92825 100644
--- a/Doc/Manual/Lua.html
+++ b/Doc/Manual/Lua.html
@@ -1740,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/Perl5.html b/Doc/Manual/Perl5.html
index 19747c3dc..4722a01ba 100644
--- a/Doc/Manual/Perl5.html
+++ b/Doc/Manual/Perl5.html
@@ -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");
+ }
}
diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html
index 30aa82115..b6df0895f 100644
--- a/Doc/Manual/Python.html
+++ b/Doc/Manual/Python.html
@@ -5208,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);
@@ -5224,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");
+ }
}
@@ -5238,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");
+ }
}
diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html
index b07f99b69..af4880217 100644
--- a/Doc/Manual/Tcl.html
+++ b/Doc/Manual/Tcl.html
@@ -3088,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);
@@ -3103,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");
+ }
}
@@ -3116,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 f83a26949..8aa5abb3f 100644
--- a/Doc/Manual/Typemaps.html
+++ b/Doc/Manual/Typemaps.html
@@ -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).
@@ -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.
@@ -4138,14 +4139,17 @@ For example:
class Foo {
+public:
int x;
};
class Bar {
+public:
int y;
};
class FooBar : public Foo, public Bar {
+public:
int z;
};
@@ -4180,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");
+}
@@ -4197,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).
@@ -4304,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");
+ }
}
@@ -4337,12 +4348,12 @@ descriptor name for any C datatype. For example:
%typemap(in) Foo * {
- if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) {
+ if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
Bar *temp;
- if ((SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *)) == -1) {
- return NULL;
+ 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;
+ $1 = (Foo *)temp;
}
}
@@ -4588,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);
}
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index b9ba746bb..c6a02f487 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -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/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/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;
+}
+%}
From 61061ff150208f28c3e95bcd0f79794a2e15a1c3 Mon Sep 17 00:00:00 2001
From: g
Date: Wed, 26 Oct 2016 23:55:04 -0700
Subject: [PATCH 38/43] Added description of the operator[] caveats
---
Doc/Manual/SWIGPlus.html | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html
index 74d9c9083..e1bc49f9e 100644
--- a/Doc/Manual/SWIGPlus.html
+++ b/Doc/Manual/SWIGPlus.html
@@ -2766,6 +2766,16 @@ have to handle it like a normal function. For example:
are ignored as well as conversion operators.
+- The index operator, operator[], is particularly difficult to overload due to the C++
+implementation. 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++, the setter only exists if the return
+type of operator[] is a reference, and if the creator of the method wanted unique logic when
+getting or setting a value, they need to use a
+temporary proxy.
+
+
- The semantics of certain C++ operators may not match those in the target language.
From f42b261b73dc53da75f7e7f3ac9cfeb3aacf7508 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Sat, 29 Oct 2016 19:45:38 +0100
Subject: [PATCH 39/43] Use Visual Studio 2015 instead of 2012 as default
compiler for Appveyor testing
---
appveyor.yml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
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
From ed3bc81dcad7b8245091c7cead5a5c26276e5152 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Sat, 29 Oct 2016 23:27:44 +0100
Subject: [PATCH 40/43] Compiler warning fixes in testcase
---
Examples/test-suite/python_builtin.i | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
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
Date: Sun, 30 Oct 2016 13:58:26 +0000
Subject: [PATCH 41/43] Java wstring directorin typemap resource leak fix
change note
---
CHANGES.current | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/CHANGES.current b/CHANGES.current
index d51b88636..477852d80 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.11 (in progress)
============================
+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.
From 0886fc6fe62a66177258b38d305e3b23f8b7f117 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Sun, 30 Oct 2016 14:52:35 +0000
Subject: [PATCH 42/43] Edit operator[] additions
---
Doc/Manual/SWIGPlus.html | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html
index e1bc49f9e..95a3d054b 100644
--- a/Doc/Manual/SWIGPlus.html
+++ b/Doc/Manual/SWIGPlus.html
@@ -2763,17 +2763,27 @@ 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:
+
-- The index operator, operator[], is particularly difficult to overload due to the C++
-implementation. Specifically, the get and set operators in other languages typically are separated
+
+
+
+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++, the setter only exists if the return
-type of operator[] is a reference, and if the creator of the method wanted unique logic when
-getting or setting a value, they need to use a
-temporary proxy.
+__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.
From eda0779e76341164fbd86c39c235a7897290bff1 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Sun, 30 Oct 2016 22:34:33 +0000
Subject: [PATCH 43/43] C# std::array changes file addition
Fix C# warnings in test-case too.
---
CHANGES.current | 6 ++++++
Examples/test-suite/csharp/cpp11_li_std_array_runme.cs | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index 477852d80..afb4fa205 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,12 @@ 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.
diff --git a/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs b/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
index a2bae1fb2..d0c956ad3 100644
--- a/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
+++ b/Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
@@ -67,7 +67,7 @@ public class cpp11_li_std_array_runme
ai[ai.Count] = 0;
throw new Exception("Out of range exception not caught");
}
- catch (ArgumentOutOfRangeException e)
+ catch (ArgumentOutOfRangeException)
{
}
try
@@ -75,7 +75,7 @@ public class cpp11_li_std_array_runme
ai[-1] = 0;
throw new Exception("Out of range exception not caught");
}
- catch (ArgumentOutOfRangeException e)
+ catch (ArgumentOutOfRangeException)
{
}
}