Merge branch 'master' into directorargout_and_java_typemaps

This commit is contained in:
Andrey Starodubtsev 2016-11-02 18:12:38 +03:00
commit 3e449ea05f
68 changed files with 2861 additions and 2151 deletions

View file

@ -4,9 +4,16 @@ matrix:
- compiler: clang - compiler: clang
os: linux os: linux
env: SWIGLANG= env: SWIGLANG=
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG= env: SWIGLANG=
- compiler: gcc
os: linux
env: SWIGLANG=
sudo: required
dist: trusty
- os: linux - os: linux
env: SWIGLANG= SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 env: SWIGLANG= SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1
sudo: required sudo: required
@ -18,12 +25,18 @@ matrix:
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=csharp env: SWIGLANG=csharp
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=d env: SWIGLANG=d
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=go env: SWIGLANG=go
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=go VER=1.5 env: SWIGLANG=go VER=1.5
@ -32,21 +45,31 @@ matrix:
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=guile env: SWIGLANG=guile
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=java env: SWIGLANG=java
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=javascript ENGINE=node env: SWIGLANG=javascript ENGINE=node
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=javascript ENGINE=jsc env: SWIGLANG=javascript ENGINE=jsc
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=javascript ENGINE=v8 env: SWIGLANG=javascript ENGINE=v8
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=lua env: SWIGLANG=lua
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=lua VER=5.3 env: SWIGLANG=lua VER=5.3
@ -64,69 +87,118 @@ matrix:
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=perl5 env: SWIGLANG=perl5
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=php env: SWIGLANG=php
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python VER=2.4 env: SWIGLANG=python VER=2.4
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python VER=2.5 env: SWIGLANG=python VER=2.5
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python VER=2.6 env: SWIGLANG=python VER=2.6
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python # 2.7 env: SWIGLANG=python # 2.7
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python PY3=3 # 3.2 env: SWIGLANG=python PY3=3 VER=3.2
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python PY3=3 VER=3.3 env: SWIGLANG=python PY3=3 VER=3.3
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python PY3=3 VER=3.4 env: SWIGLANG=python PY3=3 VER=3.4
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python PY3=3 VER=3.5 env: SWIGLANG=python PY3=3 VER=3.5
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-builtin VER=2.6 env: SWIGLANG=python SWIG_FEATURES=-builtin VER=2.6
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-builtin env: SWIGLANG=python SWIG_FEATURES=-builtin
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.4
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 SWIGOPTPY3= env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 SWIGOPTPY3=
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-O env: SWIGLANG=python SWIG_FEATURES=-O
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-classic env: SWIGLANG=python SWIG_FEATURES=-classic
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=r env: SWIGLANG=r
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=ruby env: SWIGLANG=ruby VER=1.9.3
sudo: required
dist: trusty
- compiler: gcc
os: linux
env: SWIGLANG=ruby VER=2.0.0
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=ruby VER=2.3.0 env: SWIGLANG=ruby VER=2.3.0
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=scilab env: SWIGLANG=scilab
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=tcl env: SWIGLANG=tcl
sudo: required
dist: trusty
- os: linux - os: linux
env: SWIGLANG=csharp SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1 env: SWIGLANG=csharp SWIG_CC=gcc-5 SWIG_CXX=g++-5 CPP11=1
sudo: required sudo: required
@ -151,8 +223,9 @@ matrix:
env: SWIGLANG=python SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1 env: SWIGLANG=python SWIG_CC=gcc-6 SWIG_CXX=g++-6 CPP14=1
sudo: required sudo: required
dist: trusty dist: trusty
- os: osx - compiler: gcc
env: SWIGLANG= SWIG_CC=gcc-4.2 SWIG_CXX=g++-4.2 os: osx
env: SWIGLANG=
- compiler: clang - compiler: clang
os: osx os: osx
env: SWIGLANG= env: SWIGLANG=
@ -162,6 +235,9 @@ matrix:
- compiler: clang - compiler: clang
os: osx os: osx
env: SWIGLANG=go env: SWIGLANG=go
- compiler: clang
os: osx
env: SWIGLANG=guile
- compiler: clang - compiler: clang
os: osx os: osx
env: SWIGLANG=java env: SWIGLANG=java
@ -192,14 +268,14 @@ matrix:
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=ocaml env: SWIGLANG=ocaml
sudo: required
dist: trusty
# Not quite working yet # Not quite working yet
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=python SWIG_FEATURES=-O env: SWIGLANG=python SWIG_FEATURES=-O
# brew install guile fails on Travis as OSX 10.9 is too old now, default osx_image needs changing sudo: required
- compiler: clang dist: trusty
os: osx
env: SWIGLANG=guile
before_install: before_install:
- date -u - date -u
- uname -a - uname -a
@ -240,6 +316,3 @@ script:
- echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r' - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r'
- make check-maintainer-clean && ../../configure $CONFIGOPTS - make check-maintainer-clean && ../../configure $CONFIGOPTS
- echo -en 'travis_fold:end:script.3\\r' - echo -en 'travis_fold:end:script.3\\r'
branches:
only:
- master

View file

@ -5,6 +5,38 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.11 (in progress) 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<std::wstring> C# wrappers with additional functions
(Contains, IndexOf, LastIndexOf and Remove).
2016-10-30: tobilau
[Java] Fix wrappers for wstring parameters in director methods to cleanup local
ref after director callback has finished.
2016-10-23: wsfulton
[C#] Add missing csdirectorin VOID_INT_PTR and csdirectorout VOID_INT_PTR typemaps.
2016-10-23: jiulongw
Patch #781 - Fix wrapping of C compound expressions containing char constants
in quotes such as:
#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
enum DifferentTypes {
typecharcompound='A'+1,
typecharcompound2='B' << 2
};
2016-10-13: wsfulton
[Python] Issue #808 - fix Python pickling and metaclass for builtin wrappers.
The metaclass (SwigPyObjectType) for SWIG objects was not defined in
a way that let importlib successfully import the Python wrappers.
The pickle module previously failed to pickle objects because it couldn't
determine what module the SWIG wrapped objects were in.
2016-09-29: wsfulton 2016-09-29: wsfulton
[Allegrocl, CFFI, GO, Javascript, Ocaml, R, Scilab] [Allegrocl, CFFI, GO, Javascript, Ocaml, R, Scilab]
Add missing support for the "ret" typemap in a few target languages. Add missing support for the "ret" typemap in a few target languages.

View file

@ -1166,7 +1166,6 @@ SWIGEXPORT void SWIGSTDCALL CSharp_negativesonly(int jarg1) {
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what()); SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
return ; return ;
} }
} }
</pre> </pre>
</div> </div>
@ -1233,7 +1232,6 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) {
return ; return ;
} }
} }
} }
</pre> </pre>
</div> </div>

View file

@ -229,7 +229,8 @@ void foo(SomeClass arg) {
%newobject bar(); %newobject bar();
SomeClass *bar(); SomeClass *bar();
%}</pre></div> %}
</pre></div>
<p>The code generated for <tt>foo()</tt> and <tt>bar()</tt> looks like this:</p> <p>The code generated for <tt>foo()</tt> and <tt>bar()</tt> looks like this:</p>
<div class="targetlang"><pre> <div class="targetlang"><pre>
SomeClass foo() { SomeClass foo() {

View file

@ -8315,7 +8315,7 @@ public class FooDerived extends Foo {
public static FooDerived downcastFooDerived(Foo foo_object) public static FooDerived downcastFooDerived(Foo foo_object)
{ {
try { try {
return (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object); return foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object);
} }
catch (ClassCastException exc) { catch (ClassCastException exc) {
@ -8366,10 +8366,8 @@ public abstract class UserVisibleFoo extends Foo {
public static UserVisibleFoo downcastUserVisibleFoo(Foo foo_object) public static UserVisibleFoo downcastUserVisibleFoo(Foo foo_object)
{ {
try { try {
return (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null); return foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null;
} } catch (ClassCastException exc) {
catch (ClassCastException exc) {
// Wasn't a FooDerived object, some other subclass of Foo // Wasn't a FooDerived object, some other subclass of Foo
return null; return null;
} }

View file

@ -144,7 +144,6 @@ struct bar * my_struct;
struct foo { struct foo {
int a; int a;
struct foo * b[100]; struct foo * b[100];
}; };
int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int p); int pointer_func(void (*ClosureFun)( void* _fun, void* _data, void* _evt ), int p);
@ -460,16 +459,13 @@ namespace OpenDemo {
static const Test zero; static const Test zero;
}; };
inline Test operator* (float s, const Test&amp; v) {return v*s;} inline Test operator* (float s, const Test&amp; v) {return v*s;}
inline std::ostream&amp; operator&lt;&lt; (std::ostream&amp; o, const Test&amp; v) inline std::ostream&amp; operator&lt;&lt; (std::ostream&amp; o, const Test&amp; v)
{ {
return o &lt;&lt; "(" &lt;&lt; v.x &lt;&lt; ")"; return o &lt;&lt; "(" &lt;&lt; v.x &lt;&lt; ")";
} }
inline Test RandomUnitVectorOnXZPlane (void) inline Test RandomUnitVectorOnXZPlane (void)
{ {
return RandomVectorInUnitRadiusSphere().setYtoZero().normalize(); return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();

View file

@ -1095,8 +1095,9 @@ Now we extend it with some new code
sprintf(tmp,"Complex(%g,%g)", $self-&gt;re(),$self-&gt;im()); sprintf(tmp,"Complex(%g,%g)", $self-&gt;re(),$self-&gt;im());
return tmp; return tmp;
} }
bool operator==(const Complex&amp; c) bool operator==(const Complex&amp; c) {
{ return ($self-&gt;re()==c.re() &amp;&amp; $self-&gt;im()==c.im());} return ($self-&gt;re()==c.re() &amp;&amp; $self-&gt;im()==c.im());
}
}; };
</pre></div> </pre></div>
<p> <p>
@ -1739,7 +1740,7 @@ ptr=nil -- the iMath* will be GC'ed as normal
<div class="indent"> <div class="indent">
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. 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.<br> If flags is set to SWIG_POINTER_DISOWN, this is will clear any ownership flag set on the object.<br>
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()
</div> </div>
<p><tt>void SWIG_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type,int own);</tt></p> <p><tt>void SWIG_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type,int own);</tt></p>

View file

@ -2477,7 +2477,9 @@ is usually accessed as follows:
<div class="code"> <div class="code">
<pre> <pre>
Foo *f; Foo *f;
if (SWIG_ConvertPtr($input, (void **) &amp;f, SWIGTYPE_p_Foo, 0) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;f, SWIGTYPE_p_Foo, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
SV *sv = sv_newmortal(); SV *sv = sv_newmortal();
SWIG_MakePtr(sv, f, SWIGTYPE_p_Foo, 0); SWIG_MakePtr(sv, f, SWIGTYPE_p_Foo, 0);
@ -2492,7 +2494,9 @@ variable <tt>$1_descriptor</tt>. For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &amp;$1, $1_descriptor,0)) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
} }
</pre> </pre>
</div> </div>
@ -2505,7 +2509,9 @@ For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &amp;$1, $descriptor(Foo *), 0)) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $descriptor(Foo *), 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
} }
</pre> </pre>
</div> </div>

View file

