Merge branch 'master' into javalist
This commit is contained in:
commit
4db1300622
798 changed files with 26703 additions and 7774 deletions
|
|
@ -4,6 +4,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
|
||||
%}
|
||||
|
||||
%include <exception.i> // for throws(...) typemap
|
||||
|
|
@ -31,3 +35,11 @@ void test_catches_all(int i) {
|
|||
}
|
||||
%}
|
||||
|
||||
%{
|
||||
#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
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ CPP_TEST_BROKEN += \
|
|||
director_nested_class \
|
||||
exception_partial_info \
|
||||
extend_variable \
|
||||
li_std_vector_ptr \
|
||||
li_boost_shared_ptr_template \
|
||||
nested_private \
|
||||
overload_complicated \
|
||||
|
|
@ -204,6 +203,7 @@ CPP_TEST_CASES += \
|
|||
director_thread \
|
||||
director_unroll \
|
||||
director_using \
|
||||
director_void \
|
||||
director_wombat \
|
||||
disown \
|
||||
dynamic_cast \
|
||||
|
|
@ -227,6 +227,7 @@ CPP_TEST_CASES += \
|
|||
extend_placement \
|
||||
extend_special_variables \
|
||||
extend_template \
|
||||
extend_template_method \
|
||||
extend_template_ns \
|
||||
extend_typedef_class \
|
||||
extern_c \
|
||||
|
|
@ -245,6 +246,7 @@ CPP_TEST_CASES += \
|
|||
global_vars \
|
||||
grouping \
|
||||
ignore_parameter \
|
||||
import_fragments \
|
||||
import_nomodule \
|
||||
inherit \
|
||||
inherit_member \
|
||||
|
|
@ -260,7 +262,6 @@ CPP_TEST_CASES += \
|
|||
langobj \
|
||||
li_attribute \
|
||||
li_attribute_template \
|
||||
li_boost_array \
|
||||
li_boost_shared_ptr \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_template \
|
||||
|
|
@ -278,6 +279,7 @@ CPP_TEST_CASES += \
|
|||
memberin_extend \
|
||||
member_funcptr_galore \
|
||||
member_pointer \
|
||||
member_pointer_const \
|
||||
member_template \
|
||||
minherit \
|
||||
minherit2 \
|
||||
|
|
@ -308,6 +310,7 @@ CPP_TEST_CASES += \
|
|||
nested_class \
|
||||
nested_directors \
|
||||
nested_comment \
|
||||
nested_ignore \
|
||||
nested_scope \
|
||||
nested_template_base \
|
||||
nested_workaround \
|
||||
|
|
@ -335,6 +338,7 @@ CPP_TEST_CASES += \
|
|||
preproc_constants \
|
||||
primitive_ref \
|
||||
private_assign \
|
||||
proxycode \
|
||||
protected_rename \
|
||||
pure_virtual \
|
||||
redefined \
|
||||
|
|
@ -353,6 +357,7 @@ CPP_TEST_CASES += \
|
|||
rename_pcre_encoder \
|
||||
rename_pcre_enum \
|
||||
rename_predicates \
|
||||
rename_wildcard \
|
||||
restrict_cplusplus \
|
||||
return_const_value \
|
||||
return_value_scope \
|
||||
|
|
@ -363,6 +368,7 @@ CPP_TEST_CASES += \
|
|||
smart_pointer_const2 \
|
||||
smart_pointer_const_overload \
|
||||
smart_pointer_extend \
|
||||
smart_pointer_ignore \
|
||||
smart_pointer_member \
|
||||
smart_pointer_multi \
|
||||
smart_pointer_multi_typedef \
|
||||
|
|
@ -388,6 +394,7 @@ CPP_TEST_CASES += \
|
|||
string_constants \
|
||||
struct_initialization_cpp \
|
||||
struct_value \
|
||||
swig_exception \
|
||||
symbol_clash \
|
||||
template_arg_replace \
|
||||
template_arg_scope \
|
||||
|
|
@ -405,6 +412,7 @@ CPP_TEST_CASES += \
|
|||
template_default_arg_overloaded \
|
||||
template_default_arg_overloaded_extend \
|
||||
template_default_arg_virtual_destructor \
|
||||
template_default_cache \
|
||||
template_default_class_parms \
|
||||
template_default_class_parms_typedef \
|
||||
template_default_inherit \
|
||||
|
|
@ -485,6 +493,7 @@ CPP_TEST_CASES += \
|
|||
typemap_array_qualifiers \
|
||||
typemap_delete \
|
||||
typemap_directorout \
|
||||
typemap_documentation \
|
||||
typemap_global_scope \
|
||||
typemap_manyargs \
|
||||
typemap_namespace \
|
||||
|
|
@ -518,6 +527,7 @@ CPP_TEST_CASES += \
|
|||
valuewrapper_opaque \
|
||||
varargs \
|
||||
varargs_overload \
|
||||
variable_replacement \
|
||||
virtual_destructor \
|
||||
virtual_poly \
|
||||
virtual_vs_nonvirtual_base \
|
||||
|
|
@ -526,7 +536,7 @@ CPP_TEST_CASES += \
|
|||
wrapmacro
|
||||
|
||||
# C++11 test cases.
|
||||
CPP11_TEST_CASES = \
|
||||
CPP11_TEST_CASES += \
|
||||
cpp11_alignment \
|
||||
cpp11_alternate_function_syntax \
|
||||
cpp11_constexpr \
|
||||
|
|
@ -534,6 +544,7 @@ CPP11_TEST_CASES = \
|
|||
cpp11_default_delete \
|
||||
cpp11_delegating_constructors \
|
||||
cpp11_director_enums \
|
||||
cpp11_directors \
|
||||
cpp11_explicit_conversion_operators \
|
||||
cpp11_final_override \
|
||||
cpp11_function_objects \
|
||||
|
|
@ -564,7 +575,6 @@ CPP11_TEST_CASES = \
|
|||
|
||||
# Broken C++11 test cases.
|
||||
CPP11_TEST_BROKEN = \
|
||||
# cpp11_hash_tables \ # not fully implemented yet
|
||||
# cpp11_variadic_templates \ # Broken for some languages (such as Java)
|
||||
# cpp11_reference_wrapper \ # No typemaps
|
||||
|
||||
|
|
@ -586,6 +596,7 @@ CPP_STD_TEST_CASES += \
|
|||
li_std_vector \
|
||||
li_std_vector_enum \
|
||||
li_std_vector_member_var\
|
||||
li_std_vector_ptr \
|
||||
smart_pointer_inherit \
|
||||
template_typedef_fnc \
|
||||
template_type_namespace \
|
||||
|
|
@ -755,7 +766,7 @@ swig_and_compile_external = \
|
|||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$*_wrap_hdr.h' \
|
||||
$(LANGUAGE)$(VARIANT)_externalhdr; \
|
||||
$(LANGUAGE)$(VARIANT)_externalhdr && \
|
||||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS) $*_external.cxx' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \
|
||||
|
|
@ -769,7 +780,7 @@ setup = \
|
|||
echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \
|
||||
else \
|
||||
echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \
|
||||
fi;
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@
|
|||
return b;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct ComplexPair
|
||||
{
|
||||
std::complex<double> z1, z2;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,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
|
||||
%}
|
||||
|
||||
%nodefaultctor;
|
||||
|
|
@ -26,3 +30,11 @@ 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
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,26 @@
|
|||
struct SomeStruct {
|
||||
int addNormal(int x, int y);
|
||||
auto addAlternate(int x, int y) -> int;
|
||||
auto addAlternateConst(int x, int y) const -> int;
|
||||
auto addAlternateNoExcept(int x, int y) noexcept -> int;
|
||||
auto addAlternateConstNoExcept(int x, int y) const noexcept -> int;
|
||||
auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int;
|
||||
auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int;
|
||||
|
||||
virtual auto addFinal(int x, int y) const noexcept -> int final { return x + y; }
|
||||
virtual ~SomeStruct() = default;
|
||||
};
|
||||
|
||||
auto SomeStruct::addAlternate(int x, int y) -> int {
|
||||
return x + y;
|
||||
int SomeStruct::addNormal(int x, int y) { return x + y; }
|
||||
auto SomeStruct::addAlternate(int x, int y) -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateConst(int x, int y) const -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateNoExcept(int x, int y) noexcept -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateConstNoExcept(int x, int y) const noexcept -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int {
|
||||
return 100*x + (this->*mp)(x, x);
|
||||
}
|
||||
auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int {
|
||||
return 1000*x + (this->*mp)(x, x);
|
||||
}
|
||||
|
||||
int SomeStruct::addNormal(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,17 @@
|
|||
*/
|
||||
%module cpp11_constexpr
|
||||
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIG
|
||||
#define CONST const
|
||||
#else
|
||||
#define CONST
|
||||
#endif
|
||||
constexpr int AAA = 10;
|
||||
constexpr const int BBB = 20;
|
||||
constexpr int CCC() { return 30; }
|
||||
constexpr const int DDD() { return 40; }
|
||||
constexpr CONST int DDD() { return 40; }
|
||||
|
||||
constexpr int XXX() { return 10; }
|
||||
constexpr int YYY = XXX() + 100;
|
||||
|
|
@ -17,7 +23,7 @@ struct ConstExpressions {
|
|||
static constexpr int KKK = 200;
|
||||
static const int LLL = 300;
|
||||
constexpr int MMM() { return 400; }
|
||||
constexpr const int NNN() { return 500; }
|
||||
constexpr CONST int NNN() { return 500; }
|
||||
// Regression tests for support added in SWIG 3.0.4:
|
||||
static constexpr const int JJJ1 = 101;
|
||||
constexpr static int KKK1 = 201;
|
||||
|
|
|
|||
20
Examples/test-suite/cpp11_directors.i
Normal file
20
Examples/test-suite/cpp11_directors.i
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
%module(directors="1") cpp11_directors
|
||||
%feature("director");
|
||||
|
||||
%{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
};
|
||||
|
|
@ -16,6 +16,8 @@ struct Base {
|
|||
virtual void finaloverride2() {}
|
||||
virtual void finaloverride3() {}
|
||||
virtual void finaloverride4() const {}
|
||||
virtual void finaloverride5() {}
|
||||
virtual void finaloverride6() const {}
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
|
|
@ -31,6 +33,8 @@ struct Derived /*final*/ : Base {
|
|||
virtual void finaloverride2() override final {}
|
||||
virtual void finaloverride3() noexcept override final {}
|
||||
virtual void finaloverride4() const noexcept override final {}
|
||||
virtual void finaloverride5() throw(int) override final {}
|
||||
virtual void finaloverride6() const throw(int) override final {}
|
||||
virtual ~Derived() override final {}
|
||||
};
|
||||
void Derived::override2() const noexcept {}
|
||||
|
|
@ -78,6 +82,7 @@ struct Destructors4 : Base {
|
|||
struct FinalOverrideMethods {
|
||||
virtual void final() {}
|
||||
virtual void override(int) {}
|
||||
virtual ~FinalOverrideMethods() = default;
|
||||
};
|
||||
struct FinalOverrideVariables {
|
||||
int final;
|
||||
|
|
|
|||
|
|
@ -4,19 +4,27 @@
|
|||
|
||||
%inline %{
|
||||
#include <set>
|
||||
//#include <map>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
//#include <unordered_map>
|
||||
#include <unordered_map>
|
||||
%}
|
||||
|
||||
%include "std_set.i"
|
||||
//%include "std_map.i"
|
||||
%include "std_multiset.i"
|
||||
%include "std_map.i"
|
||||
%include "std_multimap.i"
|
||||
%include "std_unordered_set.i"
|
||||
//%include "std_unordered_map.i"
|
||||
%include "std_unordered_multiset.i"
|
||||
%include "std_unordered_map.i"
|
||||
%include "std_unordered_multimap.i"
|
||||
%template (SetInt) std::set<int>;
|
||||
//%template (MapIntInt) std::map<int, int>;
|
||||
%template (MultiSetInt) std::multiset<int>;
|
||||
%template (MapIntInt) std::map<int, int>;
|
||||
%template (MultiMapIntInt) std::multimap<int, int>;
|
||||
%template (UnorderedSetInt) std::unordered_set<int>;
|
||||
//%template (UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
%template (UnorderedMultiSetInt) std::unordered_multiset<int>;
|
||||
%template (UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
%template (UnorderedMultiMapIntInt) std::unordered_multimap<int, int>;
|
||||
|
||||
%inline %{
|
||||
using namespace std;
|
||||
|
|
@ -25,19 +33,19 @@ class MyClass {
|
|||
public:
|
||||
set<int> getSet() { return _set; }
|
||||
void addSet(int elt) { _set.insert(_set.begin(), elt); }
|
||||
// map<int, int> getMap() { return _map; }
|
||||
// void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); }
|
||||
map<int, int> getMap() { return _map; }
|
||||
void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); }
|
||||
|
||||
unordered_set<int> getUnorderedSet() { return _unordered_set; }
|
||||
void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); }
|
||||
// unordered_map<int, int> getUnorderedMap() { return _unordered_map; }
|
||||
// void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); }
|
||||
unordered_map<int, int> getUnorderedMap() { return _unordered_map; }
|
||||
void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); }
|
||||
private:
|
||||
set<int> _set;
|
||||
// map<int, int> _map;
|
||||
map<int, int> _map;
|
||||
|
||||
unordered_set<int> _unordered_set;
|
||||
// unordered_map<int, int> _unordered_map;
|
||||
unordered_map<int, int> _unordered_map;
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%module cpp11_li_std_array
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA)
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
|
||||
%{
|
||||
#include <array>
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@
|
|||
%ignore NoExceptClass(NoExceptClass&&);
|
||||
%rename(Assignment) NoExceptClass::operator=;
|
||||
|
||||
%{
|
||||
extern "C" void global_noexcept(int, bool) noexcept {}
|
||||
%}
|
||||
%inline %{
|
||||
|
||||
extern "C" void global_noexcept(int, bool) noexcept;
|
||||
extern "C" void global_noexcept2(int, bool) noexcept {}
|
||||
|
||||
struct NoExceptClass {
|
||||
static const bool VeryTrue = true;
|
||||
|
|
@ -14,7 +18,7 @@ struct NoExceptClass {
|
|||
NoExceptClass(const NoExceptClass&) noexcept {}
|
||||
NoExceptClass(NoExceptClass&&) noexcept {}
|
||||
NoExceptClass& operator=(const NoExceptClass&) noexcept { return *this; }
|
||||
~NoExceptClass() noexcept {}
|
||||
virtual ~NoExceptClass() noexcept {}
|
||||
|
||||
void noex0() noexcept {}
|
||||
void noex1() noexcept(sizeof(int) == 4) {}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ii;
|
||||
|
||||
#if defined(SWIGTCL) || defined(SWIGCSHARP) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGPYTHON) || defined(SWIGJAVA)
|
||||
%include <std_wstring.i>
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ struct Thingy {
|
|||
int val;
|
||||
int &lvalref;
|
||||
int &&rvalref;
|
||||
Thingy(int v) : val(v), lvalref(val), rvalref(22) {}
|
||||
Thingy(int v, int &&rvalv) : val(v), lvalref(val), rvalref(std::move(rvalv)) {}
|
||||
void refIn(long &i) {}
|
||||
void rvalueIn(long &&i) {}
|
||||
short && rvalueInOut(short &&i) { return std::move(i); }
|
||||
|
|
@ -32,7 +32,7 @@ struct Thingy {
|
|||
void compactDefaultArgs(const bool &&b = (const bool &&)PublicGlobalTrue, const UserDef &&u = (const UserDef &&)PublicUserDef) {}
|
||||
void privateDefaultArgs(const bool &&b = (const bool &&)PrivateTrue) {}
|
||||
operator int &&() { return std::move(0); }
|
||||
Thingy(const Thingy& rhs) : val(rhs.val), lvalref(rhs.lvalref), rvalref(copy_int(rhs.rvalref)) {}
|
||||
Thingy(const Thingy& rhs) : val(rhs.val), lvalref(rhs.lvalref), rvalref(std::move(rhs.rvalref)) {}
|
||||
Thingy& operator=(const Thingy& rhs) {
|
||||
val = rhs.val;
|
||||
lvalref = rhs.lvalref;
|
||||
|
|
@ -41,17 +41,18 @@ struct Thingy {
|
|||
}
|
||||
private:
|
||||
static const bool PrivateTrue;
|
||||
int copy_int(int& i) { return i; }
|
||||
Thingy();
|
||||
};
|
||||
const bool Thingy::PrivateTrue = true;
|
||||
|
||||
short && globalRvalueInOut(short &&i) { return std::move(i); }
|
||||
|
||||
Thingy &&globalrrval = Thingy(55);
|
||||
int glob = 123;
|
||||
|
||||
Thingy &&globalrrval = Thingy(55, std::move(glob));
|
||||
|
||||
short && func(short &&i) { return std::move(i); }
|
||||
Thingy getit() { return Thingy(22); }
|
||||
Thingy getit() { return Thingy(22, std::move(glob)); }
|
||||
|
||||
void rvalrefFunction1(int &&v = (int &&)5) {}
|
||||
void rvalrefFunctionBYVAL(short (Thingy::*memFunc)(short)) {}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,13 @@ struct Containing {
|
|||
Thing *const&& member_rvalue_ref_ptr3 = 0;
|
||||
Thing const*const &&member_rvalue_ref_ptr4 = 0;
|
||||
|
||||
Containing() : member_rvalue_ref(Thing()) {}
|
||||
Containing(Thing&&r, Thing*&& r1, Thing const*&& r2, Thing *const&& r3, Thing const*const && r4) :
|
||||
member_rvalue_ref(std::move(r)),
|
||||
member_rvalue_ref_ptr1(std::move(r1)),
|
||||
member_rvalue_ref_ptr2(std::move(r2)),
|
||||
member_rvalue_ref_ptr3(std::move(r3)),
|
||||
member_rvalue_ref_ptr4(std::move(r4))
|
||||
{}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
@ -62,6 +68,12 @@ struct IntContaining {
|
|||
int *const&& member_rvalue_ref_ptr3 = 0;
|
||||
int const*const &&member_rvalue_ref_ptr4 = 0;
|
||||
|
||||
IntContaining() : member_rvalue_ref(55) {}
|
||||
IntContaining(int&& r, int*&& r1, int const*&& r2, int *const&& r3, int const*const && r4) :
|
||||
member_rvalue_ref(std::move(r)),
|
||||
member_rvalue_ref_ptr1(std::move(r1)),
|
||||
member_rvalue_ref_ptr2(std::move(r2)),
|
||||
member_rvalue_ref_ptr3(std::move(r3)),
|
||||
member_rvalue_ref_ptr4(std::move(r4))
|
||||
{}
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
57
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
57
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
%module cpp11_shared_ptr_const
|
||||
|
||||
%{
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
Foo(int i) : m(i) {}
|
||||
int get_m() { return m;}
|
||||
int m;
|
||||
};
|
||||
|
||||
std::shared_ptr<Foo> foo(Foo v) {
|
||||
return std::shared_ptr<Foo>(new Foo(v));
|
||||
}
|
||||
|
||||
std::shared_ptr<const Foo> const_foo(Foo v) {
|
||||
return std::shared_ptr<const Foo>(new Foo(v));
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Foo> > foo_vec(Foo v) {
|
||||
std::vector<std::shared_ptr<Foo> > result;
|
||||
result.push_back( std::shared_ptr<Foo>(new Foo(v)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) {
|
||||
std::vector<std::shared_ptr<const Foo> > result;
|
||||
result.push_back( std::shared_ptr<Foo>(new Foo(v)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%shared_ptr(Foo);
|
||||
|
||||
%template (FooVector) std::vector<std::shared_ptr<Foo> >;
|
||||
%template (FooConstVector) std::vector<std::shared_ptr<Foo const> >;
|
||||
|
||||
class Foo
|
||||
{
|
||||
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);
|
||||
std::vector<std::shared_ptr<Foo> > foo_vec(Foo v) const;
|
||||
std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) const;
|
||||
|
||||
50
Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i
Normal file
50
Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
%module cpp11_shared_ptr_nullptr_in_containers
|
||||
|
||||
%{
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class C;
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%shared_ptr(C)
|
||||
|
||||
%inline %{
|
||||
|
||||
class C {
|
||||
public:
|
||||
C() : m(-1) {}
|
||||
C(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%template() std::vector<std::shared_ptr<C> >;
|
||||
|
||||
%inline %{
|
||||
|
||||
std::vector<std::shared_ptr<C> > ret_vec_c_shared_ptr() {
|
||||
std::vector<std::shared_ptr<C> > ret(3);
|
||||
ret[0] = std::shared_ptr<C>(new C(0));
|
||||
ret[2] = std::shared_ptr<C>(new C(2));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<C> > ret_arg_vec(const std::vector<std::shared_ptr<C> >& v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
bool is_last_null(const std::vector<std::shared_ptr<C> >& v) {
|
||||
if( v.back() ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
188
Examples/test-suite/cpp11_shared_ptr_upcast.i
Normal file
188
Examples/test-suite/cpp11_shared_ptr_upcast.i
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
%module cpp11_shared_ptr_upcast
|
||||
|
||||
%{
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
%}
|
||||
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
%{
|
||||
|
||||
class Base {
|
||||
public:
|
||||
Base() : m(-1) {}
|
||||
Base(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived() : n(-2) {}
|
||||
Derived(int i) : n(i) {}
|
||||
int get_n() { return n; }
|
||||
int n;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Base> BasePtr;
|
||||
typedef std::shared_ptr<Derived> DerivedPtr;
|
||||
|
||||
// non-overloaded
|
||||
int derived_num1(DerivedPtr v) {
|
||||
return v == nullptr ? 999 : (*v).get_n();
|
||||
}
|
||||
|
||||
int derived_num2(std::vector<DerivedPtr> v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_n();
|
||||
}
|
||||
|
||||
int derived_num3(std::map<int, DerivedPtr> v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_n();
|
||||
}
|
||||
|
||||
int base_num1(BasePtr v) {
|
||||
return v == nullptr ? 999 : (*v).get_m();
|
||||
}
|
||||
|
||||
int base_num2(std::vector<BasePtr > v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_m();
|
||||
}
|
||||
|
||||
int base_num3(std::map<int, BasePtr > v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_m();
|
||||
}
|
||||
|
||||
// overloaded
|
||||
int derived_num(DerivedPtr v) {
|
||||
return derived_num1(v);
|
||||
}
|
||||
|
||||
int derived_num(std::vector<DerivedPtr> v) {
|
||||
return derived_num2(v);
|
||||
}
|
||||
|
||||
int derived_num(std::map<int, DerivedPtr> v) {
|
||||
return derived_num3(v);
|
||||
}
|
||||
|
||||
int base_num(BasePtr v) {
|
||||
return base_num1(v);
|
||||
}
|
||||
|
||||
int base_num(std::vector<BasePtr > v) {
|
||||
return base_num2(v);
|
||||
}
|
||||
|
||||
int base_num(std::map<int, BasePtr > v) {
|
||||
return base_num3(v);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
%shared_ptr(Base);
|
||||
%shared_ptr(Derived);
|
||||
|
||||
%template(BaseList) std::vector<std::shared_ptr<Base> >;
|
||||
%template(DerivedList) std::vector<std::shared_ptr<Derived> >;
|
||||
|
||||
%template(BaseMap) std::map<int, std::shared_ptr<Base> >;
|
||||
%template(DerivedMap) std::map<int, std::shared_ptr<Derived> >;
|
||||
|
||||
class Base {
|
||||
public:
|
||||
Base();
|
||||
int get_m();
|
||||
int m;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived();
|
||||
Derived(int i);
|
||||
int get_n();
|
||||
int n;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Base> BasePtr;
|
||||
typedef std::shared_ptr<Derived> DerivedPtr;
|
||||
|
||||
// non-overloaded
|
||||
int derived_num1(DerivedPtr);
|
||||
int derived_num2(std::vector<std::shared_ptr<Derived> > v);
|
||||
int derived_num3(std::map<int, DerivedPtr> v);
|
||||
int base_num1(BasePtr);
|
||||
int base_num2(std::vector<std::shared_ptr<Base> > v);
|
||||
int base_num3(std::map<int, BasePtr > v);
|
||||
|
||||
// overloaded
|
||||
int derived_num(DerivedPtr);
|
||||
int derived_num(std::vector<std::shared_ptr<Derived> > v);
|
||||
int derived_num(std::map<int, DerivedPtr> v);
|
||||
int base_num(BasePtr);
|
||||
int base_num(std::vector<std::shared_ptr<Base> > v);
|
||||
int base_num(std::map<int, BasePtr > v);
|
||||
|
||||
// ptr to shared_ptr
|
||||
%shared_ptr(Base2);
|
||||
%shared_ptr(Derived2)
|
||||
|
||||
%inline %{
|
||||
class Base2 {
|
||||
public:
|
||||
Base2() : m(-1) {}
|
||||
Base2(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
int m;
|
||||
};
|
||||
|
||||
|
||||
class Derived2 : public Base2 {
|
||||
public:
|
||||
Derived2() : n(0) {}
|
||||
Derived2(int i) : n(i) {}
|
||||
int get_n_2() { return n; }
|
||||
int n;
|
||||
};
|
||||
%}
|
||||
|
||||
%template(Base2List) std::vector<std::shared_ptr<Base2> * >;
|
||||
%template(Base2Map) std::map<int, std::shared_ptr<Base2> * >;
|
||||
|
||||
%template(Derived2List) std::vector<std::shared_ptr<Derived2> * >;
|
||||
%template(Derived2Map) std::map<int, std::shared_ptr<Derived2> * >;
|
||||
|
||||
%inline %{
|
||||
typedef std::shared_ptr<Derived2> * Derived2Ptr;
|
||||
typedef std::shared_ptr<Base2> * Base2Ptr;
|
||||
|
||||
int base2_num1(Base2Ptr v) {
|
||||
return v == nullptr ? 999 : *v == nullptr ? 888 : (*v)->get_m();
|
||||
}
|
||||
|
||||
int base2_num2(std::vector<Base2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_m();
|
||||
}
|
||||
|
||||
int base2_num3(std::map<int, Base2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_m();
|
||||
}
|
||||
|
||||
int derived2_num1(Derived2Ptr v) {
|
||||
return v == nullptr ? 999 : *v == nullptr ? 888 : (*v)->get_n_2();
|
||||
}
|
||||
|
||||
int derived2_num2(std::vector<Derived2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_n_2();
|
||||
}
|
||||
|
||||
int derived2_num3(std::map<int, Derived2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_n_2();
|
||||
}
|
||||
%}
|
||||
5
Examples/test-suite/cpp11_std_unordered_map.i
Normal file
5
Examples/test-suite/cpp11_std_unordered_map.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%module cpp11_std_unordered_map
|
||||
|
||||
%include <std_unordered_map.i>
|
||||
|
||||
%template(UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
7
Examples/test-suite/cpp11_std_unordered_multimap.i
Normal file
7
Examples/test-suite/cpp11_std_unordered_multimap.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module cpp11_std_unordered_multimap
|
||||
|
||||
%include <std_pair.i>
|
||||
%include <std_unordered_multimap.i>
|
||||
|
||||
%template(PairIntInt) std::pair<int,int>;
|
||||
%template(UnorderedMultiMapIntInt) std::unordered_multimap<int, int>;
|
||||
5
Examples/test-suite/cpp11_std_unordered_multiset.i
Normal file
5
Examples/test-suite/cpp11_std_unordered_multiset.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%module cpp11_std_unordered_multiset
|
||||
|
||||
%include <std_unordered_multiset.i>
|
||||
|
||||
%template(UnorderedMultiSetInt) std::unordered_multiset<int>;
|
||||
5
Examples/test-suite/cpp11_std_unordered_set.i
Normal file
5
Examples/test-suite/cpp11_std_unordered_set.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%module cpp11_std_unordered_set
|
||||
|
||||
%include <std_unordered_set.i>
|
||||
|
||||
%template(UnorderedSetInt) std::unordered_set<int>;
|
||||
|
|
@ -1,56 +1,86 @@
|
|||
/* This testcase checks whether SWIG correctly parses alias templates. */
|
||||
/* This testcase checks whether SWIG correctly handles alias templates. */
|
||||
%module cpp11_template_typedefs
|
||||
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefName;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefNamePtr;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) MyIntKeyClass;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator1;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator2;
|
||||
|
||||
// This warning should go away when type aliasing is supported
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_USING_UNDEF // Nothing known about 'p.SomeType< char *,T2,4 >'.
|
||||
|
||||
%inline %{
|
||||
template< typename T1, typename T2, int >
|
||||
|
||||
template<typename T>
|
||||
using ptr_t = T*;
|
||||
|
||||
namespace ns {
|
||||
|
||||
template<typename T1, typename T2, int N>
|
||||
class SomeType {
|
||||
public:
|
||||
using type1_t = T1;
|
||||
using type2_t = T2;
|
||||
T1 a;
|
||||
T2 b;
|
||||
int c;
|
||||
constexpr int get_n() { return N; }
|
||||
};
|
||||
|
||||
// template aliasing
|
||||
template< typename T2 >
|
||||
using TypedefName = SomeType<char*, T2, 5>;
|
||||
template< typename T2 >
|
||||
using TypedefNamePtr = SomeType<char*, T2, 4>*;
|
||||
|
||||
// type aliasing
|
||||
typedef void (*PFD)(double); // Old style
|
||||
using PF = void (*)(double); // New introduced syntax
|
||||
|
||||
|
||||
// use of template aliasing
|
||||
template<typename Key,typename Val>
|
||||
class MyCPP11Class {
|
||||
// Specialization for T1=const char*, T2=bool
|
||||
template<int N>
|
||||
class SomeType<const char*, bool, N> {
|
||||
public:
|
||||
using type1_t = const char*;
|
||||
using type2_t = bool;
|
||||
type1_t a;
|
||||
type2_t b;
|
||||
constexpr int get_n() { return 3 * N; }
|
||||
};
|
||||
template<typename VAL> using MyIntKeyClass = MyCPP11Class<int,VAL>;
|
||||
MyIntKeyClass<char> intchar;
|
||||
|
||||
TypedefName<int> alias1(TypedefName<int> a) { return a; }
|
||||
TypedefNamePtr<int> alias1(TypedefNamePtr<int> a = nullptr) { return a; }
|
||||
%}
|
||||
// alias templates
|
||||
template<typename T2>
|
||||
using TypedefName = SomeType<const char*, T2, 5>;
|
||||
template<typename T2>
|
||||
using TypedefNamePtr = ptr_t<SomeType<const char*, T2, 4>>;
|
||||
|
||||
// alias template that returns T2 for a SomeType<T1,T2,N> class
|
||||
template<typename T>
|
||||
using T2_of = typename T::type2_t;
|
||||
|
||||
T2_of<TypedefName<int>> get_SomeType_b(const SomeType<const char*, int, 5>& x) { return x.b; }
|
||||
|
||||
template<typename T>
|
||||
T2_of<TypedefName<T>> get_SomeType_b2(const TypedefName<T>& x) { return x.b; }
|
||||
|
||||
} // namespace ns
|
||||
|
||||
ns::TypedefName<int> create_TypedefName() { return { "hello", 10}; }
|
||||
ns::TypedefName<bool> create_TypedefNameBool() { return { "hello", true}; }
|
||||
ns::TypedefNamePtr<int> identity(ns::TypedefNamePtr<int> a = nullptr) { return a; }
|
||||
|
||||
%inline %{
|
||||
typedef double Val;
|
||||
template<typename T> struct ListBucket {
|
||||
};
|
||||
namespace Alloc {
|
||||
template<typename T> struct rebind {
|
||||
typedef int other;
|
||||
using other = int;
|
||||
};
|
||||
}
|
||||
|
||||
using BucketAllocator1 = typename Alloc::template rebind<ListBucket<Val>>::other;
|
||||
using BucketAllocator2 = typename Alloc::template rebind<::template ListBucket<double>>::other;
|
||||
|
||||
BucketAllocator1 get_bucket_allocator1() { return 1; }
|
||||
BucketAllocator2 get_bucket_allocator2() { return 2; }
|
||||
%}
|
||||
|
||||
%immutable ns::SomeType::a;
|
||||
|
||||
// %template() directives
|
||||
|
||||
%template(SomeTypeInt5) ns::SomeType<const char*, int, 5>;
|
||||
%template(SomeTypeInt4) ns::SomeType<const char*, int, 4>;
|
||||
%template(SomeTypeBool5) ns::SomeType<const char*, bool, 5>;
|
||||
|
||||
%template(ListBucketDouble) ListBucket<Val>;
|
||||
%template(RebindListBucketDouble) Alloc::rebind<ListBucket<Val>>;
|
||||
|
||||
%template() ptr_t<ns::SomeType<const char*, int, 4>>;
|
||||
%template() ns::TypedefName<int>;
|
||||
%template() ns::TypedefName<bool>;
|
||||
%template() ns::TypedefNamePtr<int>;
|
||||
%template() ns::T2_of<ns::TypedefName<int>>;
|
||||
|
||||
%template(get_SomeType_b2) ns::get_SomeType_b2<int>;
|
||||
|
|
|
|||
|
|
@ -2,15 +2,6 @@
|
|||
|
||||
// Type aliasing seg fault : Github issue #424
|
||||
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Target;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Int;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRef;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntPtrRef;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRValueRef;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntArray;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr1;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr2;
|
||||
|
||||
%inline %{
|
||||
namespace Halide {
|
||||
|
||||
|
|
@ -53,14 +44,69 @@ public:
|
|||
|
||||
|
||||
%inline %{
|
||||
using Int = int;
|
||||
using IntRef = int&;
|
||||
using IntPtrRef = int*&;
|
||||
using IntRValueRef = int&&;
|
||||
using IntArray = int[];
|
||||
|
||||
using HalideTargetPtr1 = Halide::Target*;
|
||||
namespace Halide {
|
||||
using HalideTargetPtr2 = Target*;
|
||||
}
|
||||
%}
|
||||
|
||||
// Define some types
|
||||
|
||||
%inline %{
|
||||
using Int = int;
|
||||
using IntPtr = Int*;
|
||||
using IntRef = Int&;
|
||||
using IntPtrRef = Int*&;
|
||||
using IntRValueRef = Int&&;
|
||||
using IntArray = Int[];
|
||||
%}
|
||||
|
||||
// Test that SWIG understands these new types
|
||||
|
||||
%callback("%s_cb");
|
||||
Int mult2(Int x);
|
||||
%nocallback;
|
||||
|
||||
%inline %{
|
||||
Int mult2(Int x) { return x * 2; }
|
||||
IntPtr allocate_int() { return new Int(12); }
|
||||
void free_int(int* ptr) { delete ptr; }
|
||||
void inplace_mult2(IntRef x) { x *= 2; }
|
||||
Int read_int(IntPtr ptr) { return *ptr; }
|
||||
|
||||
template <typename T> class Pair {
|
||||
public:
|
||||
using data_t = T;
|
||||
|
||||
data_t a, b;
|
||||
|
||||
Pair() : a(), b() { }
|
||||
Pair(data_t a, data_t b) : a(a), b(b) { }
|
||||
data_t first() { return a; }
|
||||
data_t second() { return b; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template(int_pair) Pair<Int>;
|
||||
|
||||
%inline %{
|
||||
using PairInt = Pair<Int>;
|
||||
|
||||
class PairSubclass : public PairInt {
|
||||
public:
|
||||
PairSubclass(data_t a, data_t b) : PairInt(a, b) { }
|
||||
|
||||
using const_ref_data_t = const data_t&;
|
||||
};
|
||||
|
||||
PairSubclass::data_t plus1(PairSubclass::const_ref_data_t x) { return x + 1; }
|
||||
%}
|
||||
|
||||
// Test function pointers
|
||||
|
||||
%inline %{
|
||||
using callback_t = int(*)(int);
|
||||
|
||||
callback_t get_callback() { return mult2; }
|
||||
int call(callback_t func, int param) { return func(param); }
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@ The primary purpose of this testcase is to ensure that enums used along with the
|
|||
|
||||
%inline %{
|
||||
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for anonymous enums */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
enum SOME_ENUM {ENUM_ONE, ENUM_TWO};
|
||||
|
||||
struct StructWithEnums {
|
||||
|
|
|
|||
|
|
@ -22,5 +22,28 @@ public:
|
|||
%}
|
||||
|
||||
%{
|
||||
int StaticMemberTest::static_int;
|
||||
int StaticMemberTest::static_int = 99;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct StaticBase {
|
||||
static int statty;
|
||||
virtual ~StaticBase() {}
|
||||
};
|
||||
struct StaticDerived : StaticBase {
|
||||
static int statty;
|
||||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
int StaticBase::statty = 11;
|
||||
int StaticDerived::statty = 111;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ top_srcdir = ../@top_srcdir@
|
|||
top_builddir = ../@top_builddir@
|
||||
|
||||
CPP_TEST_CASES = \
|
||||
complextest \
|
||||
csharp_attributes \
|
||||
csharp_swig2_compatibility \
|
||||
csharp_exceptions \
|
||||
|
|
@ -40,6 +41,7 @@ CSHARPFLAGSSPECIAL =
|
|||
|
||||
# Custom tests - tests with additional commandline options
|
||||
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
|
||||
complextest.cpptest: CSHARPFLAGSSPECIAL = -r:System.Numerics.dll
|
||||
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP
|
||||
|
||||
|
|
|
|||
34
Examples/test-suite/csharp/complextest_runme.cs
Normal file
34
Examples/test-suite/csharp/complextest_runme.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// This is the complex runtime testcase. It checks that the C++ std::complex type works.
|
||||
// It requires .NET 4.0 as the previous versions didn't have System.Numerics.Complex type.
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
using complextestNamespace;
|
||||
|
||||
public class complextest_runme {
|
||||
|
||||
public static void Main() {
|
||||
var a = new Complex(-1, 2);
|
||||
if ( complextest.Conj(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<double> test failed");
|
||||
|
||||
if ( complextest.Conjf(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");
|
||||
|
||||
var p = new ComplexPair();
|
||||
p.z1 = new Complex(0, 1);
|
||||
p.z2 = new Complex(0, -1);
|
||||
if ( Complex.Conjugate(p.z2) != p.z1 )
|
||||
throw new Exception("vector<complex> test failed");
|
||||
}
|
||||
}
|
||||
82
Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
Normal file
82
Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// This test tests all the methods in the C# collection wrapper
|
||||
using System;
|
||||
using cpp11_li_std_arrayNamespace;
|
||||
|
||||
public class cpp11_li_std_array_runme
|
||||
{
|
||||
private static ArrayInt6 ToArray6(int[] a)
|
||||
{
|
||||
if (a.Length != 6)
|
||||
throw new Exception("a is incorrect size");
|
||||
return new ArrayInt6(a);
|
||||
}
|
||||
|
||||
private static void compareContainers(ArrayInt6 actual, int[] expected)
|
||||
{
|
||||
if (actual.Count != expected.Length)
|
||||
throw new Exception("Sizes are different: " + actual.Count + " " + expected.Length);
|
||||
for (int i=0; i<actual.Count; ++i)
|
||||
{
|
||||
int actualValue = actual[i];
|
||||
int expectedValue = expected[i];
|
||||
if (actualValue != expectedValue)
|
||||
throw new Exception("Value is wrong for element " + i + ". Expected " + expectedValue + " got: " + actualValue);
|
||||
}
|
||||
if (actual.IsEmpty)
|
||||
throw new Exception("ai should not be empty");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
ArrayInt6 ai = new ArrayInt6();
|
||||
compareContainers(ai, new int[] { 0, 0, 0, 0, 0, 0 });
|
||||
|
||||
int[] vals = { 10, 20, 30, 40, 50, 60 };
|
||||
for (int i = 0; i < ai.Count; ++i)
|
||||
ai[i] = vals[i];
|
||||
compareContainers(ai, vals);
|
||||
|
||||
// Check return
|
||||
compareContainers(cpp11_li_std_array.arrayOutVal(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutConstRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutPtr(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
|
||||
// Check passing arguments
|
||||
ai = cpp11_li_std_array.arrayInVal(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = cpp11_li_std_array.arrayInConstRef(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_li_std_array.arrayInRef(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_li_std_array.arrayInPtr(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
// fill
|
||||
ai.Fill(111);
|
||||
compareContainers(ai, new int[] { 111, 111, 111, 111, 111, 111 });
|
||||
|
||||
// out of range errors
|
||||
try
|
||||
{
|
||||
ai[ai.Count] = 0;
|
||||
throw new Exception("Out of range exception not caught");
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
ai[-1] = 0;
|
||||
throw new Exception("Out of range exception not caught");
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,29 @@ public class runme
|
|||
}
|
||||
}
|
||||
|
||||
private class director_smartptr_MyBarFooDerived : FooDerived
|
||||
{
|
||||
public override string ping()
|
||||
{
|
||||
return "director_smartptr_MyBarFooDerived.ping()";
|
||||
}
|
||||
|
||||
public override string pong()
|
||||
{
|
||||
return "director_smartptr_MyBarFooDerived.pong();" + ping();
|
||||
}
|
||||
|
||||
public override string upcall(FooBar fooBarPtr)
|
||||
{
|
||||
return "overrideDerived;" + fooBarPtr.FooBarDo();
|
||||
}
|
||||
|
||||
public override Foo makeFoo()
|
||||
{
|
||||
return new Foo();
|
||||
}
|
||||
}
|
||||
|
||||
private static void check(string got, string expected)
|
||||
{
|
||||
if (got != expected)
|
||||
|
|
@ -49,5 +72,11 @@ public class runme
|
|||
Foo myFoo2 = new Foo().makeFoo();
|
||||
check(myFoo2.pong(), "Foo::pong();Foo::ping()");
|
||||
check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()");
|
||||
|
||||
FooDerived myBarFooDerived = new director_smartptr_MyBarFooDerived();
|
||||
check(myBarFooDerived.ping(), "director_smartptr_MyBarFooDerived.ping()");
|
||||
check(FooDerived.callPong(myBarFooDerived), "director_smartptr_MyBarFooDerived.pong();director_smartptr_MyBarFooDerived.ping()");
|
||||
check(FooDerived.callUpcall(myBarFooDerived, fooBar), "overrideDerived;Bar::Foo2::Foo2Bar()");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
83
Examples/test-suite/csharp/director_void_runme.cs
Normal file
83
Examples/test-suite/csharp/director_void_runme.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using director_voidNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
runme r = new runme();
|
||||
r.run();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
Caller caller = new Caller();
|
||||
{
|
||||
DirectorVoidPointer dvp = new DirectorVoidPointer(5);
|
||||
int x = caller.callVirtualIn(dvp, 6);
|
||||
if (x != 106)
|
||||
throw new Exception("Fail1 should be 106, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = Caller.VoidToInt(ptr);
|
||||
if (x != 106)
|
||||
throw new Exception("Fail2 should be 106, got " + x);
|
||||
x = Caller.VoidToInt(dvp.voidPtrOut());
|
||||
if (x != 106)
|
||||
throw new Exception("Fail3 should be 106, got " + x);
|
||||
}
|
||||
|
||||
{
|
||||
DirectorVoidPointer dvp = new director_void_VoidPointer(5);
|
||||
int x = caller.callVirtualIn(dvp, 6);
|
||||
if (x != 12)
|
||||
throw new Exception("Fail1 should be 12, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = Caller.VoidToInt(ptr);
|
||||
if (x != 25)
|
||||
throw new Exception("Fail2 should be 25, got " + x);
|
||||
x = Caller.VoidToInt(dvp.voidPtrOut());
|
||||
if (x != 1234)
|
||||
throw new Exception("Fail3 should be 1234, got " + x);
|
||||
}
|
||||
|
||||
{
|
||||
DirectorVoidPointer dvp = new DirectorVoidPointer(10);
|
||||
int x = caller.callVirtualOut(dvp);
|
||||
if (x != 10)
|
||||
throw new Exception("Bad1 should be 10, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = dvp.nonVirtualVoidPtrIn(ptr);
|
||||
if (x != 110)
|
||||
throw new Exception("Bad2 should be 110, got " + x);
|
||||
}
|
||||
{
|
||||
DirectorVoidPointer dvp = new director_void_VoidPointer(10);
|
||||
int x = caller.callVirtualOut(dvp);
|
||||
if (x != 1234)
|
||||
throw new Exception("Bad3 should be 1234, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = dvp.nonVirtualVoidPtrIn(ptr);
|
||||
if (x != 1334)
|
||||
throw new Exception("Bad4 should be 1334, got " + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class director_void_VoidPointer : DirectorVoidPointer {
|
||||
public director_void_VoidPointer(int num) : base(num*num) {
|
||||
}
|
||||
public override int voidPtrIn(global::System.IntPtr p) {
|
||||
return Caller.VoidToInt(p) * 2;
|
||||
}
|
||||
public override global::System.IntPtr voidPtrOut() {
|
||||
setNewValue(1234);
|
||||
return nonVirtualVoidPtrOut();
|
||||
}
|
||||
}
|
||||
|
|
@ -405,6 +405,10 @@ public class runme {
|
|||
if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed");
|
||||
if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed");
|
||||
}
|
||||
{
|
||||
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue != (('A' << 24) | ('B' << 16) | ('C' << 8) | 'D')) throw new Exception("enumWithMacroTest 1 failed");
|
||||
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD2).swigValue != enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue) throw new Exception("enumWithMacroTest 2 failed");
|
||||
}
|
||||
// different types
|
||||
{
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed");
|
||||
|
|
@ -413,6 +417,8 @@ public class runme {
|
|||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeboolfalse).swigValue != 0) throw new Exception("differentTypes 4 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typechar).swigValue != (int)'C') throw new Exception("differentTypes 5 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typedefaultint).swigValue != (int)'D') throw new Exception("differentTypes 6 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound).swigValue != (int)'A' + 1) throw new Exception("differentTypes 7 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound2).swigValue != (int)'B' << 2) throw new Exception("differentTypes 8 failed");
|
||||
|
||||
int global_enum = enum_thorough_typesafe.global_typeint;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
|
||||
|
|
@ -426,6 +432,10 @@ public class runme {
|
|||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typedefaultint;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typecharcompound;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'A' + 1) throw new Exception("global differentTypes 7 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typecharcompound2;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'B' << 2) throw new Exception("global differentTypes 8 failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public class li_std_except_runme {
|
|||
|
||||
public static void Main() {
|
||||
Test test = new Test();
|
||||
try { test.throw_bad_cast(); throw new Exception("throw_bad_cast failed"); } catch (InvalidCastException) {}
|
||||
try { test.throw_bad_exception(); throw new Exception("throw_bad_exception failed"); } catch (ApplicationException) {}
|
||||
try { test.throw_domain_error(); throw new Exception("throw_domain_error failed"); } catch (ApplicationException) {}
|
||||
try { test.throw_exception(); throw new Exception("throw_exception failed"); } catch (ApplicationException) {}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class li_std_vector_runme {
|
|||
throw new Exception("Contains test 4 failed");
|
||||
|
||||
{
|
||||
// ICollection constructor
|
||||
// IEnumerable constructor
|
||||
double[] doubleArray = new double[] { 0.0, 11.1, 22.2, 33.3, 44.4, 55.5, 33.3 };
|
||||
DoubleVector dv = new DoubleVector(doubleArray);
|
||||
if (doubleArray.Length != dv.Count)
|
||||
|
|
@ -619,6 +619,55 @@ public class li_std_vector_runme {
|
|||
}
|
||||
}
|
||||
|
||||
// Test construction
|
||||
{
|
||||
string[] one_two_three = new string[] { "one", "two", "three" };
|
||||
|
||||
// Test construction from array
|
||||
{
|
||||
string[] collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from IEnumerable
|
||||
{
|
||||
global::System.Collections.IEnumerable collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from IEnumerable<>
|
||||
{
|
||||
global::System.Collections.Generic.IEnumerable<string> collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from IList<>
|
||||
{
|
||||
global::System.Collections.Generic.IList<string> collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from ICollection
|
||||
{
|
||||
global::System.Collections.ICollection collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from ICollection<>
|
||||
{
|
||||
global::System.Collections.Generic.ICollection<string> collection = new global::System.Collections.Generic.List<string>(one_two_three);
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void check123(StringVector stringv) {
|
||||
string concatenated = "";
|
||||
foreach (string s in stringv)
|
||||
concatenated = concatenated + s;
|
||||
if (concatenated != "onetwothree")
|
||||
throw new Exception("concatenated string failed: " + concatenated);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
33
Examples/test-suite/csharp/proxycode_runme.cs
Normal file
33
Examples/test-suite/csharp/proxycode_runme.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using proxycodeNamespace;
|
||||
|
||||
public class proxycode_runme {
|
||||
|
||||
public static void Main() {
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2a(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2b(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy3().proxycode3(100) != 103)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy4().proxycode4(100) != 104)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy5a().proxycode5((short)100) != (short)100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100) != 100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100, 100) != 255)
|
||||
throw new Exception("Fail");
|
||||
|
||||
uint t1 = 10;
|
||||
uint t2 = 100;
|
||||
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
|
||||
p.useT(t1, t2);
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,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
|
||||
|
||||
// %exception tests
|
||||
void ThrowByValue() { throw Ex("ThrowByValue"); }
|
||||
|
|
@ -239,3 +243,12 @@ struct ThrowsClass {
|
|||
%inline %{
|
||||
void InnerExceptionTest() { throw Ex("My InnerException message"); }
|
||||
%}
|
||||
|
||||
%{
|
||||
#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
|
||||
%}
|
||||
|
|
|
|||
41
Examples/test-suite/d/proxycode_runme.2.d
Normal file
41
Examples/test-suite/d/proxycode_runme.2.d
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
module proxycode_runme;
|
||||
|
||||
import std.exception;
|
||||
import proxycode.Proxy1;
|
||||
import proxycode.Proxy2;
|
||||
import proxycode.Proxy3;
|
||||
import proxycode.Proxy4;
|
||||
import proxycode.Proxy5a;
|
||||
import proxycode.Proxy5b;
|
||||
import proxycode.Proxy6;
|
||||
|
||||
void main() {
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2a(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2b(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy3().proxycode3(100) != 103)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy4().proxycode4(100) != 104)
|
||||
throw new Exception("Fail");
|
||||
// if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
|
||||
// throw new Exception("Fail");
|
||||
|
||||
if (new Proxy5a().proxycode5(100) != 100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100) != 100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100, 100) != 255)
|
||||
throw new Exception("Fail");
|
||||
|
||||
uint t1 = 10;
|
||||
uint t2 = 100;
|
||||
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
|
||||
p.useT(t1, t2);
|
||||
}
|
||||
|
|
@ -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
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
|
@ -152,6 +156,9 @@
|
|||
int double_if_handle_is_null(int n, MyHandle h = 0) { return h ? n : 2*n; }
|
||||
int double_if_dbl_ptr_is_null(int n, double* null_by_default)
|
||||
{ return null_by_default ? n : 2*n; }
|
||||
|
||||
void defaulted1(unsigned offset = -1U) {} // minus unsigned!
|
||||
void defaulted2(int offset = -1U) {} // minus unsigned!
|
||||
};
|
||||
int Foo::bar = 1;
|
||||
int Foo::spam = 2;
|
||||
|
|
@ -305,3 +312,11 @@ struct CDA {
|
|||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
#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
|
||||
%}
|
||||
|
|
|
|||
14
Examples/test-suite/default_args_c.i
Normal file
14
Examples/test-suite/default_args_c.i
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%module default_args_c
|
||||
|
||||
/* Default arguments for C code */
|
||||
int foo1(int x = 42 || 3);
|
||||
int foo43(int x = 42 | 3);
|
||||
|
||||
%{
|
||||
int foo1(int x) {
|
||||
return x;
|
||||
}
|
||||
int foo43(int x) {
|
||||
return x;
|
||||
}
|
||||
%}
|
||||
|
|
@ -7,6 +7,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
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
@ -28,12 +32,27 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
|
||||
%include "std_string.i"
|
||||
|
||||
#ifdef SWIGPHP
|
||||
|
||||
%feature("director:except") {
|
||||
if ($error == FAILURE) {
|
||||
Swig::DirectorMethodException::raise("$symname");
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
if ($error != NULL) {
|
||||
Swig::DirectorMethodException::raise("$symname");
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
|
|
@ -69,7 +88,7 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
#ifdef SWIGRUBY
|
||||
|
||||
%feature("director:except") {
|
||||
throw Swig::DirectorMethodException($error);
|
||||
Swig::DirectorMethodException::raise($error);
|
||||
}
|
||||
|
||||
%exception {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public:
|
|||
%include <boost_shared_ptr.i>
|
||||
|
||||
%shared_ptr(Foo)
|
||||
|
||||
%feature("director") Foo;
|
||||
|
||||
class FooBar {
|
||||
|
|
@ -72,5 +71,12 @@ public:
|
|||
static Foo* get_self(Foo *self_);
|
||||
};
|
||||
|
||||
%shared_ptr(FooDerived)
|
||||
%feature("director") FooDerived;
|
||||
|
||||
%inline %{
|
||||
struct FooDerived : Foo {
|
||||
};
|
||||
%}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -11,25 +11,36 @@
|
|||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include "swig_examples_lock.h"
|
||||
|
||||
class Foo;
|
||||
extern "C" {
|
||||
#ifdef _WIN32
|
||||
unsigned int __stdcall working(void* t);
|
||||
unsigned int thread_id(0);
|
||||
static unsigned int __stdcall working(void* t);
|
||||
static HANDLE thread_handle = 0;
|
||||
#else
|
||||
void* working(void* t);
|
||||
pthread_t thread;
|
||||
static pthread_t thread;
|
||||
#endif
|
||||
|
||||
static int thread_terminate = 0;
|
||||
|
||||
static SwigExamples::CriticalSection critical_section;
|
||||
int get_thread_terminate() {
|
||||
SwigExamples::Lock lock(critical_section);
|
||||
return thread_terminate;
|
||||
}
|
||||
void set_thread_terminate(int value) {
|
||||
SwigExamples::Lock lock(critical_section);
|
||||
thread_terminate = value;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
@ -55,9 +66,10 @@ extern "C" {
|
|||
}
|
||||
|
||||
void stop() {
|
||||
thread_terminate = 1;
|
||||
set_thread_terminate(1);
|
||||
%#ifdef _WIN32
|
||||
/*TODO(bhy) what to do for win32? */
|
||||
WaitForSingleObject(thread_handle, INFINITE);
|
||||
CloseHandle(thread_handle);
|
||||
%#else
|
||||
pthread_join(thread, NULL);
|
||||
%#endif
|
||||
|
|
@ -65,9 +77,18 @@ extern "C" {
|
|||
|
||||
void run() {
|
||||
%#ifdef _WIN32
|
||||
_beginthreadex(NULL,0,working,this,0,&thread_id);
|
||||
unsigned int thread_id = 0;
|
||||
thread_handle = (HANDLE)_beginthreadex(NULL,0,working,this,0,&thread_id);
|
||||
if (thread_handle == 0) {
|
||||
fprintf(stderr, "_beginthreadex failed in run()\n");
|
||||
assert(0);
|
||||
}
|
||||
%#else
|
||||
pthread_create(&thread,NULL,working,this);
|
||||
int create = pthread_create(&thread,NULL,working,this);
|
||||
if (create != 0) {
|
||||
fprintf(stderr, "pthread_create failed in run()\n");
|
||||
assert(0);
|
||||
}
|
||||
%#endif
|
||||
MilliSecondSleep(500);
|
||||
}
|
||||
|
|
@ -87,15 +108,10 @@ extern "C" {
|
|||
#endif
|
||||
{
|
||||
Foo* f = static_cast<Foo*>(t);
|
||||
while ( ! thread_terminate ) {
|
||||
while (!get_thread_terminate()) {
|
||||
MilliSecondSleep(50);
|
||||
f->do_foo();
|
||||
}
|
||||
#ifdef _WIN32
|
||||
/* TODO(bhy) what's the corresponding of pthread_exit in win32? */
|
||||
#else
|
||||
pthread_exit(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
Examples/test-suite/director_void.i
Normal file
47
Examples/test-suite/director_void.i
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
%module(directors="1") director_void
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) voidPtrOut;
|
||||
|
||||
%feature("director") DirectorVoidPointer;
|
||||
|
||||
#if defined(SWIGCSHARP)
|
||||
%apply void *VOID_INT_PTR { void * }
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
class DirectorVoidPointer {
|
||||
int *ptr;
|
||||
public:
|
||||
DirectorVoidPointer(int val) : ptr(new int(val)) {}
|
||||
virtual ~DirectorVoidPointer() { delete ptr; }
|
||||
|
||||
virtual void * voidPtrOut() { return ptr; }
|
||||
virtual int voidPtrIn(void *p) {
|
||||
return nonVirtualVoidPtrIn(p);
|
||||
}
|
||||
|
||||
void setNewValue(int val) {
|
||||
delete ptr;
|
||||
ptr = new int(val);
|
||||
}
|
||||
void *nonVirtualVoidPtrOut() { return ptr; }
|
||||
int nonVirtualVoidPtrIn(void *p) {
|
||||
int val = *(int *)p;
|
||||
setNewValue(val + 100);
|
||||
return *ptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct Caller {
|
||||
int callVirtualIn(DirectorVoidPointer *d, int num) {
|
||||
return d->voidPtrIn(&num);
|
||||
}
|
||||
int callVirtualOut(DirectorVoidPointer *d) {
|
||||
return *(int *)d->voidPtrOut();
|
||||
}
|
||||
static int VoidToInt(void *p) {
|
||||
return *(int *)p;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
@ -47,6 +47,12 @@
|
|||
|
||||
%inline %{
|
||||
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for anonymous enums */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
enum { AnonEnum1, AnonEnum2 = 100 };
|
||||
enum { ReallyAnInteger = 200 };
|
||||
//enum { AnonEnum3, AnonEnum4 } instance;
|
||||
|
|
@ -563,6 +569,17 @@ repeat repeatTest(repeat e) { return e; }
|
|||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
namespace EnumWithMacro {
|
||||
#define PACK(C1,C2,C3,C4) ((C1<<24)|(C2<<16)|(C3<<8)|C4)
|
||||
typedef enum {
|
||||
ABCD = PACK('A','B','C','D'),
|
||||
ABCD2 = ABCD
|
||||
} enumWithMacro;
|
||||
enumWithMacro enumWithMacroTest(enumWithMacro e) { return e; }
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
namespace DifferentSpace {
|
||||
enum DifferentTypes {
|
||||
|
|
@ -571,7 +588,9 @@ enum DifferentTypes {
|
|||
typebooltrue = true,
|
||||
typebooltwo,
|
||||
typechar = 'C',
|
||||
typedefaultint
|
||||
typedefaultint,
|
||||
typecharcompound='A'+1,
|
||||
typecharcompound2='B' << 2
|
||||
};
|
||||
DifferentTypes differentTypesTest(DifferentTypes n) { return n; }
|
||||
|
||||
|
|
@ -581,7 +600,9 @@ enum {
|
|||
global_typebooltrue = true,
|
||||
global_typebooltwo,
|
||||
global_typechar = 'C',
|
||||
global_typedefaultint
|
||||
global_typedefaultint,
|
||||
global_typecharcompound='A'+1,
|
||||
global_typecharcompound2='B' << 2
|
||||
};
|
||||
int globalDifferentTypesTest(int n) { return n; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@
|
|||
|
||||
%inline %{
|
||||
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for anonymous enums */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CSP_ITERATION_FWD,
|
||||
CSP_ITERATION_BWD = 11
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
int foo(int x = 42 || 3);
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
int foo(int x, ...);
|
||||
6
Examples/test-suite/errors/cpp_bad_global_memberptr.i
Normal file
6
Examples/test-suite/errors/cpp_bad_global_memberptr.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%module xxx
|
||||
|
||||
struct Funcs {};
|
||||
|
||||
short (Funcs::* *)(bool) = 0;
|
||||
short (Funcs::* const*)(bool) = 0;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
cpp_bad_global_memberptr.i:5: Error: Missing symbol name for global declaration
|
||||
cpp_bad_global_memberptr.i:6: Error: Missing symbol name for global declaration
|
||||
80
Examples/test-suite/errors/cpp_namewarn.i
Normal file
80
Examples/test-suite/errors/cpp_namewarn.i
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
%module xxx
|
||||
|
||||
%namewarn("314:'key1' is a keyword, renaming to '_key1'", rename="_%s") "key1";
|
||||
%namewarn("314:'key2' is a keyword, renaming to '_key2'", rename="_%s") "key2";
|
||||
%namewarn("314:'key3' is a keyword, renaming to '_key3'", rename="_%s") "key3";
|
||||
%namewarn("314:'key4' is a keyword, renaming to '_key4'", rename="_%s") "key4";
|
||||
%namewarn("314:'key5' is a keyword, renaming to '_key5'", rename="_%s") "key5";
|
||||
|
||||
// Non-templated
|
||||
%ignore KlassA::key1;
|
||||
%rename(key2renamed) KlassA::key2;
|
||||
%rename(key3renamed) KlassA::key3;
|
||||
%rename(key4renamed) KlassA::key4;
|
||||
|
||||
// Templated
|
||||
%ignore KlassB::key1;
|
||||
%rename(key2renamed) KlassB::key2;
|
||||
%rename(key3renamed) KlassB<double>::key3;
|
||||
|
||||
// Template specialized
|
||||
%ignore KlassC::key1;
|
||||
%rename(key2renamed) KlassC::key2;
|
||||
%rename(key3renamed) KlassC<double>::key3;
|
||||
|
||||
// No warnings for these...
|
||||
%inline %{
|
||||
struct KlassA {
|
||||
void key1() {}
|
||||
void key2() {}
|
||||
void key3() {}
|
||||
template<typename X> void key4(X x) {}
|
||||
};
|
||||
|
||||
template<class T> struct KlassB {
|
||||
void key1() {}
|
||||
void key2() {}
|
||||
void key3() {}
|
||||
};
|
||||
|
||||
template<class T> struct KlassC {};
|
||||
template<> struct KlassC<double> {
|
||||
void key1() {}
|
||||
void key2() {}
|
||||
void key3() {}
|
||||
};
|
||||
|
||||
template<typename T> void key5(T t) {}
|
||||
|
||||
%}
|
||||
|
||||
%template(KlassBDouble) KlassB<double>;
|
||||
%template(KlassCInt) KlassC<double>;
|
||||
%template(key5renamed) key5<double>;
|
||||
|
||||
// These should create a single warning for each keyword...
|
||||
%inline %{
|
||||
struct ClassA {
|
||||
void key1() {}
|
||||
void key2() {}
|
||||
void key3() {}
|
||||
template<typename X> void key4(X x) {}
|
||||
};
|
||||
|
||||
template<class T> struct ClassB {
|
||||
void key1() {}
|
||||
void key2() {}
|
||||
void key3() {}
|
||||
};
|
||||
|
||||
template<class T> struct ClassC {};
|
||||
template<> struct ClassC<double> {
|
||||
void key1() {}
|
||||
void key2() {}
|
||||
void key3() {}
|
||||
};
|
||||
%}
|
||||
|
||||
%template(ClassBDouble) ClassB<double>;
|
||||
%template(ClassCInt) ClassC<double>;
|
||||
%template(key5) key5<int>;
|
||||
10
Examples/test-suite/errors/cpp_namewarn.stderr
Normal file
10
Examples/test-suite/errors/cpp_namewarn.stderr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
cpp_namewarn.i:58: Warning 314: 'key1' is a keyword, renaming to '_key1'
|
||||
cpp_namewarn.i:59: Warning 314: 'key2' is a keyword, renaming to '_key2'
|
||||
cpp_namewarn.i:60: Warning 314: 'key3' is a keyword, renaming to '_key3'
|
||||
cpp_namewarn.i:65: Warning 314: 'key1' is a keyword, renaming to '_key1'
|
||||
cpp_namewarn.i:66: Warning 314: 'key2' is a keyword, renaming to '_key2'
|
||||
cpp_namewarn.i:67: Warning 314: 'key3' is a keyword, renaming to '_key3'
|
||||
cpp_namewarn.i:72: Warning 314: 'key1' is a keyword, renaming to '_key1'
|
||||
cpp_namewarn.i:73: Warning 314: 'key2' is a keyword, renaming to '_key2'
|
||||
cpp_namewarn.i:74: Warning 314: 'key3' is a keyword, renaming to '_key3'
|
||||
cpp_namewarn.i:80: Warning 314: 'key5' is a keyword, renaming to '_key5'
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
%module xxx
|
||||
int foo(int x);
|
||||
int foo(double x);
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
int bar(int);
|
||||
int bar(double);
|
||||
};
|
||||
|
||||
class Spam {
|
||||
public:
|
||||
Spam();
|
||||
Spam(int);
|
||||
};
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
class foo {
|
||||
static const int BAR = 42;
|
||||
public:
|
||||
int blah(int x = BAR);
|
||||
};
|
||||
4
Examples/test-suite/errors/cpp_raw_string_termination.i
Normal file
4
Examples/test-suite/errors/cpp_raw_string_termination.i
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
%module xxx
|
||||
|
||||
%feature("docstring") func2 R"ABC(Calculate :math:`D^\nu \rho(x)`.)AB";
|
||||
void func2(double* foo, int bar, char** baz);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
cpp_raw_string_termination.i:3: Error: Unterminated raw string, started with R"ABC( is not terminated by )ABC"
|
||||
cpp_raw_string_termination.i:3: Error: Syntax error in input(1).
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
template<T> T blah(T x);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -4,4 +4,4 @@ template<class T> T blah(T x) { };
|
|||
|
||||
%template(iblah) blah<int>;
|
||||
%template(iiblah) blah<int>;
|
||||
|
||||
// The second %template instantiation above should surely be ignored with a warning, but doesn't atm
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
%module cpp_using_type_aliasing
|
||||
|
||||
namespace Space {
|
||||
template<typename T> struct Okay {
|
||||
};
|
||||
struct User {
|
||||
protected:
|
||||
using OkayInt = Okay<int>;
|
||||
};
|
||||
struct Derived : User {
|
||||
Okay<OkayInt> ff();
|
||||
};
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
cpp_using_type_aliasing.i:8: Warning 341: The 'using' keyword in type aliasing is not fully supported yet.
|
||||
cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'.
|
||||
cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'.
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
#define foo(a,x) a x
|
||||
|
||||
#if foo
|
||||
#endif
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
%module exception_classname
|
||||
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME);
|
||||
#ifdef SWIGPHP
|
||||
#if defined(SWIGPHP) || defined(SWIGD)
|
||||
%rename(ExceptionClass) Exception;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,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
|
||||
%}
|
||||
|
||||
/*
|
||||
|
|
@ -23,7 +27,17 @@
|
|||
user's throw declarations.
|
||||
*/
|
||||
|
||||
#if defined(SWIGUTL)
|
||||
#if defined(SWIGOCTAVE)
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
}
|
||||
SWIG_RETHROW_OCTAVE_EXCEPTIONS
|
||||
catch(...) {
|
||||
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
|
||||
}
|
||||
}
|
||||
#elif defined(SWIGUTL)
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
|
|
@ -136,3 +150,12 @@ bool is_python_builtin() { return false; }
|
|||
|
||||
%template(ET_i) ET<int>;
|
||||
%template(ET_d) ET<double>;
|
||||
|
||||
%{
|
||||
#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
|
||||
%}
|
||||
|
|
|
|||
92
Examples/test-suite/extend_template_method.i
Normal file
92
Examples/test-suite/extend_template_method.i
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
%module extend_template_method
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%inline %{
|
||||
namespace Space {
|
||||
class ExtendMe {
|
||||
public:
|
||||
ExtendMe() {}
|
||||
template <typename T>
|
||||
T do_stuff_impl(int a, T b, double d) {
|
||||
return b;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%extend Space::ExtendMe {
|
||||
template<typename T>
|
||||
T do_stuff(int a, T b) {
|
||||
return $self->do_stuff_impl(a, b, 4.0);
|
||||
}
|
||||
template<typename T>
|
||||
T do_overloaded_stuff(T b) {
|
||||
return $self->do_stuff_impl(0, b, 4.0);
|
||||
}
|
||||
template<typename T>
|
||||
static T static_method(T t) {
|
||||
return t;
|
||||
}
|
||||
template<typename T>
|
||||
ExtendMe(T x) {
|
||||
Space::ExtendMe *em = new Space::ExtendMe();
|
||||
return em;
|
||||
}
|
||||
}
|
||||
%template(do_stuff_double) Space::ExtendMe::do_stuff<double>;
|
||||
%template(do_stuff_string) Space::ExtendMe::do_stuff<std::string>;
|
||||
|
||||
%template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff<std::string>;
|
||||
%template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff<double>;
|
||||
|
||||
%template(static_method) Space::ExtendMe::static_method<int>;
|
||||
|
||||
%template(ExtendMe) Space::ExtendMe::ExtendMe<int>;
|
||||
|
||||
%inline %{
|
||||
namespace Space {
|
||||
template<typename X>
|
||||
class TemplateExtendMe {
|
||||
public:
|
||||
TemplateExtendMe() {}
|
||||
template <typename T>
|
||||
T template_stuff_impl(X a, T b, double d) {
|
||||
return b;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%extend Space::TemplateExtendMe {
|
||||
template<typename T>
|
||||
T do_template_stuff(int a, T b) {
|
||||
return $self->template_stuff_impl(a, b, 4.0);
|
||||
}
|
||||
template<typename T>
|
||||
T do_template_overloaded_stuff(T b) {
|
||||
return $self->template_stuff_impl(0, b, 4.0);
|
||||
}
|
||||
template<typename T>
|
||||
static T static_template_method(T t) {
|
||||
return t;
|
||||
}
|
||||
template<typename T>
|
||||
TemplateExtendMe(T x) {
|
||||
Space::TemplateExtendMe<X> *em = new Space::TemplateExtendMe<X>();
|
||||
return em;
|
||||
}
|
||||
|
||||
%template(do_template_stuff_double) do_template_stuff<double>;
|
||||
%template(do_template_stuff_string) do_template_stuff<std::string>;
|
||||
|
||||
%template(do_template_overloaded_stuff) do_template_overloaded_stuff<std::string>;
|
||||
%template(do_template_overloaded_stuff) do_template_overloaded_stuff<double>;
|
||||
|
||||
%template(static_template_method) static_template_method<int>;
|
||||
|
||||
%template(TemplateExtendMe) Space::TemplateExtendMe::TemplateExtendMe<int>;
|
||||
}
|
||||
|
||||
%template(TemplateExtend) Space::TemplateExtendMe<int>;
|
||||
|
||||
|
|
@ -4,6 +4,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
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
|
@ -16,3 +20,11 @@ extern int get() throw(std::exception);
|
|||
int get() throw(std::exception) { 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
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
%warnfilter(SWIGWARN_LANG_IDENTIFIER);
|
||||
|
||||
|
||||
#if defined(SWIGOCTAVE)
|
||||
%warnfilter(SWIGWARN_IGNORE_OPERATOR_LSHIFT_MSG) operator<<;
|
||||
%warnfilter(SWIGWARN_IGNORE_OPERATOR_RSHIFT_MSG) operator>>;
|
||||
#endif
|
||||
|
||||
|
||||
%inline
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
%module friends_template
|
||||
|
||||
#if defined(SWIGOCTAVE)
|
||||
%warnfilter(SWIGWARN_IGNORE_OPERATOR_RSHIFT_MSG) operator>>;
|
||||
#endif
|
||||
|
||||
|
||||
%{
|
||||
template <typename Type> class MyClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -182,12 +182,3 @@ clean:
|
|||
rm -f import_stl_a.go import_stl_a.gox
|
||||
rm -f import_stl_b.go import_stl_b.gox
|
||||
rm -rf gopath
|
||||
|
||||
cvsignore:
|
||||
@echo '*_gc.c *_wrap.* *.so *.dll *.exp *.lib'
|
||||
@echo Makefile
|
||||
@echo mod_a.go mod_b.go imports_a.go imports_b.go
|
||||
@echo clientdata_prop_a.go clientdata_prop_b.go
|
||||
@echo multi_import_a.go multi_import_b.go
|
||||
@echo packageoption_a.go packageoption_b.go packageoption_c.go
|
||||
@for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do echo $$i.go; done
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
package main
|
||||
|
||||
import . "./li_std_vector_ptr"
|
||||
import "fmt"
|
||||
|
||||
func check(val1 int, val2 int) {
|
||||
if val1 != val2 {
|
||||
panic(fmt.Sprintf("Values are not the same %d %d", val1, val2))
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
ip1 := MakeIntPtr(11)
|
||||
ip2 := MakeIntPtr(22)
|
||||
vi := NewIntPtrVector()
|
||||
vi.Add(ip1)
|
||||
vi.Add(ip2)
|
||||
DisplayVector(vi)
|
||||
check(GetValueFromVector(vi, 0), 11)
|
||||
check(GetValueFromVector(vi, 1), 22)
|
||||
}
|
||||
|
|
|
|||
29
Examples/test-suite/go/typedef_funcptr_runme.go
Normal file
29
Examples/test-suite/go/typedef_funcptr_runme.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import . "./typedef_funcptr"
|
||||
|
||||
func main() {
|
||||
a := 100
|
||||
b := 10
|
||||
|
||||
if Do_op(a,b,Addf) != 110 {
|
||||
panic(0)
|
||||
}
|
||||
if Do_op(a,b,Subf) != 90 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if Do_op_typedef_int(a,b,Addf) != 110 {
|
||||
panic(0)
|
||||
}
|
||||
if Do_op_typedef_int(a,b,Subf) != 90 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if Do_op_typedef_Integer(a,b,Addf) != 110 {
|
||||
panic(0)
|
||||
}
|
||||
if Do_op_typedef_Integer(a,b,Subf) != 90 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
20
Examples/test-suite/guile/argout_runme.scm
Normal file
20
Examples/test-suite/guile/argout_runme.scm
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
;; tests support for native guile pointers
|
||||
;; https://www.gnu.org/software/guile/manual/html_node/Void-Pointers-and-Byte-Access.html
|
||||
(dynamic-call "scm_init_argout_module" (dynamic-link "./libargout"))
|
||||
|
||||
(define initial-value 42)
|
||||
(define some-s32-data (s32vector initial-value))
|
||||
|
||||
;; if we're running guile 1.8, then bytevector->pointer won't exist and this
|
||||
;; test is useless
|
||||
(if (>= (string->number (major-version)) 2)
|
||||
(begin
|
||||
(use-modules (srfi srfi-4) (system foreign))
|
||||
|
||||
(if (not (= (incp (bytevector->pointer some-s32-data)) initial-value))
|
||||
(error "Didn't read s32 data" initial-value some-s32-data))
|
||||
|
||||
(if (not (= (s32vector-ref some-s32-data 0) (+ initial-value 1)))
|
||||
(error "Failed to increment s32 data" some-s32-data))))
|
||||
|
||||
(exit 0)
|
||||
18
Examples/test-suite/import_fragments.i
Normal file
18
Examples/test-suite/import_fragments.i
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
%module import_fragments
|
||||
|
||||
// Check %fragments forced inclusion does not result in code generation when using %import
|
||||
%import "import_fragments_a.i"
|
||||
|
||||
%{
|
||||
template<typename T>
|
||||
struct TemplateA4 {};
|
||||
%}
|
||||
|
||||
%template(TemplateA4Int) TemplateA4<int>;
|
||||
|
||||
%inline %{
|
||||
int getImport4() {
|
||||
// Requires the ImportA4 fragment to be generated in order to compile
|
||||
return ImportA4;
|
||||
}
|
||||
%}
|
||||
45
Examples/test-suite/import_fragments_a.i
Normal file
45
Examples/test-suite/import_fragments_a.i
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
%module import_fragments_a
|
||||
|
||||
%fragment("ImportA1", "header") %{
|
||||
ImportA1_this_will_not_compile;
|
||||
%}
|
||||
%fragment("ImportA2", "header") %{
|
||||
ImportA2_this_will_not_compile;
|
||||
%}
|
||||
%fragment("ImportA3", "header") %{
|
||||
ImportA3_this_will_not_compile;
|
||||
%}
|
||||
%fragment("ImportA4", "header") %{
|
||||
static int ImportA4 = 99;
|
||||
%}
|
||||
%fragment("ImportA5", "header") %{
|
||||
ImportA5_this_will_not_compile;
|
||||
%}
|
||||
|
||||
%fragment("ImportA1");
|
||||
|
||||
%{
|
||||
Import_will_not_compile;
|
||||
%}
|
||||
|
||||
struct StructA {
|
||||
%fragment("ImportA2");
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct TemplateA3 {
|
||||
%fragment("ImportA3");
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct TemplateA4 {
|
||||
%fragment("ImportA4");
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct TemplateA5 {
|
||||
%fragment("ImportA5");
|
||||
};
|
||||
%template(TemplateA5Double) TemplateA5<double>;
|
||||
|
||||
%include "import_fragments_b.i"
|
||||
9
Examples/test-suite/import_fragments_b.i
Normal file
9
Examples/test-suite/import_fragments_b.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module import_fragments_b
|
||||
|
||||
%fragment("ImportB", "header") %{
|
||||
ImportB_this_will_not_compile;
|
||||
%}
|
||||
|
||||
%fragment("ImportB");
|
||||
|
||||
|
||||
|
|
@ -18,4 +18,12 @@ class A {
|
|||
virtual MemberEnum member_virtual_test(MemberEnum e) { return e; }
|
||||
virtual GlobalEnum global_virtual_test(GlobalEnum e) { return global_test(e); }
|
||||
};
|
||||
|
||||
/* This class overrides nothing. Inherited classes should see base functions.
|
||||
*/
|
||||
class A_Intermediate : public A {
|
||||
public:
|
||||
A_Intermediate(){}
|
||||
~A_Intermediate(){}
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "imports_a.h"
|
||||
|
||||
class B : public A
|
||||
class B : public A_Intermediate
|
||||
{
|
||||
public:
|
||||
B() {};
|
||||
|
|
|
|||
2
Examples/test-suite/insert_directive.h
Normal file
2
Examples/test-suite/insert_directive.h
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// %inserted code %header from file
|
||||
int inserted_header4(int i) { return inserted_header3(i); }
|
||||
|
|
@ -27,9 +27,11 @@ int inserted_header2(int i) { return inserted_header1(i); }
|
|||
int inserted_header3(int i) { return inserted_header2(i); }
|
||||
%}
|
||||
|
||||
%header "insert_directive.h"
|
||||
|
||||
%wrapper %{
|
||||
// %inserted code %wrapper
|
||||
int inserted_wrapper(int i) { return inserted_header3(i); }
|
||||
int inserted_wrapper(int i) { return inserted_header4(i); }
|
||||
%}
|
||||
|
||||
%init %{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ CPP_TEST_CASES = \
|
|||
java_director_exception_feature \
|
||||
java_director_exception_feature_nspace \
|
||||
java_director_ptrclass \
|
||||
java_director_typemaps \
|
||||
java_enums \
|
||||
java_jnitypes \
|
||||
java_lib_arrays_dimensionless \
|
||||
|
|
|
|||
|
|
@ -33,6 +33,19 @@ public class director_smartptr_runme {
|
|||
director_smartptr.Foo myFoo2 = new director_smartptr.Foo().makeFoo();
|
||||
check(myFoo2.pong(), "Foo::pong();Foo::ping()");
|
||||
check(director_smartptr.Foo.callPong(myFoo2), "Foo::pong();Foo::ping()");
|
||||
|
||||
director_smartptr.FooDerived myBarFooDerived = new director_smartptr_MyBarFooDerived();
|
||||
check(myBarFooDerived.ping(), "director_smartptr_MyBarFooDerived.ping()");
|
||||
check(director_smartptr.FooDerived.callPong(myBarFooDerived), "director_smartptr_MyBarFooDerived.pong();director_smartptr_MyBarFooDerived.ping()");
|
||||
check(director_smartptr.FooDerived.callUpcall(myBarFooDerived, fooBar), "overrideDerived;Bar::Foo2::Foo2Bar()");
|
||||
|
||||
director_smartptr.Foo myFoo3 = myBarFoo.makeFoo();
|
||||
myFoo3.swigReleaseOwnership();
|
||||
myFoo3.swigTakeOwnership();
|
||||
director_smartptr.FooDerived myBarFooDerived2 = new director_smartptr_MyBarFooDerived();
|
||||
myBarFooDerived2.swigReleaseOwnership();
|
||||
myBarFooDerived2.swigTakeOwnership();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,3 +71,26 @@ class director_smartptr_MyBarFoo extends director_smartptr.Foo {
|
|||
return new director_smartptr.Foo();
|
||||
}
|
||||
}
|
||||
|
||||
class director_smartptr_MyBarFooDerived extends director_smartptr.FooDerived {
|
||||
|
||||
@Override
|
||||
public String ping() {
|
||||
return "director_smartptr_MyBarFooDerived.ping()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pong() {
|
||||
return "director_smartptr_MyBarFooDerived.pong();" + ping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upcall(director_smartptr.FooBar fooBarPtr) {
|
||||
return "overrideDerived;" + fooBarPtr.FooBarDo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public director_smartptr.Foo makeFoo() {
|
||||
return new director_smartptr.Foo();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
63
Examples/test-suite/java/extend_template_method_runme.java
Normal file
63
Examples/test-suite/java/extend_template_method_runme.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
import extend_template_method.*;
|
||||
|
||||
public class extend_template_method_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("extend_template_method");
|
||||
} 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[]) {
|
||||
{
|
||||
ExtendMe em = new ExtendMe();
|
||||
|
||||
{
|
||||
double ret_double = em.do_stuff_double(1, 1.1);
|
||||
if (ret_double != 1.1)
|
||||
throw new RuntimeException("double failed " + ret_double);
|
||||
String ret_string = em.do_stuff_string(1, "hello there");
|
||||
if (!ret_string.equals("hello there"))
|
||||
throw new RuntimeException("string failed " + ret_string);
|
||||
}
|
||||
{
|
||||
double ret_double = em.do_overloaded_stuff(1.1);
|
||||
if (ret_double != 1.1)
|
||||
throw new RuntimeException("double failed " + ret_double);
|
||||
String ret_string = em.do_overloaded_stuff("hello there");
|
||||
if (!ret_string.equals("hello there"))
|
||||
throw new RuntimeException("string failed " + ret_string);
|
||||
}
|
||||
if (ExtendMe.static_method(123) != 123)
|
||||
throw new RuntimeException("static_method failed");
|
||||
ExtendMe em2 = new ExtendMe(123);
|
||||
}
|
||||
{
|
||||
TemplateExtend em = new TemplateExtend();
|
||||
|
||||
{
|
||||
double ret_double = em.do_template_stuff_double(1, 1.1);
|
||||
if (ret_double != 1.1)
|
||||
throw new RuntimeException("double failed " + ret_double);
|
||||
String ret_string = em.do_template_stuff_string(1, "hello there");
|
||||
if (!ret_string.equals("hello there"))
|
||||
throw new RuntimeException("string failed " + ret_string);
|
||||
}
|
||||
{
|
||||
double ret_double = em.do_template_overloaded_stuff(1.1);
|
||||
if (ret_double != 1.1)
|
||||
throw new RuntimeException("double failed " + ret_double);
|
||||
String ret_string = em.do_template_overloaded_stuff("hello there");
|
||||
if (!ret_string.equals("hello there"))
|
||||
throw new RuntimeException("string failed " + ret_string);
|
||||
}
|
||||
if (TemplateExtend.static_template_method(123) != 123)
|
||||
throw new RuntimeException("static_template_method failed");
|
||||
TemplateExtend em2 = new TemplateExtend(123);
|
||||
}
|
||||
}
|
||||
}
|
||||
151
Examples/test-suite/java/java_director_typemaps_runme.java
Normal file
151
Examples/test-suite/java/java_director_typemaps_runme.java
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
// tests for java/typemaps.i used for directors
|
||||
|
||||
import java_director_typemaps.*;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class java_director_typemaps_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("java_director_typemaps");
|
||||
} 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[]) {
|
||||
Quux quux = new java_director_typemaps_MyQuux();
|
||||
quux.etest();
|
||||
}
|
||||
}
|
||||
|
||||
class java_director_typemaps_MyQuux extends Quux {
|
||||
public java_director_typemaps_MyQuux() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void director_method_bool_output(
|
||||
boolean[] bool_arg,
|
||||
|
||||
byte[] signed_char_arg,
|
||||
short[] unsigned_char_arg,
|
||||
|
||||
short[] short_arg,
|
||||
int[] unsigned_short_arg,
|
||||
|
||||
int[] int_arg,
|
||||
long[] unsigned_int_arg,
|
||||
|
||||
int[] long_arg,
|
||||
long[] unsigned_long_arg,
|
||||
|
||||
long[] long_long_arg,
|
||||
// BigInteger[] unsigned_long_long_arg,
|
||||
|
||||
float[] float_arg,
|
||||
double[] double_arg)
|
||||
{
|
||||
bool_arg[0] = true;
|
||||
signed_char_arg[0] = 1;
|
||||
unsigned_char_arg[0] = 2;
|
||||
short_arg[0] = 3;
|
||||
unsigned_short_arg[0] = 4;
|
||||
int_arg[0] = 5;
|
||||
unsigned_int_arg[0] = 6;
|
||||
long_arg[0] = 7;
|
||||
unsigned_long_arg[0] = 8;
|
||||
long_long_arg[0] = 9;
|
||||
// unsigned_long_long_arg[0] = 10;
|
||||
float_arg[0] = 11;
|
||||
double_arg[0] = 12;
|
||||
}
|
||||
|
||||
public void director_method_bool_inout(
|
||||
boolean[] bool_arg,
|
||||
|
||||
byte[] signed_char_arg,
|
||||
short[] unsigned_char_arg,
|
||||
|
||||
short[] short_arg,
|
||||
int[] unsigned_short_arg,
|
||||
|
||||
int[] int_arg,
|
||||
long[] unsigned_int_arg,
|
||||
|
||||
int[] long_arg,
|
||||
long[] unsigned_long_arg,
|
||||
|
||||
long[] long_long_arg,
|
||||
// BigInteger[] unsigned_long_long_arg,
|
||||
|
||||
float[] float_arg,
|
||||
double[] double_arg)
|
||||
{
|
||||
if (bool_arg[0]) throw new RuntimeException("unexpected value for bool_arg");
|
||||
|
||||
if (signed_char_arg[0] != 101) throw new RuntimeException("unexpected value for signed_char_arg");
|
||||
if (unsigned_char_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_char_arg");
|
||||
if (short_arg[0] != 101) throw new RuntimeException("unexpected value for short_arg");
|
||||
if (unsigned_short_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_short_arg");
|
||||
if (int_arg[0] != 101) throw new RuntimeException("unexpected value for int_arg");
|
||||
if (unsigned_int_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_int_arg");
|
||||
if (long_arg[0] != 101) throw new RuntimeException("unexpected value for long_arg");
|
||||
if (unsigned_long_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_long_arg");
|
||||
if (long_long_arg[0] != 101) throw new RuntimeException("unexpected value for long_long_arg");
|
||||
// if (unsigned_long_long_arg[0] != 101) throw new RuntimeException("unexpected value for unsigned_long_long_arg");
|
||||
if (float_arg[0] != 101) throw new RuntimeException("unexpected value for float_arg");
|
||||
if (double_arg[0] != 101) throw new RuntimeException("unexpected value for double_arg");
|
||||
|
||||
bool_arg[0] = false;
|
||||
signed_char_arg[0] = 11;
|
||||
unsigned_char_arg[0] = 12;
|
||||
short_arg[0] = 13;
|
||||
unsigned_short_arg[0] = 14;
|
||||
int_arg[0] = 15;
|
||||
unsigned_int_arg[0] = 16;
|
||||
long_arg[0] = 17;
|
||||
unsigned_long_arg[0] = 18;
|
||||
long_long_arg[0] = 19;
|
||||
// unsigned_long_long_arg[0] = 110;
|
||||
float_arg[0] = 111;
|
||||
double_arg[0] = 112;
|
||||
}
|
||||
|
||||
public void director_method_bool_nameless_args(
|
||||
boolean[] bool_arg,
|
||||
|
||||
byte[] signed_char_arg,
|
||||
short[] unsigned_char_arg,
|
||||
|
||||
short[] short_arg,
|
||||
int[] unsigned_short_arg,
|
||||
|
||||
int[] int_arg,
|
||||
long[] unsigned_int_arg,
|
||||
|
||||
int[] long_arg,
|
||||
long[] unsigned_long_arg,
|
||||
|
||||
long[] long_long_arg,
|
||||
// BigInteger[] unsigned_long_long_arg,
|
||||
|
||||
float[] float_arg,
|
||||
double[] double_arg)
|
||||
{
|
||||
bool_arg[0] = true;
|
||||
signed_char_arg[0] = 12;
|
||||
unsigned_char_arg[0] = 13;
|
||||
short_arg[0] = 14;
|
||||
unsigned_short_arg[0] = 15;
|
||||
int_arg[0] = 16;
|
||||
unsigned_int_arg[0] = 17;
|
||||
long_arg[0] = 18;
|
||||
unsigned_long_arg[0] = 19;
|
||||
long_long_arg[0] = 20;
|
||||
// unsigned_long_long_arg[0] = 111;
|
||||
float_arg[0] = 112;
|
||||
double_arg[0] = 113;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
public class li_boost_shared_ptr_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("li_boost_shared_ptr");
|
||||
} 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))
|
||||
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);
|
||||
|
||||
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_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(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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class li_boost_shared_ptr_director_Derived extends li_boost_shared_ptr_director.Base {
|
||||
|
||||
@Override
|
||||
public String ping() {
|
||||
return "li_boost_shared_ptr_director_MyBarFoo.ping()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pong() {
|
||||
return "li_boost_shared_ptr_director_MyBarFoo.pong();" + ping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upcall(li_boost_shared_ptr_director.FooBar fooBarPtr) {
|
||||
return "override;" + fooBarPtr.FooBarDo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public li_boost_shared_ptr_director.Foo makeFoo() {
|
||||
return new li_boost_shared_ptr_director.Foo();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ public class li_std_vector_runme {
|
|||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("li_std_vector");
|
||||
System.loadLibrary("li_std_vector");
|
||||
} 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);
|
||||
|
|
@ -17,8 +17,34 @@ public class li_std_vector_runme {
|
|||
IntPtrVector v2 = li_std_vector.vecintptr(new IntPtrVector());
|
||||
IntConstPtrVector v3 = li_std_vector.vecintconstptr(new IntConstPtrVector());
|
||||
|
||||
v1.add(123);
|
||||
if (v1.get(0) != 123) throw new RuntimeException("v1 test failed");
|
||||
for (int n : v1) {
|
||||
if (n != 123) throw new RuntimeException("v1 loop test failed");
|
||||
}
|
||||
|
||||
if (!v1.isEmpty()) throw new RuntimeException("v1 test (1) failed");
|
||||
if (v1.size() != 0) throw new RuntimeException("v1 test (2) failed");
|
||||
if (!v1.add(123)) throw new RuntimeException("v1 test (3) failed");
|
||||
if (v1.size() != 1) throw new RuntimeException("v1 test (4) failed");
|
||||
if (v1.isEmpty()) throw new RuntimeException("v1 test (5) failed");
|
||||
if (v1.set(0, 456) != 123) throw new RuntimeException("v1 test (6) failed");
|
||||
if (v1.size() != 1) throw new RuntimeException("v1 test (7) failed");
|
||||
if (v1.get(0) != 456) throw new RuntimeException("v1 test (8) failed");
|
||||
|
||||
java.util.Iterator<Integer> v1_iterator = v1.iterator();
|
||||
if (!v1_iterator.hasNext()) throw new RuntimeException("v1 test (9) failed");
|
||||
if (v1_iterator.next() != 456) throw new RuntimeException("v1 test (10) failed");
|
||||
if (v1_iterator.hasNext()) throw new RuntimeException("v1 test (11) failed");
|
||||
try {
|
||||
v1_iterator.next();
|
||||
throw new RuntimeException("v1 test (12) failed");
|
||||
} catch (java.util.NoSuchElementException e) {
|
||||
}
|
||||
|
||||
if (v1.remove(new Integer(123))) throw new RuntimeException("v1 test (13) failed");
|
||||
if (!v1.remove(new Integer(456))) throw new RuntimeException("v1 test (14) failed");
|
||||
if (!v1.isEmpty()) throw new RuntimeException("v1 test (15) failed");
|
||||
if (v1.size() != 0) throw new RuntimeException("v1 test (16) failed");
|
||||
if (v1.remove(new Integer(456))) throw new RuntimeException("v1 test (17) failed");
|
||||
|
||||
StructVector v4 = li_std_vector.vecstruct(new StructVector());
|
||||
StructPtrVector v5 = li_std_vector.vecstructptr(new StructPtrVector());
|
||||
|
|
@ -28,9 +54,68 @@ public class li_std_vector_runme {
|
|||
v5.add(new Struct(34));
|
||||
v6.add(new Struct(56));
|
||||
|
||||
Struct s = null;
|
||||
if (v4.get(0).getNum() != 12) throw new RuntimeException("v4 test failed");
|
||||
if (v5.get(0).getNum() != 34) throw new RuntimeException("v5 test failed");
|
||||
if (v6.get(0).getNum() != 56) throw new RuntimeException("v6 test failed");
|
||||
|
||||
for (Struct s : v4) {
|
||||
if (s.getNum() != 12) throw new RuntimeException("v4 loop test failed");
|
||||
}
|
||||
for (Struct s : v5) {
|
||||
if (s.getNum() != 34) throw new RuntimeException("v5 loop test failed");
|
||||
}
|
||||
for (Struct s : v6) {
|
||||
if (s.getNum() != 56) throw new RuntimeException("v6 loop test failed");
|
||||
}
|
||||
|
||||
StructVector v7 = li_std_vector.vecstruct(new StructVector());
|
||||
v7.add(new Struct(1));
|
||||
v7.add(new Struct(23));
|
||||
v7.add(new Struct(456));
|
||||
v7.add(new Struct(7890));
|
||||
if (v7.size() != 4) throw new RuntimeException("v7 test (1) failed");
|
||||
{
|
||||
double[] a7 = {1, 23, 456, 7890};
|
||||
int i7 = 0;
|
||||
for (Struct s7 : v7) {
|
||||
if (s7.getNum() != a7[i7]) throw new RuntimeException("v7 test (2) failed");
|
||||
i7++;
|
||||
}
|
||||
if (i7 != a7.length) throw new RuntimeException("v7 test (3) failed");
|
||||
}
|
||||
if (v7.remove(2).getNum() != 456) throw new RuntimeException("v7 test (4) failed");
|
||||
{
|
||||
double[] a7 = {1, 23, 7890};
|
||||
int i7 = 0;
|
||||
for (Struct s7 : v7) {
|
||||
if (s7.getNum() != a7[i7]) throw new RuntimeException("v7 test (5) failed");
|
||||
i7++;
|
||||
}
|
||||
if (i7 != a7.length) throw new RuntimeException("v7 test (6) failed");
|
||||
}
|
||||
v7.add(1, new Struct(123));
|
||||
{
|
||||
double[] a7 = {1, 123, 23, 7890};
|
||||
int i7 = 0;
|
||||
for (Struct s7 : v7) {
|
||||
if (s7.getNum() != a7[i7]) throw new RuntimeException("v7 test (7) failed");
|
||||
i7++;
|
||||
}
|
||||
if (i7 != a7.length) throw new RuntimeException("v7 test (8) failed");
|
||||
}
|
||||
|
||||
BoolVector v8 = new BoolVector();
|
||||
if (!v8.add(true)) throw new RuntimeException("v8 test (1) failed");;
|
||||
if (v8.get(0) != true) throw new RuntimeException("v8 test (2) failed");;
|
||||
if (v8.set(0, false) != true) throw new RuntimeException("v8 test (3) failed");;
|
||||
if (v8.set(0, false) != false) throw new RuntimeException("v8 test (4) failed");;
|
||||
if (v8.size() != 1) throw new RuntimeException("v8 test (5) failed");;
|
||||
|
||||
java.util.ArrayList<Boolean> bl = new java.util.ArrayList<Boolean>(java.util.Arrays.asList(true, false, true, false));
|
||||
BoolVector bv = new BoolVector(java.util.Arrays.asList(true, false, true, false));
|
||||
BoolVector bv2 = new BoolVector(bl);
|
||||
java.util.ArrayList<Boolean> bl2 = new java.util.ArrayList<Boolean>(bv);
|
||||
boolean bbb1 = bv.get(0);
|
||||
Boolean bbb2 = bv.get(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
60
Examples/test-suite/java/member_pointer_const_runme.java
Normal file
60
Examples/test-suite/java/member_pointer_const_runme.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import member_pointer_const.*;
|
||||
|
||||
public class member_pointer_const_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("member_pointer_const");
|
||||
} 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 SWIGTYPE_m_Shape__f_void__double memberPtr = null;
|
||||
|
||||
public static void main(String argv[]) {
|
||||
// Get the pointers
|
||||
|
||||
SWIGTYPE_m_Shape__f_void__double area_pt = member_pointer_const.areapt();
|
||||
SWIGTYPE_m_Shape__f_void__double perim_pt = member_pointer_const.perimeterpt();
|
||||
|
||||
// Create some objects
|
||||
|
||||
Square s = new Square(10);
|
||||
|
||||
// Do some calculations
|
||||
|
||||
check( "Square area ", 100.0, member_pointer_const.do_op(s,area_pt) );
|
||||
check( "Square perim", 40.0, member_pointer_const.do_op(s,perim_pt) );
|
||||
|
||||
memberPtr = member_pointer_const.getAreavar();
|
||||
memberPtr = member_pointer_const.getPerimetervar();
|
||||
|
||||
// Try the variables
|
||||
check( "Square area ", 100.0, member_pointer_const.do_op(s,member_pointer_const.getAreavar()) );
|
||||
check( "Square perim", 40.0, member_pointer_const.do_op(s,member_pointer_const.getPerimetervar()) );
|
||||
|
||||
// Modify one of the variables
|
||||
member_pointer_const.setAreavar(perim_pt);
|
||||
|
||||
check( "Square perimeter", 40.0, member_pointer_const.do_op(s,member_pointer_const.getAreavar()) );
|
||||
|
||||
// Try the constants
|
||||
|
||||
memberPtr = member_pointer_const.AREAPT;
|
||||
memberPtr = member_pointer_const.PERIMPT;
|
||||
memberPtr = member_pointer_const.NULLPT;
|
||||
|
||||
check( "Square area ", 100.0, member_pointer_const.do_op(s,member_pointer_const.AREAPT) );
|
||||
check( "Square perim", 40.0, member_pointer_const.do_op(s,member_pointer_const.PERIMPT) );
|
||||
|
||||
// Typedefs
|
||||
check( "Square perim", 40.0, member_pointer_const.do_op_td(s,perim_pt) );
|
||||
}
|
||||
|
||||
private static void check(String what, double expected, double actual) {
|
||||
if (expected != actual)
|
||||
throw new RuntimeException("Failed: " + what + " Expected: " + expected + " Actual: " + actual);
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,8 @@ public class member_pointer_runme {
|
|||
check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.AREAPT) );
|
||||
check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.PERIMPT) );
|
||||
|
||||
// Typedefs
|
||||
check( "Square perim", 40.0, member_pointer.do_op_td(s,perim_pt) );
|
||||
}
|
||||
|
||||
private static void check(String what, double expected, double actual) {
|
||||
|
|
|
|||
42
Examples/test-suite/java/proxycode_runme.java
Normal file
42
Examples/test-suite/java/proxycode_runme.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import proxycode.*;
|
||||
|
||||
public class proxycode_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("proxycode");
|
||||
} 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[]) throws Throwable
|
||||
{
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new RuntimeException("Fail");
|
||||
if (new Proxy2().proxycode2a(100) != 102)
|
||||
throw new RuntimeException("Fail");
|
||||
if (new Proxy2().proxycode2b(100) != 102)
|
||||
throw new RuntimeException("Fail");
|
||||
if (new Proxy3().proxycode3(100) != 103)
|
||||
throw new RuntimeException("Fail");
|
||||
|
||||
if (new Proxy4().proxycode4(100) != 104)
|
||||
throw new RuntimeException("Fail");
|
||||
if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
|
||||
throw new RuntimeException("Fail");
|
||||
|
||||
if (new Proxy5a().proxycode5((short)100) != (short)100)
|
||||
throw new RuntimeException("Fail");
|
||||
if (new Proxy5b().proxycode5(100) != 100)
|
||||
throw new RuntimeException("Fail");
|
||||
if (new Proxy5b().proxycode5(100, 100) != 255)
|
||||
throw new RuntimeException("Fail");
|
||||
|
||||
long t1 = 10;
|
||||
long t2 = 100;
|
||||
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
|
||||
p.useT(t1, t2);
|
||||
}
|
||||
}
|
||||
90
Examples/test-suite/java/rename_wildcard_runme.java
Normal file
90
Examples/test-suite/java/rename_wildcard_runme.java
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
import rename_wildcard.*;
|
||||
|
||||
public class rename_wildcard_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("rename_wildcard");
|
||||
} 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[]) {
|
||||
// Wildcard check
|
||||
{
|
||||
new GlobalWildStruct().mm1();
|
||||
new GlobalWildTemplateStructInt().mm1();
|
||||
new SpaceWildStruct().mm1();
|
||||
new SpaceWildTemplateStructInt().mm1();
|
||||
}
|
||||
// No declaration
|
||||
{
|
||||
new GlobalWildStruct().mm2a();
|
||||
new GlobalWildTemplateStructInt().mm2b();
|
||||
new SpaceWildStruct().mm2c();
|
||||
new SpaceWildTemplateStructInt().mm2d();
|
||||
|
||||
new GlobalWildTemplateStructInt().tt2b();
|
||||
new SpaceWildTemplateStructInt().tt2d();
|
||||
}
|
||||
// With declaration
|
||||
{
|
||||
new GlobalWildStruct().mm3a();
|
||||
new GlobalWildTemplateStructInt().mm3b();
|
||||
new SpaceWildStruct().mm3c();
|
||||
new SpaceWildTemplateStructInt().mm3d();
|
||||
|
||||
new GlobalWildTemplateStructInt().tt3b();
|
||||
new SpaceWildTemplateStructInt().tt3d();
|
||||
}
|
||||
// Global override too
|
||||
{
|
||||
new GlobalWildStruct().mm4a();
|
||||
new GlobalWildTemplateStructInt().mm4b();
|
||||
new SpaceWildStruct().mm4c();
|
||||
new SpaceWildTemplateStructInt().mm4d();
|
||||
|
||||
new GlobalWildTemplateStructInt().tt4b();
|
||||
new SpaceWildTemplateStructInt().tt4d();
|
||||
}
|
||||
// %extend renames
|
||||
{
|
||||
new GlobalWildStruct().mm5a();
|
||||
new GlobalWildTemplateStructInt().mm5b();
|
||||
new SpaceWildStruct().mm5c();
|
||||
new SpaceWildTemplateStructInt().mm5d();
|
||||
|
||||
new GlobalWildTemplateStructInt().tt5b();
|
||||
new SpaceWildTemplateStructInt().tt5d();
|
||||
}
|
||||
// operators
|
||||
{
|
||||
new GlobalWildStruct().opinta();
|
||||
new GlobalWildTemplateStructInt().opintb();
|
||||
new SpaceWildStruct().opintc();
|
||||
new SpaceWildTemplateStructInt().opintd();
|
||||
|
||||
new GlobalWildTemplateStructInt().opdoubleb();
|
||||
new SpaceWildTemplateStructInt().opdoubled();
|
||||
}
|
||||
// Wildcard renames expected for these
|
||||
{
|
||||
new NoChangeStruct().mm1();
|
||||
new NoChangeStruct().mm2();
|
||||
new NoChangeStruct().mm3();
|
||||
new NoChangeStruct().mm4();
|
||||
new NoChangeStruct().mm5();
|
||||
new NoChangeStruct().opint();
|
||||
new SpaceNoChangeStruct().mm1();
|
||||
new SpaceNoChangeStruct().mm2();
|
||||
new SpaceNoChangeStruct().mm3();
|
||||
new SpaceNoChangeStruct().mm4();
|
||||
new SpaceNoChangeStruct().mm5();
|
||||
new SpaceNoChangeStruct().opint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
19
Examples/test-suite/java/smart_pointer_ignore_runme.java
Normal file
19
Examples/test-suite/java/smart_pointer_ignore_runme.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import smart_pointer_ignore.*;
|
||||
|
||||
public class smart_pointer_ignore_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("smart_pointer_ignore");
|
||||
} 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[]) {
|
||||
DerivedPtr d = smart_pointer_ignore.makeDerived();
|
||||
d.baseMethod();
|
||||
d.derivedMethod();
|
||||
}
|
||||
}
|
||||
18
Examples/test-suite/java/template_default_cache_runme.java
Normal file
18
Examples/test-suite/java/template_default_cache_runme.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import template_default_cache.*;
|
||||
|
||||
public class template_default_cache_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("template_default_cache");
|
||||
} 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[]) {
|
||||
AModelPtr ap = template_default_cache.get_mp_a();
|
||||
BModelPtr bp = template_default_cache.get_mp_b();
|
||||
}
|
||||
}
|
||||
34
Examples/test-suite/java/typedef_funcptr_runme.java
Normal file
34
Examples/test-suite/java/typedef_funcptr_runme.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
import typedef_funcptr.*;
|
||||
|
||||
public class typedef_funcptr_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("typedef_funcptr");
|
||||
} 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[]) {
|
||||
int a = 100;
|
||||
int b = 10;
|
||||
|
||||
if (typedef_funcptr.do_op(a,b,typedef_funcptr.addf) != 110)
|
||||
throw new RuntimeException("addf failed");
|
||||
if (typedef_funcptr.do_op(a,b,typedef_funcptr.subf) != 90)
|
||||
throw new RuntimeException("subf failed");
|
||||
|
||||
if (typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.addf) != 110)
|
||||
throw new RuntimeException("addf failed");
|
||||
if (typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.subf) != 90)
|
||||
throw new RuntimeException("subf failed");
|
||||
|
||||
if (typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.addf) != 110)
|
||||
throw new RuntimeException("addf failed");
|
||||
if (typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.subf) != 90)
|
||||
throw new RuntimeException("subf failed");
|
||||
}
|
||||
}
|
||||
|
|
@ -8,14 +8,17 @@
|
|||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
// DEFINE exceptions in header section using std::runtime_error
|
||||
%{
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
|||
|
|
@ -15,14 +15,17 @@
|
|||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11
|
||||
#endif
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
// DEFINE exceptions in header section using std::runtime_error
|
||||
%{
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
|||
367
Examples/test-suite/java_director_typemaps.i
Normal file
367
Examples/test-suite/java_director_typemaps.i
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
%module(directors="1") java_director_typemaps
|
||||
|
||||
%feature("director", assumeoverride=1) Quux;
|
||||
|
||||
%include <typemaps.i>
|
||||
|
||||
%apply bool& OUTPUT {bool&};
|
||||
|
||||
%apply signed char& OUTPUT {signed char&};
|
||||
%apply unsigned char& OUTPUT {unsigned char&};
|
||||
|
||||
%apply short& OUTPUT {short&};
|
||||
%apply unsigned short& OUTPUT {unsigned short&};
|
||||
|
||||
%apply int& OUTPUT {int&};
|
||||
%apply unsigned int& OUTPUT {unsigned int&};
|
||||
|
||||
%apply long& OUTPUT {long&};
|
||||
%apply unsigned long& OUTPUT {unsigned long&};
|
||||
|
||||
%apply long long& OUTPUT {long long&};
|
||||
// %apply unsigned long long& OUTPUT {unsigned long long&};
|
||||
|
||||
%apply float& OUTPUT {float&};
|
||||
%apply double& OUTPUT {double&};
|
||||
|
||||
%apply bool& OUTPUT {bool& boolarg_output};
|
||||
|
||||
%apply signed char& OUTPUT {signed char& signed_chararg_output};
|
||||
%apply unsigned char& OUTPUT {unsigned char& unsigned_chararg_output};
|
||||
|
||||
%apply short& OUTPUT {short& shortarg_output};
|
||||
%apply unsigned short& OUTPUT {unsigned short& unsigned_shortarg_output};
|
||||
|
||||
%apply int& OUTPUT {int& intarg_output};
|
||||
%apply unsigned int& OUTPUT {unsigned int& unsigned_intarg_output};
|
||||
|
||||
%apply long& OUTPUT {long& longarg_output};
|
||||
%apply unsigned long& OUTPUT {unsigned long& unsigned_longarg_output};
|
||||
|
||||
%apply long long& OUTPUT {long long& long_longarg_output};
|
||||
// %apply unsigned long long& OUTPUT {unsigned long long& unsigned_long_longarg_output};
|
||||
|
||||
%apply float& OUTPUT {float& floatarg_output};
|
||||
%apply double& OUTPUT {double& doublearg_output};
|
||||
|
||||
%apply bool& INOUT {bool& boolarg_inout};
|
||||
|
||||
%apply signed char& INOUT {signed char& signed_chararg_inout};
|
||||
%apply unsigned char& INOUT {unsigned char& unsigned_chararg_inout};
|
||||
|
||||
%apply short& INOUT {short& shortarg_inout};
|
||||
%apply unsigned short& INOUT {unsigned short& unsigned_shortarg_inout};
|
||||
|
||||
%apply int& INOUT {int& intarg_inout};
|
||||
%apply unsigned int& INOUT {unsigned int& unsigned_intarg_inout};
|
||||
|
||||
%apply long& INOUT {long& longarg_inout};
|
||||
%apply unsigned long& INOUT {unsigned long& unsigned_longarg_inout};
|
||||
|
||||
%apply long long& INOUT {long long& long_longarg_inout};
|
||||
// %apply unsigned long long& INOUT {unsigned long long& unsigned_long_longarg_inout};
|
||||
|
||||
%apply float& INOUT {float& floatarg_inout};
|
||||
%apply double& INOUT {double& doublearg_inout};
|
||||
|
||||
%{
|
||||
#include <stdexcept>
|
||||
#define verify(ok) if (!(ok)) throw std::runtime_error(# ok);
|
||||
%}
|
||||
%inline %{
|
||||
|
||||
class Quux {
|
||||
public:
|
||||
Quux() {}
|
||||
virtual ~Quux() {}
|
||||
|
||||
virtual void director_method_bool_output(
|
||||
bool& boolarg_output,
|
||||
|
||||
signed char& signed_chararg_output,
|
||||
unsigned char& unsigned_chararg_output,
|
||||
|
||||
short& shortarg_output,
|
||||
unsigned short& unsigned_shortarg_output,
|
||||
|
||||
int& intarg_output,
|
||||
unsigned int& unsigned_intarg_output,
|
||||
|
||||
long& longarg_output,
|
||||
unsigned long& unsigned_longarg_output,
|
||||
|
||||
long long& long_longarg_output,
|
||||
// unsigned long long& unsigned_long_longarg_output,
|
||||
|
||||
float& floatarg_output,
|
||||
double& doublearg_output)
|
||||
{
|
||||
boolarg_output = false;
|
||||
|
||||
signed_chararg_output = 50;
|
||||
unsigned_chararg_output = 50;
|
||||
|
||||
shortarg_output = 50;
|
||||
unsigned_shortarg_output = 50;
|
||||
|
||||
intarg_output = 50;
|
||||
unsigned_intarg_output = 50;
|
||||
|
||||
longarg_output = 50;
|
||||
unsigned_longarg_output = 50;
|
||||
|
||||
long_longarg_output = 50;
|
||||
// unsigned_long_longarg_output = 50;
|
||||
|
||||
floatarg_output = 50;
|
||||
doublearg_output = 50;
|
||||
}
|
||||
|
||||
virtual void director_method_bool_inout(
|
||||
bool& boolarg_inout,
|
||||
|
||||
signed char& signed_chararg_inout,
|
||||
unsigned char& unsigned_chararg_inout,
|
||||
|
||||
short& shortarg_inout,
|
||||
unsigned short& unsigned_shortarg_inout,
|
||||
|
||||
int& intarg_inout,
|
||||
unsigned int& unsigned_intarg_inout,
|
||||
|
||||
long& longarg_inout,
|
||||
unsigned long& unsigned_longarg_inout,
|
||||
|
||||
long long& long_longarg_inout,
|
||||
// unsigned long long& unsigned_long_longarg_inout,
|
||||
|
||||
float& floatarg_inout,
|
||||
double& doublearg_inout)
|
||||
{
|
||||
boolarg_inout = false;
|
||||
|
||||
signed_chararg_inout = 50;
|
||||
unsigned_chararg_inout = 50;
|
||||
|
||||
shortarg_inout = 50;
|
||||
unsigned_shortarg_inout = 50;
|
||||
|
||||
intarg_inout = 50;
|
||||
unsigned_intarg_inout = 50;
|
||||
|
||||
longarg_inout = 50;
|
||||
unsigned_longarg_inout = 50;
|
||||
|
||||
long_longarg_inout = 50;
|
||||
// unsigned_long_longarg_inout = 50;
|
||||
|
||||
floatarg_inout = 50;
|
||||
doublearg_inout = 50;
|
||||
}
|
||||
|
||||
virtual void director_method_bool_nameless_args(
|
||||
bool& ,
|
||||
|
||||
signed char& ,
|
||||
unsigned char& ,
|
||||
|
||||
short& ,
|
||||
unsigned short& ,
|
||||
|
||||
int& ,
|
||||
unsigned int& ,
|
||||
|
||||
long& ,
|
||||
unsigned long& ,
|
||||
|
||||
long long& ,
|
||||
// unsigned long long& ,
|
||||
|
||||
float& ,
|
||||
double&)
|
||||
{
|
||||
}
|
||||
|
||||
void etest() {
|
||||
bool boolarg_inout = false;
|
||||
|
||||
signed char signed_chararg_inout = 111;
|
||||
unsigned char unsigned_chararg_inout = 150;
|
||||
|
||||
short shortarg_inout = 150;
|
||||
unsigned short unsigned_shortarg_inout = 150;
|
||||
|
||||
int intarg_inout = 150;
|
||||
unsigned int unsigned_intarg_inout = 150;
|
||||
|
||||
long longarg_inout = 150;
|
||||
unsigned long unsigned_longarg_inout = 150;
|
||||
|
||||
long long long_longarg_inout = 150;
|
||||
// unsigned long long unsigned_long_longarg_inout = 150;
|
||||
|
||||
float floatarg_inout = 150;
|
||||
double doublearg_inout = 150;
|
||||
|
||||
director_method_bool_output(
|
||||
boolarg_inout,
|
||||
|
||||
signed_chararg_inout,
|
||||
unsigned_chararg_inout,
|
||||
|
||||
shortarg_inout,
|
||||
unsigned_shortarg_inout,
|
||||
|
||||
intarg_inout,
|
||||
unsigned_intarg_inout,
|
||||
|
||||
longarg_inout,
|
||||
unsigned_longarg_inout,
|
||||
|
||||
long_longarg_inout,
|
||||
// unsigned_long_longarg_inout,
|
||||
|
||||
floatarg_inout,
|
||||
doublearg_inout);
|
||||
|
||||
verify(boolarg_inout == true);
|
||||
verify(signed_chararg_inout == 1);
|
||||
verify(unsigned_chararg_inout == 2);
|
||||
|
||||
verify(shortarg_inout == 3);
|
||||
verify(unsigned_shortarg_inout == 4);
|
||||
|
||||
verify(intarg_inout == 5);
|
||||
verify(unsigned_intarg_inout == 6);
|
||||
|
||||
verify(longarg_inout == 7);
|
||||
verify(unsigned_longarg_inout == 8);
|
||||
|
||||
verify(long_longarg_inout == 9);
|
||||
// verify(unsigned_long_longarg_inout == 10);
|
||||
|
||||
verify(floatarg_inout == 11);
|
||||
verify(doublearg_inout == 12);
|
||||
|
||||
boolarg_inout = false;
|
||||
|
||||
signed_chararg_inout = 101;
|
||||
unsigned_chararg_inout = 101;
|
||||
|
||||
shortarg_inout = 101;
|
||||
unsigned_shortarg_inout = 101;
|
||||
|
||||
intarg_inout = 101;
|
||||
unsigned_intarg_inout = 101;
|
||||
|
||||
longarg_inout = 101;
|
||||
unsigned_longarg_inout = 101;
|
||||
|
||||
long_longarg_inout = 101;
|
||||
// unsigned_long_longarg_inout = 101;
|
||||
|
||||
floatarg_inout = 101;
|
||||
doublearg_inout = 101;
|
||||
|
||||
director_method_bool_inout(
|
||||
boolarg_inout,
|
||||
|
||||
signed_chararg_inout,
|
||||
unsigned_chararg_inout,
|
||||
|
||||
shortarg_inout,
|
||||
unsigned_shortarg_inout,
|
||||
|
||||
intarg_inout,
|
||||
unsigned_intarg_inout,
|
||||
|
||||
longarg_inout,
|
||||
unsigned_longarg_inout,
|
||||
|
||||
long_longarg_inout,
|
||||
// unsigned_long_longarg_inout,
|
||||
|
||||
floatarg_inout,
|
||||
doublearg_inout);
|
||||
|
||||
verify(boolarg_inout == false);
|
||||
verify(signed_chararg_inout == 11);
|
||||
verify(unsigned_chararg_inout == 12);
|
||||
|
||||
verify(shortarg_inout == 13);
|
||||
verify(unsigned_shortarg_inout == 14);
|
||||
|
||||
verify(intarg_inout == 15);
|
||||
verify(unsigned_intarg_inout == 16);
|
||||
|
||||
verify(longarg_inout == 17);
|
||||
verify(unsigned_longarg_inout == 18);
|
||||
|
||||
verify(long_longarg_inout == 19);
|
||||
// verify(unsigned_long_longarg_inout == 110);
|
||||
|
||||
verify(floatarg_inout == 111);
|
||||
verify(doublearg_inout == 112);
|
||||
|
||||
director_method_bool_nameless_args(
|
||||
boolarg_inout,
|
||||
|
||||
signed_chararg_inout,
|
||||
unsigned_chararg_inout,
|
||||
|
||||
shortarg_inout,
|
||||
unsigned_shortarg_inout,
|
||||
|
||||
intarg_inout,
|
||||
unsigned_intarg_inout,
|
||||
|
||||
longarg_inout,
|
||||
unsigned_longarg_inout,
|
||||
|
||||
long_longarg_inout,
|
||||
// unsigned_long_longarg_inout,
|
||||
|
||||
floatarg_inout,
|
||||
doublearg_inout);
|
||||
|
||||
verify(boolarg_inout == true);
|
||||
verify(signed_chararg_inout == 12);
|
||||
verify(unsigned_chararg_inout == 13);
|
||||
|
||||
verify(shortarg_inout == 14);
|
||||
verify(unsigned_shortarg_inout == 15);
|
||||
|
||||
verify(intarg_inout == 16);
|
||||
verify(unsigned_intarg_inout == 17);
|
||||
|
||||
verify(longarg_inout == 18);
|
||||
verify(unsigned_longarg_inout == 19);
|
||||
|
||||
verify(long_longarg_inout == 20);
|
||||
// verify(unsigned_long_longarg_inout == 111);
|
||||
|
||||
verify(floatarg_inout == 112);
|
||||
verify(doublearg_inout == 113);
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%clear bool&;
|
||||
|
||||
%clear signed char&;
|
||||
%clear unsigned char&;
|
||||
|
||||
%clear short&;
|
||||
%clear unsigned short&;
|
||||
|
||||
%clear int&;
|
||||
%clear unsigned int&;
|
||||
|
||||
%clear long&;
|
||||
%clear unsigned long&;
|
||||
|
||||
%clear long long&;
|
||||
// %clear unsigned long long&;
|
||||
|
||||
%clear float&;
|
||||
%clear double&;
|
||||
|
|
@ -42,10 +42,19 @@ short full_of_exceptions(int num) {
|
|||
#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
|
||||
|
||||
bool throw_spec_function(int value) throw (int) { throw (int)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
|
||||
%}
|
||||
|
||||
%catches(int) catches_function(int value);
|
||||
|
|
|
|||
30
Examples/test-suite/javascript/swig_exception_runme.js
Normal file
30
Examples/test-suite/javascript/swig_exception_runme.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
var swig_exception = require("swig_exception");
|
||||
|
||||
var c = new swig_exception.Circle(10);
|
||||
var s = new swig_exception.Square(10);
|
||||
|
||||
if (swig_exception.Shape.nshapes != 2) {
|
||||
throw "Shape.nshapes should be 2, actually " + swig_exception.Shape.nshapes;
|
||||
}
|
||||
|
||||
// ----- Throw exception -----
|
||||
try {
|
||||
c.throwException();
|
||||
throw "Exception wasn't thrown";
|
||||
} catch (e) {
|
||||
if (e.message != "OK") {
|
||||
throw "Exception message should be \"OK\", actually \"" + e.message + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Delete everything -----
|
||||
|
||||
c = null;
|
||||
s = null;
|
||||
e = null;
|
||||
|
||||
/* FIXME: Garbage collection needs to happen before this check will work.
|
||||
if (swig_exception.Shape.nshapes != 0) {
|
||||
throw "Shape.nshapes should be 0, actually " + swig_exception.Shape.nshapes;
|
||||
}
|
||||
*/
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue