Merge branch 'master' into doxygen

This commit is contained in:
Vadim Zeitlin 2018-03-19 21:54:46 +01:00
commit b7f78dd5a7
232 changed files with 5648 additions and 2419 deletions

View file

@ -3,7 +3,7 @@
%module class_scope_namespace
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) H::HH;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I::II;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I_::II;
%inline %{
struct A;
@ -107,12 +107,12 @@ void hhh(H::HH) {}
namespace Space8 {
struct II;
struct I {
struct I_ {
struct II {
void ii(Space8::I::II, I::II) {}
void ii(Space8::I_::II, I_::II) {}
};
};
void iii(Space8::I::II, I::II) {}
void iii(Space8::I_::II, I_::II) {}
}
struct J;

View file

@ -89,7 +89,6 @@ CPP_TEST_BROKEN += \
extend_variable \
li_boost_shared_ptr_template \
nested_private \
overload_complicated \
rename_camel \
template_default_pointer \
template_private_assignment \
@ -165,6 +164,7 @@ CPP_TEST_CASES += \
cpp_typedef \
curiously_recurring_template_pattern \
default_args \
default_arg_expressions \
default_arg_values \
default_constructor \
defvalue_constructor \
@ -182,6 +182,7 @@ CPP_TEST_CASES += \
director_detect \
director_enum \
director_exception \
director_exception_catches \
director_extend \
director_finalizer \
director_frob \
@ -193,6 +194,7 @@ CPP_TEST_CASES += \
director_nspace_director_name_collision \
director_overload \
director_overload2 \
director_ownership \
director_pass_by_value \
director_primitives \
director_property \
@ -264,9 +266,10 @@ CPP_TEST_CASES += \
li_attribute \
li_attribute_template \
li_boost_shared_ptr \
li_boost_shared_ptr_bits \
li_boost_shared_ptr_template \
li_boost_shared_ptr_attribute \
li_boost_shared_ptr_bits \
li_boost_shared_ptr_director \
li_boost_shared_ptr_template \
li_carrays_cpp \
li_cdata_cpp \
li_cpointer_cpp \
@ -317,6 +320,7 @@ CPP_TEST_CASES += \
nested_template_base \
nested_workaround \
newobject1 \
newobject3 \
null_pointer \
operator_overload \
operator_overload_break \
@ -325,6 +329,7 @@ CPP_TEST_CASES += \
ordering \
overload_arrays \
overload_bool \
overload_complicated \
overload_copy \
overload_extend \
overload_method \
@ -405,6 +410,7 @@ CPP_TEST_CASES += \
template_basic \
template_base_template \
template_classes \
template_class_reuse_name \
template_const_ref \
template_construct \
template_templated_constructors \
@ -486,6 +492,7 @@ CPP_TEST_CASES += \
throw_exception \
typedef_array_member \
typedef_class \
typedef_classforward_same_name \
typedef_funcptr \
typedef_inherit \
typedef_mptr \
@ -506,6 +513,7 @@ CPP_TEST_CASES += \
typemap_numinputs \
typemap_template \
typemap_template_parm_typedef \
typemap_template_typedef \
typemap_out_optimal \
typemap_qualifier_strip \
typemap_variables \
@ -534,6 +542,7 @@ CPP_TEST_CASES += \
varargs_overload \
variable_replacement \
virtual_destructor \
virtual_derivation \
virtual_poly \
virtual_vs_nonvirtual_base \
voidtest \
@ -650,6 +659,7 @@ C_TEST_CASES += \
char_constant \
const_const \
constant_expr \
default_args_c \
empty_c \
enums \
enum_forward \
@ -692,6 +702,7 @@ C_TEST_CASES += \
string_simple \
struct_rename \
struct_initialization \
typedef_classforward_same_name \
typedef_struct \
typemap_subst \
union_parameter \

View file

@ -14,31 +14,53 @@
%template(VectorStdCplx) std::vector<std::complex<double> >;
#endif
%inline
%inline
{
std::complex<double> Conj(const std::complex<double>& a)
std::complex<double> Conj(std::complex<double> a)
{
return std::conj(a);
}
}
std::complex<float> Conjf(const std::complex<float>& a)
std::complex<float> Conjf(std::complex<float> a)
{
return std::conj(a);
}
}
#if 1
std::vector<std::complex<double> > Copy_h(const std::vector<std::complex<double> >& a)
std::vector<std::complex<double> > CopyHalf(std::vector<std::complex<double> > a)
{
std::vector<std::complex<double> > b(a.size()/2);
std::copy(a.begin(), a.begin()+a.size()/2, b.begin());
return b;
}
#endif
}
using namespace std;
struct ComplexPair
{
std::complex<double> z1, z2;
std::complex<double> z1;
complex<double> z2;
};
const complex<double>& Conj2(const complex<double>& a)
{
static complex<double> ret;
ret = std::conj(a);
return ret;
}
const complex<float>& Conjf2(const complex<float>& a)
{
static complex<float> ret;
ret = std::conj(a);
return ret;
}
const vector<complex<double> >& CopyHalfRef(const vector<complex<double> >& a)
{
static vector<complex<double> > b;
b = CopyHalf(a);
return b;
}
}
@ -48,7 +70,7 @@
%{
%}
%inline
%inline
{
complex Conj(complex a)
{

View file

@ -1,20 +1,16 @@
%module(directors="1") cpp11_directors
%feature("director");
%{
%inline %{
class Foo {
public:
virtual ~Foo() noexcept {}
virtual int ping() noexcept = 0;
virtual int pong() noexcept = 0;
virtual int pang() const& noexcept = 0;
virtual int peng() & noexcept = 0;
virtual int pung() & = 0;
};
%}
class Foo {
public:
virtual ~Foo() noexcept {}
virtual int ping() noexcept = 0;
virtual int pong() noexcept = 0;
};

View file

@ -6,6 +6,16 @@
%warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final'
%warnfilter(SWIGWARN_PARSE_KEYWORD) override; // 'override' is a C# keyword, renaming to '_override'
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
#endif
%}
%inline %{
struct Base {
@ -131,3 +141,12 @@ void DerivedNoVirtualStruct::cd() {}
void DerivedNoVirtualStruct::ef() {}
DerivedNoVirtualStruct::~DerivedNoVirtualStruct() {}
%}
%{
#if defined(_MSC_VER)
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
%}

View file

@ -26,6 +26,16 @@
%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::lambda19;
%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::Space2::lambda20;
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
#endif
%}
%inline %{
/* Defined lambda function with return value. */
auto lambda1 = [](int x, int y) -> int { return x+y; };
@ -105,3 +115,11 @@ int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2);
void lambda_init(int = ([=]{ return 0; })());
%}
%{
#if defined(_MSC_VER)
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
%}

View file

@ -7,10 +7,10 @@
class Foo
{
int m;
public:
Foo(int i) : m(i) {}
int get_m() { return m;}
int m;
};
std::shared_ptr<Foo> foo(Foo v) {
@ -45,10 +45,10 @@ std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) {
class Foo
{
int m;
public:
Foo(int i);
int get_m();
int m;
};
std::shared_ptr<Foo> foo(Foo v);
std::shared_ptr<const Foo> const_foo(Foo v);

View file

@ -15,11 +15,11 @@ class C;
%inline %{
class C {
int m;
public:
C() : m(-1) {}
C(int i) : m(i) {}
int get_m() { return m; }
int m;
};
%}

View file

@ -0,0 +1,89 @@
%module cpp11_shared_ptr_overload
// Tests to ensure valid overloading in C++ between shared_ptr and other types result in code that compiles
// and all but the 1st overloaded method are automatically ignored/shadowed.
// Tests the 'equivalent' attribute in the 'typecheck' typemap.
%include <std_string.i>
%include <std_shared_ptr.i>
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseA(std::shared_ptr<MyType> mytype);
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseB(int, std::shared_ptr<MyType> mytype);
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>);
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseX(MyType &mytype);
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseY(int, MyType &mytype);
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseZ(int, MyType &mytype, std::shared_ptr<MyType>);
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo1;
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo2;
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo3;
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo4;
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo5;
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo6;
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo7;
%shared_ptr(MyType);
%inline %{
#include <memory>
#include <string>
struct MyType {
std::string val;
MyType(std::string val = std::string()) : val(val) {}
};
// ref
std::string UseA(MyType &mytype) { return mytype.val + " ref"; }
std::string UseA(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
std::string UseB(int, MyType &mytype) { return mytype.val + " ref"; }
std::string UseB(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
std::string UseC(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
std::string UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
// sharedptr
std::string UseX(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
std::string UseX(MyType &mytype) { return mytype.val + " ref"; }
std::string UseY(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
std::string UseY(int, MyType &mytype) { return mytype.val + " ref"; }
std::string UseZ(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
std::string UseZ(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
// Combo1-4
std::string Combo1(MyType mytype) { return mytype.val + "Combo1"; }
std::string Combo1(MyType *mytype) { return ""; }
std::string Combo1(std::shared_ptr<MyType> mytype) { return ""; }
std::string Combo1(std::shared_ptr<MyType>* mytype) { return ""; }
std::string Combo2(MyType *mytype) { return mytype->val + "Combo2"; }
std::string Combo2(std::shared_ptr<MyType> mytype) { return ""; }
std::string Combo2(std::shared_ptr<MyType>* mytype) { return ""; }
std::string Combo2(MyType mytype) { return ""; }
std::string Combo3(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo3"; }
std::string Combo3(std::shared_ptr<MyType>* mytype) { return ""; }
std::string Combo3(MyType mytype) { return ""; }
std::string Combo3(MyType *mytype) { return ""; }
std::string Combo4(std::shared_ptr<MyType>* mytype) { return (*mytype)->val + "Combo4"; }
std::string Combo4(MyType mytype) { return ""; }
std::string Combo4(MyType *mytype) { return ""; }
std::string Combo4(std::shared_ptr<MyType> mytype) { return ""; }
// Combo5-7
std::string Combo5(MyType &mytype) { return mytype.val + "Combo5"; }
std::string Combo5(MyType *mytype) { return ""; }
std::string Combo5(std::shared_ptr<MyType> mytype) { return ""; }
std::string Combo6(MyType *mytype) { return mytype->val + "Combo6"; }
std::string Combo6(std::shared_ptr<MyType> mytype) { return ""; }
std::string Combo6(MyType &mytype) { return ""; }
std::string Combo7(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo7"; }
std::string Combo7(MyType &mytype) { return ""; }
std::string Combo7(MyType *mytype) { return ""; }
%}

View file

@ -16,19 +16,19 @@
%{
class Base {
int m;
public:
Base() : m(-1) {}
Base(int i) : m(i) {}
int get_m() { return m; }
int m;
};
class Derived : public Base {
int n;
public:
Derived() : n(-2) {}
Derived(int i) : n(i) {}
int get_n() { return n; }
int n;
};
typedef std::shared_ptr<Base> BasePtr;
@ -96,18 +96,18 @@ int base_num(std::map<int, BasePtr > v) {
%template(DerivedMap) std::map<int, std::shared_ptr<Derived> >;
class Base {
int m;
public:
Base();
int get_m();
int m;
};
class Derived : public Base {
int n;
public:
Derived();
Derived(int i);
int get_n();
int n;
};
typedef std::shared_ptr<Base> BasePtr;
@ -135,20 +135,20 @@ int base_num(std::map<int, BasePtr > v);
%inline %{
class Base2 {
int m;
public:
Base2() : m(-1) {}
Base2(int i) : m(i) {}
int get_m() { return m; }
int m;
};
class Derived2 : public Base2 {
int n;
public:
Derived2() : n(0) {}
Derived2(int i) : n(i) {}
int get_n_2() { return n; }
int n;
};
%}

View file

@ -29,6 +29,10 @@ CPP_TEST_CASES = \
li_boost_intrusive_ptr
CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
cpp11_strongly_typed_enumerations_simple \
include $(srcdir)/../common.mk

View file

@ -16,14 +16,23 @@ public class complextest_runme {
if ( complextest.Conjf(a) != Complex.Conjugate(a) )
throw new Exception("std::complex<float> test failed");
if ( complextest.Conj2(a) != Complex.Conjugate(a) )
throw new Exception("std::complex<double> test failed");
if ( complextest.Conjf2(a) != Complex.Conjugate(a) )
throw new Exception("std::complex<float> test failed");
var vec = new VectorStdCplx();
vec.Add(new Complex(1, 2));
vec.Add(new Complex(2, 3));
vec.Add(new Complex(4, 3));
vec.Add(new Complex(1, 0));
if ( complextest.Copy_h(vec).Count != 2 )
throw new Exception("vector<complex> test failed");
if ( complextest.CopyHalf(vec).Count != 2 )
throw new Exception("CopyHalf test failed");
if ( complextest.CopyHalfRef(vec).Count != 2 )
throw new Exception("CopyHalfRef test failed");
var p = new ComplexPair();
p.z1 = new Complex(0, 1);

View file

@ -16,6 +16,7 @@ Expected output if PrintDebug enabled:
Base - Val(444.555)
Base - Ref(444.555)
Base - Ptr(444.555)
Base - ConstPtrRef(444.555)
Base - FullyOverloaded(int 10)
Base - FullyOverloaded(bool 1)
Base - SemiOverloaded(int -678)
@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1)
Derived - Val(444.555)
Derived - Ref(444.555)
Derived - Ptr(444.555)
Derived - ConstPtrRef(444.555)
Derived - FullyOverloaded(int 10)
Derived - FullyOverloaded(bool 1)
Derived - SemiOverloaded(int -678)
@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1)
CSharpDerived - Val(444.555)
CSharpDerived - Ref(444.555)
CSharpDerived - Ptr(444.555)
CSharpDerived - ConstPtrRef(444.555)
CSharpDerived - FullyOverloaded(int 10)
CSharpDerived - FullyOverloaded(bool True)
CSharpDerived - SemiOverloaded(-678)
@ -59,7 +62,7 @@ public class runme
void run()
{
if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------ ");
if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------");
Caller myCaller = new Caller();
@ -85,7 +88,7 @@ public class runme
makeCalls(myCaller, myBase);
}
if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------ ");
if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------");
}
void makeCalls(Caller myCaller, Base myBase)
@ -99,6 +102,7 @@ public class runme
if (myCaller.ValCall(dh).val != dh.val) throw new Exception("failed");
if (myCaller.RefCall(dh).val != dh.val) throw new Exception("failed");
if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("failed");
if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("failed");
// Fully overloaded method test (all methods in base class are overloaded)
if (NAMESPACE + myCaller.FullyOverloadedCall(10) != myBase.GetType() + "::FullyOverloaded(int)") throw new Exception("failed");
@ -142,6 +146,11 @@ public class CSharpDerived : Base
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - Ptr({0})", x.val);
return x;
}
public override DoubleHolder ConstPtrRef(DoubleHolder x)
{
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - ConstPtrRef({0})", x.val);
return x;
}
public override String FullyOverloaded(int x)
{
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - FullyOverloaded(int {0})", x);

View file

@ -0,0 +1,111 @@
using System;
using li_boost_shared_ptr_directorNamespace;
public class li_boost_shared_ptr_director_runme {
private static void check(int got, int expected) {
if (got != expected)
throw new Exception("Failed, got: " + got + " expected: " + expected);
}
public static void Main() {
Derived a = new Derived(false);
Derived b = new Derived(true);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
check(li_boost_shared_ptr_director.call_take_c_by_value(a), 5);
check(li_boost_shared_ptr_director.call_take_c_by_ref(a), 6);
check(li_boost_shared_ptr_director.call_take_c_by_pointer(a), 7);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref(a), 8);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value(a), 9);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref(a), 10);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer(a), 11);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref(a), 12);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_with_null(a), -2);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref_with_null(a), -3);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value_with_null(a), -4);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref_with_null(a), -5);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_with_null(a), -6);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
}
}
class Derived : Base {
private bool return_none;
public Derived(bool flag) : base() {
this.return_none = flag;
}
public override C ret_c_shared_ptr() {
if (this.return_none)
return null;
else
return new C();
}
public override C ret_c_by_value() {
return new C();
}
public override int take_c_by_value(C c) {
return c.get_m();
}
public override int take_c_by_ref(C c) {
return c.get_m();
}
public override int take_c_by_pointer(C c) {
if (c != null)
return c.get_m();
else
return -2;
}
public override int take_c_by_pointer_ref(C c) {
if (c != null)
return c.get_m();
else
return -3;
}
public override int take_c_shared_ptr_by_value(C c) {
if (c != null)
return c.get_m();
else
return -4;
}
public override int take_c_shared_ptr_by_ref(C c) {
if (c != null)
return c.get_m();
else
return -5;
}
public override int take_c_shared_ptr_by_pointer(C c) {
if (c != null)
return c.get_m();
else
return -6;
}
public override int take_c_shared_ptr_by_pointer_ref(C c) {
if (c != null)
return c.get_m();
else
return -7;
}
}