@ -1527,7 +1527,6 @@ class Spam {
public: public:
static void foo(); static void foo();
static int bar; static int bar;
}; };
</pre> </pre>
</div> </div>
@ -3717,7 +3716,7 @@ or a NULL pointer perhaps). Here is a simple example of how you might handle th
$action $action
if (!result) { if (!result) {
PyErr_SetString(PyExc_MemoryError,"Not enough memory"); PyErr_SetString(PyExc_MemoryError,"Not enough memory");
return NULL; SWIG_fail;
} }
} }
void *malloc(size_t nbytes); void *malloc(size_t nbytes);
@ -3749,7 +3748,7 @@ that. For example:
$action $action
if (err_occurred()) { if (err_occurred()) {
PyErr_SetString(PyExc_RuntimeError, err_message()); PyErr_SetString(PyExc_RuntimeError, err_message());
return NULL; SWIG_fail;
} }
} }
</pre> </pre>
@ -3770,7 +3769,7 @@ C++ exceptions are also easy to handle. For example, you can write code like th
$action $action
} catch (std::out_of_range &amp;e) { } catch (std::out_of_range &amp;e) {
PyErr_SetString(PyExc_IndexError, const_cast&lt;char*&gt;(e.what())); PyErr_SetString(PyExc_IndexError, const_cast&lt;char*&gt;(e.what()));
return NULL; SWIG_fail;
} }
} }
@ -3784,7 +3783,8 @@ public:
<p> <p>
When raising a Python exception from C, use the <tt>PyErr_SetString()</tt> When raising a Python exception from C, use the <tt>PyErr_SetString()</tt>
function as shown above. The following exception types can be used as the first argument. function as shown above followed by <tt>SWIG_fail</tt>.
The following exception types can be used as the first argument.
</p> </p>
<div class="code"> <div class="code">
@ -3818,6 +3818,13 @@ PyExc_ZeroDivisionError
</pre> </pre>
</div> </div>
<p>
<tt>SWIG_fail</tt> 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 <tt>%exception</tt>, that are ultimately generated into the wrapper function.
</p>
<p> <p>
The language-independent <tt>exception.i</tt> library file can also be used The language-independent <tt>exception.i</tt> library file can also be used
to raise exceptions. See the <a href="Library.html#Library">SWIG Library</a> chapter. to raise exceptions. See the <a href="Library.html#Library">SWIG Library</a> chapter.
@ -4417,7 +4424,7 @@ You can refine this by supplying an optional parameter name. For example:
$1 = (int) PyLong_AsLong($input); $1 = (int) PyLong_AsLong($input);
if ($1 &lt; 0) { if ($1 &lt; 0) {
PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value."); PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value.");
return NULL; SWIG_fail;
} }
} }
%inline %{ %inline %{
@ -4750,18 +4757,18 @@ object to be used as a <tt>char **</tt> object.
$1 = (char **) malloc((size+1)*sizeof(char *)); $1 = (char **) malloc((size+1)*sizeof(char *));
for (i = 0; i &lt; size; i++) { for (i = 0; i &lt; size; i++) {
PyObject *o = PyList_GetItem($input,i); PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o)) if (PyString_Check(o)) {
$1[i] = PyString_AsString(PyList_GetItem($input,i)); $1[i] = PyString_AsString(PyList_GetItem($input,i));
else { } else {
PyErr_SetString(PyExc_TypeError,"list must contain strings");
free($1); free($1);
return NULL; PyErr_SetString(PyExc_TypeError,"list must contain strings");
SWIG_fail;
} }
} }
$1[i] = 0; $1[i] = 0;
} else { } else {
PyErr_SetString(PyExc_TypeError,"not a list"); PyErr_SetString(PyExc_TypeError,"not a list");
return NULL; SWIG_fail;
} }
} }
@ -4849,18 +4856,18 @@ previous example:
$2 = (char **) malloc(($1+1)*sizeof(char *)); $2 = (char **) malloc(($1+1)*sizeof(char *));
for (i = 0; i &lt; $1; i++) { for (i = 0; i &lt; $1; i++) {
PyObject *o = PyList_GetItem($input,i); PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o)) if (PyString_Check(o)) {
$2[i] = PyString_AsString(PyList_GetItem($input,i)); $2[i] = PyString_AsString(PyList_GetItem($input,i));
else { } else {
PyErr_SetString(PyExc_TypeError,"list must contain strings");
free($2); free($2);
return NULL; PyErr_SetString(PyExc_TypeError,"list must contain strings");
SWIG_fail;
} }
} }
$2[i] = 0; $2[i] = 0;
} else { } else {
PyErr_SetString(PyExc_TypeError,"not a list"); PyErr_SetString(PyExc_TypeError,"not a list");
return NULL; SWIG_fail;
} }
} }
@ -5038,12 +5045,12 @@ This too, can be handled used typemaps as follows :
if (PyTuple_Check($input)) { if (PyTuple_Check($input)) {
if (!PyArg_ParseTuple($input,"dddd",temp,temp+1,temp+2,temp+3)) { if (!PyArg_ParseTuple($input,"dddd",temp,temp+1,temp+2,temp+3)) {
PyErr_SetString(PyExc_TypeError,"tuple must have 4 elements"); PyErr_SetString(PyExc_TypeError,"tuple must have 4 elements");
return NULL; SWIG_fail;
} }
$1 = &amp;temp[0]; $1 = &amp;temp[0];
} else { } else {
PyErr_SetString(PyExc_TypeError,"expected a tuple."); PyErr_SetString(PyExc_TypeError,"expected a tuple.");
return NULL; SWIG_fail;
} }
} }
@ -5078,18 +5085,18 @@ arrays of different sizes. To do this, you might write a typemap as follows:
int i; int i;
if (!PySequence_Check($input)) { if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_TypeError,"Expecting a sequence"); PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
return NULL; SWIG_fail;
} }
if (PyObject_Length($input) != $1_dim0) { if (PyObject_Length($input) != $1_dim0) {
PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements"); PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements");
return NULL; SWIG_fail;
} }
for (i =0; i &lt; $1_dim0; i++) { for (i =0; i &lt; $1_dim0; i++) {
PyObject *o = PySequence_GetItem($input,i); PyObject *o = PySequence_GetItem($input,i);
if (!PyFloat_Check(o)) { if (!PyFloat_Check(o)) {
Py_XDECREF(o); Py_XDECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats"); PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
return NULL; SWIG_fail;
} }
temp[i] = PyFloat_AsDouble(o); temp[i] = PyFloat_AsDouble(o);
Py_DECREF(o); Py_DECREF(o);
@ -5146,7 +5153,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
%typemap(in) double [ANY](double temp[$1_dim0]) { %typemap(in) double [ANY](double temp[$1_dim0]) {
if (!convert_darray($input,temp,$1_dim0)) { if (!convert_darray($input,temp,$1_dim0)) {
return NULL; SWIG_fail;
} }
$1 = &amp;temp[0]; $1 = &amp;temp[0];
} }
@ -5201,8 +5208,9 @@ is usually accessed as follows:
<div class="code"> <div class="code">
<pre> <pre>
Foo *f; Foo *f;
if (SWIG_ConvertPtr($input, (void **) &amp;f, SWIGTYPE_p_Foo, SWIG_POINTER_EXCEPTION) == -1) if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;f, SWIGTYPE_p_Foo, 0))) {
return NULL; SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
PyObject *obj; PyObject *obj;
obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0); obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
@ -5217,8 +5225,9 @@ variable <tt>$1_descriptor</tt>. For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &amp;$1, $1_descriptor,SWIG_POINTER_EXCEPTION)) == -1) if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor, 0))) {
return NULL; SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
} }
</pre> </pre>
</div> </div>
@ -5231,9 +5240,9 @@ For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &amp;$1, $descriptor(Foo *), if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $descriptor(Foo *), 0))) {
SWIG_POINTER_EXCEPTION)) == -1) SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
return NULL; }
} }
</pre> </pre>
</div> </div>

View file

@ -2763,8 +2763,28 @@ have to handle it like a normal function. For example:
</li> </li>
<li><p>Certain operators are ignored by default. For instance, <tt>new</tt> and <tt>delete</tt> operators <li><p>Certain operators are ignored by default. For instance, <tt>new</tt> and <tt>delete</tt> 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:
</p></li> </p>
<p>
<div class="shell">
<pre>
example.i:12: Warning 503: Can't wrap 'operator []' unless renamed to a valid identifier.
</pre>
</div>
</li>
<li><p>The index operator, <tt>operator[]</tt>, 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
<tt>this[type key] { get { ... } set { ... }}</tt>, Python uses
<tt>__getitem__</tt> and <tt>__setitem__</tt>, etc. In C++ if the return
type of <tt>operator[]</tt> is a reference and the method is const, it is often indicative of the <i>setter</i>,
and and the <i>getter</i> 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.
</p>
</li>
<li>The semantics of certain C++ operators may not match those in the target language. <li>The semantics of certain C++ operators may not match those in the target language.
</li> </li>

View file

@ -448,8 +448,9 @@ int divide(int n, int d, int q*, int *r) {
*q = n / d; *q = n / d;
*r = n % d; *r = n % d;
return 1; return 1;
} else {
return 0;
} }
else return 0;
} }
%} %}
</pre></div> </pre></div>

View file

@ -1304,7 +1304,6 @@ class Spam {
public: public:
static void foo(); static void foo();
static int bar; static int bar;
}; };
</pre> </pre>
</div> </div>
@ -3032,7 +3031,6 @@ work)
int len; int len;
$1 = Tcl_GetStringFromObj(interp, &amp;len); $1 = Tcl_GetStringFromObj(interp, &amp;len);
} }
}
</pre> </pre>
</div> </div>
@ -3090,7 +3088,9 @@ is usually accessed as follows:
<div class="indent"> <div class="indent">
<pre> <pre>
Foo *f; Foo *f;
if (SWIG_ConvertPtr($input, (void **) &amp;f, SWIGTYPE_p_Foo, 0) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;f, SWIGTYPE_p_Foo, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
Tcl_Obj *; Tcl_Obj *;
obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0); obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
@ -3105,7 +3105,9 @@ variable <tt>$1_descriptor</tt>. For example:
<div class="indent"> <div class="indent">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &amp;$1, $1_descriptor,0)) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
} }
</pre> </pre>
</div> </div>
@ -3118,7 +3120,9 @@ For example:
<div class="indent"> <div class="indent">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &amp;$1, $descriptor(Foo *), 0)) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $descriptor(Foo *), 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
} }
</pre> </pre>
</div> </div>

View file

@ -376,7 +376,7 @@ example, you could write a typemap like this:
$1 = PyFloat_AsDouble($input); $1 = PyFloat_AsDouble($input);
if ($1 &lt; 0) { if ($1 &lt; 0) {
PyErr_SetString(PyExc_ValueError,"argument must be nonnegative."); PyErr_SetString(PyExc_ValueError,"argument must be nonnegative.");
return NULL; SWIG_fail;
} }
} }
@ -489,7 +489,7 @@ int foo(<b>int x, double y, char *s</b>);
<ul> <ul>
<li>Input argument conversion ("in" typemap).</li> <li>Input argument conversion ("in" typemap).</li>
<li>Input argument type checking ("typecheck" typemap).</li> <li>Input argument type checking for types used in overloaded methods ("typecheck" typemap).</li>
<li>Output argument handling ("argout" typemap).</li> <li>Output argument handling ("argout" typemap).</li>
<li>Input argument value checking ("check" typemap).</li> <li>Input argument value checking ("check" typemap).</li>
<li>Input argument initialization ("arginit" typemap).</li> <li>Input argument initialization ("arginit" typemap).</li>
@ -2586,6 +2586,7 @@ to see whether or not it matches a specific type. For example:
<p> <p>
For typechecking, the $1 variable is always a simple integer that is set to 1 or 0 depending on whether or not 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. the input argument is the correct type.
Set to 1 if the input argument is the correct type otherwise set to 0.
</p> </p>
<p> <p>
@ -2915,7 +2916,6 @@ try {
catch(char const *_e) { catch(char const *_e) {
PyErr_SetString(PyExc_RuntimeError, _e); PyErr_SetString(PyExc_RuntimeError, _e);
SWIG_fail; SWIG_fail;
} }
... ...
</pre> </pre>
@ -2964,11 +2964,11 @@ similar to this:
int i; int i;
if (!PySequence_Check($input)) { if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence"); PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL; SWIG_fail;
} }
if (PySequence_Length($input) != 4) { if (PySequence_Length($input) != 4) {
PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected 4 elements"); PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected 4 elements");
return NULL; SWIG_fail;
} }
for (i = 0; i &lt; 4; i++) { for (i = 0; i &lt; 4; i++) {
PyObject *o = PySequence_GetItem($input,i); PyObject *o = PySequence_GetItem($input,i);
@ -2976,7 +2976,7 @@ similar to this:
temp[i] = (float) PyFloat_AsDouble(o); temp[i] = (float) PyFloat_AsDouble(o);
} else { } else {
PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
return NULL; SWIG_fail;
} }
} }
$1 = temp; $1 = temp;
@ -3009,11 +3009,11 @@ If you wanted to generalize the typemap to apply to arrays of all dimensions you
int i; int i;
if (!PySequence_Check($input)) { if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence"); PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL; SWIG_fail;
} }
if (PySequence_Length($input) != $1_dim0) { if (PySequence_Length($input) != $1_dim0) {
PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements"); PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements");
return NULL; SWIG_fail;
} }
for (i = 0; i &lt; $1_dim0; i++) { for (i = 0; i &lt; $1_dim0; i++) {
PyObject *o = PySequence_GetItem($input,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); temp[i] = (float) PyFloat_AsDouble(o);
} else { } else {
PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
return NULL; SWIG_fail;
} }
} }
$1 = temp; $1 = temp;
@ -3053,11 +3053,11 @@ as shown. To work with heap allocated data, the following technique can be use
int i; int i;
if (!PySequence_Check($input)) { if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence"); PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL; SWIG_fail;
} }
if (PySequence_Length($input) != $1_dim0) { if (PySequence_Length($input) != $1_dim0) {
PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements"); PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements");
return NULL; SWIG_fail;
} }
$1 = (float *) malloc($1_dim0*sizeof(float)); $1 = (float *) malloc($1_dim0*sizeof(float));
for (i = 0; i &lt; $1_dim0; i++) { for (i = 0; i &lt; $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)) { if (PyNumber_Check(o)) {
$1[i] = (float) PyFloat_AsDouble(o); $1[i] = (float) PyFloat_AsDouble(o);
} else { } else {
PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
free($1); free($1);
return NULL; PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");
SWIG_fail;
} }
} }
} }
@ -3229,7 +3229,7 @@ pointers. For example:</p>
%typemap(check) Vector * { %typemap(check) Vector * {
if ($1 == 0) { if ($1 == 0) {
PyErr_SetString(PyExc_TypeError,"NULL Pointer not allowed"); 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; int i;
if (!PyList_Check($input)) { if (!PyList_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting a list"); PyErr_SetString(PyExc_ValueError, "Expecting a list");
return NULL; SWIG_fail;
} }
$1 = PyList_Size($input); $1 = PyList_Size($input);
$2 = (char **) malloc(($1+1)*sizeof(char *)); $2 = (char **) malloc(($1+1)*sizeof(char *));
@ -3517,7 +3517,7 @@ maps perform the conversion described for the above example:
if (!PyString_Check(s)) { if (!PyString_Check(s)) {
free($2); free($2);
PyErr_SetString(PyExc_ValueError, "List items must be strings"); PyErr_SetString(PyExc_ValueError, "List items must be strings");
return NULL; SWIG_fail;
} }
$2[i] = PyString_AsString(s); $2[i] = PyString_AsString(s);
} }
@ -3633,7 +3633,7 @@ might write typemaps like this:
%typemap(in) (void *wbuffer, size_t len) { %typemap(in) (void *wbuffer, size_t len) {
if (!PyString_Check($input)) { if (!PyString_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting a string"); PyErr_SetString(PyExc_ValueError, "Expecting a string");
return NULL; SWIG_fail;
} }
$1 = (void *) PyString_AsString($input); $1 = (void *) PyString_AsString($input);
$2 = PyString_Size($input); $2 = PyString_Size($input);
@ -3643,12 +3643,12 @@ might write typemaps like this:
%typemap(in) (void *rbuffer, size_t len) { %typemap(in) (void *rbuffer, size_t len) {
if (!PyInt_Check($input)) { if (!PyInt_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting an integer"); PyErr_SetString(PyExc_ValueError, "Expecting an integer");
return NULL; SWIG_fail;
} }
$2 = PyInt_AsLong($input); $2 = PyInt_AsLong($input);
if ($2 &lt; 0) { if ($2 &lt; 0) {
PyErr_SetString(PyExc_ValueError, "Positive integer expected"); PyErr_SetString(PyExc_ValueError, "Positive integer expected");
return NULL; SWIG_fail;
} }
$1 = (void *) malloc($2); $1 = (void *) malloc($2);
} }
@ -4139,14 +4139,17 @@ For example:
<div class="code"> <div class="code">
<pre> <pre>
class Foo { class Foo {
public:
int x; int x;
}; };
class Bar { class Bar {
public:
int y; int y;
}; };
class FooBar : public Foo, public Bar { class FooBar : public Foo, public Bar {
public:
int z; int z;
}; };
</pre> </pre>
@ -4181,12 +4184,15 @@ handling of pointer values (and to make adjustments when needed).
<p> <p>
In the wrapper code generated for each language, pointers are handled through In the wrapper code generated for each language, pointers are handled through
the use of special type descriptors and conversion functions. For example, 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):
</p> </p>
<div class="code"> <div class="code">
<pre> <pre>
if ((SWIG_ConvertPtr(obj0,(void **) &amp;arg1, SWIGTYPE_p_Foo,1)) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr(obj0, (void **) &amp;arg1, SWIGTYPE_p_Foo, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method 'GrabVal', expecting type Foo");
}
</pre> </pre>
</div> </div>
@ -4198,8 +4204,10 @@ target language, a list of equivalent typenames (via typedef or
inheritance), and pointer value handling information (if applicable). inheritance), and pointer value handling information (if applicable).
The <tt>SWIG_ConvertPtr()</tt> function is simply a utility function The <tt>SWIG_ConvertPtr()</tt> function is simply a utility function
that takes a pointer object in the target language and a that takes a pointer object in the target language and a
type-descriptor objects and uses this information to generate a C++ type-descriptor object and uses this information to generate a C++ pointer.
pointer. However, the exact name and calling conventions of the conversion The <tt>SWIG_IsOK</tt> macro checks the return value for errors and
<tt>SWIG_exception_fail</tt> 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). function depends on the target language (see language specific chapters for details).
</p> </p>
@ -4305,7 +4313,9 @@ similar to this:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor)) == -1) return NULL; if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor, 0))) {
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
}
} }
</pre> </pre>
</div> </div>
@ -4338,10 +4348,10 @@ descriptor name for any C datatype. For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
if ((SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor)) == -1) { if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor, 0))) {
Bar *temp; Bar *temp;
if ((SWIG_ConvertPtr($input, (void **) &amp;temp, <b>$descriptor(Bar *)</b>) == -1) { if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &amp;temp, $descriptor(Bar *), 0))) {
return NULL; SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo or Bar");
} }
$1 = (Foo *)temp; $1 = (Foo *)temp;
} }
@ -4589,38 +4599,13 @@ The following excerpt from the Python module illustrates this:
$1 = PyString_Check($input) ? 1 : 0; $1 = PyString_Check($input) ? 1 : 0;
} }
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &amp;, SWIGTYPE [] { %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE * {
void *ptr; void *vptr = 0;
if (SWIG_ConvertPtr($input, (void **) &amp;ptr, $1_descriptor, 0) == -1) { int res = SWIG_ConvertPtr($input, &amp;vptr, $1_descriptor, 0);
$1 = 0; $1 = SWIG_IsOK(res) ? 1 : 0;
PyErr_Clear();
} else {
$1 = 1;
}
} }
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { %typecheck(SWIG_TYPECHECK_POINTER) PyObject * {
void *ptr;
if (SWIG_ConvertPtr($input, (void **) &amp;ptr, $&amp;1_descriptor, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
void *ptr;
if (SWIG_ConvertPtr($input, (void **) &amp;ptr, 0, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_POINTER) PyObject *
{
$1 = ($input != 0); $1 = ($input != 0);
} }
</pre> </pre>

View file

@ -517,7 +517,7 @@ like this:
argc = PyTuple_Size(varargs); argc = PyTuple_Size(varargs);
if (argc &gt; 10) { if (argc &gt; 10) {
PyErr_SetString(PyExc_ValueError, "Too many arguments"); PyErr_SetString(PyExc_ValueError, "Too many arguments");
return NULL; SWIG_fail;
} }
for (i = 0; i &lt; argc; i++) { for (i = 0; i &lt; argc; i++) {
PyObject *pyobj = PyTuple_GetItem(varargs, i); PyObject *pyobj = PyTuple_GetItem(varargs, i);
@ -526,7 +526,7 @@ like this:
PyObject *pystr; PyObject *pystr;
if (!PyUnicode_Check(pyobj)) { if (!PyUnicode_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string"); PyErr_SetString(PyExc_ValueError, "Expected a string");
return NULL; SWIG_fail;
} }
pystr = PyUnicode_AsUTF8String(pyobj); pystr = PyUnicode_AsUTF8String(pyobj);
str = strdup(PyBytes_AsString(pystr)); str = strdup(PyBytes_AsString(pystr));
@ -534,7 +534,7 @@ like this:
%#else %#else
if (!PyString_Check(pyobj)) { if (!PyString_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string"); PyErr_SetString(PyExc_ValueError, "Expected a string");
return NULL; SWIG_fail;
} }
str = PyString_AsString(pyobj); str = PyString_AsString(pyobj);
%#endif %#endif
@ -635,9 +635,9 @@ example. For example:
for (i = 0; i &lt; argc; i++) { for (i = 0; i &lt; argc; i++) {
PyObject *o = PyTuple_GetItem(varargs,i); PyObject *o = PyTuple_GetItem(varargs,i);
if (!PyString_Check(o)) { if (!PyString_Check(o)) {
PyErr_SetString(PyExc_ValueError,"Expected a string");
free(argv); free(argv);
return NULL; PyErr_SetString(PyExc_ValueError,"Expected a string");
SWIG_fail;
} }
argv[i] = PyString_AsString(o); argv[i] = PyString_AsString(o);
} }
@ -676,11 +676,11 @@ example. For example:
&amp;ffi_type_uint, types) == FFI_OK) { &amp;ffi_type_uint, types) == FFI_OK) {
ffi_call(&amp;cif, (void (*)()) execlp, &amp;result, values); ffi_call(&amp;cif, (void (*)()) execlp, &amp;result, values);
} else { } else {
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
free(types); free(types);
free(values); free(values);
free(arg3); free(arg3);
return NULL; PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
SWIG_fail;
} }
free(types); free(types);
free(values); free(values);
@ -744,8 +744,8 @@ As a more extreme example of libffi, here is some code that attempts to wrap <tt
argv[i].type = VT_POINTER; argv[i].type = VT_POINTER;
argv[i].val.pvalue = (void *) PyString_AsString(o); argv[i].val.pvalue = (void *) PyString_AsString(o);
} else { } else {
PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
free(argv); free(argv);
PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
return NULL; return NULL;
} }
} }
@ -793,11 +793,11 @@ As a more extreme example of libffi, here is some code that attempts to wrap <tt
&amp;ffi_type_uint, types) == FFI_OK) { &amp;ffi_type_uint, types) == FFI_OK) {
ffi_call(&amp;cif, (void (*)()) printf, &amp;result, values); ffi_call(&amp;cif, (void (*)()) printf, &amp;result, values);
} else { } else {
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
free(types); free(types);
free(values); free(values);
free(args); free(args);
return NULL; PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
SWIG_fail;
} }
free(types); free(types);
free(values); free(values);

