Merge pull request #1 from swig/master

merge with master
This commit is contained in:
Frank Schlimbach 2016-10-05 09:17:55 +02:00 committed by GitHub
commit 1cf7a5e925
115 changed files with 1792 additions and 1251 deletions

View file

@ -162,9 +162,6 @@ matrix:
- compiler: clang
os: osx
env: SWIGLANG=go
- compiler: clang
os: osx
env: SWIGLANG=guile
- compiler: clang
os: osx
env: SWIGLANG=java
@ -199,6 +196,10 @@ matrix:
- compiler: gcc
os: linux
env: SWIGLANG=python SWIG_FEATURES=-O
# brew install guile fails on Travis as OSX 10.9 is too old now, default osx_image needs changing
- compiler: clang
os: osx
env: SWIGLANG=guile
before_install:
- date -u
- uname -a

View file

@ -5,6 +5,129 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.11 (in progress)
============================
2016-09-29: wsfulton
[Allegrocl, CFFI, GO, Javascript, Ocaml, R, Scilab]
Add missing support for the "ret" typemap in a few target languages.
The documentation also now has info on the "ret" typemap.
2016-09-27: ahmed-usman
[xml] Handle template parameters correctly.
2016-09-27: dontpanic92
[Go] Fix argument names in inherited functions taking more than 8
parameters. Fixes #795.
2016-09-26: smarchetto
[Scilab] mlists that map pointers can be given a custom type name.
2016-09-25: wsfulton
Patch #793 from q-p to expand exception handling to include std::bad_cast
in std_except.i.
2016-09-24: olly
[PHP] Fix code generated for feature("director:except") -
previously the return value of call_user_function() was ignored and
we checked an uninitialised value instead. Fixes #627. Based on
patch from Sergey Seroshtan.
2016-09-22: wsfulton
[Python] More flexible python builtin slots for overloaded C++ function.
The closure names used for builtin slots are mangled with their functype so
that overloaded C++ method names can be used for multiple slots.
For example:
%feature("python:slot", "mp_subscript", functype="binaryfunc") SimpleArray::__getitem__;
%feature("python:slot", "sq_item", functype="ssizeargfunc") SimpleArray::__getitem__(Py_ssize_t n);
will generate closures:
SWIGPY_SSIZEARGFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___ssizeargfunc_closure */
SWIGPY_BINARYFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___binaryfunc_closure */
Previously only one name was defined: _wrap_SimpleArray___getitem___closure.
Hence the overloaded __getitem__ method can be used to support both mp_subscript and sq_item slots.
2016-09-17: wsfulton
[Python] Fix iterators for containers of NULL pointers (or Python None) when using
-builtin. Previously iteration would stop at the first element that was NULL.
2016-09-16: olly
[Javascript] Fix SWIG_exception() macro to return from the current
function. Fixes #789, reported by Julien Dutriaux.
2016-09-16: olly
[PHP] Fix SWIG_exception() macro to return from the current function.
Fixes #240, reported by Sergey Seroshtan.
2016-09-12: xypron
[C#] Patch #786 Keyword rename to be CLS compliant by adding an underscore
suffix instead of an underscore suffix to the C symbol name. Please use an explicit
%rename to rename the symbol with a _ prefix if you want the old symbol name.
*** POTENTIAL INCOMPATIBILITY ***
2016-09-09: olly
[Python] Fix import handling for Python 2.6 to work in a frozen
application. Fixes #145, reported by Thomas Kluyver.
2016-09-02: smarchetto
[Scilab] Pointers are mapped to mlist instead of tlist
(mlist better for scilab overloading)
2016-09-02: olly
[PHP] Fix "out" typemap for member function pointers and "in"
typemap for char INPUT[ANY].
2016-09-01: wsfulton
[Python] More efficient Python slicing.
Call reserve for container types that support it to avoid repeated
memory reallocations for new slices or slices that grow in size.
2016-09-01: wsfulton
[Python] #771 - Make builtin types hashable by default.
Default hash is the underlying C/C++ pointer. This matches up with testing for
equivalence (Py_EQ in SwigPyObject_richcompare) which compares the pointers.
2016-08-22: wsfulton
[Python] The following builtin slots can be customized like other slots via the
"python:<x>" and "python:slot" features where <x> is the appropriate slot name:
tp_allocs
tp_bases
tp_basicsize
tp_cache
tp_del
tp_dealloc
tp_flags
tp_frees
tp_getset
tp_is_gc
tp_maxalloc
tp_methods
tp_mro
tp_new
tp_next
tp_prev
tp_richcompare
tp_subclasses
tp_weaklist
was_sq_ass_slice
was_sq_slice
A few documentation improvements for slot customization.
2016-08-09: joequant
[R] Patch #765 Fix extern "C" header includes for C++ code.
2016-08-05: olly
[xml] Fix how the output filename is built to avoid problems when
it contains the embedded strings ".c", ".cpp" or ".cxx".
Fixes #540 reported by djack42.
2016-07-01: wsfulton
Fix corner case of wrapping std::vector of T pointers where a pointer to a pointer of T
also exists in the wrapped code. SF Bug 2359417 (967).
2016-06-26: wkalinin
[Java, C#] Patch #681 Fix seg fault when ignoring nested classes.

View file

@ -52,7 +52,7 @@
<li><a href="#CPlusPlus11_general_purpose_smart_pointers">General-purpose smart pointers</a>
<li><a href="#CPlusPlus11_extensible_random_number_facility">Extensible random number facility</a>
<li><a href="#CPlusPlus11_wrapper_reference">Wrapper reference</a>
<li><a href="#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphous wrappers for function objects</a>
<li><a href="#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphic wrappers for function objects</a>
<li><a href="#CPlusPlus11_type_traits_for_metaprogramming">Type traits for metaprogramming</a>
<li><a href="#CPlusPlus11_uniform_method_for_computing_return_type_of_function_objects">Uniform method for computing return type of function objects</a>
</ul>
@ -1029,7 +1029,7 @@ Users would need to write their own typemaps if wrapper references are being use
</p>
<H3><a name="CPlusPlus11_polymorphous_wrappers_for_function_objects">7.3.8 Polymorphous wrappers for function objects</a></H3>
<H3><a name="CPlusPlus11_polymorphous_wrappers_for_function_objects">7.3.8 Polymorphic wrappers for function objects</a></H3>
<p>

View file

@ -310,7 +310,7 @@
<li><a href="CPlusPlus11.html#CPlusPlus11_general_purpose_smart_pointers">General-purpose smart pointers</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_extensible_random_number_facility">Extensible random number facility</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_wrapper_reference">Wrapper reference</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphous wrappers for function objects</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphic wrappers for function objects</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_type_traits_for_metaprogramming">Type traits for metaprogramming</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_uniform_method_for_computing_return_type_of_function_objects">Uniform method for computing return type of function objects</a>
</ul>
@ -457,6 +457,7 @@
<li><a href="Typemaps.html#Typemaps_nn32">"argout" typemap</a>
<li><a href="Typemaps.html#Typemaps_nn33">"freearg" typemap</a>
<li><a href="Typemaps.html#Typemaps_nn34">"newfree" typemap</a>
<li><a href="Typemaps.html#Typemaps_ret">"ret" typemap</a>
<li><a href="Typemaps.html#Typemaps_nn35">"memberin" typemap</a>
<li><a href="Typemaps.html#Typemaps_nn36">"varin" typemap</a>
<li><a href="Typemaps.html#Typemaps_nn37">"varout" typemap</a>
@ -1529,7 +1530,7 @@
<li><a href="Python.html#Python_builtin_types">Built-in Types</a>
<ul>
<li><a href="Python.html#Python_builtin_limitations">Limitations</a>
<li><a href="Python.html#Python_builtin_overloads">Operator overloads -- use them!</a>
<li><a href="Python.html#Python_builtin_overloads">Operator overloads and slots -- use them!</a>
</ul>
<li><a href="Python.html#Python_nn30">Memory management</a>
<li><a href="Python.html#Python_nn31">Python 2.2 and classic classes</a>

View file

@ -2534,7 +2534,7 @@ also return a pointer to the base class (<tt>Language</tt>) so that only the int
</p>
<p>
Save the code for your language module in a file named "<tt>python.cxx</tt>" and.
Save the code for your language module in a file named "<tt>python.cxx</tt>" and
place this file in the <tt>Source/Modules</tt> directory of the SWIG distribution.
To ensure that your module is compiled into SWIG along with the other language modules,
modify the file <tt>Source/Modules/Makefile.am</tt> to include the additional source

View file

@ -3359,20 +3359,20 @@ There is more than one macro in order to provide a choice for choosing the Java
</tr>
<tr>
<td><tt>%interface(CTYPE)</tt></td>
<td>Proxy class name is unchanged, interface name has <tt>SwigInterface</tt> added as a suffix for C++ class <tt>CTYPE</tt>.</td>
<td>For C++ class <tt>CTYPE</tt>, proxy class name is unchanged without any suffix added, interface name has <tt>SwigInterface</tt> added as a suffix.</td>
</tr>
<tr>
<td><tt>%interface_impl(CTYPE)</tt></td>
<td>Proxy class name has <tt>SwigImpl</tt> as a suffix, interface name has <tt>SwigInterface</tt> added as a suffix for C++ class <tt>CTYPE</tt>.</td>
<td>For C++ class <tt>CTYPE</tt>, proxy class name has <tt>SwigImpl</tt> added as a suffix, interface name has no added suffix.</td>
</tr>
<tr>
<td><tt>%interface_custom("PROXY", "INTERFACE", CTYPE)</tt></td>
<td>Proxy class name is given by the string <tt>PROXY</tt>, interface name is given by the string <tt>INTERFACE</tt> for C++ class <tt>CTYPE</tt>. The <tt>PROXY</tt> and <tt>INTERFACE</tt> names can use the <a href="SWIG.html#SWIG_advanced_renaming">string formatting functions</a> used in <tt>%rename</tt>.</td>
<td>For C++ class <tt>CTYPE</tt>, proxy class name is given by the string <tt>PROXY</tt>, interface name is given by the string <tt>INTERFACE</tt>. The <tt>PROXY</tt> and <tt>INTERFACE</tt> names can use the <a href="SWIG.html#SWIG_advanced_renaming">string formatting functions</a> used in <tt>%rename</tt>.</td>
</tr>
</table>
<p>
The table below has a few examples showing the resulting proxy and interface names.
The table below has a few examples showing the resulting proxy and interface names for a C++ class called <tt>Base</tt>.
</p>
<table BORDER summary="Java interface macro examples">

View file

@ -51,7 +51,7 @@
<li><a href="#Python_builtin_types">Built-in Types</a>
<ul>
<li><a href="#Python_builtin_limitations">Limitations</a>
<li><a href="#Python_builtin_overloads">Operator overloads -- use them!</a>
<li><a href="#Python_builtin_overloads">Operator overloads and slots -- use them!</a>
</ul>
<li><a href="#Python_nn30">Memory management</a>
<li><a href="#Python_nn31">Python 2.2 and classic classes</a>
@ -2442,7 +2442,7 @@ assert(issubclass(B.Derived, A.Base))
</li>
</ul>
<H4><a name="Python_builtin_overloads">36.4.2.2 Operator overloads -- use them!</a></H4>
<H4><a name="Python_builtin_overloads">36.4.2.2 Operator overloads and slots -- use them!</a></H4>
<p>The entire justification for the <tt>-builtin</tt> option is improved
@ -2494,52 +2494,110 @@ automatically converted to python slot operators, refer to the file
<tt>python/pyopers.swig</tt> in the SWIG library.
</p>
<p>There are other very useful python slots that you
may explicitly define using <tt>%feature</tt> directives. For example,
suppose you want to use instances of a wrapped class as keys in a native python
<tt>dict</tt>. That will work as long as you define a hash function for
instances of your class, and use it to define the python <tt>tp_hash</tt>
slot:
<p>
Read about all of the available python slots here:
<a href="http://docs.python.org/c-api/typeobj.html">http://docs.python.org/c-api/typeobj.html</a></p>
<p>
There are two ways to define a python slot function: dispatch to a
statically defined function; or dispatch to a method defined on the
operand.
</p>
<p>
To dispatch to a statically defined function, use %feature("python:&lt;slot&gt;"),
where &lt;slot&gt; is the name of a field in a <tt>PyTypeObject, PyNumberMethods,
PyMappingMethods, PySequenceMethods</tt> or <tt>PyBufferProcs</tt>.
You may override (almost) all of these slots.
</p>
<p>
Let's consider an example setting the <tt>tp_hash</tt> slot for the <tt>MyClass</tt> type.
This is akin to providing a <tt>__hash__</tt> method (for non-builtin types) to make a type hashable.
The hashable type can then for example be added to a Python <tt>dict</tt>.
</p>
<div class="code">
<pre>
%feature("python:slot", "tp_hash", functype="hashfunc") Cheese::cheeseHashFunc;
%feature("python:tp_hash") MyClass "myHashFunc";
class Cheese {
class MyClass {
public:
Cheese (const char *name);
long cheeseHashFunc () const;
long field1;
long field2;
...
};
%{
#if PY_VERSION_HEX &gt;= 0x03020000
static Py_hash_t myHashFunc(PyObject *pyobj)
#else
static long myHashFunc(PyObject *pyobj)
#endif
{
MyClass *cobj;
// Convert pyobj to cobj
return (cobj-&gt;field1 * (cobj-&gt;field2 &lt;&lt; 7));
}
%}
</pre>
</div>
<p>
If you examine the generated code, the supplied hash function will now be
the function callback in the tp_hash slot for the builtin type for <tt>MyClass</tt>:
</p>
<div class="code">
<pre>
static PyHeapTypeObject SwigPyBuiltin__MyClass_type = {
...
(hashfunc) myHashFunc, /* tp_hash */
...
</pre>
</div>
<p>
NOTE: It is the responsibility of the programmer (that's you!) to ensure
that a statically defined slot function has the correct signature, the <tt>hashfunc</tt>
typedef in this case.
</p>
<p>
If, instead, you want to dispatch to an instance method, you can
use %feature("python:slot"). For example:
</p>
<div class="code">
<pre>
%feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc;
#if PY_VERSION_HEX &lt; 0x03020000
#define Py_hash_t long
#endif
class MyClass {
public:
Py_hash_t myHashFunc() const;
...
};
</pre>
</div>
<p>This will allow you to write python code like this:</p>
<p>
NOTE: Some python slots use a method signature which does not
match the signature of SWIG-wrapped methods. For those slots,
SWIG will automatically generate a "closure" function to re-marshal
the arguments before dispatching to the wrapped method. Setting
the "functype" attribute of the feature enables SWIG to generate
the chosen closure function.
</p>
<div class="targetlang">
<pre>
from my MyPackage import Cheese
inventory = {
Cheese("cheddar") : 0,
Cheese("gouda") : 0,
Cheese("camembert") : 0
}
</pre>
</div>
<p>Because you defined the <tt>tp_hash</tt> slot, <tt>Cheese</tt> objects may
be used as hash keys; and when the <tt>cheeseHashFunc</tt> method is invoked
by a python <tt>dict</tt>, it will <b>not</b> go through named method dispatch.
A more detailed discussion about <tt>%feature("python:slot")</tt> can be found
<p>
There is further information on <tt>%feature("python:slot")</tt>
in the file <tt>python/pyopers.swig</tt> in the SWIG library.
You can read about all of the available python slots here:</p>
<p><a href="http://docs.python.org/c-api/typeobj.html">http://docs.python.org/c-api/typeobj.html</a></p>
<p>You may override (almost) all of the slots defined in the <tt>PyTypeObject,
PyNumberMethods, PyMappingMethods, PySequenceMethods</tt>, and <tt>PyBufferProcs</tt>
structs.
</p>

View file

@ -1123,7 +1123,7 @@ But we can use either use the <tt>get_perimeter()</tt> function of the parent cl
<p>
As explained in <a href="http://www.swig.org/Doc3.0/SWIGPlus.html#SWIGPlus_overloaded_methods">6.15</a> SWIG provides support for overloaded functions and constructors.
As explained in <a href="SWIGPlus.html#SWIGPlus_overloaded_methods">6.15</a> SWIG provides support for overloaded functions and constructors.
</p>
<p>As SWIG knows pointer types, the overloading works also with pointer types, here is is an example with a function <tt>magnify</tt> overloaded for the previous classes <tt>Shape</tt> and <tt>Circle</tt>:

View file

@ -63,6 +63,7 @@
<li><a href="#Typemaps_nn32">"argout" typemap</a>
<li><a href="#Typemaps_nn33">"freearg" typemap</a>
<li><a href="#Typemaps_nn34">"newfree" typemap</a>
<li><a href="#Typemaps_ret">"ret" typemap</a>
<li><a href="#Typemaps_nn35">"memberin" typemap</a>
<li><a href="#Typemaps_nn36">"varin" typemap</a>
<li><a href="#Typemaps_nn37">"varout" typemap</a>
@ -2802,7 +2803,46 @@ string *foo();
See <a href="Customization.html#Customization_ownership">Object ownership and %newobject</a> for further details.
</p>
<H3><a name="Typemaps_nn35">11.5.10 "memberin" typemap</a></H3>
<H3><a name="Typemaps_ret">11.5.10 "ret" typemap</a></H3>
<p>
The "ret" typemap is not used very often, but can be useful for anything associated with
the return type, such as resource management, return value error checking, etc.
Usually this can all be done in the "out" typemap, but sometimes it is handy to use the
"out" typemap code untouched and add to the generated code using the code in the "ret" typemap.
One such case is memory clean up. For example, a <tt>stringheap_t</tt> type is defined indicating
that the returned memory must be deleted and a <tt>string_t</tt> type is defined indicating
that the returned memory must not be deleted.
</p>
<div class="code">
<pre>
%typemap(ret) stringheap_t %{
free($1);
%}
typedef char * string_t;
typedef char * stringheap_t;
string_t MakeString1();
stringheap_t MakeString2();
</pre>
</div>
<p>
The "ret" typemap above will only be used for <tt>MakeString2</tt>, but both functions
will use the default "out" typemap for <tt>char *</tt> provided by SWIG.
The code above would ensure the appropriate memory is freed in all target languages as the need
to provide custom "out" typemaps (which involve target language specific code) is not necessary.
</p>
<p>
This approach is an alternative to using the "newfree" typemap and <tt>%newobject</tt> as there
is no need to list all the functions that require the memory cleanup, it is purely done on types.
</p>
<H3><a name="Typemaps_nn35">11.5.11 "memberin" typemap</a></H3>
<p>
@ -2824,7 +2864,7 @@ It is rarely necessary to write "memberin" typemaps---SWIG already provides
a default implementation for arrays, strings, and other objects.
</p>
<H3><a name="Typemaps_nn36">11.5.11 "varin" typemap</a></H3>
<H3><a name="Typemaps_nn36">11.5.12 "varin" typemap</a></H3>
<p>
@ -2832,7 +2872,7 @@ The "varin" typemap is used to convert objects in the target language to C for t
purposes of assigning to a C/C++ global variable. This is implementation specific.
</p>
<H3><a name="Typemaps_nn37">11.5.12 "varout" typemap</a></H3>
<H3><a name="Typemaps_nn37">11.5.13 "varout" typemap</a></H3>
<p>
@ -2840,7 +2880,7 @@ The "varout" typemap is used to convert a C/C++ object to an object in the targe
language when reading a C/C++ global variable. This is implementation specific.
</p>
<H3><a name="throws_typemap">11.5.13 "throws" typemap</a></H3>
<H3><a name="throws_typemap">11.5.14 "throws" typemap</a></H3>
<p>

View file

@ -87,7 +87,6 @@ CPP_TEST_BROKEN += \
director_nested_class \
exception_partial_info \
extend_variable \
li_std_vector_ptr \
li_boost_shared_ptr_template \
nested_private \
overload_complicated \
@ -390,6 +389,7 @@ CPP_TEST_CASES += \
string_constants \
struct_initialization_cpp \
struct_value \
swig_exception \
symbol_clash \
template_arg_replace \
template_arg_scope \
@ -520,6 +520,7 @@ CPP_TEST_CASES += \
valuewrapper_opaque \
varargs \
varargs_overload \
variable_replacement \
virtual_destructor \
virtual_poly \
virtual_vs_nonvirtual_base \
@ -588,6 +589,7 @@ CPP_STD_TEST_CASES += \
li_std_vector \
li_std_vector_enum \
li_std_vector_member_var\
li_std_vector_ptr \
smart_pointer_inherit \
template_typedef_fnc \
template_type_namespace \

View file

@ -6,6 +6,12 @@ The primary purpose of this testcase is to ensure that enums used along with the
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for anonymous enums */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
enum SOME_ENUM {ENUM_ONE, ENUM_TWO};
struct StructWithEnums {

View file

@ -7,6 +7,7 @@ public class li_std_except_runme {
public static void Main() {
Test test = new Test();
try { test.throw_bad_cast(); throw new Exception("throw_bad_cast failed"); } catch (InvalidCastException) {}
try { test.throw_bad_exception(); throw new Exception("throw_bad_exception failed"); } catch (ApplicationException) {}
try { test.throw_domain_error(); throw new Exception("throw_domain_error failed"); } catch (ApplicationException) {}
try { test.throw_exception(); throw new Exception("throw_exception failed"); } catch (ApplicationException) {}

View file

@ -28,6 +28,21 @@ class DirectorMethodException: public Swig::DirectorException {};
%include "std_string.i"
#ifdef SWIGPHP
%feature("director:except") {
if ($error == FAILURE) {
throw Swig::DirectorMethodException();
}
}
%exception {
try { $action }
catch (Swig::DirectorException &) { SWIG_fail; }
}
#endif
#ifdef SWIGPYTHON
%feature("director:except") {

View file

@ -47,6 +47,12 @@
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for anonymous enums */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
enum { AnonEnum1, AnonEnum2 = 100 };
enum { ReallyAnInteger = 200 };
//enum { AnonEnum3, AnonEnum4 } instance;

View file

@ -12,6 +12,12 @@
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for anonymous enums */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
typedef enum {
CSP_ITERATION_FWD,
CSP_ITERATION_BWD = 11

View file

@ -1,12 +1,19 @@
package main
import . "./li_std_vector_ptr"
import "fmt"
func check(val1 int, val2 int) {
if val1 != val2 {
panic(fmt.Sprintf("Values are not the same %d %d", val1, val2))
}
}
func main() {
ip1 := MakeIntPtr(11)
ip2 := MakeIntPtr(22)
vi := NewIntPtrVector()
vi.Add(ip1)
vi.Add(ip2)
DisplayVector(vi)
check(GetValueFromVector(vi, 0), 11)
check(GetValueFromVector(vi, 1), 22)
}

View file

@ -0,0 +1,30 @@
var swig_exception = require("swig_exception");
var c = new swig_exception.Circle(10);
var s = new swig_exception.Square(10);
if (swig_exception.Shape.nshapes != 2) {
throw "Shape.nshapes should be 2, actually " + swig_exception.Shape.nshapes;
}
// ----- Throw exception -----
try {
c.throwException();
throw "Exception wasn't thrown";
} catch (e) {
if (e.message != "OK") {
throw "Exception message should be \"OK\", actually \"" + e.message + "\"";
}
}
// ----- Delete everything -----
c = null;
s = null;
e = null;
/* FIXME: Garbage collection needs to happen before this check will work.
if (swig_exception.Shape.nshapes != 0) {
throw "Shape.nshapes should be 0, actually " + swig_exception.Shape.nshapes;
}
*/

View file

@ -24,6 +24,7 @@
int foo3() throw(E1) { return 0; }
int foo4() throw(E2) { return 0; }
// all the STL exceptions...
void throw_bad_cast() throw(std::bad_cast) { throw std::bad_cast(); }
void throw_bad_exception() throw(std::bad_exception) { throw std::bad_exception(); }
void throw_domain_error() throw(std::domain_error) { throw std::domain_error("oops"); }
void throw_exception() throw(std::exception) { throw std::exception(); }

View file

@ -1,4 +1,4 @@
// Bug 2359417
// SF Bug 2359417
%module li_std_vector_ptr
%include "std_vector.i"
@ -15,16 +15,76 @@ double* makeDoublePtr(double v) {
return new double(v);
}
#if 1
// pointer to pointer in the wrappers was preventing a vector of pointers from working
int** makeIntPtrPtr(int* v) {
return new int*(v);
}
#endif
void displayVector(std::vector<int *> vpi) {
cout << "displayVector..." << endl;
for (int i=0; i<vpi.size(); ++i)
for (size_t i=0; i<vpi.size(); ++i)
cout << *vpi[i] << endl;
}
int getValueFromVector(std::vector<int *> vpi, size_t index) {
return *vpi[index];
}
%}
// A not exposed to wrappers
%{
struct A {
int val;
A(int val) : val(val) {}
};
%}
%template(APtrVector) std::vector<A *>;
%inline %{
A *makeA(int val) { return new A(val); }
int getVal(A* a) { return a->val; }
int getVectorValueA(std::vector<A *> vpi, size_t index) {
return vpi[index]->val;
}
%}
// B is fully exposed to wrappers
%inline %{
struct B {
int val;
B(int val = 0) : val(val) {}
};
%}
%template(BPtrVector) std::vector<B *>;
%inline %{
B *makeB(int val) { return new B(val); }
int getVal(B* b) { return b->val; }
int getVectorValueB(std::vector<B *> vpi, size_t index) {
return vpi[index]->val;
}
%}
// C is fully exposed to wrappers (includes code using B **)
%inline %{
struct C {
int val;
C(int val = 0) : val(val) {}
};
%}
%template(CPtrVector) std::vector<C *>;
%inline %{
// pointer to pointer in the wrappers was preventing a vector of pointers from working
C** makeCIntPtrPtr(C* v) {
return new C*(v);
}
C *makeC(int val) { return new C(val); }
int getVal(C* b) { return b->val; }
int getVectorValueC(std::vector<C *> vpi, size_t index) {
return vpi[index]->val;
}
%}

View file

@ -13,6 +13,18 @@ Also tests reported error when a #define placed in a deeply embedded struct/unio
%rename(InUnNamed) OuterStructNamed::Inner_union_named;
#endif
#if defined(SWIG_JAVASCRIPT_V8)
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for nested C class wrappers compiled as C++ code */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
%}
#endif
%inline %{
struct TestStruct {

View file

@ -1,5 +1,17 @@
%module nested_extend_c
#if defined(SWIG_JAVASCRIPT_V8)
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for nested C class wrappers compiled as C++ code */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
%}
#endif
#if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8)
%extend hiA {
hiA() {

View file

@ -1,5 +1,17 @@
%module nested_structs
#if defined(SWIG_JAVASCRIPT_V8)
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for nested C class wrappers compiled as C++ code */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
%}
#endif
// bug #491476
%inline %{
struct Outer {

View file

@ -0,0 +1,20 @@
<?php
require "tests.php";
require "cpp_basic.php";
// New functions
check::functions(array(foo_func1,foo_func2,foo___str__,foosubsub___str__,bar_test,bar_testfoo,get_func1_ptr,get_func2_ptr,test_func_ptr,fl_window_show));
// New classes
check::classes(array(cpp_basic,Foo,FooSub,FooSubSub,Bar,Fl_Window));
// New vars
check::globals(array(foo_num,foo_func_ptr,bar_fptr,bar_fref,bar_fval,bar_cint,bar_global_fptr,bar_global_fref,bar_global_fval));
$f = new Foo(3);
$f->func_ptr = get_func1_ptr();
check::equal(test_func_ptr($f, 7), 2*7*3, "get_func1_ptr() didn't work");
$f->func_ptr = get_func2_ptr();
check::equal(test_func_ptr($f, 7), -7*3, "get_func2_ptr() didn't work");
check::done();
?>

View file

@ -0,0 +1,33 @@
<?php
require("swig_exception.php");
require("tests.php");
$c = new Circle(10);
$s = new Square(10);
if (Shape::nshapes() != 2) {
check::fail("Shape::nshapes() should be 2, actually ".Shape::nshapes());
}
# ----- Throw exception -----
try {
$c->throwException();
check::fail("Exception wasn't thrown");
} catch (Exception $e) {
if ($e->getMessage() != "OK") {
check::fail("Exception getMessage() should be \"OK\", actually \"".$e->getMessage()."\"");
}
}
# ----- Delete everything -----
$c = NULL;
$s = NULL;
$e = NULL;
if (Shape::nshapes() != 0) {
check::fail("Shape::nshapes() should be 0, actually ".Shape::nshapes());
}
?>

View file

@ -35,8 +35,9 @@ class check {
foreach($_original_functions[internal] as $func) unset($df[$func]);
// Now chop out any get/set accessors
foreach(array_keys($df) as $func)
if ((GETSET && ereg('_[gs]et$',$func)) || ereg('^new_', $func)
|| ereg('_(alter|get)_newobject$', $func))
if ((GETSET && preg_match('/_[gs]et$/', $func)) ||
preg_match('/^new_/', $func) ||
preg_match('/_(alter|get)_newobject$/', $func))
$extrags[]=$func;
else $extra[]=$func;
// $extra=array_keys($df);
@ -52,7 +53,8 @@ class check {
if (GETSET) {
$_extra=array();
foreach(check::get_extra_functions(false,1) as $global) {
if (ereg('^(.*)_[sg]et$',$global,$match)) $_extra[$match[1]]=1;
if (preg_match('/^(.*)_[sg]et$/', $global, $match))
$_extra[$match[1]] = 1;
}
$extra=array_keys($_extra);
} else {
@ -61,7 +63,8 @@ class check {
$df=array_flip(array_keys($GLOBALS));
foreach($_original_globals as $func) unset($df[$func]);
// MASK xxxx_LOADED__ variables
foreach(array_keys($df) as $func) if (ereg('_LOADED__$',$func)) unset($df[$func]);
foreach(array_keys($df) as $func)
if (preg_match('/_LOADED__$/', $func)) unset($df[$func]);
$extra=array_keys($df);
}
}
@ -185,7 +188,8 @@ class check {
}
function functionref($a,$type,$message) {
if (! eregi("^_[a-f0-9]+$type$",$a)) return check::fail($message);
if (! preg_match("/^_[a-f0-9]+$type$/i", $a))
return check::fail($message);
return TRUE;
}
@ -196,7 +200,8 @@ class check {
function resource($a,$b,$message) {
$resource=trim(check::var_dump($a));
if (! eregi("^resource\([0-9]+\) of type \($b\)",$resource)) return check::fail($message);
if (! preg_match("/^resource\([0-9]+\) of type \($b\)/i", $resource))
return check::fail($message);
return TRUE;
}

View file

@ -58,6 +58,7 @@ CPP_TEST_CASES += \
primitive_types \
python_abstractbase \
python_append \
python_builtin \
python_destructor_exception \
python_director \
python_docstring \

View file

@ -1,7 +1,56 @@
from li_std_vector_ptr import *
def check(val1, val2):
if val1 != val2:
raise RuntimeError("Values are not the same %s %s" % (val1, val2))
ip1 = makeIntPtr(11)
ip2 = makeIntPtr(22)
vi = IntPtrVector((ip1, ip2))
displayVector(vi)
check(getValueFromVector(vi, 0), 11)
check(getValueFromVector(vi, 1), 22)
vA = APtrVector([makeA(33), makeA(34)])
check(getVectorValueA(vA, 0), 33)
vB = BPtrVector([makeB(133), makeB(134)])
check(getVectorValueB(vB, 0), 133)
vC = CPtrVector([makeC(1133), makeC(1134)])
check(getVectorValueC(vC, 0), 1133)
vA = [makeA(233), makeA(234)]
check(getVectorValueA(vA, 0), 233)
vB = [makeB(333), makeB(334)]
check(getVectorValueB(vB, 0), 333)
vC = [makeC(3333), makeC(3334)]
check(getVectorValueC(vC, 0), 3333)
# mixed A and B should not be accepted
vAB = [makeA(999), makeB(999)]
try:
check(getVectorValueA(vAB, 0), 999)
raise RuntimeError("missed exception")
except TypeError:
pass
b111 = makeB(111)
bNones = BPtrVector([None, b111, None])
bCount = 0
noneCount = 0
for b in bNones:
if b == None:
noneCount = noneCount + 1
else:
if b.val != 111:
raise RuntimeError("b.val is wrong")
bCount = bCount + 1
if bCount != 1:
raise RuntimeError("bCount wrong")
if noneCount != 2:
raise RuntimeError("noneCount wrong")

View file

@ -2,3 +2,9 @@ from li_std_vector import *
if typedef_test(101) != 101:
raise RuntimeError
try:
sv = StructVector([None, None])
raise RuntimeError("Using None should result in a TypeError")
except TypeError:
pass

View file

@ -0,0 +1,94 @@
from python_builtin import *
if is_python_builtin():
# Test 0 for default tp_hash
vs = ValueStruct(1234)
h = hash(vs)
d = dict()
d[h] = "hi"
if h not in d:
raise RuntimeError("h should be in d")
h2 = hash(ValueStruct.inout(vs))
if h != h2:
raise RuntimeError("default tp_hash not working")
# Test 1 for tp_hash
if hash(SimpleValue(222)) != 222:
raise RuntimeError("tp_hash not working")
# Test 2 for tp_hash
try:
# Was incorrectly raising: SystemError: error return without exception set
h = hash(BadHashFunctionReturnType())
raise RuntimeError("Missing TypeError")
except TypeError:
pass
# Test 3 for tp_hash
passed = False
try:
h = hash(ExceptionHashFunction())
except RuntimeError, e:
passed = str(e).find("oops") != -1
pass
if not passed:
raise RuntimeError("did not catch exception in hash()")
# Test 4 for tp_dealloc (which is handled differently to other slots in the SWIG source)
d = Dealloc1()
if cvar.Dealloc1CalledCount != 0:
raise RuntimeError("count should be 0")
del d
if cvar.Dealloc1CalledCount != 1:
raise RuntimeError("count should be 1")
d = Dealloc2()
if cvar.Dealloc2CalledCount != 0:
raise RuntimeError("count should be 0")
del d
if cvar.Dealloc2CalledCount != 1:
raise RuntimeError("count should be 1")
d = Dealloc3()
if cvar.Dealloc3CalledCount != 0:
raise RuntimeError("count should be 0")
del d
if cvar.Dealloc3CalledCount != 1:
raise RuntimeError("count should be 1")
# Test 5 for python:compare feature
m10 = MyClass(10)
m20 = MyClass(20)
m15 = MyClass(15)
if not m10 < m15:
raise RuntimeError("m10 < m15")
if not m10 < m20:
raise RuntimeError("m10 < m20")
if not m15 < m20:
raise RuntimeError("m15 < m20")
if m10 > m15:
raise RuntimeError("m10 > m15")
if m10 > m20:
raise RuntimeError("m10 > m20")
if m15 > m20:
raise RuntimeError("m15 > m20")
if MyClass.less_than_counts != 6:
raise RuntimeError("python:compare feature not working")
sa = SimpleArray(5)
elements = [x for x in sa]
if elements != [0, 10, 20, 30, 40]:
raise RuntimeError("Iteration not working")
if len(sa) != 5:
raise RuntimeError("len not working")
for i in range(5):
if sa[i] != i*10:
raise RuntimeError("indexing not working")
subslice = sa[1:3]
elements = [x for x in subslice]
if elements != [10, 20]:
raise RuntimeError("slice not working")

View file

@ -0,0 +1,201 @@
// Test customizing slots when using the -builtin option
%module python_builtin
%inline %{
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else
bool is_python_builtin() { return false; }
#endif
%}
// Test 0 for default tp_hash
%inline %{
struct ValueStruct {
int value;
ValueStruct(int value) : value(value) {}
static ValueStruct *inout(ValueStruct *v) {
return v;
}
};
%}
// Test 1 for tp_hash
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:tp_hash") SimpleValue "SimpleValueHashFunction"
#endif
%inline %{
struct SimpleValue {
int value;
SimpleValue(int value) : value(value) {}
};
%}
%{
#if PY_VERSION_HEX >= 0x03020000
Py_hash_t SimpleValueHashFunction(PyObject *v)
#else
long SimpleValueHashFunction(PyObject *v)
#endif
{
SwigPyObject *sobj = (SwigPyObject *) v;
SimpleValue *p = (SimpleValue *)sobj->ptr;
return p->value;
}
hashfunc test_hashfunc_cast() {
return SimpleValueHashFunction;
}
%}
// Test 2 for tp_hash
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_hash", functype="hashfunc") BadHashFunctionReturnType::bad_hash_function;
#endif
%inline %{
struct BadHashFunctionReturnType {
static const char * bad_hash_function() {
return "bad hash function";
}
};
%}
// Test 3 for tp_hash
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_hash", functype="hashfunc") ExceptionHashFunction::exception_hash_function;
#endif
%catches(const char *) exception_hash_function;
%inline %{
#if PY_VERSION_HEX < 0x03020000
#define Py_hash_t long
#endif
struct ExceptionHashFunction {
static Py_hash_t exception_hash_function() {
throw "oops";
}
};
%}
// Test 4 for tp_dealloc (which is handled differently to other slots in the SWIG source)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:tp_dealloc") Dealloc1 "Dealloc1Destroyer"
%feature("python:tp_dealloc") Dealloc2 "Dealloc2Destroyer"
%feature("python:slot", "tp_dealloc", functype="destructor") Dealloc3::Destroyer;
#endif
%inline %{
static int Dealloc1CalledCount = 0;
static int Dealloc2CalledCount = 0;
static int Dealloc3CalledCount = 0;
struct Dealloc1 {
};
struct Dealloc2 {
~Dealloc2() {}
};
struct Dealloc3 {
void Destroyer() {
Dealloc3CalledCount++;
delete this;
}
};
%}
%{
void Dealloc1Destroyer(PyObject *v) {
SwigPyObject *sobj = (SwigPyObject *) v;
Dealloc1 *p = (Dealloc1 *)sobj->ptr;
delete p;
Dealloc1CalledCount++;
}
void Dealloc2Destroyer(PyObject *v) {
SwigPyObject *sobj = (SwigPyObject *) v;
Dealloc2 *p = (Dealloc2 *)sobj->ptr;
delete p;
Dealloc2CalledCount++;
}
%}
// Test 5 for python:compare feature
%feature("python:compare", "Py_LT") MyClass::lessThan;
%inline %{
class MyClass {
public:
MyClass(int val = 0) : val(val) {}
bool lessThan(const MyClass& other) const {
less_than_counts++;
return val < other.val;
}
int val;
static int less_than_counts;
};
int MyClass::less_than_counts = 0;
%}
// Test 6 add in container __getitem__ to support basic sequence protocol
// Tests overloaded functions being used for more than one slot (mp_subscript and sq_item)
%include <exception.i>
%include <std_except.i>
%apply int {Py_ssize_t}
%typemap(in) PySliceObject * {
if (!PySlice_Check($input))
SWIG_exception(SWIG_TypeError, "in method '$symname', argument $argnum of type '$type'");
$1 = (PySliceObject *)$input;
}
%typemap(typecheck,precedence=300) PySliceObject* {
$1 = PySlice_Check($input);
}
%feature("python:slot", "mp_subscript", functype="binaryfunc") SimpleArray::__getitem__(PySliceObject *slice);
%feature("python:slot", "sq_item", functype="ssizeargfunc") SimpleArray::__getitem__(Py_ssize_t n);
%feature("python:slot", "sq_length", functype="lenfunc") SimpleArray::__len__;
%inline %{
class SimpleArray {
size_t size;
int numbers[5];
public:
SimpleArray(size_t size) : size(size) {
for (size_t x = 0; x<size; ++x)
numbers[x] = x*10;
}
Py_ssize_t __len__() {
return size;
}
int __getitem__(Py_ssize_t n) throw (std::out_of_range) {
if (n >= (int)size)
throw std::out_of_range("Index too large");
return numbers[n];
}
SimpleArray __getitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
if (!PySlice_Check(slice))
throw std::invalid_argument("Slice object expected");
Py_ssize_t i, j, step;
#if PY_VERSION_HEX >= 0x03020000
PySlice_GetIndices((PyObject *)slice, size, &i, &j, &step);
#else
PySlice_GetIndices((PySliceObject *)slice, size, &i, &j, &step);
#endif
if (step != 1)
throw std::invalid_argument("Only a step size of 1 is implemented");
{
Py_ssize_t ii = i<0 ? 0 : i>=size ? size-1 : i;
Py_ssize_t jj = j<0 ? 0 : j>=size ? size-1 : j;
if (ii > jj)
throw std::invalid_argument("getitem i should not be larger than j");
SimpleArray n(jj-ii);
for (size_t x = 0; x<size; ++x)
n.numbers[x] = numbers[x+ii];
return n;
}
}
};
%}

View file

@ -13,7 +13,6 @@ top_builddir = ../@top_builddir@
C_TEST_CASES += \
scilab_consts \
scilab_enums \
scilab_identifier_name \
CPP_TEST_CASES += \
@ -21,6 +20,7 @@ CPP_TEST_CASES += \
primitive_types \
scilab_li_matrix \
scilab_multivalue \
scilab_enums \
scilab_pointer_conversion_functions \
CPP_STD_TEST_CASES += \

View file

@ -24,4 +24,13 @@ checkEnum(TYPEDEF_ENUM_1_2, 22);
checkEnum(TYPEDEF_ENUM_2_1, 31);
checkEnum(TYPEDEF_ENUM_2_2, 32);
checkEnum(ENUM_REF_1, 1);
checkEnum(ENUM_REF_2, 10);
checkEnum(clsEnum_CLS_ENUM_1, 100);
checkEnum(clsEnum_CLS_ENUM_2, 101);
checkEnum(clsEnum_CLS_ENUM_REF_1, 101);
checkEnum(clsEnum_CLS_ENUM_REF_2, 110);
exec("swigtest.quit", -1);

View file

@ -35,4 +35,21 @@ typedef enum TYPEDEF_ENUM_2 {
TYPEDEF_ENUM_2_2 = 32
} TYPEDEF_ENUM_2;
enum ENUM_REF {
ENUM_REF_1 = 1,
ENUM_REF_2 = ENUM_REF_1 + 9
};
class clsEnum {
public:
enum CLS_ENUM {
CLS_ENUM_1 = 100,
CLS_ENUM_2 = 101
};
enum CLS_ENUM_REF {
CLS_ENUM_REF_1 = 101,
CLS_ENUM_REF_2 = CLS_ENUM_REF_1 + 9
};
};
%}

View file

@ -0,0 +1,91 @@
/* File : swig_exception.i
* Test SWIG_exception().
*/
%module swig_exception
%include exception.i
%exception {
try {
$action
} catch (std::exception& e) {
SWIG_exception(SWIG_SystemError, e.what());
}
}
%inline %{
class Value {
int a_;
int b_;
public:
Value(int a, int b) : a_(a), b_(b) {}
};
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
}
double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
virtual Value throwException();
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { }
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
};
%}
%{
#define PI 3.14159265358979323846
#include <stdexcept>
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
Value Shape::throwException() {
throw std::logic_error("OK");
}
int Shape::nshapes = 0;
double Circle::area() {
return PI*radius*radius;
}
double Circle::perimeter() {
return 2*PI*radius;
}
double Square::area() {
return width*width;
}
double Square::perimeter() {
return 4*width;
}
%}

View file

@ -1,6 +0,0 @@
%module traits
%include typemaps/traits.swg
%fragment("Traits");

View file

@ -1,6 +1,13 @@
%module typedef_struct
%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for anonymous enums */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
typedef struct {
int numpoints;
} LineObj;

View file

@ -25,23 +25,33 @@ void foo1(Foo<int> f, const Foo<int>& ff) {}
void foo2(Foo<short> f, const Foo<short>& ff) {}
%}
#ifdef SWIGUTL
%typemap(ret) int Bar1::foo() { /* hello1 */ };
%typemap(ret) int Bar2::foo() { /* hello2 */ };
%typemap(ret) int foo() {/* hello3 */ };
#endif
// Check "ret" typemap is implemented
%{
template<typename T> struct NeededForTest {};
%}
%fragment("NeededForTest", "header") %{
template<> struct NeededForTest<short> { NeededForTest(short) {} };
%}
%typemap(ret) short "_ret_typemap_for_short_no_compile"
%typemap(ret, fragment="NeededForTest") short Bar1::foofunction() { /* ret typemap for short */ NeededForTest<short> needed($1); };
%typemap(ret, fragment="NeededForTest") short globalfoofunction() { /* ret typemap for short */ NeededForTest<short> needed($1); };
%inline %{
struct Bar1 {
int foo() { return 1;}
};
struct Bar2 {
int foo() { return 1;}
short foofunction() { return 1;}
};
short globalfoofunction() { return 1;}
%}
%{
void CheckRetTypemapUsed() {
// If the "ret" typemap is not used, the NeededForTest template specialization will not have been
// generated and so the following code will result in a compile failure
NeededForTest<short> needed(111);
(void)needed;
}
%}
%newobject FFoo::Bar(bool) const ;
%typemap(newfree) char* Bar(bool) {
@ -62,7 +72,7 @@ void foo2(Foo<short> f, const Foo<short>& ff) {}
#endif
// Test obscure bug where named typemaps where not being applied when symbol name contained a number
%typemap(out) double "_typemap_for_double_no_compile_"
%typemap(out) double "_out_typemap_for_double_no_compile_"
%typemap(out) double ABCD::meth {$1 = 0.0; TYPEMAP_OUT_INIT}
%typemap(out) double ABCD::m1 {$1 = 0.0; TYPEMAP_OUT_INIT}
%typemap(out) double ABCD::_x2 {$1 = 0.0; TYPEMAP_OUT_INIT}

View file

@ -0,0 +1,16 @@
%module variable_replacement
%inline %{
class A {
public:
int a(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12)
{
return 0;
}
};
class B : public A {
};
%}

View file

@ -2,9 +2,9 @@
#define CSHARP_CSHARPKW_SWG_
/* Warnings for C# keywords */
#define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword, renaming to '_" `x` "'",rename="_%s") `x`
#define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword, renaming to '" `x` "_'",rename="%s_") `x`
#define CSHARPCLASSKW(x) %keywordwarn("'" `x` "' is a special method name used in the C# wrapper classes, class renamed to '_" `x` "'",%$isclass,rename="_%s") `x`
#define CSHARPCLASSKW(x) %keywordwarn("'" `x` "' is a special method name used in the C# wrapper classes, class renamed to '" `x` "_'",%$isclass,rename="%s_") `x`
/*
from

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_cast "SWIG_CSharpSetPendingException(SWIG_CSharpInvalidCastException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::bad_exception "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::domain_error "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::exception "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_cast "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::bad_exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::domain_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"

View file

@ -15,7 +15,7 @@
#ifdef SWIGPHP
%{
#include "zend_exceptions.h"
#define SWIG_exception(code, msg) zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC)
#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); goto thrown; } while (0)
%}
#endif
@ -258,6 +258,7 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
}
*/
%{
#include <typeinfo>
#include <stdexcept>
%}
%define SWIG_CATCH_STDEXCEPT
@ -274,6 +275,8 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
SWIG_exception(SWIG_IndexError, e.what() );
} catch (std::runtime_error& e) {
SWIG_exception(SWIG_RuntimeError, e.what() );
} catch (std::bad_cast& e) {
SWIG_exception(SWIG_TypeError, e.what() );
} catch (std::exception& e) {
SWIG_exception(SWIG_SystemError, e.what() );
}

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws) std::bad_cast %{_swig_gopanic($1.what());%}
%typemap(throws) std::bad_exception %{_swig_gopanic($1.what());%}
%typemap(throws) std::domain_error %{_swig_gopanic($1.what());%}
%typemap(throws) std::exception %{_swig_gopanic($1.what());%}

View file

@ -1,6 +1,7 @@
// TODO: STL exception handling
// Note that the generic std_except.i file did not work
%{
#include <typeinfo>
#include <stdexcept>
%}

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws) std::bad_cast "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::bad_exception "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::domain_error "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::exception "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"

View file

@ -32,6 +32,7 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
fail:
return 0;
}
%}

View file

@ -53,7 +53,7 @@ SWIGINTERN bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObjec
} else {
SWIG_exception(SWIG_ERROR, msg);
}
fail:
return false;
}

View file

@ -4,7 +4,7 @@
* ---------------------------------------------------------------------------*/
#define SWIG_Error(code, msg) SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
#define SWIG_exception(code, msg) do { SWIG_JSC_exception(context, exception, code, msg); SWIG_fail; } while (0)
#define SWIG_fail goto fail
SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {

View file

@ -36,6 +36,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
fail:
SWIGV8_RETURN(SWIGV8_UNDEFINED());
}
%}

View file

@ -83,6 +83,7 @@ SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<
} else {
SWIG_exception(SWIG_ERROR, msg);
}
fail: ;
}
%} // v8_helper_functions

View file

@ -97,7 +97,7 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
* ---------------------------------------------------------------------------*/
#define SWIG_Error(code, msg) SWIGV8_ErrorHandler.error(code, msg)
#define SWIG_exception(code, msg) SWIGV8_ErrorHandler.error(code, msg)
#define SWIG_exception(code, msg) do { SWIGV8_ErrorHandler.error(code, msg); SWIG_fail; } while (0)
#define SWIG_fail goto fail
#define SWIGV8_OVERLOAD false

View file

@ -8,6 +8,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
%include <exception.i>
@ -27,6 +28,7 @@ namespace std
// normally objects which are thrown are returned to the interpreter as errors
// (which potentially may have problems if they are not copied)
// therefore all classes based upon std::exception are converted to their strings & returned as errors
%typemap(throws) std::bad_cast "SWIG_exception(SWIG_TypeError, $1.what());"
%typemap(throws) std::bad_exception "SWIG_exception(SWIG_RuntimeError, $1.what());"
%typemap(throws) std::domain_error "SWIG_exception(SWIG_ValueError, $1.what());"
%typemap(throws) std::exception "SWIG_exception(SWIG_SystemError, $1.what());"

View file

@ -562,8 +562,8 @@ namespace swig {
static int asptr(const octave_value& obj, sequence **seq) {
if (!obj.is_defined() || Swig::swig_value_deref(obj)) {
sequence *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<sequence>(),0) == SWIG_OK) {
swig_type_info *descriptor = swig::type_info<sequence>();
if (descriptor && SWIG_IsOK(SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0))) {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}

View file

@ -42,7 +42,8 @@ namespace swig {
struct traits_asptr {
static int asptr(const octave_value& obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
swig_type_info *descriptor = type_info<Type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}

View file

@ -98,7 +98,8 @@
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
map_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
swig_type_info *descriptor = swig::type_info<map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -47,7 +47,8 @@
return get_pair(c(0),c(1),val);
} else {
value_type *p;
int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
swig_type_info *descriptor = swig::type_info<value_type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val)
*val = *p;
return res;
@ -100,7 +101,8 @@
return get_pair(c(0),c(1),val);
} else {
value_type *p;
int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
swig_type_info *descriptor = swig::type_info<value_type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val)
*val = p;
return res;

View file

@ -393,11 +393,7 @@
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner);
ZEND_REGISTER_RESOURCE(return_value, p, swig_member_ptr);
}
%typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)

View file

@ -93,9 +93,6 @@ typedef struct {
int newobject;
} swig_object_wrapper;
/* empty zend destructor for types without one */
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; }
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a))

View file

@ -271,7 +271,7 @@ INT_TYPEMAP(unsigned long long);
%typemap(in) char INPUT[ANY] ( char temp[$1_dim0] )
%{
convert_to_string_ex($input);
strncpy(temp,Z_LVAL_PP($input),$1_dim0);
strncpy(temp,Z_STRVAL_PP($input),$1_dim0);
$1 = temp;
%}
%typemap(in,numinputs=0) char OUTPUT[ANY] ( char temp[$1_dim0] )

View file

@ -1,220 +1,29 @@
#define SWIGPY_UNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
return wrapper(a, NULL); \
}
#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper) \
SWIGINTERN void \
wrapper##_closure(PyObject *a) { \
SwigPyObject *sobj; \
sobj = (SwigPyObject *)a; \
Py_XDECREF(sobj->dict); \
if (sobj->own) { \
PyObject *o; \
PyObject *val = 0, *type = 0, *tb = 0; \
PyErr_Fetch(&val, &type, &tb); \
o = wrapper(a, NULL); \
if (!o) { \
PyObject *deallocname = PyString_FromString(#wrapper); \
PyErr_WriteUnraisable(deallocname); \
Py_DECREF(deallocname); \
} \
PyErr_Restore(val, type, tb); \
Py_XDECREF(o); \
} \
if (PyType_IS_GC(a->ob_type)) { \
PyObject_GC_Del(a); \
} else { \
PyObject_Del(a); \
} \
}
#define SWIGPY_INQUIRY_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a) { \
PyObject *pyresult; \
int result; \
pyresult = wrapper(a, NULL); \
result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \
Py_XDECREF(pyresult); \
return result; \
}
#define SWIGPY_BINARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, PyObject *b) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
Py_XINCREF(b); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
typedef ternaryfunc ternarycallfunc;
#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(b); \
Py_XINCREF(c); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_TERNARYCALLFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *callable_object, PyObject *args, PyObject *) { \
return wrapper(callable_object, args); \
}
#define SWIGPY_LENFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_ssize_t \
wrapper##_closure(PyObject *a) { \
PyObject *resultobj; \
Py_ssize_t result; \
resultobj = wrapper(a, NULL); \
result = PyNumber_AsSsize_t(resultobj, NULL); \
Py_DECREF(resultobj); \
return result; \
}
#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \
PyObject *tuple, *resultobj; \
int result; \
tuple = PyTuple_New(d ? 3 : 2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
if (d) { \
PyTuple_SET_ITEM(tuple, 2, d); \
Py_INCREF(d); \
} \
resultobj = wrapper(a, tuple); \
result = resultobj ? 0 : -1; \
Py_DECREF(tuple); \
Py_XDECREF(resultobj); \
return result; \
}
#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b) { \
PyObject *arg, *result; \
arg = _PyLong_FromSsize_t(b); \
result = wrapper(a, arg); \
Py_DECREF(arg); \
return result; \
}
#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \
PyObject *tuple, *resultobj; \
int result; \
tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(c); \
resultobj = wrapper(a, tuple); \
result = resultobj ? 0 : -1; \
Py_XDECREF(resultobj); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \
PyObject *tuple, *resultobj; \
int result; \
tuple = PyTuple_New(c ? 2 : 1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
Py_XINCREF(b); \
if (c) { \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(c); \
} \
resultobj = wrapper(a, tuple); \
result = resultobj ? 0 : -1; \
Py_XDECREF(resultobj); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_REPRFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
return wrapper(a, NULL); \
}
#define SWIGPY_HASHFUNC_CLOSURE(wrapper) \
SWIGINTERN long \
wrapper##_closure(PyObject *a) { \
PyObject *pyresult; \
long result; \
pyresult = wrapper(a, NULL); \
if (!pyresult || !PyLong_Check(pyresult)) \
return -1; \
result = PyLong_AsLong(pyresult); \
Py_DECREF(pyresult); \
return result; \
}
#define SWIGPY_ITERNEXT_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
PyObject *result; \
result = wrapper(a, NULL); \
if (result && result == Py_None) { \
Py_DECREF(result); \
result = NULL; \
} \
return result; \
}
#ifdef __cplusplus
extern "C" {
#endif
SWIGINTERN Py_hash_t
SwigPyObject_hash(PyObject *obj) {
SwigPyObject *sobj = (SwigPyObject *)obj;
void *ptr = sobj->ptr;
return (Py_hash_t)ptr;
}
SWIGINTERN Py_hash_t
SWIG_PyNumber_AsPyHash(PyObject *obj) {
Py_hash_t result = -1;
#if PY_VERSION_HEX < 0x03020000
if (PyLong_Check(obj))
result = PyLong_AsLong(obj);
#else
if (PyNumber_Check(obj))
result = PyNumber_AsSsize_t(obj, NULL);
#endif
else
PyErr_Format(PyExc_TypeError, "Wrong type for hash function");
return result;
}
SWIGINTERN int
SwigPyBuiltin_BadInit(PyObject *self, PyObject *SWIGUNUSEDPARM(args), PyObject *SWIGUNUSEDPARM(kwds)) {
PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
@ -222,11 +31,10 @@ SwigPyBuiltin_BadInit(PyObject *self, PyObject *SWIGUNUSEDPARM(args), PyObject *
}
SWIGINTERN void
SwigPyBuiltin_BadDealloc(PyObject *pyobj) {
SwigPyObject *sobj;
sobj = (SwigPyObject *)pyobj;
SwigPyBuiltin_BadDealloc(PyObject *obj) {
SwigPyObject *sobj = (SwigPyObject *)obj;
if (sobj->own) {
PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", pyobj->ob_type->tp_name);
PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", obj->ob_type->tp_name);
}
}
@ -387,16 +195,15 @@ SwigPyStaticVar_Type(void) {
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0,
0, /* ob_size */
#endif
"swig_static_var_getset_descriptor",
sizeof(PyGetSetDescrObject),
0,
"swig_static_var_getset_descriptor", /* tp_name */
sizeof(PyGetSetDescrObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
@ -527,6 +334,295 @@ SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype)
#endif
}
/* Start of callback function macros for use in PyTypeObject */
typedef PyObject *(*SwigPyWrapperFunction)(PyObject *, PyObject *);
#define SWIGPY_UNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_unaryfunc_closure(PyObject *a) { \
return SwigPyBuiltin_unaryfunc_closure(wrapper, a); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_unaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper) \
SWIGINTERN void \
wrapper##_destructor_closure(PyObject *a) { \
SwigPyBuiltin_destructor_closure(wrapper, #wrapper, a); \
}
SWIGINTERN void
SwigPyBuiltin_destructor_closure(SwigPyWrapperFunction wrapper, const char *wrappername, PyObject *a) {
SwigPyObject *sobj;
sobj = (SwigPyObject *)a;
Py_XDECREF(sobj->dict);
if (sobj->own) {
PyObject *o;
PyObject *val = 0, *type = 0, *tb = 0;
PyErr_Fetch(&val, &type, &tb);
o = wrapper(a, NULL);
if (!o) {
PyObject *deallocname = PyString_FromString(wrappername);
PyErr_WriteUnraisable(deallocname);
Py_DECREF(deallocname);
}
PyErr_Restore(val, type, tb);
Py_XDECREF(o);
}
if (PyType_IS_GC(a->ob_type)) {
PyObject_GC_Del(a);
} else {
PyObject_Del(a);
}
}
#define SWIGPY_INQUIRY_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_inquiry_closure(PyObject *a) { \
return SwigPyBuiltin_inquiry_closure(wrapper, a); \
}
SWIGINTERN int
SwigPyBuiltin_inquiry_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
PyObject *pyresult;
int result;
pyresult = wrapper(a, NULL);
result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0;
Py_XDECREF(pyresult);
return result;
}
#define SWIGPY_GETITERFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_getiterfunc_closure(PyObject *a) { \
return SwigPyBuiltin_getiterfunc_closure(wrapper, a); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_getiterfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
#define SWIGPY_BINARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_binaryfunc_closure(PyObject *a, PyObject *b) { \
return SwigPyBuiltin_binaryfunc_closure(wrapper, a, b); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_binaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b) {
PyObject *tuple, *result;
tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, b);
Py_XINCREF(b);
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
typedef ternaryfunc ternarycallfunc;
#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ternaryfunc_closure(PyObject *a, PyObject *b, PyObject *c) { \
return SwigPyBuiltin_ternaryfunc_closure(wrapper, a, b, c); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ternaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b, PyObject *c) {
PyObject *tuple, *result;
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, b);
PyTuple_SET_ITEM(tuple, 1, c);
Py_XINCREF(b);
Py_XINCREF(c);
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_TERNARYCALLFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ternarycallfunc_closure(PyObject *a, PyObject *b, PyObject *c) { \
return SwigPyBuiltin_ternarycallfunc_closure(wrapper, a, b, c); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ternarycallfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b, PyObject *c) {
(void) c;
return wrapper(a, b);
}
#define SWIGPY_LENFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_ssize_t \
wrapper##_lenfunc_closure(PyObject *a) { \
return SwigPyBuiltin_lenfunc_closure(wrapper, a); \
}
SWIGINTERN Py_ssize_t
SwigPyBuiltin_lenfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
PyObject *resultobj;
Py_ssize_t result;
resultobj = wrapper(a, NULL);
result = PyNumber_AsSsize_t(resultobj, NULL);
Py_DECREF(resultobj);
return result;
}
#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ssizessizeargfunc_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \
return SwigPyBuiltin_ssizessizeargfunc_closure(wrapper, a, b, c); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ssizessizeargfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b, Py_ssize_t c) {
PyObject *tuple, *result;
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c));
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_ssizessizeobjargproc_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \
return SwigPyBuiltin_ssizessizeobjargproc_closure(wrapper, a, b, c, d); \
}
SWIGINTERN int
SwigPyBuiltin_ssizessizeobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) {
PyObject *tuple, *resultobj;
int result;
tuple = PyTuple_New(d ? 3 : 2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c));
if (d) {
PyTuple_SET_ITEM(tuple, 2, d);
Py_INCREF(d);
}
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_DECREF(tuple);
Py_XDECREF(resultobj);
return result;
}
#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ssizeargfunc_closure(PyObject *a, Py_ssize_t b) { \
return SwigPyBuiltin_funpack_ssizeargfunc_closure(wrapper, a, b); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_funpack_ssizeargfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b) {
PyObject *tuple, *result;
tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_ssizeargfunc_closure(PyObject *a, Py_ssize_t b) { \
return SwigPyBuiltin_ssizeargfunc_closure(wrapper, a, b); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_ssizeargfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b) {
PyObject *arg, *result;
arg = _PyLong_FromSsize_t(b);
result = wrapper(a, arg);
Py_DECREF(arg);
return result;
}
#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_ssizeobjargproc_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \
return SwigPyBuiltin_ssizeobjargproc_closure(wrapper, a, b, c); \
}
SWIGINTERN int
SwigPyBuiltin_ssizeobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py_ssize_t b, PyObject *c) {
PyObject *tuple, *resultobj;
int result;
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
PyTuple_SET_ITEM(tuple, 1, c);
Py_XINCREF(c);
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_XDECREF(resultobj);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_objobjargproc_closure(PyObject *a, PyObject *b, PyObject *c) { \
return SwigPyBuiltin_objobjargproc_closure(wrapper, a, b, c); \
}
SWIGINTERN int
SwigPyBuiltin_objobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a, PyObject *b, PyObject *c) {
PyObject *tuple, *resultobj;
int result;
tuple = PyTuple_New(c ? 2 : 1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, b);
Py_XINCREF(b);
if (c) {
PyTuple_SET_ITEM(tuple, 1, c);
Py_XINCREF(c);
}
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_XDECREF(resultobj);
Py_DECREF(tuple);
return result;
}
#define SWIGPY_REPRFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_reprfunc_closure(PyObject *a) { \
return SwigPyBuiltin_reprfunc_closure(wrapper, a); \
}
SWIGINTERN PyObject *
SwigPyBuiltin_reprfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
#define SWIGPY_HASHFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_hash_t \
wrapper##_hashfunc_closure(PyObject *a) { \
return SwigPyBuiltin_hashfunc_closure(wrapper, a); \
}
SWIGINTERN Py_hash_t
SwigPyBuiltin_hashfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
PyObject *pyresult;
Py_hash_t result;
pyresult = wrapper(a, NULL);
if (!pyresult)
return -1;
result = SWIG_PyNumber_AsPyHash(pyresult);
Py_DECREF(pyresult);
return result;
}
#define SWIGPY_ITERNEXTFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_iternextfunc_closure(PyObject *a) { \
return SwigPyBuiltin_iternextfunc_closure(wrapper, a);\
}
SWIGINTERN PyObject *
SwigPyBuiltin_iternextfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a) {
return wrapper(a, NULL);
}
/* End of callback function macros for use in PyTypeObject */
#ifdef __cplusplus
}
#endif

View file

@ -206,7 +206,7 @@ namespace swig {
if (step == 0) {
throw std::invalid_argument("slice step cannot be zero");
} else if (step > 0) {
// Required range: 0 <= i < size, 0 <= j < size
// Required range: 0 <= i < size, 0 <= j < size, i <= j
if (i < 0) {
ii = 0;
} else if (i < (Difference)size) {
@ -214,13 +214,15 @@ namespace swig {
} else if (insert && (i >= (Difference)size)) {
ii = (Difference)size;
}
if ( j < 0 ) {
if (j < 0) {
jj = 0;
} else {
jj = (j < (Difference)size) ? j : (Difference)size;
}
if (jj < ii)
jj = ii;
} else {
// Required range: -1 <= i < size-1, -1 <= j < size-1
// Required range: -1 <= i < size-1, -1 <= j < size-1, i >= j
if (i < -1) {
ii = -1;
} else if (i < (Difference) size) {
@ -233,6 +235,8 @@ namespace swig {
} else {
jj = (j < (Difference)size ) ? j : (Difference)(size-1);
}
if (ii < jj)
ii = jj;
}
}
@ -258,6 +262,13 @@ namespace swig {
seq->erase(position);
}
template <class Sequence>
struct traits_reserve {
static void reserve(Sequence & /*seq*/, typename Sequence::size_type /*n*/) {
// This should be specialized for types that support reserve
}
};
template <class Sequence, class Difference>
inline Sequence*
getslice(const Sequence* self, Difference i, Difference j, Py_ssize_t step) {
@ -275,6 +286,7 @@ namespace swig {
return new Sequence(sb, se);
} else {
Sequence *sequence = new Sequence();
swig::traits_reserve<Sequence>::reserve(*sequence, (jj - ii + step - 1) / step);
typename Sequence::const_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
@ -285,17 +297,16 @@ namespace swig {
}
} else {
Sequence *sequence = new Sequence();
if (ii > jj) {
typename Sequence::const_reverse_iterator sb = self->rbegin();
typename Sequence::const_reverse_iterator se = self->rbegin();
std::advance(sb,size-ii-1);
std::advance(se,size-jj-1);
typename Sequence::const_reverse_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
for (Py_ssize_t c=0; c<-step && it!=se; ++c)
it++;
}
swig::traits_reserve<Sequence>::reserve(*sequence, (ii - jj - step - 1) / -step);
typename Sequence::const_reverse_iterator sb = self->rbegin();
typename Sequence::const_reverse_iterator se = self->rbegin();
std::advance(sb,size-ii-1);
std::advance(se,size-jj-1);
typename Sequence::const_reverse_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
for (Py_ssize_t c=0; c<-step && it!=se; ++c)
it++;
}
return sequence;
}
@ -309,12 +320,11 @@ namespace swig {
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj, true);
if (step > 0) {
if (jj < ii)
jj = ii;
if (step == 1) {
size_t ssize = jj - ii;
if (ssize <= is.size()) {
// expanding/staying the same size
swig::traits_reserve<Sequence>::reserve(*self, self->size() - ssize + is.size());
typename Sequence::iterator sb = self->begin();
typename InputSeq::const_iterator isit = is.begin();
std::advance(sb,ii);
@ -348,8 +358,6 @@ namespace swig {
}
}
} else {
if (jj > ii)
jj = ii;
size_t replacecount = (ii - jj - step - 1) / -step;
if (is.size() != replacecount) {
char msg[1024];
@ -375,37 +383,33 @@ namespace swig {
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj, true);
if (step > 0) {
if (jj > ii) {
typename Sequence::iterator sb = self->begin();
std::advance(sb,ii);
if (step == 1) {
typename Sequence::iterator se = self->begin();
std::advance(se,jj);
self->erase(sb,se);
} else {
typename Sequence::iterator it = sb;
size_t delcount = (jj - ii + step - 1) / step;
while (delcount) {
it = self->erase(it);
for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c)
it++;
delcount--;
}
}
}
} else {
if (ii > jj) {
typename Sequence::reverse_iterator sb = self->rbegin();
std::advance(sb,size-ii-1);
typename Sequence::reverse_iterator it = sb;
size_t delcount = (ii - jj - step - 1) / -step;
typename Sequence::iterator sb = self->begin();
std::advance(sb,ii);
if (step == 1) {
typename Sequence::iterator se = self->begin();
std::advance(se,jj);
self->erase(sb,se);
} else {
typename Sequence::iterator it = sb;
size_t delcount = (jj - ii + step - 1) / step;
while (delcount) {
it = typename Sequence::reverse_iterator(self->erase((++it).base()));
for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c)
it = self->erase(it);
for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c)
it++;
delcount--;
}
}
} else {
typename Sequence::reverse_iterator sb = self->rbegin();
std::advance(sb,size-ii-1);
typename Sequence::reverse_iterator it = sb;
size_t delcount = (ii - jj - step - 1) / -step;
while (delcount) {
it = typename Sequence::reverse_iterator(self->erase((++it).base()));
for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c)
it++;
delcount--;
}
}
}
}
@ -968,8 +972,8 @@ namespace swig {
static int asptr(PyObject *obj, sequence **seq) {
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
sequence *p;
if (::SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<sequence>(),0) == SWIG_OK) {
swig_type_info *descriptor = swig::type_info<sequence>();
if (descriptor && SWIG_IsOK(::SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0))) {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}

View file

@ -211,4 +211,5 @@ typedef destructor freefunc;
#if PY_VERSION_HEX < 0x03020000
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
#define Py_hash_t long
#endif

View file

@ -145,7 +145,6 @@ swig_varlink_type(void) {
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(NULL, 0)
#else

View file

@ -18,31 +18,35 @@
where <slot> is the name of a field in a PyTypeObject, PyNumberMethods,
PyMappingMethods, PySequenceMethods, or PyBufferProcs. For example:
%{
static long myHashFunc (PyObject *pyobj) {
MyClass *cobj;
// Convert pyobj to cobj
return (cobj->field1 * (cobj->field2 << 7));
}
%}
%feature("python:tp_hash") MyClass "myHashFunc";
class MyClass {
public:
...
};
%{
// Note: Py_hash_t was introduced in Python 3.2
static Py_hash_t myHashFunc(PyObject *pyobj) {
MyClass *cobj;
// Convert pyobj to cobj
return (cobj->field1 * (cobj->field2 << 7));
}
%}
NOTE: It is the responsibility of the programmer (that's you) to ensure
that a statically defined slot function has the correct signature.
If, instead, you want to dispatch to an instance method, you can
use %feature("python:slot"). For example:
%feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc;
class MyClass {
public:
long myHashFunc () const;
Py_hash_t myHashFunc () const;
...
};
%feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc;
NOTE: Some python slots use a method signature which does not
match the signature of SWIG-wrapped methods. For those slots,
@ -58,20 +62,21 @@
operator overloads for comparison (operator==, operator<, etc.), they
will be called from the generated rich compare function. If you
want to explicitly choose a method to handle a certain comparison
operation, you may use %feature("python:slot") like this:
operation, you may use a different feature, %feature("python:compare")
like this:
%feature("python:compare", "Py_LT") MyClass::lessThan;
class MyClass {
public:
bool lessThan (const MyClass& x) const;
bool lessThan(const MyClass& other) const;
...
};
%feature("python:slot", "Py_LT") MyClass::lessThan;
... where "Py_LT" is one of the rich comparison opcodes defined in the
python header file object.h.
If there's no method defined to handle a particular comparsion operation,
If there's no method defined to handle a particular comparison operation,
the default behavior is to compare pointer values of the wrapped
C++ objects.

View file

@ -312,7 +312,7 @@ SWIG_AsVal_dec(double)(PyObject *obj, double *val)
return SWIG_OK;
%#if PY_VERSION_HEX < 0x03000000
} else if (PyInt_Check(obj)) {
if (val) *val = PyInt_AsLong(obj);
if (val) *val = (double) PyInt_AsLong(obj);
return SWIG_OK;
%#endif
} else if (PyLong_Check(obj)) {

View file

@ -758,7 +758,6 @@ SwigPyObject_TypeOnce(void) {
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(NULL, 0)
#else
@ -769,7 +768,7 @@ SwigPyObject_TypeOnce(void) {
sizeof(SwigPyObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyObject_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_print */
#if PY_VERSION_HEX < 0x02020000
(getattrfunc)SwigPyObject_getattr, /* tp_getattr */
#else
@ -777,7 +776,7 @@ SwigPyObject_TypeOnce(void) {
#endif
(setattrfunc)0, /* tp_setattr */
#if PY_VERSION_HEX >= 0x03000000
0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */
0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */
#else
(cmpfunc)SwigPyObject_compare, /* tp_compare */
#endif
@ -787,7 +786,7 @@ SwigPyObject_TypeOnce(void) {
0, /* tp_as_mapping */
(hashfunc)0, /* tp_hash */
(ternaryfunc)0, /* tp_call */
0, /* tp_str */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
@ -950,7 +949,6 @@ SwigPyPacked_TypeOnce(void) {
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX>=0x03000000
PyVarObject_HEAD_INIT(NULL, 0)
#else

View file

@ -46,7 +46,8 @@ namespace swig {
struct traits_asptr {
static int asptr(PyObject *obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
swig_type_info *descriptor = type_info<Type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}

View file

@ -102,7 +102,8 @@
res = traits_asptr_stdseq<map_type, std::pair<K, T> >::asptr(items, val);
} else {
map_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
swig_type_info *descriptor = swig::type_info<map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
SWIG_PYTHON_THREAD_END_BLOCK;

View file

@ -26,7 +26,8 @@
return traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
multimap_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<multimap_type>(),0);
swig_type_info *descriptor = swig::type_info<multimap_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -48,7 +48,8 @@
}
} else {
value_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = *p;
}
return res;
@ -98,7 +99,8 @@
}
} else {
value_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -15,6 +15,13 @@
}
}
template <class K, class T>
struct traits_reserve<std::unordered_map<K,T> > {
static void reserve(std::unordered_map<K,T> &seq, typename std::unordered_map<K,T>::size_type n) {
seq.reserve(n);
}
};
template <class K, class T>
struct traits_asptr<std::unordered_map<K,T> > {
typedef std::unordered_map<K,T> unordered_map_type;
@ -29,7 +36,8 @@
res = traits_asptr_stdseq<std::unordered_map<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
unordered_map_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<unordered_map_type>(),0);
swig_type_info *descriptor = swig::type_info<unordered_map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -16,6 +16,13 @@
}
}
template <class K, class T>
struct traits_reserve<std::unordered_multimap<K,T> > {
static void reserve(std::unordered_multimap<K,T> &seq, typename std::unordered_multimap<K,T>::size_type n) {
seq.reserve(n);
}
};
template <class K, class T>
struct traits_asptr<std::unordered_multimap<K,T> > {
typedef std::unordered_multimap<K,T> unordered_multimap_type;
@ -26,7 +33,8 @@
return traits_asptr_stdseq<std::unordered_multimap<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
unordered_multimap_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<unordered_multimap_type>(),0);
swig_type_info *descriptor = swig::type_info<unordered_multimap_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -18,6 +18,13 @@
}
}
template <class T>
struct traits_reserve<std::unordered_multiset<T> > {
static void reserve(std::unordered_multiset<T> &seq, typename std::unordered_multiset<T>::size_type n) {
seq.reserve(n);
}
};
template <class T>
struct traits_asptr<std::unordered_multiset<T> > {
static int asptr(PyObject *obj, std::unordered_multiset<T> **m) {

View file

@ -16,6 +16,13 @@
}
}
template <class T>
struct traits_reserve<std::unordered_set<T> > {
static void reserve(std::unordered_set<T> &seq, typename std::unordered_set<T>::size_type n) {
seq.reserve(n);
}
};
template <class T>
struct traits_asptr<std::unordered_set<T> > {
static int asptr(PyObject *obj, std::unordered_set<T> **s) {

View file

@ -5,6 +5,13 @@
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T>
struct traits_reserve<std::vector<T> > {
static void reserve(std::vector<T> &seq, typename std::vector<T>::size_type n) {
seq.reserve(n);
}
};
template <class T>
struct traits_asptr<std::vector<T> > {
static int asptr(PyObject *obj, std::vector<T> **vec) {

View file

@ -1,15 +1,4 @@
#ifdef __cplusplus
#include <exception>
extern "C" {
#endif
/* for raw pointer */
#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_R_ConvertPtr(obj, pptr, type, flags)
#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_R_ConvertPtr(obj, pptr, type, flags)
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_R_NewPointerObj(ptr, type, flags)
/* Remove global namespace pollution */
#if !defined(SWIG_NO_R_NO_REMAP)
# define R_NO_REMAP
@ -20,6 +9,17 @@ extern "C" {
#include <Rdefines.h>
#include <Rversion.h>
#ifdef __cplusplus
#include <exception>
extern "C" {
#endif
/* for raw pointer */
#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_R_ConvertPtr(obj, pptr, type, flags)
#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_R_ConvertPtr(obj, pptr, type, flags)
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_R_NewPointerObj(ptr, type, flags)
#include <stdlib.h>
#include <assert.h>

View file

@ -40,7 +40,8 @@ namespace swig {
struct traits_asptr {
static int asptr(SWIG_Object obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
swig_type_info *descriptor = type_info<Type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}

View file

@ -464,8 +464,7 @@ namespace swig
%typemap(in,noblock=1,fragment="RubySequence_Cont")
const_iterator(swig::ConstIterator *iter = 0, int res),
const_reverse_iterator(swig::ConstIterator *iter = 0, int res) {
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
swig::ConstIterator::descriptor(), 0);
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::ConstIterator::descriptor(), 0);
if (!SWIG_IsOK(res) || !iter) {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
} else {
@ -497,16 +496,14 @@ namespace swig
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="RubySequence_Cont")
const_iterator, const_reverse_iterator {
swig::ConstIterator *iter = 0;
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
swig::ConstIterator::descriptor(), 0);
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::ConstIterator::descriptor(), 0);
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::ConstIterator_T<$type > *>(iter) != 0));
}
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="RubySequence_Cont")
iterator, reverse_iterator {
swig::ConstIterator *iter = 0;
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
swig::Iterator::descriptor(), 0);
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::Iterator::descriptor(), 0);
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::Iterator_T<$type > *>(iter) != 0));
}
@ -1037,8 +1034,8 @@ namespace swig {
}
} else {
sequence *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<sequence>(),0) == SWIG_OK) {
swig_type_info *descriptor = swig::type_info<sequence>();
if (descriptor && SWIG_IsOK(SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0))) {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}
@ -1077,8 +1074,8 @@ namespace swig {
}
} else {
sequence *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<sequence>(),0) == SWIG_OK) {
swig_type_info *descriptor = swig::type_info<sequence>();
if (descriptor && SWIG_IsOK(SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0))) {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}