View file

@ -177,6 +177,17 @@ public class li_std_vector_runme {
if (doubleArray[i] != dvCopy[i])
throw new Exception("Copy constructor failed, index:" + i);
}
if (dvCopy.Count != doubleArray.Length)
throw new Exception("Copy constructor lengths mismatch");
// ToArray test
double[] dvArray = dv.ToArray();
for (int i=0; i<doubleArray.Length; i++) {
if (doubleArray[i] != dvArray[i])
throw new Exception("ToArray failed, index:" + i);
}
if (dvArray.Length != doubleArray.Length)
throw new Exception("ToArray lengths mismatch");
}
{
// Repeat() test

View file

@ -24,6 +24,12 @@ CPP_TEST_CASES = \
d_nativepointers \
exception_partial_info
CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
include $(srcdir)/../common.mk
# Overridden variables here

View file

@ -18,6 +18,7 @@
* Base - Val(444.555)
* Base - Ref(444.555)
* Base - Ptr(444.555)
* Base - ConstPtrRef(444.555)
* Base - FullyOverloaded(int 10)
* Base - FullyOverloaded(bool 1)
* Base - SemiOverloaded(int -678)
@ -28,6 +29,7 @@
* Derived - Val(444.555)
* Derived - Ref(444.555)
* Derived - Ptr(444.555)
* Derived - ConstPtrRef(444.555)
* Derived - FullyOverloaded(int 10)
* Derived - FullyOverloaded(bool 1)
* Derived - SemiOverloaded(int -678)
@ -38,6 +40,7 @@
* DDerived - Val(444.555)
* DDerived - Ref(444.555)
* DDerived - Ptr(444.555)
* DDerived - ConstPtrRef(444.555)
* DDerived - FullyOverloaded(int 10)
* DDerived - FullyOverloaded(bool True)
* DDerived - SemiOverloaded(-678)
@ -57,7 +60,7 @@ import director_classes.Derived;
import director_classes.DoubleHolder;
void main() {
if (PrintDebug) Stdout.formatln("------------ Start ------------ ");
if (PrintDebug) Stdout.formatln("------------ Start ------------");
auto myCaller = new Caller();
@ -83,7 +86,7 @@ void main() {
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout.formatln("------------ Finish ------------ ");
if (PrintDebug) Stdout.formatln("------------ Finish ------------");
}
void makeCalls(Caller myCaller, Base myBase) {
@ -96,6 +99,7 @@ void makeCalls(Caller myCaller, Base myBase) {
if (myCaller.ValCall(dh).val != dh.val) throw new Exception("[1] failed");
if (myCaller.RefCall(dh).val != dh.val) throw new Exception("[2] failed");
if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("[3] failed");
if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("[3] failed");
// Fully overloaded method test (all methods in base class are overloaded)
if (myCaller.FullyOverloadedCall(10) != myBaseType ~ "::FullyOverloaded(int)") throw new Exception("[4] failed");
@ -136,6 +140,11 @@ public class DDerived : Base {
return x;
}
public override DoubleHolder ConstPtrRef(DoubleHolder x) {
if (PrintDebug) Stdout.formatln("DDerived - ConstPtrRef({0:d3})", x.val);
return x;
}
public override char[] FullyOverloaded(int x) {
if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(int {0})", x);
return "DDerived::FullyOverloaded(int)";

View file

@ -18,6 +18,7 @@
* Base - Val(444.555)
* Base - Ref(444.555)
* Base - Ptr(444.555)
* Base - ConstPtrRef(444.555)
* Base - FullyOverloaded(int 10)
* Base - FullyOverloaded(bool 1)
* Base - SemiOverloaded(int -678)
@ -28,6 +29,7 @@
* Derived - Val(444.555)
* Derived - Ref(444.555)
* Derived - Ptr(444.555)
* Derived - ConstPtrRef(444.555)
* Derived - FullyOverloaded(int 10)
* Derived - FullyOverloaded(bool 1)
* Derived - SemiOverloaded(int -678)
@ -38,6 +40,7 @@
* DDerived - Val(444.555)
* DDerived - Ref(444.555)
* DDerived - Ptr(444.555)
* DDerived - ConstPtrRef(444.555)
* DDerived - FullyOverloaded(int 10)
* DDerived - FullyOverloaded(bool true)
* DDerived - SemiOverloaded(-678)
@ -58,7 +61,7 @@ import director_classes.Derived;
import director_classes.DoubleHolder;
void main() {
if (PrintDebug) writeln("------------ Start ------------ ");
if (PrintDebug) writeln("------------ Start ------------");
auto myCaller = new Caller();
@ -84,7 +87,7 @@ void main() {
makeCalls(myCaller, myBase);
}
if (PrintDebug) writeln("------------ Finish ------------ ");
if (PrintDebug) writeln("------------ Finish ------------");
}
void makeCalls(Caller myCaller, Base myBase) {
@ -97,6 +100,7 @@ void makeCalls(Caller myCaller, Base myBase) {
enforce(myCaller.ValCall(dh).val == dh.val, "[1] failed");
enforce(myCaller.RefCall(dh).val == dh.val, "[2] failed");
enforce(myCaller.PtrCall(dh).val == dh.val, "[3] failed");
enforce(myCaller.ConstPtrRefCall(dh).val == dh.val, "[3] failed");
// Fully overloaded method test (all methods in base class are overloaded)
enforce(myCaller.FullyOverloadedCall(10) == myBaseType ~ "::FullyOverloaded(int)", "[4] failed");
@ -137,6 +141,11 @@ public class DDerived : Base {
return x;
}
public override DoubleHolder ConstPtrRef(DoubleHolder x) {
if (PrintDebug) writefln("DDerived - ConstPtrRef(%s)", x.val);
return x;
}
public override string FullyOverloaded(int x) {
if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x);
return "DDerived::FullyOverloaded(int)";

View file

@ -0,0 +1,114 @@
module li_boost_shared_ptr_director_runme;
import std.conv;
import std.exception;
import std.stdio;
import std.string;
import li_boost_shared_ptr_director.li_boost_shared_ptr_director;
import li_boost_shared_ptr_director.Base;
import li_boost_shared_ptr_director.C;
void check(int got, int expected) {
enforce(got == expected, "Failed. got: " ~ to!string(got) ~ " Expected: " ~ to!string(expected));
}
void main() {
Derived a = new Derived(false);
Derived b = new Derived(true);
check(call_ret_c_shared_ptr(a), 1);
check(call_ret_c_shared_ptr(b), -1);
check(call_ret_c_by_value(a), 1);
check(call_ret_c_shared_ptr(a), 1);
check(call_ret_c_shared_ptr(b), -1);
check(call_ret_c_by_value(a), 1);
check(call_take_c_by_value(a), 5);
check(call_take_c_by_ref(a), 6);
check(call_take_c_by_pointer(a), 7);
check(call_take_c_by_pointer_ref(a), 8);
check(call_take_c_shared_ptr_by_value(a), 9);
check(call_take_c_shared_ptr_by_ref(a), 10);
check(call_take_c_shared_ptr_by_pointer(a), 11);
check(call_take_c_shared_ptr_by_pointer_ref(a), 12);
check(call_take_c_by_pointer_with_null(a), -2);
check(call_take_c_by_pointer_ref_with_null(a), -3);
check(call_take_c_shared_ptr_by_value_with_null(a), -4);
check(call_take_c_shared_ptr_by_ref_with_null(a), -5);
check(call_take_c_shared_ptr_by_pointer_with_null(a), -6);
check(call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
}
public class Derived : Base {
private bool return_none;
public this(bool flag) {
super();
this.return_none = flag;
}
public override C ret_c_shared_ptr() {
if (this.return_none)
return null;
else
return new C();
}
public override C ret_c_by_value() {
return new C();
}
public override int take_c_by_value(C c) {
return c.get_m();
}
public override int take_c_by_ref(C c) {
return c.get_m();
}
public override int take_c_by_pointer(C c) {
if (c !is null)
return c.get_m();
else
return -2;
}
public override int take_c_by_pointer_ref(C c) {
if (c !is null)
return c.get_m();
else
return -3;
}
public override int take_c_shared_ptr_by_value(C c) {
if (c !is null)
return c.get_m();
else
return -4;
}
public override int take_c_shared_ptr_by_ref(C c) {
if (c !is null)
return c.get_m();
else
return -5;
}
public override int take_c_shared_ptr_by_pointer(C c) {
if (c !is null)
return c.get_m();
else
return -6;
}
public override int take_c_shared_ptr_by_pointer_ref(C c) {
if (c !is null)
return c.get_m();
else
return -7;
}
}

View file

@ -0,0 +1,30 @@
%module default_arg_expressions
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ptr;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) UsdGeomTokensPtr;
%immutable UsdGeomTokens;
%inline %{
struct Numbers {
int val;
int *ptr;
Numbers() : val(), ptr(&val) {}
};
struct TfToken {
Numbers val;
Numbers *ptr;
TfToken() : val(), ptr(&val) {}
};
struct Tokens {
const TfToken face;
const TfToken *pface;
Tokens() : face(), pface(&face) {}
};
static Tokens UsdGeomTokens;
static Tokens *UsdGeomTokensPtr = &UsdGeomTokens;
void CreateMaterialBindSubset1(const Tokens &elementType = UsdGeomTokens) {}
void CreateMaterialBindSubset2(int num = UsdGeomTokensPtr->pface->val.val) {}
void CreateMaterialBindSubset3(int num = UsdGeomTokensPtr->pface->ptr->val) {}
void CreateMaterialBindSubset4(int num = UsdGeomTokensPtr->face.val.val) {}
//void CreateMaterialBindSubset5(int num = UsdGeomTokens.face.val.val) {}
%}

View file

@ -28,6 +28,13 @@
int value_perm(int first, int mode = 0640 | 0004) { return mode; }
int value_m01(int first, int val = -01) { return val; }
bool booltest2(bool x = 0 | 1) { return x; }
int max_32bit_int1(int a = 0x7FFFFFFF) { return a; }
int max_32bit_int2(int a = 2147483647) { return a; }
int min_32bit_int1(int a = -0x80000000) { return a; }
long long too_big_32bit_int1(long long a = 0x80000000) { return a; }
long long too_big_32bit_int2(long long a = 2147483648LL) { return a; }
long long too_small_32bit_int1(long long a = -0x80000001) { return a; }
long long too_small_32bit_int2(long long a = -2147483649LL) { return a; }
};
void doublevalue1(int first, double num = 0.0e-1) {}

View file

@ -1,5 +1,13 @@
%module default_args_c
%{
#if defined(__clang__)
#pragma clang diagnostic push
// Suppress: use of logical '||' with constant operand
#pragma clang diagnostic ignored "-Wconstant-logical-operand"
#endif
%}
/* Default arguments for C code */
int foo1(int x = 42 || 3);
int foo43(int x = 42 | 3);

View file

@ -3,6 +3,7 @@
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ref;
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ptr;
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::ConstPtrRef;
%module(directors="1") director_classes
@ -43,6 +44,7 @@ public:
virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Base - Val(" << x.val << ")" << std::endl; return x; }
virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Base - Ref(" << x.val << ")" << std::endl; return x; }
virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Base - Ptr(" << x->val << ")" << std::endl; return x; }
virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Base - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; }
virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(int " << x << ")" << std::endl; return "Base::FullyOverloaded(int)"; }
virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(bool " << x << ")" << std::endl; return "Base::FullyOverloaded(bool)"; }
@ -68,6 +70,7 @@ public:
virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Derived - Val(" << x.val << ")" << std::endl; return x; }
virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Derived - Ref(" << x.val << ")" << std::endl; return x; }
virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Derived - Ptr(" << x->val << ")" << std::endl; return x; }
virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Derived - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; }
virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(int " << x << ")" << std::endl; return "Derived::FullyOverloaded(int)"; }
virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(bool " << x << ")" << std::endl; return "Derived::FullyOverloaded(bool)"; }
@ -99,6 +102,7 @@ public:
DoubleHolder ValCall(DoubleHolder x) { return m_base->Val(x); }
DoubleHolder& RefCall(DoubleHolder& x) { return m_base->Ref(x); }
DoubleHolder* PtrCall(DoubleHolder* x) { return m_base->Ptr(x); }
DoubleHolder *const& ConstPtrRefCall(DoubleHolder *const& cprx) { return m_base->ConstPtrRef(cprx); }
std::string FullyOverloadedCall(int x) { return m_base->FullyOverloaded(x); }
std::string FullyOverloadedCall(bool x) { return m_base->FullyOverloaded(x); }
std::string SemiOverloadedCall(int x) { return m_base->SemiOverloaded(x); }

View file

@ -20,14 +20,10 @@
#ifndef SWIG_DIRECTORS
namespace Swig {
class DirectorException {};
class DirectorMethodException: public Swig::DirectorException {};
class DirectorException {};
class DirectorMethodException: public Swig::DirectorException {};
}
#ifndef SWIG_fail
#define SWIG_fail
#endif
#endif /* !SWIG_DIRECTORS */
%}
%include "std_string.i"
@ -41,8 +37,8 @@ class DirectorMethodException: public Swig::DirectorException {};
}
%exception {
try { $action }
catch (Swig::DirectorException &) { SWIG_fail; }
try { $action }
catch (Swig::DirectorException &) { SWIG_fail; }
}
#endif
@ -56,8 +52,8 @@ class DirectorMethodException: public Swig::DirectorException {};
}
%exception {
try { $action }
catch (Swig::DirectorException &) { SWIG_fail; }
try { $action }
catch (Swig::DirectorException &) { SWIG_fail; }
}
#endif
@ -75,12 +71,12 @@ class DirectorMethodException: public Swig::DirectorException {};
// Change back to old 2.0 default behavior
%feature("director:except") {
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
// Dont clear exception, still be active when return to java execution
// Essentially ignore exception occurred -- old behavior.
return $null;
}
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
// Dont clear exception, still be active when return to java execution
// Essentially ignore exception occurred -- old behavior.
return $null;
}
}
#endif