View file

@ -20,7 +20,7 @@
PyObject *o = PyTuple_GetItem(varargs,i); PyObject *o = PyTuple_GetItem(varargs,i);
if (!PyString_Check(o)) { if (!PyString_Check(o)) {
PyErr_SetString(PyExc_ValueError,"Expected a string"); PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL; SWIG_fail;
} }
argv[i] = PyString_AsString(o); argv[i] = PyString_AsString(o);
} }
@ -58,11 +58,11 @@
&ffi_type_uint, types) == FFI_OK) { &ffi_type_uint, types) == FFI_OK) {
ffi_call(&cif, (void (*)()) execlp, &result, values); ffi_call(&cif, (void (*)()) execlp, &result, values);
} else { } else {
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
free(types); free(types);
free(values); free(values);
free(arg3); free(arg3);
return NULL; PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
SWIG_fail;
} }
free(types); free(types);
free(values); free(values);
@ -107,9 +107,9 @@ int execlp(const char *path, const char *arg1, ...);
argv[i].type = VT_POINTER; argv[i].type = VT_POINTER;
argv[i].val.pvalue = (void *) PyString_AsString(o); argv[i].val.pvalue = (void *) PyString_AsString(o);
} else { } else {
PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
free(argv); free(argv);
return NULL; PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
SWIG_fail;
} }
} }
@ -157,11 +157,11 @@ int execlp(const char *path, const char *arg1, ...);
&ffi_type_uint, types) == FFI_OK) { &ffi_type_uint, types) == FFI_OK) {
ffi_call(&cif, (void (*)()) printf, &result, values); ffi_call(&cif, (void (*)()) printf, &result, values);
} else { } else {
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
free(types); free(types);
free(values); free(values);
free(args); free(args);
return NULL; PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
SWIG_fail;
} }
free(types); free(types);
free(values); free(values);

View file

@ -69,7 +69,7 @@ extern int gcdmain(int argc, char *argv[]);
PyObject *utf8str; PyObject *utf8str;
if (!PyUnicode_Check($input)) { if (!PyUnicode_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a string"); PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL; SWIG_fail;
} }
utf8str = PyUnicode_AsUTF8String($input); utf8str = PyUnicode_AsUTF8String($input);
PyBytes_AsStringAndSize(utf8str, &cstr, &len); PyBytes_AsStringAndSize(utf8str, &cstr, &len);
@ -79,7 +79,7 @@ extern int gcdmain(int argc, char *argv[]);
%#else %#else
if (!PyString_Check($input)) { if (!PyString_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a string"); PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL; SWIG_fail;
} }
$1 = PyString_AsString($input); $1 = PyString_AsString($input);
$2 = (int)PyString_Size($input); $2 = (int)PyString_Size($input);

View file

@ -203,6 +203,7 @@ CPP_TEST_CASES += \
director_thread \ director_thread \
director_unroll \ director_unroll \
director_using \ director_using \
director_void \
director_wombat \ director_wombat \
disown \ disown \
dynamic_cast \ dynamic_cast \
@ -259,7 +260,6 @@ CPP_TEST_CASES += \
langobj \ langobj \
li_attribute \ li_attribute \
li_attribute_template \ li_attribute_template \
li_boost_array \
li_boost_shared_ptr \ li_boost_shared_ptr \
li_boost_shared_ptr_bits \ li_boost_shared_ptr_bits \
li_boost_shared_ptr_template \ li_boost_shared_ptr_template \
@ -487,6 +487,7 @@ CPP_TEST_CASES += \
typemap_array_qualifiers \ typemap_array_qualifiers \
typemap_delete \ typemap_delete \
typemap_directorout \ typemap_directorout \
typemap_documentation \
typemap_global_scope \ typemap_global_scope \
typemap_manyargs \ typemap_manyargs \
typemap_namespace \ typemap_namespace \

View file

@ -1,6 +1,6 @@
%module cpp11_li_std_array %module cpp11_li_std_array
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) #if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP)
%{ %{
#include <array> #include <array>

View file

@ -22,5 +22,28 @@ public:
%} %}
%{ %{
int StaticMemberTest::static_int; int StaticMemberTest::static_int = 99;
%}
%inline %{
struct StaticBase {
static int statty;
virtual ~StaticBase() {}
};
struct StaticDerived : StaticBase {
static int statty;
};
%}
%{
int StaticBase::statty = 11;
int StaticDerived::statty = 111;
%}
%inline %{
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else
bool is_python_builtin() { return false; }
#endif
%} %}

View file

@ -0,0 +1,82 @@
// This test tests all the methods in the C# collection wrapper
using System;
using cpp11_li_std_arrayNamespace;
public class cpp11_li_std_array_runme
{
private static ArrayInt6 ToArray6(int[] a)
{
if (a.Length != 6)
throw new Exception("a is incorrect size");
return new ArrayInt6(a);
}
private static void compareContainers(ArrayInt6 actual, int[] expected)
{
if (actual.Count != expected.Length)
throw new Exception("Sizes are different: " + actual.Count + " " + expected.Length);
for (int i=0; i<actual.Count; ++i)
{
int actualValue = actual[i];
int expectedValue = expected[i];
if (actualValue != expectedValue)
throw new Exception("Value is wrong for element " + i + ". Expected " + expectedValue + " got: " + actualValue);
}
if (actual.IsEmpty)
throw new Exception("ai should not be empty");
}
static void Main()
{
ArrayInt6 ai = new ArrayInt6();
compareContainers(ai, new int[] { 0, 0, 0, 0, 0, 0 });
int[] vals = { 10, 20, 30, 40, 50, 60 };
for (int i = 0; i < ai.Count; ++i)
ai[i] = vals[i];
compareContainers(ai, vals);
// Check return
compareContainers(cpp11_li_std_array.arrayOutVal(), new int[] { -2, -1, 0, 0, 1, 2 });
compareContainers(cpp11_li_std_array.arrayOutConstRef(), new int[] { -2, -1, 0, 0, 1, 2 });
compareContainers(cpp11_li_std_array.arrayOutRef(), new int[] { -2, -1, 0, 0, 1, 2 });
compareContainers(cpp11_li_std_array.arrayOutPtr(), new int[] { -2, -1, 0, 0, 1, 2 });
// Check passing arguments
ai = cpp11_li_std_array.arrayInVal(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
ai = cpp11_li_std_array.arrayInConstRef(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
cpp11_li_std_array.arrayInRef(ai);
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
cpp11_li_std_array.arrayInPtr(ai);
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
// fill
ai.Fill(111);
compareContainers(ai, new int[] { 111, 111, 111, 111, 111, 111 });
// out of range errors
try
{
ai[ai.Count] = 0;
throw new Exception("Out of range exception not caught");
}
catch (ArgumentOutOfRangeException)
{
}
try
{
ai[-1] = 0;
throw new Exception("Out of range exception not caught");
}
catch (ArgumentOutOfRangeException)
{
}
}
}

View file

@ -0,0 +1,83 @@
using System;
using director_voidNamespace;
public class runme
{
private static void WaitForGC()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.Threading.Thread.Sleep(10);
}
static void Main()
{
runme r = new runme();
r.run();
}
void run()
{
Caller caller = new Caller();
{
DirectorVoidPointer dvp = new DirectorVoidPointer(5);
int x = caller.callVirtualIn(dvp, 6);
if (x != 106)
throw new Exception("Fail1 should be 106, got " + x);
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
x = Caller.VoidToInt(ptr);
if (x != 106)
throw new Exception("Fail2 should be 106, got " + x);
x = Caller.VoidToInt(dvp.voidPtrOut());
if (x != 106)
throw new Exception("Fail3 should be 106, got " + x);
}
{
DirectorVoidPointer dvp = new director_void_VoidPointer(5);
int x = caller.callVirtualIn(dvp, 6);
if (x != 12)
throw new Exception("Fail1 should be 12, got " + x);
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
x = Caller.VoidToInt(ptr);
if (x != 25)
throw new Exception("Fail2 should be 25, got " + x);
x = Caller.VoidToInt(dvp.voidPtrOut());
if (x != 1234)
throw new Exception("Fail3 should be 1234, got " + x);
}
{
DirectorVoidPointer dvp = new DirectorVoidPointer(10);
int x = caller.callVirtualOut(dvp);
if (x != 10)
throw new Exception("Bad1 should be 10, got " + x);
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
x = dvp.nonVirtualVoidPtrIn(ptr);
if (x != 110)
throw new Exception("Bad2 should be 110, got " + x);
}
{
DirectorVoidPointer dvp = new director_void_VoidPointer(10);
int x = caller.callVirtualOut(dvp);
if (x != 1234)
throw new Exception("Bad3 should be 1234, got " + x);
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
x = dvp.nonVirtualVoidPtrIn(ptr);
if (x != 1334)
throw new Exception("Bad4 should be 1334, got " + x);
}
}
}
class director_void_VoidPointer : DirectorVoidPointer {
public director_void_VoidPointer(int num) : base(num*num) {
}
public override int voidPtrIn(global::System.IntPtr p) {
return Caller.VoidToInt(p) * 2;
}
public override global::System.IntPtr voidPtrOut() {
setNewValue(1234);
return nonVirtualVoidPtrOut();
}
}

View file

@ -405,6 +405,10 @@ public class runme {
if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed"); if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed"); if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed");
} }
{
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue != (('A' << 24) | ('B' << 16) | ('C' << 8) | 'D')) throw new Exception("enumWithMacroTest 1 failed");
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD2).swigValue != enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue) throw new Exception("enumWithMacroTest 2 failed");
}
// different types // different types
{ {
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed"); if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed");
@ -413,6 +417,8 @@ public class runme {
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeboolfalse).swigValue != 0) throw new Exception("differentTypes 4 failed"); if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeboolfalse).swigValue != 0) throw new Exception("differentTypes 4 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typechar).swigValue != (int)'C') throw new Exception("differentTypes 5 failed"); if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typechar).swigValue != (int)'C') throw new Exception("differentTypes 5 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typedefaultint).swigValue != (int)'D') throw new Exception("differentTypes 6 failed"); if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typedefaultint).swigValue != (int)'D') throw new Exception("differentTypes 6 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound).swigValue != (int)'A' + 1) throw new Exception("differentTypes 7 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound2).swigValue != (int)'B' << 2) throw new Exception("differentTypes 8 failed");
int global_enum = enum_thorough_typesafe.global_typeint; int global_enum = enum_thorough_typesafe.global_typeint;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed"); if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
@ -426,6 +432,10 @@ public class runme {
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed"); if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed");
global_enum = enum_thorough_typesafe.global_typedefaultint; global_enum = enum_thorough_typesafe.global_typedefaultint;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed"); if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed");
global_enum = enum_thorough_typesafe.global_typecharcompound;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'A' + 1) throw new Exception("global differentTypes 7 failed");
global_enum = enum_thorough_typesafe.global_typecharcompound2;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'B' << 2) throw new Exception("global differentTypes 8 failed");
} }
} }
} }

View file

@ -0,0 +1,47 @@
%module(directors="1") director_void
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) voidPtrOut;
%feature("director") DirectorVoidPointer;
#if defined(SWIGCSHARP)
%apply void *VOID_INT_PTR { void * }
#endif
%inline %{
class DirectorVoidPointer {
int *ptr;
public:
DirectorVoidPointer(int val) : ptr(new int(val)) {}
virtual ~DirectorVoidPointer() { delete ptr; }
virtual void * voidPtrOut() { return ptr; }
virtual int voidPtrIn(void *p) {
return nonVirtualVoidPtrIn(p);
}
void setNewValue(int val) {
delete ptr;
ptr = new int(val);
}
void *nonVirtualVoidPtrOut() { return ptr; }
int nonVirtualVoidPtrIn(void *p) {
int val = *(int *)p;
setNewValue(val + 100);
return *ptr;
}
};
struct Caller {
int callVirtualIn(DirectorVoidPointer *d, int num) {
return d->voidPtrIn(&num);
}
int callVirtualOut(DirectorVoidPointer *d) {
return *(int *)d->voidPtrOut();
}
static int VoidToInt(void *p) {
return *(int *)p;
}
};
%}

View file

@ -569,6 +569,17 @@ repeat repeatTest(repeat e) { return e; }
} }
%} %}
%inline %{
namespace EnumWithMacro {
#define PACK(C1,C2,C3,C4) ((C1<<24)|(C2<<16)|(C3<<8)|C4)
typedef enum {
ABCD = PACK('A','B','C','D'),
ABCD2 = ABCD
} enumWithMacro;
enumWithMacro enumWithMacroTest(enumWithMacro e) { return e; }
}
%}
%inline %{ %inline %{
namespace DifferentSpace { namespace DifferentSpace {
enum DifferentTypes { enum DifferentTypes {
@ -577,7 +588,9 @@ enum DifferentTypes {
typebooltrue = true, typebooltrue = true,
typebooltwo, typebooltwo,
typechar = 'C', typechar = 'C',
typedefaultint typedefaultint,
typecharcompound='A'+1,
typecharcompound2='B' << 2
}; };
DifferentTypes differentTypesTest(DifferentTypes n) { return n; } DifferentTypes differentTypesTest(DifferentTypes n) { return n; }
@ -587,7 +600,9 @@ enum {
global_typebooltrue = true, global_typebooltrue = true,
global_typebooltwo, global_typebooltwo,
global_typechar = 'C', global_typechar = 'C',
global_typedefaultint global_typedefaultint,
global_typecharcompound='A'+1,
global_typecharcompound2='B' << 2
}; };
int globalDifferentTypesTest(int n) { return n; } int globalDifferentTypesTest(int n) { return n; }
} }

View file

@ -1,7 +1,7 @@
%module exception_classname %module exception_classname
%warnfilter(SWIGWARN_RUBY_WRONG_NAME); %warnfilter(SWIGWARN_RUBY_WRONG_NAME);
#ifdef SWIGPHP #if defined(SWIGPHP) || defined(SWIGD)
%rename(ExceptionClass) Exception; %rename(ExceptionClass) Exception;
#endif #endif

View file

@ -13,7 +13,7 @@ public class smart_pointer_ignore_runme {
public static void main(String argv[]) { public static void main(String argv[]) {
DerivedPtr d = smart_pointer_ignore.makeDerived(); DerivedPtr d = smart_pointer_ignore.makeDerived();
d.base(); d.baseMethod();
d.derived(); d.derivedMethod();
} }
} }

View file

@ -1,87 +0,0 @@
%module li_boost_array
#if defined(SWIGPYTHON) || defined(SWIGRUBY)
// Hack to use the std::array support for boost::array.
// Is limited as it currently exposes some 'using' bugs in SWIG though.
// For example, the type system fails to see that pointers to std::array
// and pointers to boost::array are the same.
%{
#if __cplusplus >= 201103 || (defined(_MSC_VER) && _MSC_VER >= 1900)
// Use C++11 array as this is unfortunately sometimes included by <algorithm>
#include <array>
namespace boost {
using std::array;
}
#else
#include <boost/array.hpp>
namespace std {
using boost::array;
}
#endif
%}
namespace boost {
using std::array;
}
%ignore std::array::fill; // Some older versions of boost don't have this function
%include <std_array.i>
%template(ArrayInt6) std::array<int, 6>;
%inline %{
boost::array<int, 6> arrayOutVal() {
const signed char carray[] = { -2, -1, 0, 0, 1, 2 };
boost::array<int, 6> myarray;
for (size_t i=0; i<6; ++i) {
myarray[i] = carray[i];
}
return myarray;
}
boost::array<int, 6> & arrayOutRef() {
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
return a;
}
const boost::array<int, 6> & arrayOutConstRef() {
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
return a;
}
boost::array<int, 6> * arrayOutPtr() {
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
return &a;
}
boost::array<int, 6> arrayInVal(boost::array<int, 6> myarray) {
for (boost::array<int, 6>::iterator it = myarray.begin(); it!=myarray.end(); ++it) {
*it *= 10;
}
return myarray;
}
const boost::array<int, 6> & arrayInConstRef(const boost::array<int, 6> & myarray) {
static boost::array<int, 6> a = myarray;
for (boost::array<int, 6>::iterator it = a.begin(); it!=a.end(); ++it) {
*it *= 10;
}
return a;
}
void arrayInRef(boost::array<int, 6> & myarray) {
for (boost::array<int, 6>::iterator it = myarray.begin(); it!=myarray.end(); ++it) {
*it *= 10;
}
}
void arrayInPtr(boost::array<int, 6> * myarray) {
for (boost::array<int, 6>::iterator it = myarray->begin(); it!=myarray->end(); ++it) {
*it *= 10;
}
}
%}
#endif

View file

@ -50,7 +50,7 @@ namespace test {
PyComplex_ImagAsDouble($input)); PyComplex_ImagAsDouble($input));
} else { } else {
PyErr_SetString(PyExc_TypeError,"Expected test_complex.\n"); PyErr_SetString(PyExc_TypeError,"Expected test_complex.\n");
return NULL; SWIG_fail;
} }
} }
%typemap(freearg) test::test_complex * { %typemap(freearg) test::test_complex * {
@ -242,7 +242,7 @@ namespace Split {
$1 = PyInt_AsLong($input); $1 = PyInt_AsLong($input);
if ($1 < 0) { if ($1 < 0) {
PyErr_SetString(PyExc_ValueError,"domain error\n"); PyErr_SetString(PyExc_ValueError,"domain error\n");
return NULL; SWIG_fail;
} }
} }
#endif #endif

View file

@ -4,11 +4,11 @@ require "tests.php";
require "cpp_static.php"; require "cpp_static.php";
// New functions // New functions
check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3)); check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3,is_python_builtin));
// New classes // New classes
check::classes(array(StaticMemberTest,StaticFunctionTest)); check::classes(array(StaticMemberTest,StaticFunctionTest,cpp_static,StaticBase,StaticDerived));
// New vars // New vars
check::globals(array(staticmembertest_static_int)); check::globals(array(staticmembertest_static_int,staticbase_statty,staticderived_statty));
check::done(); check::done();
?> ?>

View file

@ -51,7 +51,7 @@
// Expressions - runtime tests check the type for any necessary type promotions of the expressions // Expressions - runtime tests check the type for any necessary type promotions of the expressions
#define INT_AND_BOOL 0xFF & true #define INT_AND_BOOL 0xFF & true
//#define INT_AND_CHAR 0xFF & 'A' /* FIXME compile error */ #define INT_AND_CHAR 0xFF & 'A'
#define INT_AND_INT 0xFF & 2 #define INT_AND_INT 0xFF & 2
#define INT_AND_UINT 0xFF & 2u #define INT_AND_UINT 0xFF & 2u
#define INT_AND_LONG 0xFF & 2l #define INT_AND_LONG 0xFF & 2l
@ -60,8 +60,7 @@
#define INT_AND_ULLONG 0xFF & 2ull #define INT_AND_ULLONG 0xFF & 2ull
#define BOOL_AND_BOOL true & true // Note integral promotion to type int #define BOOL_AND_BOOL true & true // Note integral promotion to type int
//#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int #define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int
/* FIXME ABOVE */
#define EXPR_MULTIPLY 0xFF * 2 #define EXPR_MULTIPLY 0xFF * 2
@ -88,6 +87,9 @@
#define EXPR_LOR 0xFF || 1 #define EXPR_LOR 0xFF || 1
#define EXPR_CONDITIONAL true ? 2 : 2.2 #define EXPR_CONDITIONAL true ? 2 : 2.2
#define EXPR_CHAR_COMPOUND_ADD 'A' + 12
#define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6
#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
/// constant assignment in enum /// constant assignment in enum
#if defined(SWIGCSHARP) #if defined(SWIGCSHARP)

View file

@ -64,6 +64,7 @@ CPP_TEST_CASES += \
python_docstring \ python_docstring \
python_nondynamic \ python_nondynamic \
python_overload_simple_cast \ python_overload_simple_cast \
python_pickle \
python_pythoncode \ python_pythoncode \
python_richcompare \ python_richcompare \
python_strict_unicode \ python_strict_unicode \

View file

@ -13,6 +13,31 @@ else:
StaticFunctionTest().static_func() StaticFunctionTest().static_func()
StaticFunctionTest().static_func_2(1) StaticFunctionTest().static_func_2(1)
StaticFunctionTest().static_func_3(1, 2) StaticFunctionTest().static_func_3(1, 2)
if is_python_builtin():
if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99")
StaticMemberTest.static_int = 10 StaticMemberTest.static_int = 10
if not StaticMemberTest.static_int == 10: if not StaticMemberTest.static_int == 10: raise RuntimeError("static_int not 10")
raise RuntimeError("static_int not 10")
if not StaticBase.statty == 11: raise RuntimeError("statty not 11")
if not StaticDerived.statty == 111: raise RuntimeError("statty not 111")
StaticBase.statty = 22
StaticDerived.statty = 222
if not StaticBase.statty == 22: raise RuntimeError("statty not 22")
if not StaticDerived.statty == 222: raise RuntimeError("statty not 222")
# Restore
StaticMemberTest.static_int = 99
StaticBase.statty = 11
StaticDerived.statty = 111
if not cvar.StaticMemberTest_static_int == 99: raise RuntimeError("cvar static_int not 99")
cvar.StaticMemberTest_static_int = 10
if not cvar.StaticMemberTest_static_int == 10: raise RuntimeError("cvar static_int not 10")
if not cvar.StaticBase_statty == 11: raise RuntimeError("cvar statty not 11")
if not cvar.StaticDerived_statty == 111: raise RuntimeError("cvar statty not 111")
cvar.StaticBase_statty = 22
cvar.StaticDerived_statty = 222
if not cvar.StaticBase_statty == 22: raise RuntimeError("cvar statty not 22")
if not cvar.StaticDerived_statty == 222: raise RuntimeError("cvar statty not 222")