View file

@ -53,7 +53,8 @@ namespace swig {
struct traits_asptr {
static int asptr(VALUE obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
swig_type_info *descriptor = type_info<Type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}

View file

@ -100,7 +100,8 @@
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
map_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
swig_type_info *descriptor = swig::type_info<map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -44,8 +44,8 @@
}
} else {
value_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<value_type>(),0);
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = *p;
}
return res;
@ -90,8 +90,8 @@
}
} else {
value_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<value_type>(),0);
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
}
return res;

View file

@ -125,7 +125,6 @@ SWIG_SciBoolean_AsIntArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCo
}
if (isBooleanType(pvApiCtx, piAddrVar)) {
int i;
sciErr = getMatrixOfBoolean(pvApiCtx, piAddrVar, iRows, iCols, piValue);
if (sciErr.iErr) {
printError(&sciErr, 0);

View file

@ -6,7 +6,7 @@
}
%fragment("SWIG_NewPointerObj", "header") {
#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, flags)
#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, flags, NULL)
}
/*
@ -17,7 +17,7 @@
}
%fragment("SWIG_NewFunctionPtrObj", "header") {
#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, 0)
#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, 0, NULL)
}
// No fragment used here, the functions "SwigScilabPtrToObject" and "SwigScilabPtrFromObject" are defined in sciruntime.swg

View file

@ -120,7 +120,7 @@ SwigScilabCheckPtr(void *pvApiCtx, int iVar, swig_type_info *descriptor, char *f
return SWIG_ERROR;
}
if (iType == sci_tlist) {
if (iType == sci_mlist) {
int iItemCount = 0;
void *pvTypeinfo = NULL;
@ -142,10 +142,10 @@ SwigScilabCheckPtr(void *pvApiCtx, int iVar, swig_type_info *descriptor, char *f
if (descriptor) {
swig_cast_info *cast = SWIG_TypeCheck(SWIG_TypeName((swig_type_info*)pvTypeinfo), descriptor);
return (cast != NULL);
}
}
else {
return SWIG_ERROR;
}
}
}
else {
return (iType == sci_pointer);
@ -171,7 +171,7 @@ SwigScilabPtrToObject(void *pvApiCtx, int iVar, void **pvObj, swig_type_info *de
return SWIG_ERROR;
}
if (iType == sci_tlist) {
if (iType == sci_mlist) {
int iItemCount = 0;
void *pvTypeinfo = NULL;
@ -232,34 +232,36 @@ SwigScilabPtrToObject(void *pvApiCtx, int iVar, void **pvObj, swig_type_info *de
}
SWIGRUNTIMEINLINE int
SwigScilabPtrFromObject(void *pvApiCtx, int iVarOut, void *pvObj, swig_type_info *descriptor, int flags) {
SwigScilabPtrFromObject(void *pvApiCtx, int iVarOut, void *pvObj, swig_type_info *descriptor, int flags, const char *pstTypeName) {
SciErr sciErr;
if (descriptor) {
int *piTListAddr = NULL;
const char *pstString;
int *piMListAddr = NULL;
sciErr = createTList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, 3, &piTListAddr);
sciErr = createMList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, 3, &piMListAddr);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
pstString = SWIG_TypeName(descriptor);
sciErr = createMatrixOfStringInList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, piTListAddr, 1, 1, 1, &pstString);
if (pstTypeName == NULL) {
pstTypeName = SWIG_TypeName(descriptor);
}
sciErr = createMatrixOfStringInList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, piMListAddr, 1, 1, 1, &pstTypeName);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
sciErr = createPointerInList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, piTListAddr, 2, descriptor);
sciErr = createPointerInList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, piMListAddr, 2, descriptor);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
sciErr = createPointerInList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, piTListAddr, 3, pvObj);
sciErr = createPointerInList(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, piMListAddr, 3, pvObj);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
@ -451,7 +453,7 @@ int SWIG_ptr(SWIG_GatewayParameters) {
}
SWIG_Scilab_SetOutputPosition(1);
return SWIG_Scilab_SetOutput(pvApiCtx,
SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, NULL, 0));
SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, NULL, 0, NULL));
}
else {
return SWIG_ERROR;

View file

@ -84,7 +84,7 @@ SWIG_FromSet_Sequence_dec(bool)(int size, int *pSequence) {
SWIGINTERN bool
SWIG_AsVal_SequenceItem_dec(bool)(SwigSciObject obj, int *pSequence, int iItemIndex) {
return pSequence[iItemIndex];
return (bool) pSequence[iItemIndex];
}
}

View file

@ -1,5 +1,5 @@
/*
*char
*
* Scilab matrix of string <-> C++ std::string container
*
*/
@ -88,7 +88,7 @@ SWIG_AsVal_SequenceItem_dec(std::string)(SwigSciObject obj, char **pSequence, in
SWIGINTERN int
SWIG_From_SequenceItem_dec(std::string)(char **pSequence, int iItemIndex, std::string itemValue) {
char *pChar = new char(itemValue.size() + 1);
char *pChar = new char((int) itemValue.size() + 1);
strcpy(pChar, itemValue.c_str());
pSequence[iItemIndex] = pChar;
return SWIG_OK;

View file

@ -42,7 +42,8 @@ namespace swig {
struct traits_asptr {
static int asptr(const SwigSciObject& obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
swig_type_info *descriptor = type_info<Type>();
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}

View file

@ -4,6 +4,13 @@
// to use a pointer to the smart pointer of the type, rather than the usual pointer to the underlying type.
// So for some type T, shared_ptr<T> * is used rather than T *.
// Another key part of the implementation is the smartptr feature:
// %feature("smartptr") T { shared_ptr<T> }
// This feature marks the class T as having a smartptr to it (the shared_ptr<T> type). This is then used to
// support smart pointers and inheritance. Say class D derives from base B, then shared_ptr<D> is marked
// with a fake inheritance from shared_ptr<B> in the type system if the "smartptr" feature is used on both
// B and D. This is to emulate the conversion of shared_ptr<D> to shared_ptr<B> in the target language.
// shared_ptr namespaces could be boost or std or std::tr1
// For example for std::tr1, use:
// #define SWIG_SHARED_PTR_NAMESPACE std

View file

@ -99,8 +99,21 @@ namespace swig {
return traits<typename noconst_traits<Type >::noconst_type >::type_name();
}
template <class Type>
struct traits_info {
template <class Type> struct traits_info {
static swig_type_info *type_query(std::string name) {
name += " *";
return SWIG_TypeQuery(name.c_str());
}
static swig_type_info *type_info() {
static swig_type_info *info = type_query(type_name<Type>());
return info;
}
};
/*
Partial specialization for pointers (traits_info)
*/
template <class Type> struct traits_info<Type *> {
static swig_type_info *type_query(std::string name) {
name += " *";
return SWIG_TypeQuery(name.c_str());
@ -117,7 +130,7 @@ namespace swig {
}
/*
Partial specialization for pointers
Partial specialization for pointers (traits)
*/
template <class Type> struct traits <Type *> {
typedef pointer_category category;

View file

@ -3,6 +3,7 @@
#endif
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -15,6 +16,10 @@ namespace std {
virtual const char* what() const throw();
};
struct bad_cast : exception
{
};
struct bad_exception : exception
{
};

View file

@ -24,6 +24,7 @@
#endif
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -40,6 +41,7 @@
%enddef
namespace std {
%std_exception_map(bad_cast, SWIG_TypeError);
%std_exception_map(bad_exception, SWIG_SystemError);
%std_exception_map(domain_error, SWIG_ValueError);
%std_exception_map(exception, SWIG_SystemError);

View file

@ -203,7 +203,7 @@
* This macro is used to return Character data along with a size
* parameter.
*
* %cstring_output_maxsize(Char *outx, int *max) {
* %cstring_output_withsize(Char *outx, int *max) {
* void foo(Char *outx, int *max) {
* sprintf(outx,"blah blah\n");
* *max = strlen(outx);
@ -236,7 +236,7 @@
* This macro is used to return Character data that was
* allocated with new or malloc.
*
* %cstring_output_allocated(Char **outx, free($1));
* %cstring_output_allocate(Char **outx, free($1));
* void foo(Char **outx) {
* *outx = (Char *) malloc(512);
* sprintf(outx,"blah blah\n");
@ -263,7 +263,7 @@
* This macro is used to return Character data that was
* allocated with new or malloc.
*
* %cstring_output_allocated(Char **outx, int *sz, free($1));
* %cstring_output_allocate_size(Char **outx, int *sz, free($1));
* void foo(Char **outx, int *sz) {
* *outx = (Char *) malloc(512);
* sprintf(outx,"blah blah\n");

View file

@ -73,8 +73,8 @@ namespace swig {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* desc = SWIG_TypeQuery("Type *");
int res = SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0);
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return res;
@ -109,8 +109,8 @@ namespace swig {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* desc = SWIG_TypeQuery("Type *");
int res = SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0);
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return res;
@ -147,8 +147,8 @@ namespace swig {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* desc = SWIG_TypeQuery("Type *");
int res = SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0);
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
@ -188,8 +188,8 @@ namespace swig {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* desc = SWIG_TypeQuery("Type *");
int res = SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0);
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return res;

View file

@ -20,6 +20,7 @@
%enddef
namespace std {
%std_exception_map(bad_cast, SWIG_TypeError);
%std_exception_map(bad_exception, SWIG_SystemError);
%std_exception_map(domain_error, SWIG_ValueError);
%std_exception_map(exception, SWIG_SystemError);

View file

@ -1,305 +0,0 @@
//
// Use the following macro with modern STL implementations
//
//#define SWIG_STD_MODERN_STL
//
// Use this to deactive the previous definition, when using gcc-2.95
// or similar old compilers.
//
//#define SWIG_STD_NOMODERN_STL
// Here, we identify compilers we now have problems with STL.
%{
#if defined(__GNUC__)
# if __GNUC__ == 2 && __GNUC_MINOR <= 96
# define SWIG_STD_NOMODERN_STL
# endif
#endif
%}
//
// Common code for supporting the STD C++ namespace
//
%fragment("<string>");
%fragment("<stdexcept>");
%fragment("Traits","header",fragment="<string>")
{
namespace swig {
/*
type categories
*/
struct pointer_category { };
struct value_category { };
/*
General traits that provides type_name and type_info
*/
template <class Type> struct traits { };
template <class Type>
inline const char* type_name() {
return traits<Type>::type_name();
}
template <class Type>
struct traits_info {
static swig_type_info *type_query(std::string name) {
name += " *";
return SWIG_TypeQuery(name.c_str());
}
static swig_type_info *type_info() {
static swig_type_info *info = type_query(type_name<Type>());
return info;
}
};
template <class Type>
inline swig_type_info *type_info() {
return traits_info<Type>::type_info();
}
/*
Partial specialization for pointers
*/
template <class Type> struct traits <Type *> {
typedef pointer_category category;
static std::string make_ptr_name(const char* name) {
std::string ptrname = name;
ptrname += " *";
return ptrname;
}
static const char* type_name() {
static std::string name = make_ptr_name(swig::type_name<Type>());
return name.c_str();
}
};
template <class Type, class Category = typename traits<Type>::category >
struct traits_check { };
/*
Traits that provides the from method for an unknown type
*/
template <int flags, class Type> struct traits_from_ptr {
static SWIG_Object from SWIG_FROM_DECL_ARGS(Type *val) {
return SWIG_NewPointerObj(val, type_info<Type>(), flags);
}
};
template <class Type> struct traits_from {
static SWIG_Object from SWIG_FROM_DECL_ARGS(const Type& val) {
return traits_from_ptr<SWIG_POINTER_OWN, Type>::from(new Type(val));
}
};
template <class Type> struct traits_from<Type *> {
static SWIG_Object from SWIG_FROM_DECL_ARGS(Type* val) {
return traits_from_ptr<0, Type>::from(val);
}
};
template <class Type>
inline SWIG_Object from SWIG_FROM_DECL_ARGS(const Type& val) {
return traits_from<Type>::from(val);
}
/*
Traits that provides the asptr/asval method for an unknown type
*/
template <class Type>
struct traits_asptr {
static int asptr SWIG_AS_DECL_ARGS (SWIG_Object obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, %as_voidptrptr(&p), type_info<Type>(), 0);
if (SWIG_IsOK(res) && val) *val = p;
return res;
}
};
template <class Type>
inline int asptr SWIG_AS_DECL_ARGS(SWIG_Object obj, Type **vptr) {
return traits_asptr<Type>::asptr SWIG_AS_CALL_ARGS(obj, vptr);
}
template <class Type>
struct traits_asval {
static int asval SWIG_AS_DECL_ARGS(SWIG_Object obj, Type *val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr SWIG_AS_CALL_ARGS(obj, &p);
if (SWIG_IsOK(res) && p) {
*val = *p;
if (SWIG_IsNewObj(res)) {
%delete(p);
res = SWIG_DelNewMask(res);
}
}
return res;
} else {
return traits_asptr<Type>::asptr SWIG_AS_CALL_ARGS(obj, (Type **)(0));
}
}
};
template <class Type>
inline int asval SWIG_AS_DECL_ARGS (SWIG_Object obj, Type *val) {
return traits_asval<Type>::asval SWIG_AS_CALL_ARGS(obj, val);
}
/*
Traits that provides the check method for an unknown type
*/
#define SWIG_CHECK_DECL_ARGS(obj) SWIG_AS_DECL_ARGS(obj, void * = 0)
#define SWIG_CHECK_CALL_ARGS(obj) SWIG_AS_CALL_ARGS(obj, 0)
template <class Type>
struct traits_checkval {
static int check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
if (obj) {
int res = asval SWIG_AS_CALL_ARGS(obj, (Type *)(0));
return SWIG_CheckState(res);
} else {
return 0;
}
}
};
template <class Type>
struct traits_checkptr {
static int check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
if (obj) {
int res = asptr SWIG_AS_CALL_ARGS(obj, (Type **)(0));
return SWIG_CheckState(res);
} else {
return 0;
}
}
};
template <class Type>
struct traits_check<Type, value_category> : traits_checkval<Type> {
};
template <class Type>
struct traits_check<Type, pointer_category> : traits_checkptr<Type> {
};
template <class Type>
inline int check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
return traits_check<Type>::check SWIG_CHECK_CALL_ARGS(obj);
}
}
}
/*
Generate the traits for an unknown SWIGTYPE
*/
%define %traits_swigtype(Type...)
%fragment(SWIG_Traits_frag(Type),"header",fragment="Traits") {
namespace swig {
template <> struct traits<Type > {
typedef pointer_category category;
static const char* type_name() { return #Type; }
};
}
}
%enddef
/*
Generate the traits for a 'value' type, such as 'double',
for which the SWIG_AsVal and SWIG_From methods are already defined.
*/
%define %traits_value(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="Traits") {
namespace swig {
template <> struct traits<Type > {
typedef value_category category;
static const char* type_name() { return #Type; }
};
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval SWIG_AS_DECL_ARGS (SWIG_Object obj, value_type *val) {
return SWIG_AsVal(Type)(obj, val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static SWIG_Object from SWIG_FROM_DECL_ARGS (const value_type& val) {
return SWIG_From(Type)(val);
}
};
}
}
%enddef
/*
Generate the traits for a 'pointer' type, such as 'std::string',
for which the SWIG_AsPtr and SWIG_From methods are already defined.
*/
%define %traits_pointer(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="Traits") {
namespace swig {
template <> struct traits<Type > {
typedef pointer_category category;
static const char* type_name() { return #Type; }
};
template <> struct traits_asptr<Type > {
typedef Type value_type;
static int asptr SWIG_AS_DECL_ARGS (SWIG_Object obj, value_type **val) {
return SWIG_AsPtr(Type)(obj, val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static SWIG_Object from SWIG_FROM_DECL_ARGS (const value_type& val) {
return SWIG_From(Type)(val);
}
};
}
}
%enddef
/*
Generate the typemaps for a class that has 'value' traits
*/
%define %typemap_traits_value(Code,Type...)
%typemaps_asvalfrom(%arg(Code),
%arg(swig::asval),
%arg(swig::from),
%arg(SWIG_Traits_frag(Type)),
%arg(SWIG_Traits_frag(Type)),
Type);
%enddef
/*
Generate the typemaps for a class that has 'pointer' traits
*/
%define %typemap_traits_pointer(Code,Type...)
%typemaps_asptrfrom(%arg(Code),
%arg(swig::asptr),
%arg(swig::from),
%arg(SWIG_Traits_frag(Type)),
%arg(SWIG_Traits_frag(Type)),
Type);
%enddef

View file

@ -2722,6 +2722,13 @@ int ALLEGROCL::functionWrapper(Node *n) {
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
emit_return_variable(n, t, f);
if (CPlusPlus) {

View file

@ -543,6 +543,14 @@ int CFFI::functionWrapper(Node *n) {
cleanupFunction(n, f, parms);
/* See if there is any return cleanup code */
String *tm = 0;
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
if (!is_void_return) {
Printf(f->code, " return lresult;\n");
}

View file

@ -2445,7 +2445,8 @@ private:
}
String *code = Copy(Getattr(n, "wrap:action"));
Replaceall(code, Getattr(parms, "lname"), current);
Replace(code, Getattr(parms, "lname"), current, DOH_REPLACE_ANY | DOH_REPLACE_ID);
Delete(current);
Printv(actioncode, code, "\n", NULL);
}
@ -2598,6 +2599,14 @@ private:
Replaceall(f->code, "$cleanup", cleanup);
Delete(cleanup);
/* See if there is any return cleanup code */
String *tm;
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
Replaceall(f->code, "$symname", Getattr(n, "sym:name"));
}

View file

@ -1354,6 +1354,11 @@ void JSEmitter::emitCleanupCode(Node *n, Wrapper *wrapper, ParmList *params) {
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Printf(wrapper->code, "%s\n", tm);
Delete(tm);
}
}
int JSEmitter::switchNamespace(Node *n) {

View file

@ -676,6 +676,14 @@ public:
Printv(f->code, tm, "\n", NIL);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("swig_result", n, Swig_cresult_name(), 0))) {

Some files were not shown because too many files have changed in this diff Show more