View file

@ -0,0 +1,25 @@
%module(directors="1") director_exception_catches
%include <std_string.i>
%feature("director") BaseClass;
%{
// define dummy director exception classes to prevent spurious errors
// in target languages that do not support directors.
#ifndef SWIG_DIRECTORS
namespace Swig {
class DirectorException {};
}
#endif /* !SWIG_DIRECTORS */
%}
%catches(Swig::DirectorException) BaseClass::call_description;
%inline %{
struct BaseClass {
virtual std::string description() const = 0;
static std::string call_description(BaseClass& bc) { return bc.description(); }
virtual ~BaseClass() {}
};
%}

View file

@ -0,0 +1,72 @@
%module(directors="1") director_ownership
// Github issue #1184
%include "std_string.i"
%feature("director") example::ContentBase;
%feature("director") example::ContentDerived;
%newobject example::make_content;
%inline %{
#include <string>
namespace example
{
class ContentBase
{
public:
ContentBase() {}
virtual ~ContentBase() {}
virtual std::string get_name() const = 0;
};
class ContentDerived: public ContentBase
{
public:
ContentDerived():ContentBase() { m_name = "ContentDerived"; }
virtual ~ContentDerived() {}
virtual std::string get_name() const { return m_name; }
private:
std::string m_name;
};
class Container
{
public:
Container() { m_content = 0; }
~Container()
{
clear_content();
}
// the container takes the ownership of the content
void set_content(ContentBase* content)
{
clear_content();
m_content = content;
}
ContentBase* get_content() { return m_content; }
private:
void clear_content()
{
if(m_content)
{
delete m_content;
m_content = 0;
}
}
private:
ContentBase* m_content;
};
static ContentBase* make_content() { return new ContentDerived(); }
} // namespace example
%}

View file

@ -0,0 +1,4 @@
%module xxx
void bad(double nn = 5e);

View file

@ -0,0 +1,2 @@
cpp_invalid_exponents1.i:3: Error: Exponent does not have any digits
cpp_invalid_exponents1.i:3: Error: Syntax error in input(1).

View file

@ -0,0 +1,4 @@
%module xxx
void bad(double nn = 6.6e);

View file

@ -0,0 +1,2 @@
cpp_invalid_exponents2.i:3: Error: Exponent does not have any digits
cpp_invalid_exponents2.i:3: Error: Syntax error in input(1).

View file

@ -0,0 +1,51 @@
%module cpp_template_duplicate_names
// From test-suite/template_class_reuse.i test
%{
namespace Space {
template <bool B> struct Duplicate1 { void f(){}; };
}
%}
// %warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate1;
namespace Space {
template <bool B> struct Duplicate1 { void f(){}; };
template <bool B> struct Duplicate1 { void f(){}; };
}
// %warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate2;
%inline %{
namespace Space {
template <int I> struct Duplicate2 { void n(){}; };
}
%}
%template(Duplicate2_0) Space::Duplicate2<0>;
%template(Duplicate2_0) Space::Duplicate2<0>;
// %warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate3;
%inline %{
namespace Space {
template <int I> struct Duplicate3 { void n(){}; };
}
%}
%template(Duplicate3) Space::Duplicate3<0>;
%template(Duplicate3) Space::Duplicate3<0>;
%{
namespace Space {
template <bool B> struct Duplicate4 { void f(){}; };
}
%}
// %warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate4;
namespace Space {
template <bool B> struct Duplicate4 { void f(){}; };
template <bool B> struct Duplicate4 { void f(){}; };
}
%template(Duplicate4) Space::Duplicate4<0>;
%template(Duplicate4) Space::Duplicate4<0>;

View file

@ -0,0 +1,14 @@
cpp_template_duplicate_names.i:14: Warning 302: Identifier 'Duplicate1' redefined (ignored),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:14: Warning 302: Identifier 'Duplicate1' redefined (ignored),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:25: Warning 302: Identifier 'Duplicate2_0' redefined (ignored) (Renamed from 'Duplicate2< 0 >'),
cpp_template_duplicate_names.i:24: Warning 302: previous definition of 'Duplicate2_0' (Renamed from 'Duplicate2< 0 >').
cpp_template_duplicate_names.i:35: Warning 302: Identifier 'Duplicate3' redefined (ignored) (Renamed from 'Duplicate3< 0 >'),
cpp_template_duplicate_names.i:31: Warning 302: previous definition of 'Duplicate3'.
cpp_template_duplicate_names.i:47: Warning 302: Identifier 'Duplicate4' redefined (ignored),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:47: Warning 302: Identifier 'Duplicate4' redefined (ignored),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:50: Warning 302: Identifier 'Duplicate4' redefined (ignored) (Renamed from 'Duplicate4< 0 >'),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.

View file

@ -0,0 +1,43 @@
%module xxx
/* Note: needs -Wextra to see these warnings */
/* Divide by zero */
#define ZERO 0
#if 1%ZERO
#endif
#if 2/ZERO
#endif
#if 1%(5-5)
#endif
#if 2/(55-55)
#endif
/* Floating point */
#if 1.2
#endif
#if 2e3
#endif
#if 0
#elif 8.8
#endif
/* Missing whitespace after preproc directive */
#if123
#endif
#if456e
#endif
#if 0
#warning This should not warn
#elif1
#warning This should also not warn
#endif
#if(1)
#warning Warning okay: #if(1)
#endif

View file

@ -0,0 +1,19 @@
pp_expressions_bad.i:7: Warning 202: Could not evaluate expression '1%ZERO'
pp_expressions_bad.i:7: Warning 202: Error: 'Modulo by zero in expression'
pp_expressions_bad.i:9: Warning 202: Could not evaluate expression '2/ZERO'
pp_expressions_bad.i:9: Warning 202: Error: 'Division by zero in expression'
pp_expressions_bad.i:12: Warning 202: Could not evaluate expression '1%(5-5)'
pp_expressions_bad.i:12: Warning 202: Error: 'Modulo by zero in expression'
pp_expressions_bad.i:14: Warning 202: Could not evaluate expression '2/(55-55)'
pp_expressions_bad.i:14: Warning 202: Error: 'Division by zero in expression'
pp_expressions_bad.i:18: Warning 202: Could not evaluate expression '1.2'
pp_expressions_bad.i:18: Warning 202: Error: 'Floating point constant in preprocessor expression'
pp_expressions_bad.i:21: Warning 202: Could not evaluate expression '2e3'
pp_expressions_bad.i:21: Warning 202: Error: 'Floating point constant in preprocessor expression'
pp_expressions_bad.i:25: Warning 202: Could not evaluate expression '8.8'
pp_expressions_bad.i:25: Warning 202: Error: 'Floating point constant in preprocessor expression'
pp_expressions_bad.i:29: Error: Unknown SWIG preprocessor directive: if123 (if this is a block of target language code, delimit it with %{ and %})
pp_expressions_bad.i:30: Error: Extraneous #endif.
pp_expressions_bad.i:32: Error: Unknown SWIG preprocessor directive: if456e (if this is a block of target language code, delimit it with %{ and %})
pp_expressions_bad.i:33: Error: Extraneous #endif.
pp_expressions_bad.i:42: Warning 204: CPP #warning, "Warning okay: #if(1)".

View file

@ -0,0 +1,7 @@
%module xxx
#if 123e
#endif
#if 456.e
#endif

View file

@ -0,0 +1,6 @@
:EOF: Error: Exponent does not have any digits
pp_invalid_exponents.i:3: Warning 202: Could not evaluate expression '123e'
pp_invalid_exponents.i:3: Warning 202: Error: 'Syntax error'
:EOF: Error: Exponent does not have any digits
pp_invalid_exponents.i:6: Warning 202: Could not evaluate expression '456.e'
pp_invalid_exponents.i:6: Warning 202: Error: 'Syntax error'