View file

@ -1,55 +0,0 @@
from li_boost_array import *
import sys
def failed(a, b, msg):
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b))
def compare_sequences(a, b):
if len(a) != len(b):
failed(a, b, "different sizes")
for i in range(len(a)):
if a[i] != b[i]:
failed(a, b, "elements are different")
def compare_containers(pythonlist, swigarray):
compare_sequences(pythonlist, swigarray)
ps = [0, 1, 2, 3, 4, 5]
ai = ArrayInt6(ps)
compare_containers(ps, ai)
# Modify content
for i in range(len(ps)):
ps[i] = (ps[i] + 1) * 10
ai[i] = (ai[i] + 1) * 10
compare_containers(ps, ai)
# Empty
ai = ArrayInt6()
compare_containers([0, 0, 0, 0, 0, 0], ai)
# Check return
compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2])
compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2])
#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2])
#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2])
# Check passing arguments
ai = arrayInVal([9, 8, 7, 6, 5, 4])
compare_containers(ai, [90, 80, 70, 60, 50, 40])
ai = arrayInConstRef([9, 8, 7, 6, 5, 4])
compare_containers(ai, [90, 80, 70, 60, 50, 40])
#ai = ArrayInt6([9, 8, 7, 6, 5, 4])
#arrayInRef(ai)
#compare_containers(ai, [90, 80, 70, 60, 50, 40])
#ai = ArrayInt6([9, 8, 7, 6, 5, 4])
#arrayInPtr(ai)
#compare_containers(ai, [90, 80, 70, 60, 50, 40])

View file

@ -0,0 +1,35 @@
import python_pickle
import pickle
import sys
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def check(p):
msg = p.msg
if msg != "hi there":
raise RuntimeError("Bad, got: " + msg)
if not is_new_style_class(python_pickle.PickleMe):
sys.exit(0)
python_pickle.cvar.debug = False
p = python_pickle.PickleMe("hi there")
check(p)
r = p.__reduce__()
if python_pickle.cvar.debug:
print "__reduce__ returned:", r
pickle_string = pickle.dumps(p)
newp = pickle.loads(pickle_string)
check(newp)
# Not yet working... some crash and others are not producing a sensible "can't be pickled" error
#nfp = python_pickle.NotForPickling("no no")
#print nfp.__reduce__()
#pickle_string = pickle.dumps(nfp)
#print pickle_string
#newp = pickle.loads(pickle_string)
#print newp.msg

View file

@ -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")

View file

@ -2,6 +2,12 @@
%module python_builtin %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 %{ %inline %{
#ifdef SWIGPYTHON_BUILTIN #ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; } bool is_python_builtin() { return true; }
@ -156,12 +162,12 @@ void Dealloc2Destroyer(PyObject *v) {
%feature("python:slot", "sq_length", functype="lenfunc") SimpleArray::__len__; %feature("python:slot", "sq_length", functype="lenfunc") SimpleArray::__len__;
%inline %{ %inline %{
class SimpleArray { class SimpleArray {
size_t size; Py_ssize_t size;
int numbers[5]; int numbers[5];
public: public:
SimpleArray(size_t size) : size(size) { SimpleArray(Py_ssize_t size) : size(size) {
for (size_t x = 0; x<size; ++x) for (Py_ssize_t x = 0; x<size; ++x)
numbers[x] = x*10; numbers[x] = (int)x*10;
} }
Py_ssize_t __len__() { Py_ssize_t __len__() {
@ -192,7 +198,7 @@ void Dealloc2Destroyer(PyObject *v) {
if (ii > jj) if (ii > jj)
throw std::invalid_argument("getitem i should not be larger than j"); throw std::invalid_argument("getitem i should not be larger than j");
SimpleArray n(jj-ii); SimpleArray n(jj-ii);
for (size_t x = 0; x<size; ++x) for (Py_ssize_t x = 0; x<size; ++x)
n.numbers[x] = numbers[x+ii]; n.numbers[x] = numbers[x+ii];
return n; return n;
} }

View file

@ -0,0 +1,56 @@
%module python_pickle
%include <std_string.i>
%extend PickleMe {
#if 0
// Note: %pythoncode can't be used with -builtin
%pythoncode %{
def __reduce__(self):
print "In Python __reduce__"
return (type(self), (self.msg, ))
%}
#else
// Equivalent to Python code above
PyObject *__reduce__() {
if (debug)
std::cout << "In C++ __reduce__" << std::endl;
PyObject *args = PyTuple_New(1);
PyTuple_SetItem(args, 0, SWIG_From_std_string(self->msg));
swig_type_info *ty = SWIGTYPE_p_PickleMe;
SwigPyClientData *data = (SwigPyClientData *)ty->clientdata;
#if defined(SWIGPYTHON_BUILTIN)
PyObject *callable = (PyObject *)data->pytype;
#else
PyObject *callable = data->klass;
#endif
Py_INCREF(callable);
PyObject *ret = PyTuple_New(2);
PyTuple_SetItem(ret, 0, callable);
PyTuple_SetItem(ret, 1, args);
return ret;
}
#endif
}
%inline %{
#include <iostream>
bool debug = false;
struct PickleMe {
std::string msg;
PickleMe(const std::string& msg) : msg(msg) {
if (debug)
std::cout << "In C++ constructor " << " [" << msg << "]" << std::endl;
}
};
struct NotForPickling {
std::string msg;
NotForPickling(const std::string& msg) : msg(msg) {}
};
%}

View file

@ -11,7 +11,7 @@
argc = PyTuple_Size(varargs); argc = PyTuple_Size(varargs);
if (argc > 10) { if (argc > 10) {
PyErr_SetString(PyExc_ValueError, "Too many arguments"); PyErr_SetString(PyExc_ValueError, "Too many arguments");
return NULL; SWIG_fail;
} }
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
PyObject *pyobj = PyTuple_GetItem(varargs, i); PyObject *pyobj = PyTuple_GetItem(varargs, i);
@ -20,7 +20,7 @@
PyObject *pystr; PyObject *pystr;
if (!PyUnicode_Check(pyobj)) { if (!PyUnicode_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string"); PyErr_SetString(PyExc_ValueError, "Expected a string");
return NULL; SWIG_fail;
} }
pystr = PyUnicode_AsUTF8String(pyobj); pystr = PyUnicode_AsUTF8String(pyobj);
str = strdup(PyBytes_AsString(pystr)); str = strdup(PyBytes_AsString(pystr));
@ -28,7 +28,7 @@
%#else %#else
if (!PyString_Check(pyobj)) { if (!PyString_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string"); PyErr_SetString(PyExc_ValueError, "Expected a string");
return NULL; SWIG_fail;
} }
str = PyString_AsString(pyobj); str = PyString_AsString(pyobj);
%#endif %#endif

View file

@ -1,70 +0,0 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'swig_assert'
require 'li_boost_array'
include Li_boost_array
def failed(a, b, msg)
raise RuntimeError, "#{msg} #{a} #{b}"
end
def compare_sequences(a, b)
if a.size != b.size
failed(a, b, "different sizes")
end
for i in 0..a.size-1
failed(a, b, "elements are different:") if a[i] != b[i]
end
end
def compare_containers(rubyarray, swigarray)
compare_sequences(rubyarray, swigarray)
end
ps = [0, 1, 2, 3, 4, 5]
ai = ArrayInt6.new(ps)
compare_containers(ps, ai)
# Modify content
for i in 0..ps.size-1
ps[i] = ps[i] * 10
ai[i] = ai[i] * 10
end
compare_containers(ps, ai)
# Empty
ai = ArrayInt6.new()
# Check return
compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2])
compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2])
#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2])
#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2])
# Check passing arguments
ai = arrayInVal([9, 8, 7, 6, 5, 4])
compare_containers(ai, [90, 80, 70, 60, 50, 40])
ai = arrayInConstRef([9, 8, 7, 6, 5, 4])
compare_containers(ai, [90, 80, 70, 60, 50, 40])
#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
#arrayInRef(ai)
#compare_containers(ai, [90, 80, 70, 60, 50, 40])
#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
#arrayInPtr(ai)
#compare_containers(ai, [90, 80, 70, 60, 50, 40])

View file

@ -6,12 +6,12 @@
%inline %{ %inline %{
class Base { class Base {
public: public:
void base() {} void baseMethod() {}
}; };
class Derived : public Base { class Derived : public Base {
public: public:
void derived() {} void derivedMethod() {}
}; };
template <class T> template <class T>

View file

@ -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;
}
%}

View file

@ -860,7 +860,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
global::System.IntPtr ret = $imcall;$excode global::System.IntPtr ret = $imcall;$excode
return ret; return ret;
} }
%typemap(csdirectorin) void *VOID_INT_PTR "$iminput"
%typemap(csdirectorout) void *VOID_INT_PTR "$cscall"
/* Typemaps used for the generation of proxy and type wrapper class code */ /* Typemaps used for the generation of proxy and type wrapper class code */
%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) ""

227
Lib/csharp/std_array.i Normal file
View file

@ -0,0 +1,227 @@
/* -----------------------------------------------------------------------------
* std_array.i
*
* SWIG typemaps for std::array<T, N>
* C# implementation
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IReadOnlyList<> collection.
* ----------------------------------------------------------------------------- */
%{
#include <algorithm>
#include <array>
#include <stdexcept>
%}
%include <std_common.i>
%define SWIG_STD_ARRAY_INTERNAL(T, N)
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n";
%typemap(cscode) std::array< T, N > %{
public $csclassname(global::System.Collections.ICollection c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
int end = global::System.Math.Min(this.Count, c.Count);
int i = 0;
foreach ($typemap(cstype, T) elem in c) {
if (i >= end)
break;
this[i++] = elem;
}
}
public int Count {
get {
return (int)size();
}
}
public $typemap(cstype, T) this[int index] {
get {
return getitem(index);
}
set {
setitem(index, value);
}
}
public bool IsEmpty {
get {
return empty();
}
}
public void CopyTo($typemap(cstype, T)[] array)
{
CopyTo(0, array, 0, this.Count);
}
public void CopyTo($typemap(cstype, T)[] array, int arrayIndex)
{
CopyTo(0, array, arrayIndex, this.Count);
}
public void CopyTo(int index, $typemap(cstype, T)[] array, int arrayIndex, int count)
{
if (array == null)
throw new global::System.ArgumentNullException("array");
if (index < 0)
throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero");
if (arrayIndex < 0)
throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (count < 0)
throw new global::System.ArgumentOutOfRangeException("count", "Value is less than zero");
if (array.Rank > 1)
throw new global::System.ArgumentException("Multi dimensional array.", "array");
if (index+count > this.Count || arrayIndex+count > array.Length)
throw new global::System.ArgumentException("Number of elements to copy is too large.");
for (int i=0; i<count; i++)
array.SetValue(getitemcopy(index+i), arrayIndex+i);
}
global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
public $csclassnameEnumerator GetEnumerator() {
return new $csclassnameEnumerator(this);
}
// Type-safe enumerator
/// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown
/// whenever the collection is modified. This has been done for changes in the size of the
/// collection but not when one of the elements of the collection is modified as it is a bit
/// tricky to detect unmanaged code that modifies the collection under our feet.
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator
, global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)>
{
private $csclassname collectionRef;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
currentIndex = -1;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public $typemap(cstype, T) Current {
get {
if (currentIndex == -1)
throw new global::System.InvalidOperationException("Enumeration not started.");
if (currentIndex > currentSize - 1)
throw new global::System.InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new global::System.InvalidOperationException("Collection modified.");
return ($typemap(cstype, T))currentObject;
}
}
// Type-unsafe IEnumerator.Current
object global::System.Collections.IEnumerator.Current {
get {
return Current;
}
}
public bool MoveNext() {
int size = collectionRef.Count;
bool moveOkay = (currentIndex+1 < size) && (size == currentSize);
if (moveOkay) {
currentIndex++;
currentObject = collectionRef[currentIndex];
} else {
currentObject = null;
}
return moveOkay;
}
public void Reset() {
currentIndex = -1;
currentObject = null;
if (collectionRef.Count != currentSize) {
throw new global::System.InvalidOperationException("Collection modified.");
}
}
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
%}
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
array();
array(const array &other);
size_type size() const;
bool empty() const;
%rename(Fill) fill;
void fill(const value_type& val);
%rename(Swap) swap;
void swap(array& other);
%extend {
T getitemcopy(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
const_reference getitem(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
void setitem(int index, const_reference val) throw (std::out_of_range) {
if (index>=0 && index<(int)$self->size())
(*$self)[index] = val;
else
throw std::out_of_range("index");
}
void Reverse() {
std::reverse($self->begin(), $self->end());
}
void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0)
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
std::reverse($self->begin()+index, $self->begin()+index+count);
}
}
%enddef
%csmethodmodifiers std::array::empty "private"
%csmethodmodifiers std::array::getitemcopy "private"
%csmethodmodifiers std::array::getitem "private"
%csmethodmodifiers std::array::setitem "private"
%csmethodmodifiers std::array::size "private"
namespace std {
template<class T, size_t N> class array {
SWIG_STD_ARRAY_INTERNAL(T, N)
};
}

View file

@ -398,4 +398,5 @@ SWIG_STD_VECTOR_ENHANCED(unsigned long long)
SWIG_STD_VECTOR_ENHANCED(float) SWIG_STD_VECTOR_ENHANCED(float)
SWIG_STD_VECTOR_ENHANCED(double) SWIG_STD_VECTOR_ENHANCED(double)
SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i> SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i>
SWIG_STD_VECTOR_ENHANCED(std::wstring) // also requires a %include <std_wstring.i>

View file

@ -60,16 +60,15 @@ class wstring;
%} %}
%typemap(directorin,descriptor="Ljava/lang/String;") wstring %{ %typemap(directorin,descriptor="Ljava/lang/String;") wstring %{
{
jsize $1_len = $1.length(); jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len]; jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) { for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)$1[i]; $1_conv_buf[i] = (jchar)$1[i];
} }
$input = jenv->NewString(conv_buf, $1_len); $input = jenv->NewString($1_conv_buf, $1_len);
delete [] conv_buf; Swig::LocalRefGuard $1_refguard(jenv, $input);
} delete [] $1_conv_buf;
Swig::LocalRefGuard $1_refguard(jenv, $input); %} %}
%typemap(out) wstring %typemap(out) wstring
%{jsize $1_len = $1.length(); %{jsize $1_len = $1.length();
@ -139,16 +138,15 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); %}
jenv->ReleaseStringChars($input, $1_pstr); %} jenv->ReleaseStringChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") const wstring & %{ %typemap(directorin,descriptor="Ljava/lang/String;") const wstring & %{
{
jsize $1_len = $1.length(); jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len]; jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) { for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)($1)[i]; $1_conv_buf[i] = (jchar)($1)[i];
} }
$input = jenv->NewString(conv_buf, $1_len); $input = jenv->NewString($1_conv_buf, $1_len);
delete [] conv_buf; Swig::LocalRefGuard $1_refguard(jenv, $input);
} delete [] $1_conv_buf;
Swig::LocalRefGuard $1_refguard(jenv, $input); %} %}
%typemap(out) const wstring & %typemap(out) const wstring &
%{jsize $1_len = $1->length(); %{jsize $1_len = $1->length();

View file

@ -4,8 +4,7 @@
* Global variables - add the variable to PHP * Global variables - add the variable to PHP
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%typemap(varinit) char *, %typemap(varinit) char *
char []
{ {
zval *z_var; zval *z_var;
MAKE_STD_ZVAL(z_var); MAKE_STD_ZVAL(z_var);
@ -20,6 +19,16 @@
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL); zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
} }
%typemap(varinit) char []
{
zval *z_var;
MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING;
z_var->value.str.val = estrdup($1);
z_var->value.str.len = strlen($1);
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) int, %typemap(varinit) int,
unsigned int, unsigned int,
unsigned short, unsigned short,
@ -95,10 +104,7 @@
zval *z_var; zval *z_var;
MAKE_STD_ZVAL(z_var); MAKE_STD_ZVAL(z_var);
z_var->type = IS_STRING; z_var->type = IS_STRING;
if ($1) {
/* varinit char [ANY] */
ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1); ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1);
}
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL); zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL);
} }

View file

@ -164,9 +164,13 @@ SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
} }
SWIGINTERN int SWIGINTERN int
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { SwigPyObjectType_setattro(PyObject *typeobject, PyObject *name, PyObject *value) {
PyObject *attribute; PyObject *attribute;
PyTypeObject *type;
descrsetfunc local_set; descrsetfunc local_set;
assert(PyType_Check(typeobject));
type = (PyTypeObject *)typeobject;
attribute = _PyType_Lookup(type, name); attribute = _PyType_Lookup(type, name);
if (attribute != NULL) { if (attribute != NULL) {
/* Implement descriptor functionality, if any */ /* Implement descriptor functionality, if any */
@ -276,6 +280,95 @@ SwigPyStaticVar_Type(void) {
return &staticvar_type; return &staticvar_type;
} }
SWIGINTERN PyTypeObject*
SwigPyObjectType(void) {
static char swigpyobjecttype_doc[] = "Metaclass for SWIG wrapped types";
static PyTypeObject swigpyobjecttype_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
#endif
"SwigPyObjectType", /* tp_name */
PyType_Type.tp_basicsize, /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
SwigPyObjectType_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
swigpyobjecttype_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
swigpyobjecttype_type = tmp;
type_init = 1;
swigpyobjecttype_type.tp_base = &PyType_Type;
#if PY_VERSION_HEX < 0x02020000
swigpyobjecttype_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&swigpyobjecttype_type) < 0)
return NULL;
#endif
}
return &swigpyobjecttype_type;
}
SWIGINTERN PyGetSetDescrObject * SWIGINTERN PyGetSetDescrObject *
SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {

View file

@ -374,13 +374,13 @@ SWIG_init(void) {
static PyGetSetDef thisown_getset_def = { static PyGetSetDef thisown_getset_def = {
(char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
}; };
PyObject *metatype_args;
PyTypeObject *builtin_pytype; PyTypeObject *builtin_pytype;
int builtin_base_count; int builtin_base_count;
swig_type_info *builtin_basetype; swig_type_info *builtin_basetype;
PyObject *tuple; PyObject *tuple;
PyGetSetDescrObject *static_getset; PyGetSetDescrObject *static_getset;
PyTypeObject *metatype; PyTypeObject *metatype;
PyTypeObject *swigpyobject;
SwigPyClientData *cd; SwigPyClientData *cd;
PyObject *public_interface, *public_symbol; PyObject *public_interface, *public_symbol;
PyObject *this_descr; PyObject *this_descr;
@ -395,14 +395,9 @@ SWIG_init(void) {
(void)static_getset; (void)static_getset;
(void)self; (void)self;
/* metatype is used to implement static member variables. */ /* Metaclass is used to implement static member variables */
metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); metatype = SwigPyObjectType();
assert(metatype_args);
metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL);
assert(metatype); assert(metatype);
Py_DECREF(metatype_args);
metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro;
assert(PyType_Ready(metatype) >= 0);
#endif #endif
/* Fix SwigMethods to carry the callback ptrs when needed */ /* Fix SwigMethods to carry the callback ptrs when needed */
@ -420,13 +415,15 @@ SWIG_init(void) {
SWIG_InitializeModule(0); SWIG_InitializeModule(0);
#ifdef SWIGPYTHON_BUILTIN #ifdef SWIGPYTHON_BUILTIN
swigpyobject = SwigPyObject_TypeOnce();
SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
assert(SwigPyObject_stype); assert(SwigPyObject_stype);
cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
if (!cd) { if (!cd) {
SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce(); SwigPyObject_clientdata.pytype = swigpyobject;
} else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) { } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) {
PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
# if PY_VERSION_HEX >= 0x03000000 # if PY_VERSION_HEX >= 0x03000000
return NULL; return NULL;

View file

@ -78,4 +78,7 @@ extern "C" {
#define SWIG_WARN_NODE_END(Node) \ #define SWIG_WARN_NODE_END(Node) \
if (wrnfilter) Swig_warnfilter(wrnfilter,0); \ if (wrnfilter) Swig_warnfilter(wrnfilter,0); \
} }
#define COMPOUND_EXPR_VAL(dtype) \
((dtype).type == T_CHAR || (dtype).type == T_WCHAR ? (dtype).rawval : (dtype).val)
#endif #endif

View file

@ -5828,7 +5828,7 @@ definetype : { /* scanner_check_typedef(); */ } expr {
if ($$.type == T_STRING) { if ($$.type == T_STRING) {
$$.rawval = NewStringf("\"%(escape)s\"",$$.val); $$.rawval = NewStringf("\"%(escape)s\"",$$.val);
} else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) { } else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) {
$$.rawval = 0; $$.rawval = NewStringf("%s", $$.val);
} }
$$.qualifier = 0; $$.qualifier = 0;
$$.bitfield = 0; $$.bitfield = 0;
@ -6095,81 +6095,81 @@ exprnum : NUM_INT { $$ = $1; }
; ;
exprcompound : expr PLUS expr { exprcompound : expr PLUS expr {
$$.val = NewStringf("%s+%s",$1.val,$3.val); $$.val = NewStringf("%s+%s", COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr MINUS expr { | expr MINUS expr {
$$.val = NewStringf("%s-%s",$1.val,$3.val); $$.val = NewStringf("%s-%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr STAR expr { | expr STAR expr {
$$.val = NewStringf("%s*%s",$1.val,$3.val); $$.val = NewStringf("%s*%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr SLASH expr { | expr SLASH expr {
$$.val = NewStringf("%s/%s",$1.val,$3.val); $$.val = NewStringf("%s/%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr MODULO expr { | expr MODULO expr {
$$.val = NewStringf("%s%%%s",$1.val,$3.val); $$.val = NewStringf("%s%%%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr AND expr { | expr AND expr {
$$.val = NewStringf("%s&%s",$1.val,$3.val); $$.val = NewStringf("%s&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr OR expr { | expr OR expr {
$$.val = NewStringf("%s|%s",$1.val,$3.val); $$.val = NewStringf("%s|%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr XOR expr { | expr XOR expr {
$$.val = NewStringf("%s^%s",$1.val,$3.val); $$.val = NewStringf("%s^%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type); $$.type = promote($1.type,$3.type);
} }
| expr LSHIFT expr { | expr LSHIFT expr {
$$.val = NewStringf("%s << %s",$1.val,$3.val); $$.val = NewStringf("%s << %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote_type($1.type); $$.type = promote_type($1.type);
} }
| expr RSHIFT expr { | expr RSHIFT expr {
$$.val = NewStringf("%s >> %s",$1.val,$3.val); $$.val = NewStringf("%s >> %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote_type($1.type); $$.type = promote_type($1.type);
} }
| expr LAND expr { | expr LAND expr {
$$.val = NewStringf("%s&&%s",$1.val,$3.val); $$.val = NewStringf("%s&&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
| expr LOR expr { | expr LOR expr {
$$.val = NewStringf("%s||%s",$1.val,$3.val); $$.val = NewStringf("%s||%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
| expr EQUALTO expr { | expr EQUALTO expr {
$$.val = NewStringf("%s==%s",$1.val,$3.val); $$.val = NewStringf("%s==%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
| expr NOTEQUALTO expr { | expr NOTEQUALTO expr {
$$.val = NewStringf("%s!=%s",$1.val,$3.val); $$.val = NewStringf("%s!=%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
/* Sadly this causes 2 reduce-reduce conflicts with templates. FIXME resolve these. /* Sadly this causes 2 reduce-reduce conflicts with templates. FIXME resolve these.
| expr GREATERTHAN expr { | expr GREATERTHAN expr {
$$.val = NewStringf("%s > %s", $1.val, $3.val); $$.val = NewStringf("%s > %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
| expr LESSTHAN expr { | expr LESSTHAN expr {
$$.val = NewStringf("%s < %s", $1.val, $3.val); $$.val = NewStringf("%s < %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
*/ */
| expr GREATERTHANOREQUALTO expr { | expr GREATERTHANOREQUALTO expr {
$$.val = NewStringf("%s >= %s", $1.val, $3.val); $$.val = NewStringf("%s >= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
| expr LESSTHANOREQUALTO expr { | expr LESSTHANOREQUALTO expr {
$$.val = NewStringf("%s <= %s", $1.val, $3.val); $$.val = NewStringf("%s <= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT; $$.type = cparse_cplusplus ? T_BOOL : T_INT;
} }
| expr QUESTIONMARK expr COLON expr %prec QUESTIONMARK { | expr QUESTIONMARK expr COLON expr %prec QUESTIONMARK {
$$.val = NewStringf("%s?%s:%s", $1.val, $3.val, $5.val); $$.val = NewStringf("%s?%s:%s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3), COMPOUND_EXPR_VAL($5));
/* This may not be exactly right, but is probably good enough /* This may not be exactly right, but is probably good enough
* for the purposes of parsing constant expressions. */ * for the purposes of parsing constant expressions. */
$$.type = promote($3.type, $5.type); $$.type = promote($3.type, $5.type);
@ -6187,7 +6187,7 @@ exprcompound : expr PLUS expr {
$$.type = $2.type; $$.type = $2.type;
} }
| LNOT expr { | LNOT expr {
$$.val = NewStringf("!%s",$2.val); $$.val = NewStringf("!%s",COMPOUND_EXPR_VAL($2));
$$.type = T_INT; $$.type = T_INT;
} }
| type LPAREN { | type LPAREN {

View file

@ -2809,6 +2809,14 @@ private:
String *get = NewString(""); String *get = NewString("");
Printv(get, Swig_cresult_name(), " = ", NULL); Printv(get, Swig_cresult_name(), " = ", NULL);
String *rawval = Getattr(n, "rawval");
if (rawval && Len(rawval)) {
if (SwigType_type(type) == T_STRING) {
Printv(get, "(char *)", NULL);
}
Printv(get, rawval, NULL);
} else {
char quote; char quote;
if (Getattr(n, "wrappedasconstant")) { if (Getattr(n, "wrappedasconstant")) {
quote = '\0'; quote = '\0';
@ -2830,8 +2838,10 @@ private:
if (quote != '\0') { if (quote != '\0') {
Printf(get, "%c", quote); Printf(get, "%c", quote);
} }
}
Printv(get, ";\n", NULL); Printv(get, ";\n", NULL);
Setattr(n, "wrap:action", get); Setattr(n, "wrap:action", get);
String *sname = Copy(symname); String *sname = Copy(symname);

View file

@ -3339,6 +3339,8 @@ public:
Printf(builtin_closures_code, "%s /* defines %s */\n\n", closure_decl, closure_name); Printf(builtin_closures_code, "%s /* defines %s */\n\n", closure_decl, closure_name);
SetFlag(builtin_closures, closure_name); SetFlag(builtin_closures, closure_name);
Delete(closure_decl); Delete(closure_decl);
} else {
closure_name = Copy(wrapper_name);
} }
if (func_type) { if (func_type) {
String *s = NewStringf("(%s) %s", func_type, closure_name); String *s = NewStringf("(%s) %s", func_type, closure_name);
@ -3923,8 +3925,14 @@ public:
String *pmname = SwigType_manglestr(pname); String *pmname = SwigType_manglestr(pname);
String *templ = NewStringf("SwigPyBuiltin_%s", mname); String *templ = NewStringf("SwigPyBuiltin_%s", mname);
int funpack = modernargs && fastunpack; int funpack = modernargs && fastunpack;
static String *tp_new = NewString("PyType_GenericNew");
Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL); Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL);
// We can’t statically initialize a structure member with a function defined in another C module
// So this is done in the initialization function instead, see https://docs.python.org/2/extending/newtypes.html
Printf(f_init, " builtin_pytype->tp_new = %s;\n", getSlot(n, "feature:python:tp_new", tp_new));
Printv(f_init, " builtin_base_count = 0;\n", NIL); Printv(f_init, " builtin_base_count = 0;\n", NIL);
List *baselist = Getattr(n, "bases"); List *baselist = Getattr(n, "bases");
if (baselist) { if (baselist) {
@ -4062,7 +4070,6 @@ public:
static String *tp_basicsize = NewStringf("sizeof(SwigPyObject)"); static String *tp_basicsize = NewStringf("sizeof(SwigPyObject)");
static String *tp_dictoffset_default = NewString("offsetof(SwigPyObject, dict)"); static String *tp_dictoffset_default = NewString("offsetof(SwigPyObject, dict)");
static String *tp_new = NewString("PyType_GenericNew");
static String *tp_hash = NewString("SwigPyObject_hash"); static String *tp_hash = NewString("SwigPyObject_hash");
String *tp_as_number = NewStringf("&%s_type.as_number", templ); String *tp_as_number = NewStringf("&%s_type.as_number", templ);
String *tp_as_sequence = NewStringf("&%s_type.as_sequence", templ); String *tp_as_sequence = NewStringf("&%s_type.as_sequence", templ);
@ -4123,7 +4130,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_dictoffset", tp_dictoffset_default), "tp_dictoffset", "Py_ssize_t"); printSlot(f, getSlot(n, "feature:python:tp_dictoffset", tp_dictoffset_default), "tp_dictoffset", "Py_ssize_t");
printSlot(f, getSlot(n, "feature:python:tp_init", tp_init), "tp_init", "initproc"); printSlot(f, getSlot(n, "feature:python:tp_init", tp_init), "tp_init", "initproc");
printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc"); printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc");
printSlot(f, getSlot(n, "feature:python:tp_new", tp_new), "tp_new", "newfunc"); printSlot(f, getSlot(), "tp_new", "newfunc");
printSlot(f, getSlot(n, "feature:python:tp_free"), "tp_free", "freefunc"); printSlot(f, getSlot(n, "feature:python:tp_free"), "tp_free", "freefunc");
printSlot(f, getSlot(n, "feature:python:tp_is_gc"), "tp_is_gc", "inquiry"); printSlot(f, getSlot(n, "feature:python:tp_is_gc"), "tp_is_gc", "inquiry");
printSlot(f, getSlot(n, "feature:python:tp_bases"), "tp_bases", "PyObject *"); printSlot(f, getSlot(n, "feature:python:tp_bases"), "tp_bases", "PyObject *");

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -e # exit on failure set -e # exit on failure (same as -o errexit)
lsb_release -a lsb_release -a
sudo apt-get -qq update sudo apt-get -qq update
@ -51,7 +51,7 @@ case "$SWIGLANG" in
;; ;;
"lua") "lua")
if [[ -z "$VER" ]]; then if [[ -z "$VER" ]]; then
sudo apt-get -qq install lua5.1 liblua5.1-dev sudo apt-get -qq install lua5.2 liblua5.2-dev
else else
sudo add-apt-repository -y ppa:ubuntu-cloud-archive/mitaka-staging sudo add-apt-repository -y ppa:ubuntu-cloud-archive/mitaka-staging
sudo apt-get -qq update sudo apt-get -qq update
@ -72,16 +72,10 @@ case "$SWIGLANG" in
fi fi
;; ;;
"php") "php")
sudo apt-get install php5-cli php5-dev sudo apt-get -qq install php5-cli php5-dev
;; ;;
"python") "python")
git clone https://github.com/jcrocholl/pep8.git sudo apt-get -qq install pep8
(
cd pep8
git checkout tags/1.5.7
python ./setup.py build
sudo python ./setup.py install
)
if [[ "$PY3" ]]; then if [[ "$PY3" ]]; then
sudo apt-get install -qq python3-dev sudo apt-get install -qq python3-dev
fi fi
@ -105,6 +99,8 @@ case "$SWIGLANG" in
sudo apt-get -qq install scilab sudo apt-get -qq install scilab
;; ;;
"tcl") "tcl")
sudo apt-get -qq install tcl8.4-dev sudo apt-get -qq install tcl-dev
;; ;;
esac esac
set +e # turn off exit on failure (same as +o errexit)

View file

@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
set -e # exit on failure set -e # exit on failure (same as -o errexit)
sw_vers sw_vers
brew update brew update
brew list brew list
brew install pcre # brew install pcre # Travis Xcode-7.3 has pcre
# brew install boost # brew install boost
WITHLANG=$SWIGLANG WITHLANG=$SWIGLANG
case "$SWIGLANG" in case "$SWIGLANG" in
"csharp") "csharp")
brew install https://s3.amazonaws.com/travisbuilds.swig.org/mono.rb brew install mono
;; ;;
"guile") "guile")
Tools/brew-install guile Tools/brew-install guile
@ -28,3 +28,6 @@ case "$SWIGLANG" in
fi fi
;; ;;
esac esac
# Workaround for https://github.com/travis-ci/travis-ci/issues/6522
set +e # turn off exit on failure (same as +o errexit)

View file

@ -5,16 +5,16 @@ platform:
environment: environment:
matrix: matrix:
- SWIGLANG: csharp - SWIGLANG: csharp
VSVER: 14 VSVER: 12
- SWIGLANG: csharp - SWIGLANG: csharp
VSVER: 12 VSVER: 14
- SWIGLANG: java - SWIGLANG: java
VSVER: 12 VSVER: 14
- SWIGLANG: python - SWIGLANG: python
VSVER: 12 VSVER: 14
VER: 27 VER: 27
- SWIGLANG: python - SWIGLANG: python
VSVER: 12 VSVER: 14
VER: 35 VER: 35
PY3: 1 PY3: 1