View file

@ -6,6 +6,10 @@
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
#endif
%}
%{
@ -49,3 +53,11 @@ class Impl
#warning "UTL needs fixing for partial exception information"
#endif
%{
#if defined(_MSC_VER)
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
%}

View file

@ -14,8 +14,8 @@
(check (=~ (foo 1 2 "bar" 4) 15))
;; Check second method
(check (=~ (foo 1 2) 4811.4))
(check (=~ (foo 1 2 3.2) 4797.2))
(check (=~ (foo 1 2 3.2 #\Q) 4798.2))
(check (=~ (foo 1 2) 118))
(check (=~ (foo 1 2 3.2) 104))
(check (=~ (foo 1 2 3.2 #\Q) 4798))
(exit 0)

View file

@ -44,6 +44,10 @@ template<class T> class vector {
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
#endif
class Base {
public:
@ -70,6 +74,9 @@ public:
#if defined(_MSC_VER)
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
#if __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
%}
%template(maxint) maximum<int>;

View file

@ -47,6 +47,10 @@ CPP_TEST_CASES = \
# li_boost_intrusive_ptr
CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
cpp11_strongly_typed_enumerations_simple \
DOXYGEN_TEST_CASES := \

View file

@ -22,7 +22,7 @@ public class class_scope_namespace_runme {
F f = new F();
G g = new G();
H.HH h = new H.HH();
I.II i = new I.II();
I_.II i = new I_.II();
J j = new J();
K k = new K();
L l = new L();

View file

@ -0,0 +1,60 @@
import cpp11_shared_ptr_overload.*;
public class cpp11_shared_ptr_overload_runme {
static {
try {
System.loadLibrary("cpp11_shared_ptr_overload");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
String ret = null;
// ref
ret = cpp11_shared_ptr_overload.UseA(new MyType("123"));
if (!ret.equals("123 ref")) throw new RuntimeException("UseA fail:" + ret);
ret = cpp11_shared_ptr_overload.UseB(0, new MyType("123"));
if (!ret.equals("123 ref")) throw new RuntimeException("UseB fail:" + ret);
ret = cpp11_shared_ptr_overload.UseC(0, new MyType("123"), new MyType("456"));
if (!ret.equals("123 ref")) throw new RuntimeException("UseC fail:" + ret);
// sharedptr
ret = cpp11_shared_ptr_overload.UseX(new MyType("123"));
if (!ret.equals("123 sharedptr")) throw new RuntimeException("UseX fail:" + ret);
ret = cpp11_shared_ptr_overload.UseY(0, new MyType("123"));
if (!ret.equals("123 sharedptr")) throw new RuntimeException("UseY fail:" + ret);
ret = cpp11_shared_ptr_overload.UseZ(0, new MyType("123"), new MyType("456"));
if (!ret.equals("123 sharedptr")) throw new RuntimeException("UseZ fail:" + ret);
// Combo1-4
ret = cpp11_shared_ptr_overload.Combo1(new MyType("XXX"));
if (!ret.equals("XXXCombo1")) throw new RuntimeException("Combo1 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo2(new MyType("XXX"));
if (!ret.equals("XXXCombo2")) throw new RuntimeException("Combo2 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo3(new MyType("XXX"));
if (!ret.equals("XXXCombo3")) throw new RuntimeException("Combo3 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo4(new MyType("XXX"));
if (!ret.equals("XXXCombo4")) throw new RuntimeException("Combo4 fail:" + ret);
// Combo5-7
ret = cpp11_shared_ptr_overload.Combo5(new MyType("XXX"));
if (!ret.equals("XXXCombo5")) throw new RuntimeException("Combo5 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo6(new MyType("XXX"));
if (!ret.equals("XXXCombo6")) throw new RuntimeException("Combo6 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo7(new MyType("XXX"));
if (!ret.equals("XXXCombo7")) throw new RuntimeException("Combo7 fail:" + ret);
}
}

View file

@ -16,6 +16,7 @@ Expected output if PrintDebug enabled:
Base - Val(444.555)
Base - Ref(444.555)
Base - Ptr(444.555)
Base - ConstPtrRef(444.555)
Base - FullyOverloaded(int 10)
Base - FullyOverloaded(bool 1)
Base - SemiOverloaded(int -678)
@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1)
Derived - Val(444.555)
Derived - Ref(444.555)
Derived - Ptr(444.555)
Derived - ConstPtrRef(444.555)
Derived - FullyOverloaded(int 10)
Derived - FullyOverloaded(bool 1)
Derived - SemiOverloaded(int -678)
@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1)
JavaDerived - Val(444.555)
JavaDerived - Ref(444.555)
JavaDerived - Ptr(444.555)
JavaDerived - ConstPtrRef(444.555)
JavaDerived - FullyOverloaded(int 10)
JavaDerived - FullyOverloaded(bool True)
JavaDerived - SemiOverloaded(-678)
@ -67,7 +70,7 @@ public class director_classes_runme {
void run()
{
if (director_classes.getPrintDebug()) System.out.println("------------ Start ------------ ");
if (director_classes.getPrintDebug()) System.out.println("------------ Start ------------");
Caller myCaller = new Caller();
@ -96,7 +99,7 @@ public class director_classes_runme {
myBase.delete();
}
if (director_classes.getPrintDebug()) System.out.println("------------ Finish ------------ ");
if (director_classes.getPrintDebug()) System.out.println("------------ Finish ------------");
}
void makeCalls(Caller myCaller, Base myBase)
@ -111,6 +114,7 @@ public class director_classes_runme {
if (myCaller.ValCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
if (myCaller.RefCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
if (myCaller.PtrCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
if (myCaller.ConstPtrRefCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
// Fully overloaded method test (all methods in base class are overloaded)
if (!myCaller.FullyOverloadedCall(10).equals(baseSimpleName + "::FullyOverloaded(int)")) {
@ -170,6 +174,11 @@ class JavaDerived extends Base
if (director_classes.getPrintDebug()) System.out.println("JavaDerived - Ptr(" + x.getVal() + ")");
return x;
}
public DoubleHolder ConstPtrRef(DoubleHolder x)
{
if (director_classes.getPrintDebug()) System.out.println("JavaDerived - ConstPtrRef(" + x.getVal() + ")");
return x;
}
public String FullyOverloaded(int x)
{
if (director_classes.getPrintDebug()) System.out.println("JavaDerived - FullyOverloaded(int " + x + ")");

View file

@ -0,0 +1,35 @@
import director_exception_catches.*;
public class director_exception_catches_runme {
static {
try {
System.loadLibrary("director_exception_catches");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) {
BaseClass b = new director_exception_catches_MyClass();
try {
String s = BaseClass.call_description(b);
throw new RuntimeException("Failed to catch exception");
} catch (NullPointerException e) {
if (!e.getMessage().startsWith("Testing exception thrown in BaseClass.description"))
throw new RuntimeException("Unexpected exception message: " + e.getMessage());
}
}
}
class director_exception_catches_MyClass extends BaseClass {
@Override
public String description() {
throw new NullPointerException("Testing exception thrown in BaseClass.description");
}
}

View file

@ -0,0 +1,42 @@
import director_ownership.*;
public class director_ownership_runme {
static {
try {
System.loadLibrary("director_ownership");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void set_content_and_release(Container container, ContentBase content) {
content.swigReleaseOwnership();
container.set_content(content);
}
public static void main(String argv[]) {
Container container = new Container();
// make a content in java (cMemoryOwn true)
ContentBase content_java = new ContentDerived();
// make a content in c++ (cMemoryOwn true)
ContentBase content_cpp = director_ownership.make_content();
set_content_and_release(container, content_java);
if (!container.get_content().get_name().equals("ContentDerived"))
throw new RuntimeException("did not get ContentDerived");
// when swigReleaseOwnership() is called on content_cpp, swig tries a static_cast to director and calls the method
// director->swig_java_change_ownership. The content created in c++ native library is not a director, therefore a
// segfault may occur.
// With a check done using dynamic_cast this issue could be avoided.
set_content_and_release(container, content_cpp);
if (!container.get_content().get_name().equals("ContentDerived"))
throw new RuntimeException("did not get ContentDerived");
}
}

View file

@ -126,19 +126,28 @@ public class java_director_exception_feature_nspace_runme {
try { b.genericpong(1); fail("No exception thrown in genericpong(1)"); }
catch (MyJavaException1 e) {
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_nspace_MyFooDirectorImpl.genericpong(java_director_exception_feature_nspace_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(2); fail("No exception thrown in genericpong(2)");}
catch (java_director_exception_feature_nspace_NewCheckedException e) {
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_nspace_MyFooDirectorImpl.genericpong(java_director_exception_feature_nspace_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(3); fail("No exception thrown in genericpong(3)");}
catch (java_director_exception_feature_nspace_NewUncheckedException e) {
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_nspace_MyFooDirectorImpl.genericpong(java_director_exception_feature_nspace_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(4); fail("No exception thrown in genericpong(4)");}
catch (RuntimeException e) {
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RumtimeException");
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RuntimeException");
failif( ! "Unspecified DirectorException message".equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
}
}
catch (Exception e) {

View file

@ -127,19 +127,28 @@ public class java_director_exception_feature_runme {
try { b.genericpong(1); fail("No exception thrown in genericpong(1)"); }
catch (MyJavaException1 e) {
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_MyFooDirectorImpl.genericpong(java_director_exception_feature_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(2); fail("No exception thrown in genericpong(2)");}
catch (NewCheckedException e) {
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_MyFooDirectorImpl.genericpong(java_director_exception_feature_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(3); fail("No exception thrown in genericpong(3)");}
catch (NewUncheckedException e) {
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_MyFooDirectorImpl.genericpong(java_director_exception_feature_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(4); fail("No exception thrown in genericpong(4)");}
catch (RuntimeException e) {
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RumtimeException");
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP4.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RuntimeException");
failif( ! "Unspecified DirectorException message".equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
}
}

View file

@ -93,6 +93,28 @@ public class java_throws_runme {
if (!pass)
throw new RuntimeException("Test 6 failed");
// Interface function
pass = false;
try {
InterfaceTestImpl iti = new InterfaceTestImpl();
iti.imethod(true);
}
catch (MyException e) { pass = true; }
if (!pass)
throw new RuntimeException("Test interface 1 failed");
pass = false;
try {
InterfaceTestImpl iti = new InterfaceTestImpl();
iti.imethod(false);
pass = true;
}
catch (MyException e) { pass = false; }
if (!pass)
throw new RuntimeException("Test interface 2 failed");
// Global function
pass = false;
try {

View file

@ -1,60 +1,129 @@
public class li_boost_shared_ptr_runme {
import li_boost_shared_ptr_director.*;
public class li_boost_shared_ptr_director_runme {
static {
try {
System.loadLibrary("li_boost_shared_ptr");
System.loadLibrary("li_boost_shared_ptr_director");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
private static void check(String got, String expected) {
if (!got.equals(expected))
private static void check(int got, int expected) {
if (got != expected)
throw new RuntimeException("Failed, got: " + got + " expected: " + expected);
}
public static void main(String argv[]) {
li_boost_shared_ptr_director_Derived a = li_boost_shared_ptr_director_Derived.new(false);
li_boost_shared_ptr_director_Derived b = li_boost_shared_ptr_director_Derived.new(true);
li_boost_shared_ptr_director_Derived a = new li_boost_shared_ptr_director_Derived(false);
li_boost_shared_ptr_director_Derived b = new li_boost_shared_ptr_director_Derived(true);
check(call_ret_c_shared_ptr(a) == 1);
check(call_ret_c_shared_ptr(b) == -1);
check(call_ret_c_by_value(a) == 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
check(call_take_c_by_value(a) == 5);
check(call_take_c_shared_ptr_by_value(a) == 6);
check(call_take_c_shared_ptr_by_ref(a) == 7);
check(call_take_c_shared_ptr_by_pointer(a) == 8);
check(call_take_c_shared_ptr_by_pointer_ref(a) == 9);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
check(call_take_c_shared_ptr_by_value_with_null(a) == -2);
check(call_take_c_shared_ptr_by_ref_with_null(a) == -3);
check(call_take_c_shared_ptr_by_pointer_with_null(a) == -4);
check(call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -5);
check(li_boost_shared_ptr_director.call_take_c_by_value(a), 5);
check(li_boost_shared_ptr_director.call_take_c_by_ref(a), 6);
check(li_boost_shared_ptr_director.call_take_c_by_pointer(a), 7);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref(a), 8);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value(a), 9);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref(a), 10);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer(a), 11);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref(a), 12);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_with_null(a), -2);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref_with_null(a), -3);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value_with_null(a), -4);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref_with_null(a), -5);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_with_null(a), -6);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
}
}
class li_boost_shared_ptr_director_Derived extends li_boost_shared_ptr_director.Base {
class li_boost_shared_ptr_director_Derived extends Base {
@Override
public String ping() {
return "li_boost_shared_ptr_director_MyBarFoo.ping()";
private boolean return_none;
li_boost_shared_ptr_director_Derived(boolean flag) {
super();
this.return_none = flag;
}
@Override
public String pong() {
return "li_boost_shared_ptr_director_MyBarFoo.pong();" + ping();
public C ret_c_shared_ptr() {
if (this.return_none)
return null;
else
return new C();
}
@Override
public String upcall(li_boost_shared_ptr_director.FooBar fooBarPtr) {
return "override;" + fooBarPtr.FooBarDo();
public C ret_c_by_value() {
return new C();
}
@Override
public li_boost_shared_ptr_director.Foo makeFoo() {
return new li_boost_shared_ptr_director.Foo();
public int take_c_by_value(C c) {
return c.get_m();
}
@Override
public int take_c_by_ref(C c) {
return c.get_m();
}
@Override
public int take_c_by_pointer(C c) {
if (c != null)
return c.get_m();
else
return -2;
}
@Override
public int take_c_by_pointer_ref(C c) {
if (c != null)
return c.get_m();
else
return -3;
}
@Override
public int take_c_shared_ptr_by_value(C c) {
if (c != null)
return c.get_m();
else
return -4;
}
@Override
public int take_c_shared_ptr_by_ref(C c) {
if (c != null)
return c.get_m();
else
return -5;
}
@Override
public int take_c_shared_ptr_by_pointer(C c) {
if (c != null)
return c.get_m();
else
return -6;
}
@Override
public int take_c_shared_ptr_by_pointer_ref(C c) {
if (c != null)
return c.get_m();
else
return -7;
}
}

View file

@ -0,0 +1,57 @@
import template_class_reuse_name.*;
public class template_class_reuse_name_runme {
static {
try {
System.loadLibrary("template_class_reuse_name");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
new Bool1().tt();
new Bool1False().ff();
new Bool2().tt();
new Bool2False().ff();
new Bool3().tt();
new Bool3False().ff();
new Bool4().tt();
new Bool4False().ff();
new BoolForward1().tt();
new BoolForward1False().ff();
new BoolForward2().tt();
new BoolForward2False().ff();
new BoolForward3().tt();
new BoolForward3False().ff();
new BoolForward4().tt();
new BoolForward4False().ff();
new IntBool1().tt();
new IntBool1False().ff();
new IntBool2().tt();
new IntBool2False().ff();
new IntBool3().tt();
new IntBool3False().ff();
new IntBool4().tt();
new IntBool4False().ff();
new Duplicate2_0().n();
new Duplicate3().n();
}
}

View file

@ -23,10 +23,10 @@ public class template_partial_specialization_runme {
new G().g();
new H().h();
new I().i();
new J().j();
new K().k();
new L().l();
new M().m();
new N().n();
new BB().b();
new BBB().b();

View file

@ -23,10 +23,10 @@ public class template_partial_specialization_typedef_runme {
new G().g();
new H().h();
new I().i();
new J().j();
new K().k();
new L().l();
new M().m();
new N().n();
new BB().b();
new BBB().b();

View file

@ -0,0 +1,26 @@
import typedef_classforward_same_name.*;
public class typedef_classforward_same_name_runme {
static {
try {
System.loadLibrary("typedef_classforward_same_name");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) {
Foo foo = new Foo();
foo.setX(5);
if (typedef_classforward_same_name.extractFoo(foo) != 5)
throw new RuntimeException("unexpected value");
Boo boo = new Boo();
boo.setX(5);
if (typedef_classforward_same_name.extractBoo(boo) != 5)
throw new RuntimeException("unexpected value");
}
}

View file

@ -42,7 +42,6 @@
%feature("director:except") MyNS::Foo::ping {
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
jenv->ExceptionClear(); // clear java exception since mapping to c++ exception
if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyJavaException1")) {
throw 1;
} else if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyJavaException2")) {
@ -71,7 +70,6 @@
%feature("director:except") MyNS::Foo::pong %{
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
jenv->ExceptionClear();
$directorthrowshandlers
throw ::MyNS::Unexpected(Swig::JavaExceptionMessage(jenv,$error).message());
}
@ -121,7 +119,10 @@
%feature("director:except") MyNS::Foo::genericpong {
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
jenv->ExceptionClear();
if (Swig::ExceptionMatches(jenv,$error,"UnconstructableException")) {
// Purposefully test NULL
throw Swig::DirectorException(jenv, NULL);
}
throw Swig::DirectorException(jenv,$error);
}
}
@ -131,9 +132,10 @@
%}
%feature ("except",throws="Exception") MyNS::Bar::genericpong %{
try { $action }
catch (Swig::DirectorException & direxcp) {
direxcp.raiseJavaException(jenv); // jenv always available in JNI code
try {
$action
} catch (Swig::DirectorException & direxcp) {
direxcp.throwException(jenv); // jenv always available in JNI code
return $null;
}
%}

View file

@ -49,7 +49,6 @@
%feature("director:except") MyNS::Foo::ping {
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
jenv->ExceptionClear(); // clear java exception since mapping to c++ exception
if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyNS/MyJavaException1")) {
throw 1;
} else if (Swig::ExceptionMatches(jenv,$error,"$packagepath/MyNS/MyJavaException2")) {
@ -78,7 +77,6 @@
%feature("director:except") MyNS::Foo::pong %{
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
jenv->ExceptionClear();
$directorthrowshandlers
throw ::MyNS::Unexpected(Swig::JavaExceptionMessage(jenv,$error).message());
}
@ -128,7 +126,10 @@
%feature("director:except") MyNS::Foo::genericpong {
jthrowable $error = jenv->ExceptionOccurred();
if ($error) {
jenv->ExceptionClear();
if (Swig::ExceptionMatches(jenv,$error,"java_director_exception_feature_nspace_UnconstructibleException")) {
// Purposefully test NULL
throw Swig::DirectorException(jenv, NULL);
}
throw Swig::DirectorException(jenv,$error);
}
}
@ -138,9 +139,10 @@
%}
%feature ("except",throws="Exception") MyNS::Bar::genericpong %{
try { $action }
catch (Swig::DirectorException & direxcp) {
direxcp.raiseJavaException(jenv); // jenv always available in JNI code
try {
$action
} catch (Swig::DirectorException & direxcp) {
direxcp.throwException(jenv); // jenv always available in JNI code
return $null;
}
%}

View file

@ -135,6 +135,24 @@ JAVAEXCEPTION(FeatureTest::staticMethod)
};
%}
%include <swiginterface.i>
%interface_impl(InterfaceTest);
JAVAEXCEPTION(imethod)
%inline %{
struct InterfaceTest {
virtual void imethod(bool raise) = 0;
virtual ~InterfaceTest() {}
};
struct InterfaceTestImpl : InterfaceTest {
void imethod(bool raise) {
if (raise)
throw MyException("raise message");
}
};
%}
// Mixing except feature and typemaps when both generate a class for the throws clause
%typemap(in, throws="ClassNotFoundException") int both {
$1 = (int)$input;

View file

@ -8,8 +8,16 @@ a_c = complextest.Conj(a);
if (a_c.toString() != expected.toString())
throw "Error in Conj(a)";
a_c_f = complextest.Conjf(a);
if (a_c_f.toString() != expected.toString())
a_c = complextest.Conjf(a);
if (a_c.toString() != expected.toString())
throw "Error in Conjf(a)";
a_c = complextest.Conj2(a);
if (a_c.toString() != expected.toString())
throw "Error in Conj(a)";
a_c = complextest.Conjf2(a);
if (a_c.toString() != expected.toString())
throw "Error in Conjf(a)";
v = new complextest.VectorStdCplx();
@ -19,4 +27,5 @@ v.add([4,3]);
v.add(1);
// TODO: how to check validity?
complextest.Copy_h(v);
complextest.CopyHalf(v);
complextest.CopyHalfRef(v);

View file

@ -4,7 +4,13 @@
#include <boost/shared_ptr.hpp>
%}
%include "boost_shared_ptr.i";
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
%include <boost_shared_ptr.i>
%shared_ptr(C);
%feature("director") Base;
@ -13,6 +19,7 @@ struct C {
C() : m(1) {}
C(int n) : m(n) {}
int get_m() { return m; }
private:
int m;
};
@ -21,10 +28,23 @@ struct Base {
virtual boost::shared_ptr<C> ret_c_shared_ptr() = 0;
virtual C ret_c_by_value() = 0;
virtual int take_c_by_value(C c) = 0;
virtual int take_c_by_ref(C& c) = 0;
virtual int take_c_by_pointer(C* c) = 0;
virtual int take_c_by_pointer_ref(C*const& c) = 0;
virtual int take_c_shared_ptr_by_value(boost::shared_ptr<C> c) = 0;
virtual int take_c_shared_ptr_by_ref(boost::shared_ptr<C>& c) = 0;
virtual int take_c_shared_ptr_by_pointer(boost::shared_ptr<C>* c) = 0;
virtual int take_c_shared_ptr_by_pointer_ref(boost::shared_ptr<C>*const&c) = 0;
virtual int take_many_args(
C v1, C v2,
C &r1, C &r2,
C *p1, C *p2,
C *const& cr1, C *const& cr2,
boost::shared_ptr<C> sv1, boost::shared_ptr<C> sv2,
boost::shared_ptr<C> &sr1, boost::shared_ptr<C> &sr2,
boost::shared_ptr<C> *sp1, boost::shared_ptr<C> *sp2,
boost::shared_ptr<C> *const& spr1, boost::shared_ptr<C> *const& spr2
) = 0;
virtual ~Base() {}
};
@ -47,8 +67,34 @@ int call_take_c_by_value(Base* b) {
return b->take_c_by_value(c);
}
int call_take_c_by_ref(Base* b) {
C c(6);
return b->take_c_by_ref(c);
}
int call_take_c_by_pointer(Base* b) {
C c(7);
return b->take_c_by_pointer(&c);
}
int call_take_c_by_pointer_ref(Base* b) {
C c(8);
C* p(&c);
return b->take_c_by_pointer_ref(p);
}
int call_take_c_by_pointer_with_null(Base* b) {
C* p = NULL;
return b->take_c_by_pointer(p);
}
int call_take_c_by_pointer_ref_with_null(Base* b) {
C* p = NULL;
return b->take_c_by_pointer_ref(p);
}
int call_take_c_shared_ptr_by_value(Base* b) {
boost::shared_ptr<C> ptr(new C(6));
boost::shared_ptr<C> ptr(new C(9));
return b->take_c_shared_ptr_by_value(ptr);
}
@ -58,7 +104,7 @@ int call_take_c_shared_ptr_by_value_with_null(Base* b) {
}
int call_take_c_shared_ptr_by_ref(Base* b) {
boost::shared_ptr<C> ptr(new C(7));
boost::shared_ptr<C> ptr(new C(10));
return b->take_c_shared_ptr_by_ref(ptr);
}
@ -68,7 +114,7 @@ int call_take_c_shared_ptr_by_ref_with_null(Base* b) {
}
int call_take_c_shared_ptr_by_pointer(Base* b) {
boost::shared_ptr<C> ptr(new C(8));
boost::shared_ptr<C> ptr(new C(11));
return b->take_c_shared_ptr_by_pointer(&ptr);
}
@ -78,7 +124,7 @@ int call_take_c_shared_ptr_by_pointer_with_null(Base* b) {
}
int call_take_c_shared_ptr_by_pointer_ref(Base* b) {
boost::shared_ptr<C> *ptr = new boost::shared_ptr<C>(new C(9));
boost::shared_ptr<C> *ptr = new boost::shared_ptr<C>(new C(12));
return b->take_c_shared_ptr_by_pointer_ref(ptr);
}
@ -88,3 +134,5 @@ int call_take_c_shared_ptr_by_pointer_ref_with_null(Base* b) {
}
%}
#endif

View file

@ -49,6 +49,14 @@ std::basic_string<char,std::char_traits<char>,std::allocator<char> > test_value_
return x;
}
std::basic_string<char,std::char_traits<char>,std::allocator<char> > test_value_basic_overload(std::basic_string<char,std::char_traits<char>,std::allocator<char> > x) {
return x;
}
std::basic_string<char,std::char_traits<char>,std::allocator<char> > test_value_basic_overload(int) {
return "int";
}
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else

View file

@ -12,11 +12,11 @@ assert(oc.foo(1,1,"test",1) == 15)
p1 = oc.Pop(nil)
p1 = oc.Pop(nil,false)
assert(p1:hip(true) == 701)
assert(p1:hip(false) == 701)
assert(p1:hip(nil) == 702)
assert(p1:hop(true) == 801)
assert(p1:hop(false) == 801)
assert(p1:hop(nil) == 805)
assert(oc.muzak(true) == 3001)
assert(oc.muzak(false) == 3001)
assert(oc.muzak(nil) == 3002)

View file

@ -50,9 +50,9 @@
%shared_ptr(Space::Bottom3)
%include "swiginterface.i"
SWIG_SHARED_PTR_INTERFACE_TYPEMAPS(SWIGEMPTYHACK, Space::ABase1)
SWIG_SHARED_PTR_INTERFACE_TYPEMAPS(SWIGEMPTYHACK, Space::CBase1)
SWIG_SHARED_PTR_INTERFACE_TYPEMAPS(SWIGEMPTYHACK, Space::CBase2)
SWIG_SHARED_PTR_INTERFACE_TYPEMAPS(, Space::ABase1)
SWIG_SHARED_PTR_INTERFACE_TYPEMAPS(, Space::CBase1)
SWIG_SHARED_PTR_INTERFACE_TYPEMAPS(, Space::CBase2)
%interface_impl(Space::ABase1)
%interface_impl(Space::CBase1)
%interface_impl(Space::CBase2)

View file

@ -0,0 +1,25 @@
/**
* Regression test for PHP bug: https://sourceforge.net/p/swig/bugs/1350/
*/
%module newobject3
%newobject factory::create;
%inline %{
class Product {};
class factory {
public:
Product * create(short id, short type = 0);
Product * create(const char * name, short type = 0);
};
%}
%{
Product * factory::create(short id, short type) {
return (id && type >= 0) ? new Product : NULL;
}
Product * factory::create(const char * name, short type) {
return (name && type >= 0) ? new Product : NULL;
}
%}

View file

@ -16,6 +16,12 @@ CPP_TEST_CASES += \
octave_cell_deref\
octave_dim
CPP11_TEST_CASES += \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
CPP_TEST_BROKEN += \
implicittest \
li_implicit \

View file

@ -15,10 +15,16 @@ if (complextest.Conjf(a) != a.conjugate())
error("bad complex mapping")
endif
if (complextest.Conj2(a) != a.conjugate())
error("bad complex mapping")
endif
if (complextest.Conjf2(a) != a.conjugate())
error("bad complex mapping")
endif
v = (complex(1,2), complex(2,3), complex(4,3), 1);
try
complextest.Copy_h(v);
catch
end_try_catch
complextest.CopyHalf(v);
complextest.CopyHalfRef(v);

View file

@ -5,15 +5,15 @@ endif
overload_complicated
pInt = None;
pInt = []; # NULL
# Check the correct constructors are available
p = Pop(pInt);
p = Pop(pInt, 0);
p = Pop(pInt, false);
# Check overloaded in const only and pointers/references which target languages cannot disambiguate
if (p.hip(0) != 701)
if (p.hip(false) != 701)
error("Test 1 failed")
endif
@ -26,16 +26,16 @@ if (p.hop(pInt) != 805)
error("Test 3 failed")
endif
if (p.hop(0) != 801)
if (p.hop(false) != 801)
error("Test 4 failed")
endif
# Few more variations and order shuffled
if (p.pop(0) != 901)
if (p.pop(false) != 901)
error("Test 5 failed")
endif
if (p.pop(pInt) != 902)
if (p.pop(pInt) != 904)
error("Test 6 failed")
endif
@ -48,12 +48,12 @@ if (p.bop(pInt) != 1001)
error("Test 8 failed")
endif
if (p.bip(pInt) != 2001)
if (p.bip(pInt) != 2002)
error("Test 9 failed")
endif
# Globals
if (muzak(0) != 3001)
if (muzak(false) != 3001)
error("Test 10 failed")
endif

View file

@ -19,8 +19,6 @@
#endif
#ifndef SWIG_NO_OVERLOAD
%immutable Spam::type;
%inline %{
@ -130,8 +128,6 @@ static char *bar(void *[SIZE]) {
%}
#endif
%inline {
class ClassA

View file

@ -1,27 +1,27 @@
// A complicated test of overloaded functions
%module overload_complicated
#ifndef SWIG_NO_OVERLOAD
// Different warning filters needed for scripting languages (eg Python) and for statically typed languages (eg C#).
%warnfilter(509, 516) Pop::Pop; // Overloaded xxxx is shadowed by xxxx at xxx:y. | Overloaded method xxxx ignored. Method at xxx:y used.
%warnfilter(509, 516) Pop::hip; // Overloaded xxxx is shadowed by xxxx at xxx:y. | Overloaded method xxxx ignored. Method at xxx:y used.
%warnfilter(509, 516) Pop::hop; // Overloaded xxxx is shadowed by xxxx at xxx:y. | Overloaded method xxxx ignored. Method at xxx:y used.
%warnfilter(509, 516) Pop::pop; // Overloaded xxxx is shadowed by xxxx at xxx:y. | Overloaded method xxxx ignored. Method at xxx:y used.
%warnfilter(516) Pop::bop; // Overloaded method xxxx ignored. Method at xxx:y used.
%warnfilter(516) Pop::bip; // Overloaded method xxxx ignored. Method at xxx:y used.
%warnfilter(509, 516) ::muzak; // Overloaded xxxx is shadowed by xxxx at xxx:y. | Overloaded method xxxx ignored. Method at xxx:y used.
// Different overloaded warning filters needed for scripting languages (eg Python) and for statically typed languages (eg C#).
%warnfilter(509, 516) Pop::Pop;
%warnfilter(509, 516) Pop::hip;
%warnfilter(509, 516) Pop::hop;
%warnfilter(509, 516) Pop::pop;
%warnfilter(516) Pop::bop;
%warnfilter(516) Pop::bip;
%warnfilter(509, 516) ::muzak;
%warnfilter(509, 516) foo;
%typemap(in, numinputs=0) int l { $1 = 4711; }
%inline %{
double foo(int, int, char *, int) {
int foo(int, int, char *, int) {
return 15;
}
double foo(int i, int j, double k = 17.4, int l = 18, char m = 'P') {
return i + j + k + l + (int) m;
int foo(int i, int j, double k = 17.4, int l = 18 /* Note numinputs typemap above */, char m = 'P') {
int sum = i + j + (int)k + l + (int)m;
return sum;
}
struct Pop {
@ -67,6 +67,3 @@ int muzak(int& i) { return 3003; }
int muzak(const int* i) { return 3004; }
%}
#endif

View file

@ -1,7 +1,6 @@
// Tests copy constructor
%module overload_copy
#ifndef SWIG_NO_OVERLOAD
%inline %{
class Foo {
@ -11,6 +10,3 @@ public:
};
%}
#endif

View file

@ -19,7 +19,6 @@
%rename(Foos) Foo;
#endif
#ifndef SWIG_NO_OVERLOAD
%immutable Spam::type;
%inline %{
@ -177,8 +176,6 @@ long long ll(long long ull) { return ull; }
%malloc(void);
%free(void);
#endif
%inline {
class ClassA

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 29;
use Test::More tests => 32;
BEGIN { use_ok 'director_classes' }
require_ok 'director_classes';
@ -10,6 +10,7 @@ require_ok 'director_classes';
sub Val { $_[1] }
sub Ref { $_[1] }
sub Ptr { $_[1] }
sub ConstPtrRef { $_[1] }
sub FullyOverloaded {
my $rv = shift->SUPER::FullyOverloaded(@_);
$rv =~ s/Base/__PACKAGE__/sge;
@ -45,6 +46,7 @@ sub makeCalls { my($caller, $base) = @_;
is($caller->ValCall($dh)->{val}, $dh->{val}, "$bname.Val");
is($caller->RefCall($dh)->{val}, $dh->{val}, "$bname.Ref");
is($caller->PtrCall($dh)->{val}, $dh->{val}, "$bname.Ptr");
is($caller->ConstPtrRefCall($dh)->{val}, $dh->{val}, "$bname.ConstPtrRef");
is($caller->FullyOverloadedCall(1),
"${bname}::FullyOverloaded(int)",
"$bname.FullyOverloaded(int)");

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 4;
use Test::More tests => 6;
BEGIN { use_ok('global_vars') }
require_ok('global_vars');
@ -9,3 +9,9 @@ isa_ok($an, 'global_vars::A');
$global_vars::ap = $an;
is($global_vars::ap, $an, "global var assignment");
# Regression test for https://sourceforge.net/p/swig/bugs/564/ - changing the
# value in C/C++ apparently wasn't reflected in Perl:
$global_vars::x = 17;
is($global_vars::x, 17, "global var assignment");
global_vars::init();
is($global_vars::x, 1234, "C++ global var change visible in Perl");

View file

@ -0,0 +1,18 @@
<?php
require "tests.php";
require "newobject3.php";
$factory = new factory();
check::classname("Product", $factory->create(7));
check::classname("Product", $factory->create(7, 6));
check::classname("Product", $factory->create("test"));
check::classname("Product", $factory->create("test", 2));
check::isnull($factory->create(0), "create(0) should be NULL");
check::isnull($factory->create(7, -1), "create(7, -1) should be NULL");
check::isnull($factory->create(0, -1), "create(0, -1) should be NULL");
check::isnull($factory->create("bad", -1), "create(\"bad\", -1) should be NULL");
?>

View file

@ -0,0 +1,18 @@
<?php
require "tests.php";
require "newobject3.php";
$factory = new factory();
check::classname("Product", $factory->create(7));
check::classname("Product", $factory->create(7, 6));
check::classname("Product", $factory->create("test"));
check::classname("Product", $factory->create("test", 2));
check::isnull($factory->create(0), "create(0) should be NULL");
check::isnull($factory->create(7, -1), "create(7, -1) should be NULL");
check::isnull($factory->create(0, -1), "create(0, -1) should be NULL");
check::isnull($factory->create("bad", -1), "create(\"bad\", -1) should be NULL");
?>

View file

@ -16,6 +16,9 @@
//Suppress: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
#pragma clang diagnostic ignored "-Wconstant-logical-operand"
#endif
#if defined(_MSC_VER)
#pragma warning(disable: 4003) // not enough actual parameters for macro 'FOO2'
#endif
%}
/* check __cplusplus case */
@ -370,7 +373,8 @@ int methodX(int x);
int methodX(int x) { return x+100; }
%}
// Comma in macro - Github issue #974
// Comma in macro - https://github.com/swig/swig/issues/974 (for /* */)
// and https://github.com/swig/swig/pull/1166 (for //)
%inline %{
#define swig__attribute__(x)
#define TCX_PACKED(d) d swig__attribute__ ((__packed__))
@ -386,5 +390,58 @@ TCX_PACKED (typedef struct tcxMessageBugImpl
{
int mBid; /**< Bid price and size, check PresentMap if available in message */
}) tcxMessageBug;
TCX_PACKED (typedef struct tcxMessageTestImpl2
{
int mHeader; ///< comment
}) tcxMessageTest2;
TCX_PACKED (typedef struct tcxMessageBugImpl2
{
int mBid; ///< Bid price and size, check PresentMap if available in message
}) tcxMessageBug2;
%}
// Regression tests for https://github.com/swig/swig/pull/1111
%{
static int foo_func(int x) { return x; }
static int foo_func2() { return 0; }
static int bar_func() { return 0; }
static int baz_func(int a, int b, int c) { return a + b - c; }
%}
%inline %{
#define FOO(X) int foo_func(X);
#define FOO2(X) int foo_func2(X);
#define BAR() int bar_func();
#define BAR2() int bar_func2()
#define BAZ(A,B,C) baz_func(A+0,B,C)
#define FOOVAR(...) foo_func(__VA_ARGS__)
#define BARVAR(...) bar_func(__VA_ARGS__)
#define BAZVAR(...) baz_func(__VA_ARGS__)
// This has probably always worked, but make sure that the fix to accept
// an empty X doesn't cause this case to be incorrectly expanded:
const int FOO = 7;
// BAR was incorrectly expanded here, causing:
// Error: Syntax error in input(1).
const int BAR = 6;
// This has probably always worked, but make sure that the fix to accept
// an empty X doesn't stop a non-empty X from working:
FOO(int x)
// FOO() didn't used to get expanded here, causing:
// Syntax error in input(1).
FOO2()
// Check BAR2() still gets expanded here.
BAR2() {
// Regression test - this used to fail with:
// Error: Macro 'BAZ' expects 3 arguments
BAZ(,2,3);
BARVAR();
FOOVAR(1);
BAZVAR(1,2,3);
return 0;
}
%}

View file

@ -95,6 +95,11 @@
#define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6
#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
// https://sourceforge.net/p/swig/bugs/1168/
#define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
#define DEFAULT_LANG CHR('d','f','l','t')
%constant DEFAULT_LANG_SIMPLIFIED = ('d')<<24;
/// constant assignment in enum
#if defined(SWIGCSHARP)
%csconstvalue("1<<2") kValue;

View file

@ -10,13 +10,13 @@ endif
LANGUAGE = python
PYTHON = $(PYBIN)
PEP8 = @PEP8@
PEP8_FLAGS = --ignore=E30,E402,E501,E731,W291,W391
PYCODESTYLE = @PYCODESTYLE@
PYCODESTYLE_FLAGS = --ignore=E30,E402,E501,E731,W291,W391
#*_runme.py for Python 2.x, *_runme3.py for Python 3.x
PY2SCRIPTSUFFIX = _runme.py
PY3SCRIPTSUFFIX = _runme3.py
PY2TO3 = 2to3 -x import
PY2TO3 = @PY2TO3@ -x import
ifeq (,$(PY3))
SCRIPTSUFFIX = $(PY2SCRIPTSUFFIX)
@ -70,6 +70,7 @@ CPP_TEST_CASES += \
python_pythoncode \
python_richcompare \
python_strict_unicode \
python_threads \
simutry \
std_containers \
swigobject \
@ -81,6 +82,10 @@ CPP_TEST_CASES += \
CPP11_TEST_CASES = \
cpp11_hash_tables \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
C_TEST_CASES += \
file_test \
@ -136,12 +141,12 @@ py_runme = $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
py2_runme = $(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
py3_runme = $(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
ifneq (,$(PEP8))
check_pep8 = $(COMPILETOOL) $(PEP8) $(PEP8_FLAGS) $(SCRIPTPREFIX)$*.py
ifneq (,$(PYCODESTYLE))
check_pep8 = $(COMPILETOOL) $(PYCODESTYLE) $(PYCODESTYLE_FLAGS) $(SCRIPTPREFIX)$*.py
check_pep8_multi_cpp = \
for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \
$(COMPILETOOL) $(PEP8) $(PEP8_FLAGS) $$f.py; \
$(COMPILETOOL) $(PYCODESTYLE) $(PYCODESTYLE_FLAGS) $$f.py; \
done
endif

View file

@ -8,13 +8,20 @@ if complextest.Conj(a) != a.conjugate():
if complextest.Conjf(a) != a.conjugate():
raise RuntimeError, "bad complex mapping"
if complextest.Conj2(a) != a.conjugate():
raise RuntimeError, "bad complex mapping"
if complextest.Conjf2(a) != a.conjugate():
raise RuntimeError, "bad complex mapping"
v = (complex(1, 2), complex(2, 3), complex(4, 3), 1)
try:
complextest.Copy_h(v)
except:
pass
if len(complextest.CopyHalf(v)) != 2:
raise RuntimeError("CopyHalf failed")
if len(complextest.CopyHalfRef(v)) != 2:
raise RuntimeError("CopyHalfRef failed")
p = complextest.ComplexPair()
p.z1 = complex(0, 1)

View file

@ -0,0 +1,45 @@
import cpp11_shared_ptr_overload
from cpp11_shared_ptr_overload import MyType
# ref
ret = cpp11_shared_ptr_overload.UseA(MyType("123"))
if ret != "123 ref": raise RuntimeError("UseA fail:" + ret)
ret = cpp11_shared_ptr_overload.UseB(0, MyType("123"))
if ret != "123 ref": raise RuntimeError("UseB fail:" + ret)
ret = cpp11_shared_ptr_overload.UseC(0, MyType("123"), MyType("456"))
if ret != "123 ref": raise RuntimeError("UseC fail:" + ret)
# sharedptr
ret = cpp11_shared_ptr_overload.UseX(MyType("123"))
if ret != "123 sharedptr": raise RuntimeError("UseX fail:" + ret)
ret = cpp11_shared_ptr_overload.UseY(0, MyType("123"))
if ret != "123 sharedptr": raise RuntimeError("UseY fail:" + ret)
ret = cpp11_shared_ptr_overload.UseZ(0, MyType("123"), MyType("456"))
if ret != "123 sharedptr": raise RuntimeError("UseZ fail:" + ret)
# Combo1-4
ret = cpp11_shared_ptr_overload.Combo1(MyType("XXX"))
if ret != "XXXCombo1": raise RuntimeError("Combo1 fail:" + ret)
ret = cpp11_shared_ptr_overload.Combo2(MyType("XXX"))
if ret != "XXXCombo2": raise RuntimeError("Combo2 fail:" + ret)
ret = cpp11_shared_ptr_overload.Combo3(MyType("XXX"))
if ret != "XXXCombo3": raise RuntimeError("Combo3 fail:" + ret)
ret = cpp11_shared_ptr_overload.Combo4(MyType("XXX"))
if ret != "XXXCombo4": raise RuntimeError("Combo4 fail:" + ret)
# Combo5-7
ret = cpp11_shared_ptr_overload.Combo5(MyType("XXX"))
if ret != "XXXCombo5": raise RuntimeError("Combo5 fail:" + ret)
ret = cpp11_shared_ptr_overload.Combo6(MyType("XXX"))
if ret != "XXXCombo6": raise RuntimeError("Combo6 fail:" + ret)
ret = cpp11_shared_ptr_overload.Combo7(MyType("XXX"))
if ret != "XXXCombo7": raise RuntimeError("Combo7 fail:" + ret)

View file

@ -139,6 +139,21 @@ def run(module_name):
print "booltest2 failed"
tricky_failure = True
if tricky.max_32bit_int1() != 0x7FFFFFFF:
print "max_32bit_int1 failed"
tricky_failure = True
if tricky.min_32bit_int1() != -2147483648:
print "min_32bit_int1 failed"
tricky_failure = True
if tricky.max_32bit_int2() != 0x7FFFFFFF:
print "max_32bit_int2 failed"
tricky_failure = True
tricky.too_big_32bit_int1()
tricky.too_small_32bit_int1()
tricky.too_big_32bit_int2()
tricky.too_small_32bit_int2()
if tricky_failure:
raise RuntimeError

View file

@ -0,0 +1,80 @@
from li_boost_shared_ptr_director import *
class Derived(Base):
def __init__(self, flag):
self.return_none = flag
Base.__init__(self)
def ret_c_shared_ptr(self):
if self.return_none:
return None
else:
return C()
def ret_c_by_value(self):
return C()
def take_c_by_value(self,c):
return c.get_m()
def take_c_by_ref(self,c):
return c.get_m()
def take_c_by_pointer(self,c):
if c:
return c.get_m()
else:
return -2
def take_c_by_pointer_ref(self,c):
if c:
return c.get_m()
else:
return -3
def take_c_shared_ptr_by_value(self,c):
if c:
return c.get_m()
else:
return -4
def take_c_shared_ptr_by_ref(self,c):
if c:
return c.get_m()
else:
return -5
def take_c_shared_ptr_by_pointer(self,c):
if c:
return c.get_m()
else:
return -6
def take_c_shared_ptr_by_pointer_ref(self,c):
if c:
return c.get_m()
else:
return -7
a = Derived(False)
b = Derived(True)
assert call_ret_c_shared_ptr(a) == 1
assert call_ret_c_shared_ptr(b) == -1
assert call_ret_c_by_value(a) == 1
assert call_take_c_by_value(a) == 5
assert call_take_c_by_ref(a) == 6
assert call_take_c_by_pointer(a) == 7
assert call_take_c_by_pointer_ref(a) == 8
assert call_take_c_shared_ptr_by_value(a) == 9
assert call_take_c_shared_ptr_by_ref(a) == 10
assert call_take_c_shared_ptr_by_pointer(a) == 11
assert call_take_c_shared_ptr_by_pointer_ref(a) == 12
assert call_take_c_by_pointer_with_null(a) == -2
assert call_take_c_by_pointer_ref_with_null(a) == -3
assert call_take_c_shared_ptr_by_value_with_null(a) == -4
assert call_take_c_shared_ptr_by_ref_with_null(a) == -5
assert call_take_c_shared_ptr_by_pointer_with_null(a) == -6
assert call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -7

View file

@ -87,6 +87,24 @@ if li_std_string_extra.test_value_basic2(x) != x:
if li_std_string_extra.test_value_basic3(x) != x:
raise RuntimeError, "bad string mapping"
if li_std_string_extra.test_value_basic_overload(x) != x:
raise RuntimeError, "bad overload string"
if li_std_string_extra.test_value_basic_overload(123) != "int":
raise RuntimeError, "bad overload int"
try:
li_std_string_extra.test_value_basic_overload([x])
raise RuntimeError, "should throw NotImplementedError"
except NotImplementedError:
pass
try:
li_std_string_extra.test_value_basic_overload([123])
raise RuntimeError, "should throw NotImplementedError"
except NotImplementedError:
pass
# Global variables
s = "initial string"
if li_std_string_extra.cvar.GlobalString2 != "global string 2":

View file

@ -5,11 +5,11 @@ pInt = None
# Check the correct constructors are available
p = Pop(pInt)
p = Pop(pInt, 0)
p = Pop(pInt, False)
# Check overloaded in const only and pointers/references which target
# languages cannot disambiguate
if p.hip(0) != 701:
if p.hip(False) != 701:
raise RuntimeError, "Test 1 failed"
if p.hip(pInt) != 702:
@ -19,14 +19,14 @@ if p.hip(pInt) != 702:
if p.hop(pInt) != 805:
raise RuntimeError, "Test 3 failed"
if p.hop(0) != 801:
if p.hop(False) != 801:
raise RuntimeError, "Test 4 failed"
# Few more variations and order shuffled
if p.pop(0) != 901:
if p.pop(False) != 901:
raise RuntimeError, "Test 5 failed"
if p.pop(pInt) != 902:
if p.pop(pInt) != 904:
raise RuntimeError, "Test 6 failed"
if p.pop() != 905:
@ -36,11 +36,11 @@ if p.pop() != 905:
if p.bop(pInt) != 1001:
raise RuntimeError, "Test 8 failed"
if p.bip(pInt) != 2001:
if p.bip(pInt) != 2002:
raise RuntimeError, "Test 9 failed"
# Globals
if muzak(0) != 3001:
if muzak(False) != 3001:
raise RuntimeError, "Test 10 failed"
if muzak(pInt) != 3002:

View file

@ -0,0 +1,42 @@
from template_class_reuse_name import *
Bool1().tt()
Bool1False().ff()
Bool2().tt()
Bool2False().ff()
Bool3().tt()
Bool3False().ff()
Bool4().tt()
Bool4False().ff()
BoolForward1().tt()
BoolForward1False().ff()
BoolForward2().tt()
BoolForward2False().ff()
BoolForward3().tt()
BoolForward3False().ff()
BoolForward4().tt()
BoolForward4False().ff()
IntBool1().tt()
IntBool1False().ff()
IntBool2().tt()
IntBool2False().ff()
IntBool3().tt()
IntBool3False().ff()
IntBool4().tt()
IntBool4False().ff()
Duplicate2_0().n()
Duplicate3().n()

View file

@ -0,0 +1,11 @@
from typedef_classforward_same_name import *
foo = Foo()
foo.x = 5
if extractFoo(foo) != 5:
raise RuntimeError("unexpected value")
boo = Boo()
boo.x = 5
if extractBoo(boo) != 5:
raise RuntimeError("unexpected value")

View file

@ -25,3 +25,13 @@ if sys.version_info[0:2] < (3, 0):
check(unicode_strings.charstring(unicode("hello4")), "hello4")
unicode_strings.charstring(u"hell\xb05")
unicode_strings.charstring(u"hell\u00f66")
low_surrogate_string = u"\udcff"
try:
unicode_strings.instring(low_surrogate_string)
# Will succeed with Python 2
except TypeError, e:
# Python 3 will fail the PyUnicode_AsUTF8String conversion resulting in a TypeError.
# The real error is actually:
# UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed
pass

View file

@ -23,8 +23,11 @@
SWIG_fail;
}
pystr = PyUnicode_AsUTF8String(pyobj);
if (!pystr) {
SWIG_fail;
}
str = strdup(PyBytes_AsString(pystr));
Py_XDECREF(pystr);
Py_DECREF(pystr);
%#else
if (!PyString_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");

View file

@ -20,7 +20,18 @@ CPP_TEST_CASES += \
r_double_delete \
r_overload_array \
r_sexp \
r_overload_comma
r_overload_comma \
r_use_isnull
# These tests are failing because enums currently cannot handle
# arithmetic expressions
FAILING_CPP_TESTS = \
enum_thorough \
preproc_constants
FAILING_C_TESTS = \
preproc_constants_c
include $(srcdir)/../common.mk

View file

@ -0,0 +1,11 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("r_use_isnull", .Platform$dynlib.ext, sep=""))
source("r_use_isnull.R")
cacheMetaData(1)
tp <- pointerTest()
circ1 <- tp$getCircle(1)
circ1
unittest(is.null(circ1), TRUE)

View file

@ -0,0 +1,34 @@
%module r_use_isnull
%inline %{
// C++ code
class circle {
public:
circle(double radius)
{
m_radius = radius;
}
double getArea() const
{
return (3.14 * m_radius * m_radius);
}
private:
double m_radius;
};
class pointerTest {
public:
pointerTest() : m_circle(2) {}
const circle * getCircle(int index) const {
if (index == 0)
return & m_circle;
else
return 0;
}
private:
circle m_circle;
};
%}

View file

@ -11,7 +11,6 @@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES = \
li_boost_shared_ptr_director \
li_cstring \
li_factory \
li_std_functors \
@ -36,6 +35,7 @@ CPP11_TEST_CASES = \
cpp11_hash_tables \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
cpp11_std_unordered_map \
cpp11_std_unordered_multimap \

View file

@ -25,7 +25,11 @@ class Derived < Base
c.get_m
end
def take_c_shared_ptr_by_value(c)
def take_c_by_ref(c)
c.get_m
end
def take_c_by_pointer(c)
if c
c.get_m
else
@ -33,7 +37,7 @@ class Derived < Base
end
end
def take_c_shared_ptr_by_ref(c)
def take_c_by_pointer_ref(c)
if c
c.get_m
else
@ -41,7 +45,7 @@ class Derived < Base
end
end
def take_c_shared_ptr_by_pointer(c)
def take_c_shared_ptr_by_value(c)
if c
c.get_m
else
@ -49,7 +53,7 @@ class Derived < Base
end
end
def take_c_shared_ptr_by_pointer_ref(c)
def take_c_shared_ptr_by_ref(c)
if c
c.get_m
else
@ -57,6 +61,22 @@ class Derived < Base
end
end
def take_c_shared_ptr_by_pointer(c)
if c
c.get_m
else
-6
end
end
def take_c_shared_ptr_by_pointer_ref(c)
if c
c.get_m
else
-7
end
end
end
a = Derived.new(false)
@ -67,13 +87,17 @@ raise unless call_ret_c_shared_ptr(b) == -1
raise unless call_ret_c_by_value(a) == 1
raise unless call_take_c_by_value(a) == 5
raise unless call_take_c_shared_ptr_by_value(a) == 6
raise unless call_take_c_shared_ptr_by_ref(a) == 7
raise unless call_take_c_shared_ptr_by_pointer(a) == 8
raise unless call_take_c_shared_ptr_by_pointer_ref(a) == 9
raise unless call_take_c_shared_ptr_by_value_with_null(a) == -2
raise unless call_take_c_shared_ptr_by_ref_with_null(a) == -3
raise unless call_take_c_shared_ptr_by_pointer_with_null(a) == -4
raise unless call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -5
raise unless call_take_c_by_ref(a) == 6
raise unless call_take_c_by_pointer(a) == 7
raise unless call_take_c_by_pointer_ref(a) == 8
raise unless call_take_c_shared_ptr_by_value(a) == 9
raise unless call_take_c_shared_ptr_by_ref(a) == 10
raise unless call_take_c_shared_ptr_by_pointer(a) == 11
raise unless call_take_c_shared_ptr_by_pointer_ref(a) == 12
raise unless call_take_c_by_pointer_with_null(a) == -2
raise unless call_take_c_by_pointer_ref_with_null(a) == -3
raise unless call_take_c_shared_ptr_by_value_with_null(a) == -4
raise unless call_take_c_shared_ptr_by_ref_with_null(a) == -5
raise unless call_take_c_shared_ptr_by_pointer_with_null(a) == -6
raise unless call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -7

View file

@ -4,8 +4,6 @@
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) test;
#endif
#ifndef SWIG_NO_OVERLOAD
%inline %{
struct Foo {
int x;
@ -24,5 +22,3 @@ public:
};
%}
#endif

View file

@ -0,0 +1,132 @@
%module template_class_reuse_name
// One parameter templates
%inline %{
namespace Space {
template <bool B> struct Bool1 { void tt(){}; void ff(){}; };
template <bool B = true> struct Bool2 { void tt(){}; void ff(){}; };
template <bool B> struct Bool3 {};
template <> struct Bool3<true> { void tt(){}; };
template <> struct Bool3<false> { void ff(){}; };
template <bool B = true> struct Bool4 { void tt(){}; };
template <> struct Bool4<false> { void ff(){}; };
}
%}
// Instantiated names are the same as C++ template name
%template(Bool1) Space::Bool1<true>;
%template(Bool2) Space::Bool2<true>;
%template(Bool3) Space::Bool3<true>;
%template(Bool4) Space::Bool4<true>;
// Instantiated names are not the same as C++ template name
%template(Bool1False) Space::Bool1<false>;
%template(Bool2False) Space::Bool2<false>;
%template(Bool3False) Space::Bool3<false>;
%template(Bool4False) Space::Bool4<false>;
// Forward declarated templates
%inline %{
namespace Space {
template <bool B> struct BoolForward1;
template <bool B> struct BoolForward2;
template <bool B> struct BoolForward3;
template <bool B> struct BoolForward4;
template <bool B> struct BoolForward1 { void tt(){}; void ff(){}; };
template <bool B = true> struct BoolForward2 { void tt(){}; void ff(){}; };
template <bool B> struct BoolForward3 {};
template <> struct BoolForward3<true> { void tt(){}; };
template <> struct BoolForward3<false> { void ff(){}; };
template <bool B = true> struct BoolForward4 { void tt(){}; };
template <> struct BoolForward4<false> { void ff(){}; };
}
%}
// Instantiated names are the same as C++ template name
%template(BoolForward1) Space::BoolForward1<true>;
%template(BoolForward2) Space::BoolForward2<true>;
%template(BoolForward3) Space::BoolForward3<true>;
%template(BoolForward4) Space::BoolForward4<true>;
// Instantiated names are not the same as C++ template name
%template(BoolForward1False) Space::BoolForward1<false>;
%template(BoolForward2False) Space::BoolForward2<false>;
%template(BoolForward3False) Space::BoolForward3<false>;
%template(BoolForward4False) Space::BoolForward4<false>;
// Two parameter templates
%inline %{
namespace Space {
template <int I, bool B> struct IntBool1 { void tt(){}; void ff(){}; };
template <int I, bool B = true> struct IntBool2 { void tt(){}; void ff(){}; };
template <int I, bool B> struct IntBool3 {};
template <int I> struct IntBool3<I, true> { void tt(){}; };
template <int I> struct IntBool3<I, false> { void ff(){}; };
template <int I, bool B = true> struct IntBool4 { void tt(){}; };
template <int I> struct IntBool4<I, false> { void ff(){}; };
}
%}
// Instantiated names are the same as C++ template name
%template(IntBool1) Space::IntBool1<0, true>;
%template(IntBool2) Space::IntBool2<0, true>;
%template(IntBool3) Space::IntBool3<0, true>;
%template(IntBool4) Space::IntBool4<0, true>;
// Instantiated names are not the same as C++ template name
%template(IntBool1False) Space::IntBool1<0, false>;
%template(IntBool2False) Space::IntBool2<0, false>;
%template(IntBool3False) Space::IntBool3<0, false>;
%template(IntBool4False) Space::IntBool4<0, false>;
%{
namespace Space {
template <bool B> struct Duplicate1 { void ff(){}; };
}
%}
%warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate1;
namespace Space {
template <bool B> struct Duplicate1 { void ff(){}; };
template <bool B> struct Duplicate1 { void ff(){}; };
}
%warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate2;
%inline %{
namespace Space {
template <int I> struct Duplicate2 { void n(){}; };
}
%}
%template(Duplicate2_0) Space::Duplicate2<0>;
%template(Duplicate2_0) Space::Duplicate2<0>;
%warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate3;
%inline %{
namespace Space {
template <int I> struct Duplicate3 { void n(){}; };
}
%}
%template(Duplicate3) Space::Duplicate3<0>;
%template(Duplicate3) Space::Duplicate3<0>;
%{
namespace Space {
template <bool B> struct Duplicate4 { void ff(){}; };
}
%}
%warnfilter(SWIGWARN_PARSE_REDEFINED) Space::Duplicate4;
namespace Space {
template <bool B> struct Duplicate4 { void ff(){}; };
template <bool B> struct Duplicate4 { void ff(){}; };
}
%template(Duplicate4) Space::Duplicate4<0>;
%template(Duplicate4) Space::Duplicate4<0>;

View file

@ -12,10 +12,10 @@ namespace One {
template <> struct OneParm<int * const &> { void g() {} };
template <> struct OneParm<int **> { void h() {} };
template <> struct OneParm<float> { void i() {} };
template <> struct OneParm<float *> { void j() {} };
template <> struct OneParm<float **> { void k() {} };
template <> struct OneParm<float ***> { void l() {} };
template <> struct OneParm<float> { void j() {} };
template <> struct OneParm<float *> { void k() {} };
template <> struct OneParm<float **> { void m() {} };
template <> struct OneParm<float ***> { void n() {} };
}
%}
@ -33,12 +33,12 @@ namespace One {
// %template scope explicit specializations
namespace One {
%template(I) One::OneParm<float>;
%template(J) ::One::OneParm<float *>;
%template(J) One::OneParm<float>;
%template(K) ::One::OneParm<float *>;
}
%template(K) ::One::OneParm<float **>;
%template(M) ::One::OneParm<float **>;
namespace One {
%template(L) OneParm<float ***>;
%template(N) OneParm<float ***>;
}
// %template scope partial specializations

View file

@ -39,10 +39,10 @@ namespace One {
template <> struct OneParm<int * const &> { void g() {} };
template <> struct OneParm<int **> { void h() {} };
template <> struct OneParm<float> { void i() {} };
template <> struct OneParm<float *> { void j() {} };
template <> struct OneParm<float **> { void k() {} };
template <> struct OneParm<float ***> { void l() {} };
template <> struct OneParm<float> { void j() {} };
template <> struct OneParm<float *> { void k() {} };
template <> struct OneParm<float **> { void m() {} };
template <> struct OneParm<float ***> { void n() {} };
}
%}
@ -60,12 +60,12 @@ namespace One {
// %template scope explicit specializations
namespace One {
%template(I) One::OneParm<TypeDef::Float>;
%template(J) ::One::OneParm<TypeDef::FloatPtr>;
%template(J) One::OneParm<TypeDef::Float>;
%template(K) ::One::OneParm<TypeDef::FloatPtr>;
}
%template(K) ::One::OneParm<TypeDef::FloatPtrPtr>;
%template(M) ::One::OneParm<TypeDef::FloatPtrPtr>;
namespace One {
%template(L) OneParm<TypeDef::FloatPtrPtrPtr>;
%template(N) OneParm<TypeDef::FloatPtrPtrPtr>;
}
// %template scope partial specializations

View file

@ -0,0 +1,15 @@
%module typedef_classforward_same_name
%inline %{
typedef struct Foo Foo;
struct Foo {
int x;
};
int extractFoo(Foo* foo) { return foo->x; }
struct Boo {
int x;
};
typedef struct Boo Boo;
int extractBoo(Boo* boo) { return boo->x; }
%}

View file

@ -9,14 +9,14 @@
%apply int TMAP77 { XXX<int>::Long cc }
%inline %{
typedef int Integer;
typedef int MyInteger;
template<typename T> struct XXX {
#ifdef SWIG
// In swig-3.0.12 'Long aa' was actually stored as 'long aa' in typemap table instead of 'XXX<int>::Long aa'
%apply int TMAP55 { Long aa }
%apply int TMAP66 { XXX<int>::Long bb }
%apply int TMAP88 { XXX<Integer>::Long dd }
%apply int TMAP88 { XXX<MyInteger>::Long dd }
#endif
typedef long Long;
long aa1(long aa) { return aa; }
@ -30,7 +30,7 @@ template<typename T> struct XXX {
#ifdef SWIG
%clear Long aa;
%clear XXX<int>::Long bb;
%clear XXX<Integer>::Long dd;
%clear XXX<MyInteger>::Long dd;
#endif
long aa3(Long aa) { return aa; }
long bb3(Long bb) { return bb; }
@ -39,7 +39,7 @@ template<typename T> struct XXX {
};
%}
%template(XXXInt) XXX<Integer>;
%template(XXXInt) XXX<MyInteger>;
%clear XXX<int>::Long cc;
@ -50,17 +50,17 @@ template<typename T> struct XXX {
long bb2(long bb) { return bb; }
long cc1(XXX<int>::Long cc) { return cc; }
long cc2(long cc) { return cc; }
long dd1(XXX<Integer>::Long dd) { return dd; }
long dd1(XXX<MyInteger>::Long dd) { return dd; }
long dd2(long dd) { return dd; }
%}
%inline %{
typedef Integer INTEGER;
template<typename T1, typename T2 = INTEGER> struct YYY {
typedef MyInteger MY_INTEGER;
template<typename T1, typename T2 = MY_INTEGER> struct YYY {
void meff(T1 t1, T2 t2) {}
};
%}
%template(YYYIntInt) YYY<INTEGER>;
%template(YYYIntInt) YYY<MY_INTEGER>;
%inline %{
void whyohwhy(YYY<INTEGER> yy) {}
void whyohwhy(YYY<MY_INTEGER> yy) {}
%}

View file

@ -20,4 +20,6 @@ char *charstring(char *s) {
return s;
}
void instring(const char *s) {
}
%}

View file

@ -58,6 +58,7 @@
class IndexReader{
public:
virtual void norms() = 0;
virtual ~IndexReader() {}
};
class MultiReader : public IndexReader {