Merge branch 'master' of https://github.com/swig/swig into Cmerge

This commit is contained in:
Joey Yakimowich-Payne 2023-02-18 00:05:36 -07:00
commit 5a06ca1ed7
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
312 changed files with 10813 additions and 7218 deletions

File diff suppressed because it is too large Load diff

View file

@ -94,6 +94,6 @@ All of the examples were last tested with the following configuration
</ul>
Your mileage may vary. If you experience a problem, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
contacting us on the <a href="https://www.swig.org/mail.html">mailing lists</a>.
</body>
</html>

View file

@ -58,7 +58,7 @@ The examples have been extensively tested on the following platforms:
</ul>
Your mileage may vary. If you experience a problem, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
contacting us on the <a href="https://www.swig.org/mail.html">mailing lists</a>.
</body>
</html>

View file

@ -10,7 +10,7 @@ try{
if(error == -1) {
console.log("t.unknown() didn't throw");
} else {
console.log("successfully caught throw in Test::unknown().");
console.log("successfully caught throw in Test::unknown() :" + error);
}
}
@ -22,7 +22,7 @@ catch(error){
if(error == -1) {
console.log("t.simple() did not throw");
} else {
console.log("successfully caught throw in Test::simple().");
console.log("successfully caught throw in Test::simple() :" + error);
}
}
@ -33,7 +33,7 @@ try{
if(error == -1) {
console.log("t.message() did not throw");
} else {
console.log("successfully caught throw in Test::message().");
console.log("successfully caught throw in Test::message() :" + error);
}
}
@ -45,7 +45,7 @@ catch(error){
if(error == -1) {
console.log("t.hosed() did not throw");
} else {
console.log("successfully caught throw in Test::hosed().");
console.log("successfully caught throw in Test::hosed() :" + error);
}
}
@ -58,7 +58,7 @@ for (var i=1; i<4; i++) {
if(error == -1) {
console.log("t.multi(" + i + ") did not throw");
} else {
console.log("successfully caught throw in Test::multi().");
console.log("successfully caught throw in Test::multi() :" + error);
}
}
}
}

View file

@ -1,6 +1,9 @@
% test octaves concatenation operator
function ret=horzcat(a, b)
% return the concatenation of two ComplexVal values as a cell array.
function ret=horzcat(varargin)
% return the concatenation of several ComplexVal values as a cell array.
% (not really useful but it tests the concatenation of swig_ref objects)
ret={a, b};
ret={};
for i=1:length(varargin)
ret{i}=varargin{i};
end
end

View file

@ -47,6 +47,5 @@ if swig_octave_prereq(3,8,0)
endif
# concatenation operator, note: calls @swig_ref/horzcat.m
# g = [a, b, c];
# printf("g = %s\n",disp(g));
# Above temporarily removed as broken in octave-7.2.0, see https://github.com/swig/swig/issues/2353
g = [a, b, c];
printf("g = %s\n",disp(g));

View file

@ -72,7 +72,7 @@ Please see the <a href="../../Doc/Manual/Windows.html">Windows</a> page in the m
Due to wide variations in the Perl C API and differences between versions such as the ActivePerl release for Windows,
the code generated by SWIG is extremely messy.
If the code doesn't compile or work with your version of Perl, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
contacting us on the <a href="https://www.swig.org/mail.html">mailing lists</a>.
Better yet, send us a patch.
</body>

View file

@ -25,7 +25,7 @@ print "----------------------\n";
$list = new EmployeeList();
# EmployeeList owns its items, so we must surrender ownership of objects
# we add. This involves first clearing the ->disown member to tell the
# we add. This involves first clearing the ->thisown member to tell the
# C++ director to start reference counting.
$e->thisown = 0;

View file

@ -4,7 +4,7 @@ and the C/C++ part is not in any package at all. Historically SWIG has
supported this sort of thing.
From SWIG 4.0.0 onwards, split modules are not supported by default.
The %module directive needs to be customised with the moduleimport attribute
in order to import the a global C/C++ module.
in order to import a global C/C++ module.
vanilla # "plane Jane" module both halves in pkg1
vanilla_split # python 1/2 in pkg1 C 1/2 in global namespace

View file

@ -92,7 +92,7 @@ For Python 2, set the environment variable <tt>PY2=1</tt>.
<p>
Your mileage may vary. If you experience a problem, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
contacting us on the <a href="https://www.swig.org/mail.html">mailing lists</a>.
</body>
</html>

View file

@ -87,7 +87,7 @@ The examples have been extensively tested on the following platforms:
</ul>
Your mileage may vary. If you experience a problem, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
contacting us on the <a href="https://www.swig.org/mail.html">mailing lists</a>.
</body>
</html>

View file

@ -63,7 +63,7 @@ The examples have been extensively tested on the following platforms:
</ul>
Your mileage may vary. If you experience a problem, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
contacting us on the <a href="https://www.swig.org/mail.html">mailing lists</a>.
</body>
</html>

View file

@ -0,0 +1,17 @@
%module catches_strings
%include <std_string.i>
%catches(const char *) StringsThrower::charstring;
%catches(std::string) StringsThrower::stdstring;
%inline %{
struct StringsThrower {
static void charstring() {
throw "charstring message";
}
static void stdstring() {
throw std::string("stdstring message");
}
};
%}

View file

@ -1,55 +0,0 @@
#######################################################################
# Makefile for cffi test-suite
#######################################################################
LANGUAGE = cffi
CFFI = @CFFIBIN@
SCRIPTSUFFIX = _runme.lisp
HAVE_CXX11 = @HAVE_CXX11@
HAVE_CXX14 = @HAVE_CXX14@
HAVE_CXX17 = @HAVE_CXX17@
HAVE_CXX20 = @HAVE_CXX20@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
include $(srcdir)/../common.mk
# Overridden variables here
# no C++ tests for now
CPP_TEST_CASES =
#C_TEST_CASES +=
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
%.ctest:
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_testcase)
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.lisp appended after the testcase name.
run_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CFFI) -batch -s $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean: (does nothing, we don't generate extra cffi code)
%.clean:
@exit 0
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' cffi_clean

View file

@ -90,7 +90,6 @@ CPP_TEST_BROKEN += \
nested_private \
template_default_pointer \
template_private_assignment \
template_expr \
$(CPP11_TEST_BROKEN) \
$(CPP14_TEST_BROKEN) \
$(CPP17_TEST_BROKEN) \
@ -133,6 +132,7 @@ CPP_TEST_CASES += \
bloody_hell \
bools \
catches \
catches_strings \
cast_operator \
casts \
char_binary \
@ -215,13 +215,16 @@ CPP_TEST_CASES += \
director_ref \
director_simple \
director_smartptr \
director_template \
director_thread \
director_unroll \
director_unwrap_result \
director_using \
director_using_member_scopes \
director_void \
director_wombat \
disown \
duplicate_class_name_in_ns \
dynamic_cast \
empty \
enum_ignore \
@ -455,10 +458,12 @@ CPP_TEST_CASES += \
template_enum_ns_inherit \
template_enum_typedef \
template_explicit \
template_expr \
template_extend1 \
template_extend2 \
template_extend_overload \
template_extend_overload_2 \
template_function_parm \
template_forward \
template_inherit \
template_inherit_abstract \
@ -482,6 +487,7 @@ CPP_TEST_CASES += \
template_parameters_global_scope \
template_partial_arg \
template_partial_specialization \
template_partial_specialization_more \
template_partial_specialization_typedef \
template_qualifier \
template_ref_type \
@ -493,6 +499,7 @@ CPP_TEST_CASES += \
template_static \
template_tbase_template \
template_template_parameters \
template_template_template_parameters \
template_typedef \
template_typedef_class_template \
template_typedef_cplx \
@ -590,6 +597,7 @@ CPP11_TEST_CASES += \
cpp11_director_enums \
cpp11_directors \
cpp11_explicit_conversion_operators \
cpp11_final_class \
cpp11_final_directors \
cpp11_final_override \
cpp11_function_objects \
@ -619,16 +627,18 @@ CPP11_TEST_CASES += \
cpp11_thread_local \
cpp11_template_double_brackets \
cpp11_template_explicit \
cpp11_template_parameters_decltype \
cpp11_template_typedefs \
cpp11_type_traits \
cpp11_type_aliasing \
cpp11_uniform_initialization \
cpp11_unrestricted_unions \
cpp11_userdefined_literals \
cpp11_variadic_function_templates \
cpp11_variadic_templates \
# Broken C++11 test cases.
CPP11_TEST_BROKEN = \
# cpp11_variadic_templates \ # Broken for some languages (such as Java)
# cpp11_reference_wrapper \ # No typemaps
# C++14 test cases.
@ -640,6 +650,7 @@ CPP14_TEST_BROKEN = \
# C++17 test cases.
CPP17_TEST_CASES += \
cpp17_enable_if_t \
cpp17_hex_floating_literals \
cpp17_nested_namespaces \
cpp17_nspace_nested_namespaces \
@ -709,6 +720,7 @@ CPP_STD_TEST_CASES += \
li_std_vector_enum \
li_std_vector_member_var\
li_std_vector_ptr \
li_std_vector_vector \
li_std_wstring \
smart_pointer_inherit \
template_typedef_fnc \
@ -753,6 +765,7 @@ C_TEST_CASES += \
enum_macro \
enum_missing \
extern_declaration \
final_c \
funcptr \
function_typedef \
global_functions \
@ -786,6 +799,7 @@ C_TEST_CASES += \
preproc_gcc_output \
preproc_include \
preproc_line_file \
preproc_predefined \
register_par \
ret_by_value \
simple_array \

View file

@ -19,6 +19,7 @@
#if defined(_MSC_VER)
#pragma warning(disable : 4996) // For the deprecated attributes in this testcase
#pragma warning(disable : 5030) // attribute is not recognized ('likely' and 'unlikely')
#endif

View file

@ -9,11 +9,35 @@
int i;
decltype(i) j;
auto foo( decltype(i) a ) -> decltype(i) {
auto get_number(decltype(i) a) -> decltype(i) {
if (a==5)
return 10;
else
return 0;
}
};
%}
%}
// These are ignored as unable to deduce decltype for (i+j)
%ignore B::k;
%ignore B::get_number_sum;
%ignore B::get_number_address;
#pragma SWIG nowarn=SWIGWARN_CPP11_DECLTYPE
%inline %{
class B {
public:
int i;
decltype(i) j;
decltype(i+j) k;
auto get_number_sum(decltype(i+j) a) -> decltype(i+j) {
return i+j;
}
auto get_number_address(decltype(&i) a) -> decltype(&i) {
return &i;
}
};
%}

View file

@ -0,0 +1,141 @@
%module cpp11_final_class
%warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final'
%warnfilter(SWIGWARN_PARSE_KEYWORD) override; // 'override' is a C# keyword, renaming to '_override'
%ignore Space1::final::operator=;
#if defined(SWIGPHP)
%rename(Space1_final) Space1::final::final;
#endif
#if defined(SWIGOCAML)
%rename(finale) BrokenSpace::FinalEnum1::final;
#endif
%inline %{
struct FinalBase {
virtual ~FinalBase() {}
};
struct FinalClass1 final : FinalBase {
void method1() {}
};
class FinalClass2 final : public FinalBase {
public:
void method2() {}
};
struct FinalClass3 final {
void method3() {}
};
struct FinalClass4 {
void method4() {}
} final;
struct override final {
void omethod() {}
};
%}
%rename(Space1_final) Space1::final;
%inline %{
namespace Space1 {
struct final final {
void finalmethod() {}
final() {}
final(const final &other) = default;
final& operator=(const final &other) = default;
};
struct FinalClass5 final {
void method5() {}
final final_member_var;
final get_final_member() { return final_member_var; }
Space1::final get_final_member2() { return final_member_var; }
};
struct FinalClass6 {
void method6() {}
virtual void final() final {}
virtual ~FinalClass6() = default;
};
typedef final Space1_final_typedef1;
typedef struct final Space1_final_typedef2;
}
typedef Space1::final Space1_final_typedef3;
typedef struct Space1::final Space1_final_typedef4;
%}
%inline %{
namespace Space2 {
class Y {
public:
Y(int i=0) {}
};
struct FinalVar1 {
class Y notfinal;
// class Y final; // SWIG (C++ only) fails to parse (same for struct and union)
};
struct FinalVar2 {
class Y notfinal = {};
// class Y final = {}; // SWIG (C++ only) fails to parse (same for struct and union)
};
struct FinalVar3 {
class Y notfinal = Y();
// class Y final = Y(); // SWIG (C++ only) fails to parse (same for struct and union)
};
struct FinalVar4 {
class Y* final;
FinalVar4() : final() {}
};
struct FinalVar5 {
Y final;
};
struct FinalVar6 {
Y final = {};
};
struct FinalVar7 {
Y final = Y();
};
struct FinalVar8 {
Y final{};
};
struct FinalVar9 {
Y final{9};
};
struct FinalVar10 {
void b10(Y final) {}
};
}
%}
// Unfortunately the use of final in BrokenSpace does not work with Visual C++
// so we limit testing to parsing these by SWIG and then ignoring it all.
%ignore BrokenSpace::FinalVar11;
%ignore BrokenSpace::FinalEnum1;
%ignore BrokenSpace::FinalEnum2;
namespace BrokenSpace {
using Space2::Y;
struct FinalVar11 {
void a11(class Y final) {}
};
struct FinalEnum1 {
enum Enum1 { one, two, final };
void enum_in(Enum1 e) {}
};
struct FinalEnum2 {
enum Enum2 { one, two, three, four };
enum Enum2 final;
};
}
%rename(Space3_final) Space3::final;
%inline %{
namespace Space3 {
typedef struct final {
void fmethod() {}
} final;
}
%}

View file

@ -27,7 +27,7 @@ struct Base {
virtual ~Base() {}
};
struct Derived /*final*/ : Base {
struct Derived final : Base {
virtual void stuff() const noexcept override final {}
virtual void override1() const noexcept override;
virtual void override2() const noexcept override;

View file

@ -39,7 +39,7 @@ class C {
public:
C(std::initializer_list<const char *> init) {
for (auto& val : init)
joined += val;
joined = joined + val;
}
C() {}
const char * get_joined_string() {

View file

@ -2,6 +2,10 @@
%include "cpp11_move_only_helper.i"
#if defined(SWIGOCAML)
%rename(valu) val;
#endif
%ignore MoveOnly::operator=;
//%valuewrapper MoveOnly; // SWIG sets %valuewrapper by default for move-only types

View file

@ -4,7 +4,7 @@
* This test case checks SwigValueWrapper and move assignment.
* Although not necessary, the test case was developed testing with C++98 compatibility for comparing improvements.
* C++11 and later is of course required for the move assignment support.
* C++98 is not actually necesary now as the test-suite only runs this test with compilers that support C++11 and later.
* C++98 is not actually necessary now as the test-suite only runs this test with compilers that support C++11 and later.
*/
%{

View file

@ -0,0 +1,51 @@
%module cpp11_template_parameters_decltype
%include <std_string.i>
%include <std_vector.i>
%include <std_pair.i>
#pragma SWIG nowarn=SWIGWARN_CPP11_DECLTYPE
#if 0
// to fix (non-template expression equivalent to template expression further down):
%inline %{
#include <utility>
#include <vector>
void f(bool c = std::is_constructible<std::string, decltype(std::declval<std::vector<std::pair<int, int>>>().begin()->first)>::value) {}
%}
#endif
%inline %{
// Github issue #1590
struct Converter {
std::string to_json() const { return std::string(); }
};
struct Json {
Json(std::string s) {}
template < class T, class = decltype(&T::to_json) >
Json(const T & t) : Json(t.to_json()) {}
// Github issue #1589
// To fix
#if !defined(SWIG)
// Implicit constructor: map-like objects (std::map, std::unordered_map, etc)
template <class M, typename std::enable_if<
std::is_constructible<std::string, decltype(std::declval<M>().begin()->first)>::value,
int>::type = 0>
Json(const M & m) : Json(object(m.begin(), m.end())) {}
#endif
};
%}
// %template(Json) Json::Json<Converter>; // not working
%template(Json) Json::Json<Converter, std::string>; // workaround
%inline %{
// Github issue #1589
template <decltype(true) X = true>
void A() { }
%}
// %template(A) A<>; // not working
%template(A) A<true>; // workaround

View file

@ -112,3 +112,39 @@ using callback_t = int(*)(int);
callback_t get_callback() { return mult2; }
int call(callback_t funk, int param) { return funk(param); }
%}
// Template template parameters - from #1021
%inline %{
#include <type_traits>
class Node {};
struct AnyVal { typedef AnyVal Super; };
template<template<typename D, typename O> class C, typename T, typename Super, typename Root, typename O>
using DeriveToBase = typename std::conditional<std::is_same<T, AnyVal>::value, Root, C<Super, O> >::type;
template<class T, class Root, class RParent>
using ImmediateBase = typename std::conditional<std::is_same<T, AnyVal>::value, Root, RParent >::type;
template<class D, typename _Super=AnyVal> class Expression {
typedef _Super Super;
};
void TestInstantiationsPart4() {
Expression<AnyVal, AnyVal::Super> express;
DeriveToBase<Expression, AnyVal, AnyVal, AnyVal, AnyVal> derive_to_base = AnyVal();
}
%}
#if 0
// TODO define and instantiate std::conditional and std::is_same
%template(ExpressionInstantiation) Expression<AnyVal, AnyVal::Super>;
%template(AnyTypeInstantiation) DeriveToBase<Expression, AnyVal, AnyVal, AnyVal, AnyVal>;
%inline %{
AnyVal takeAnyVal(DeriveToBase<Expression, AnyVal, AnyVal, AnyVal, AnyVal> av) {
return av;
}
%}
#endif

View file

@ -4,6 +4,8 @@
// This doesn't really directly test functionality in type_traits as it doesn't provide
// much for use by target languages, rather it tests usage of it.
%warnfilter(509) elaborate;
%inline %{
#include <type_traits>

View file

@ -0,0 +1,96 @@
%module cpp11_variadic_function_templates
// Some tests for variadic function templates
%inline %{
class A {
public:
A() {
a = 100;
}
virtual ~A() {}
int a;
};
class B {
public:
B() {
b = 200;
}
virtual ~B() {}
int b;
};
class C {
public:
C() {
c = 300;
}
virtual ~C() {}
int c;
};
class D {
public:
D() {
d = 400;
}
virtual ~D() {}
int d;
};
%}
// #1863
%inline %{
class Container {
public:
template<typename... Args>
static void notifyMyTypes(void (fn)(Args...)); // unconventional function (ptr)
template<typename... Args>
static void notifyMyTypesA(void (*fn)(Args...)) {} // conventional function ptr
template<typename... Args>
static void notifyMyTypesB(void fn(Args...)) {}; // unconventional function (ptr)
};
%}
%{
template<typename... Args>
void Container::notifyMyTypes(void (fn)(Args...)) {}
// Explicit template instantiations
template void Container::notifyMyTypes<>(void (tt)());
template void Container::notifyMyTypes<int>(void (tt)(int));
template void Container::notifyMyTypes<int, double>(void (tt)(int, double));
%}
// Not supported (most vexing parse), see Extending.html#Extending_nn7
//%template(ContainerNotifyMyTypes1) Container::notifyMyTypes<int>;
%template(ContainerNotifyMyTypesA1) Container::notifyMyTypesA<int>;
%template(ContainerNotifyMyTypesB1) Container::notifyMyTypesB<int>;
// #1863
%inline %{
#include <type_traits>
class EmplaceContainer {
public:
template<typename T, typename... Args>
void emplace(Args &&... args) noexcept(
std::is_nothrow_constructible<T, Args &&...>::value) {}
};
%}
%template(emplace) EmplaceContainer::emplace<int,A>;
%template(emplace) EmplaceContainer::emplace<int,A,B>;
%template(emplace) EmplaceContainer::emplace<int,A,B,C>;
%template(emplace) EmplaceContainer::emplace<int,A,B,C,D>;
// Overloading mix of variadic and non-variadic templates
%inline %{
template<typename T, typename U> int variadicmix1(T t, U u) { return 10; }
template<typename... T> int variadicmix1(T... t) { return 20; }
%}
%template(variadicmix1) variadicmix1<>;
%template(variadicmix1) variadicmix1<A>;
%template(variadicmix1) variadicmix1<A,B>;
%template(variadicmix1) variadicmix1<A,B,C>;
%template(variadicmix1) variadicmix1<int, int>;

View file

@ -4,9 +4,21 @@
using variadic number of classes.
*/
%module cpp11_variadic_templates
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiArgs;
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) SizeOf;
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiInherit;
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE,
SWIGWARN_RUBY_MULTIPLE_INHERITANCE) MultiInherit;
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE,
SWIGWARN_RUBY_MULTIPLE_INHERITANCE) NumerousInherit;
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE,
SWIGWARN_RUBY_MULTIPLE_INHERITANCE) LotsInherit;
////////////////////////
// Variadic templates //
@ -24,7 +36,6 @@ class MultiArgs<int, std::vector<int>, std::map<std::string, std::vector<int>>>
%}
// TODO
%template (MultiArgs1) MultiArgs<int, std::vector<int>, std::map<std::string, std::vector<int>>>;
////////////////////////
@ -36,7 +47,10 @@ template<typename... Args> struct SizeOf {
};
%}
%template (SizeOf1) SizeOf<int, int>;
%template (SizeOf0) SizeOf<>;
%template (SizeOf1) SizeOf<int>;
%template (SizeOf2) SizeOf<int, int>;
%template (SizeOf3) SizeOf<int, int, int>;
//////////////////////////
// Variadic inheritance //
@ -60,18 +74,147 @@ public:
int b;
};
class C {
public:
C() {
c = 300;
}
virtual ~C() {}
int c;
};
class D {
public:
D() {
d = 400;
}
virtual ~D() {}
int d;
};
template <typename... BaseClasses> class MultiInherit : public BaseClasses... {
public:
MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
void MultiInstanceMethod(BaseClasses&... baseClasses) {}
static void MultiStaticMethod(BaseClasses&... baseClasses) {}
int InstanceMethod() { return 123; }
static int StaticMethod() { return 456; }
};
%}
// TODO
//%template (MultiInherit0) MultiInherit<>;
%template (MultiInherit0) MultiInherit<>;
%template (MultiInherit1) MultiInherit<A>;
// TODO
%template (MultiInherit2) MultiInherit<A,B>;
%template (MultiInherit3) MultiInherit<A,B,C>;
%inline %{
template <typename... BaseClasses> class NumerousInherit : public BaseClasses... {
public:
NumerousInherit(int i, BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
void NumerousInstanceMethod(int i, BaseClasses&... baseClasses) {}
static void NumerousStaticMethod(int i, BaseClasses&... baseClasses) {}
int InstanceMethod() { return 123; }
static int StaticMethod() { return 456; }
};
%}
%template (NumerousInherit0) NumerousInherit<>;
%template (NumerousInherit1) NumerousInherit<A>;
%template (NumerousInherit2) NumerousInherit<A,B>;
%template (NumerousInherit3) NumerousInherit<A,B,C>;
%inline %{
template <typename T, typename... BaseClasses> class LotsInherit : public T, public BaseClasses... {
public:
LotsInherit(T t, BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
void LotsInstanceMethod(T t, BaseClasses&... baseClasses) {}
static void LotsStaticMethod(T t, BaseClasses&... baseClasses) {}
int InstanceMethod() { return 123; }
static int StaticMethod() { return 456; }
};
%}
%template (LotsInherit1) LotsInherit<A>;
%template (LotsInherit2) LotsInherit<A,B>;
%template (LotsInherit3) LotsInherit<A,B,C>;
%template (LotsInherit4) LotsInherit<A,B,C,D>;
%inline %{
struct KlassMemFuncs {
int memfunc0() { return 0; }
int memfunc1() { return 1; }
int memfunc2() { return 2; }
int memfunc3() { return 3; }
};
template <typename... V> struct VariadicParms {
void ParmsVal(V... vparms_v) {}
void ParmsPtr(V*... vparms_p) {}
void ParmsPtrRef(V*&... vparms_pr) {}
void ParmsPtrRValueRef(V*&&... vparms_rvr) {}
void ParmsRef(V&... vparms_r) {}
void ParmsRValueRef(V&&... vparms_r) {}
void ParmsConstRef(const V&... vparms_cr) {}
// Conventional unnamed parameter function ptr
void ParmsFuncPtrVal(int (*)(V...)) {}
void ParmsFuncPtrPtr(int (*)(V*...)) {}
void ParmsFuncPtrPtrRef(int (*)(V*&...)) {}
void ParmsFuncPtrPtrRValueRef(int (*)(V*&&...)) {}
void ParmsFuncPtrRef(int (*)(V&...)) {}
void ParmsFuncPtrRValueRef(int (*)(V&&...)) {}
void ParmsFuncPtrConstRef(int (*)(const V&...)) {}
// Unconventional unnamed parameter function ptr
void ParmsFuncUnnamedVal(int (V...)) {}
void ParmsFuncUnnamedPtr(int (V*...)) {}
void ParmsFuncUnnamedPtrRef(int (V*&...)) {}
void ParmsFuncUnnamedPtrRValueRef(int (V*&&...)) {}
void ParmsFuncUnnamedRef(int (V&...)) {}
void ParmsFuncUnnamedRValueRef(int (V&&...)) {}
void ParmsFuncUnnamedConstRef(int (const V&...)) {}
// Unconventional named parameter function ptr
void ParmsFuncNamedVal(int fn(V...)) {}
void ParmsFuncNamedPtr(int fn(V*...)) {}
void ParmsFuncNamedPtrRef(int fn(V*&...)) {}
void ParmsFuncNamedPtrRValueRef(int fn(V*&&...)) {}
void ParmsFuncNamedRef(int fn(V&...)) {}
void ParmsFuncNamedRValueRef(int fn(V&&...)) {}
void ParmsFuncNamedConstRef(int fn(const V&...)) {}
// Conventional unnamed parameter member function ptr
void ParmsMemFuncPtrVal(int (KlassMemFuncs::*)(V...)) {}
void ParmsMemFuncPtrPtr(int (KlassMemFuncs::*)(V*...)) {}
void ParmsMemFuncPtrPtrRef(int (KlassMemFuncs::*)(V*&...)) {}
void ParmsMemFuncPtrPtrRValueRef(int (KlassMemFuncs::*)(V*&&...)) {}
void ParmsMemFuncPtrRef(int (KlassMemFuncs::*)(V&...)) {}
void ParmsMemFuncPtrRValueRef(int (KlassMemFuncs::*)(V&&...)) {}
void ParmsMemFuncPtrConstRef(int (KlassMemFuncs::*)(const V&...)) {}
};
%}
%template(VariadicParms0) VariadicParms<>;
%template(VariadicParms1) VariadicParms<A>;
%template(VariadicParms2) VariadicParms<A,B>;
%template(VariadicParms3) VariadicParms<A,B,C>;
%inline %{
template <typename... V> struct FixedAndVariadicParms {
public:
void ParmsVal(short shortvar, V... vparms_v) {}
void ParmsPtr(short shortvar, V*... vparms_p) {}
void ParmsPtrRef(short shortvar, V*&... vparms_pr) {}
void ParmsPtrRValueRef(short shortvar, V*&&... vparms_rvr) {}
void ParmsRef(short shortvar, V&... vparms_r) {}
void ParmsRValueRef(short shortvar, V&&... vparms_r) {}
void ParmsConstRef(short shortvar, const V&... vparms_cr) {}
void ParmsFuncPtrVal(short shortvar, int (*)(short, V...)) {}
void ParmsMemFuncPtrVal(int (KlassMemFuncs::*)(V...)) {}
};
%}
%template(FixedAndVariadicParms0) FixedAndVariadicParms<>;
%template(FixedAndVariadicParms1) FixedAndVariadicParms<A>;
%template(FixedAndVariadicParms2) FixedAndVariadicParms<A,B>;
%template(FixedAndVariadicParms3) FixedAndVariadicParms<A,B,C>;

View file

@ -0,0 +1,89 @@
%module cpp17_enable_if_t
// test use of enable_if_t but without full %template instantiation, that is no enable_if_t definition is parsed
%inline %{
#if defined(_MSC_VER) && _MSC_VER < 1920
#define or ||
#define and &&
#endif
#include <type_traits>
typedef int node_t;
typedef int position_t;
template <typename A, typename B, std::enable_if_t<std::is_integral_v<A>, bool> = true>
void enableif1(const A a, const B b) {}
// tests non-type template parameters within () brackets - was causing an infinite loop, issue #2418
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A>), bool> = true>
void enableif2(const A a, const B b) {}
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> || std::is_same_v<A, node_t>), bool> = true>
void enableif3(const A a, const B b) {}
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> or std::is_same_v<A, node_t>) and (std::is_integral_v<B> or std::is_same_v<B, position_t>), bool> = true>
void enableif4(const A a, const B b) {}
template <typename A, typename B, std::enable_if_t<(std::is_integral_v<A> and std::is_integral_v<B>), bool> = true>
int enableif5(const A a, const B b) {
return a + b;
}
void tester() {
enableif5<int, int>(10, 20);
enableif5(10, 20);
}
%}
// non-type template parameters working well in SWIG, below is a simple workaround as the 3rd parameter is defaulted for enable_if_t (which is just SFINAE to give a nice C++ compiler error)
%template(enableif5) enableif5<int, int, true>; // workaround (overriding default)
%inline %{
// #1037 infinite loop
template <typename T, std::enable_if_t<sizeof(T) <= 4>>
void destId(T el) {}
template <typename T, std::enable_if_t<sizeof(T) >= 3>>
void destId(const T& el) {}
%}
%inline %{
// #961 no name for defaulted template parameter
template<typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
void uuu() {}
template<typename T, typename E = std::enable_if_t<std::is_enum<T>::value>>
void uuuE() {}
template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
void vvv() {}
template<typename T, typename E = typename std::enable_if<std::is_floating_point<T>::value>::type>
void vvvE() {}
// More variations of enable_if and enable_if_t
template<typename T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr>
void www() {}
template<typename T, typename std::enable_if_t<std::is_enum<T>::value, int> = 0>
void xxx() {}
enum TestEnum { Enum1 = 1, Enum2 };
struct TestStruct {};
void tester2() {
uuu<TestEnum>();
// uuu<TestStruct>(); // compilation error
uuuE<TestEnum>();
// uuuE<TestStruct>(); // compilation error
vvv<double>();
// vvv<TestStruct>(); // compilation error
vvvE<double>();
// vvvE<TestStruct>(); // compilation error
www<double>();
// www<TestStruct>(); // compilation error
xxx<TestEnum>();
// xxx<TestStruct>(); // compilation error
}
%}

View file

@ -4,6 +4,8 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) global_cint; /* Ruby, wrong constant name */
%feature("php:allowdynamicproperties", 1) Foo; /* Allow PHP-specific custom property testing in _runme.php */
%module cpp_basic
%newobject Bar::testFoo;

View file

@ -0,0 +1,32 @@
using System;
using catches_stringsNamespace;
public class catches_strings_runme {
public static void Main()
{
{
bool exception_thrown = false;
try {
StringsThrower.charstring();
} catch (ApplicationException e) {
if (!e.Message.Contains("charstring message"))
throw new ApplicationException("incorrect exception message:" + e);
exception_thrown = true;
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown an exception");
}
{
bool exception_thrown = false;
try {
StringsThrower.stdstring();
} catch (ApplicationException e) {
if (!e.Message.Contains("stdstring message"))
throw new ApplicationException("incorrect exception message:" + e);
exception_thrown = true;
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown an exception");
}
}
}

View file

@ -0,0 +1,32 @@
module catches_strings_runme;
import catches_strings.catches_strings;
import catches_strings.StringsThrower;
import std.algorithm;
void main() {
{
bool exception_thrown = false;
try {
StringsThrower.charstring();
} catch (Exception e) {
if (!canFind(e.msg, "charstring message"))
throw new Exception("incorrect exception message:" ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown an exception");
}
{
bool exception_thrown = false;
try {
StringsThrower.stdstring();
} catch (Exception e) {
if (!canFind(e.msg, "stdstring message"))
throw new Exception("incorrect exception message:" ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown an exception");
}
}

View file

@ -0,0 +1,32 @@
module catches_strings_runme;
import catches_strings.catches_strings;
import catches_strings.StringsThrower;
import std.algorithm;
void main() {
{
bool exception_thrown = false;
try {
StringsThrower.charstring();
} catch (Exception e) {
if (!canFind(e.msg, "charstring message"))
throw new Exception("incorrect exception message:" ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown an exception");
}
{
bool exception_thrown = false;
try {
StringsThrower.stdstring();
} catch (Exception e) {
if (!canFind(e.msg, "stdstring message"))
throw new Exception("incorrect exception message:" ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown an exception");
}
}

View file

@ -29,7 +29,7 @@ struct TfToken {
struct Tokens {
const TfToken face;
const TfToken *pface;
const TfToken& g_face() const { return face; }
const TfToken& g_face(int = 0, int = 0) const { return face; }
const TfToken* g_pface() const { return pface; }
Tokens() : face(), pface(&face) {}
};
@ -68,4 +68,6 @@ void CreateMaterialBindSubsetu(int num = UsdGeomTokensPtr->g_pface()->g_val().g_
void CreateMaterialBindSubsetv(int num = UsdGeomTokensPtr->g_pface()->g_ptr()->g_val()) {}
void CreateMaterialBindSubsetw(int num = UsdGeomTokensPtr->g_face().g_val().g_val()) {}
void CreateMaterialBindSubsetx(int num = UsdGeomTokens.g_face().g_val().g_val()) {}
void CreateMaterialBindSubsety(int num = UsdGeomTokens.g_face(1).g_val().g_val()) {}
void CreateMaterialBindSubsetz(int num = UsdGeomTokens.g_face(1,2).g_val().g_val()) {}
%}

View file

@ -49,7 +49,7 @@
%inline %{
struct A{
A(std::complex<int> i, double d=0.0) {}
A(std::complex<double> i, double d=0.0) {}
A(int i, bool j=false) {}
virtual ~A() {}
@ -60,7 +60,7 @@
namespace hi {
struct A1 : public A {
A1(std::complex<int> i, double d=0.0) : A(i, d) {}
A1(std::complex<double> i, double d=0.0) : A(i, d) {}
A1(int i, bool j=false) : A(i, j) {}
virtual int ff(int i = 0) {return i;}

View file

@ -54,7 +54,7 @@
%inline %{
struct A{
A(std::complex<int> i, double d=0.0) {}
A(std::complex<double> i, double d=0.0) {}
A(int i, bool j=false) {}
virtual ~A() {}
@ -65,7 +65,7 @@
namespace hi {
struct A1 : public A {
A1(std::complex<int> i, double d=0.0) : A(i, d) {}
A1(std::complex<double> i, double d=0.0) : A(i, d) {}
A1(int i, bool j=false) : A(i, j) {}
virtual int ff(int i = 0) {return i;}

View file

@ -0,0 +1,28 @@
%module(directors="1") director_template
%{
#include <vector>
%}
%include <std_vector.i>
%feature("director") HandleBytes;
%inline %{
template <typename X, typename Y> class TwoTemplateParms {};
%}
%template(TT_int_double) TwoTemplateParms<int, double>;
%inline %{
class HandleBytes {
public:
virtual void handle(const std::vector<unsigned char> data) = 0; // Note: not instantiated with %template
virtual void handle2(TwoTemplateParms<int, double> data) = 0;
virtual ~HandleBytes() {}
};
void bytes_wrapper(const std::vector<unsigned char> data, HandleBytes *handler) {
handler->handle(data);
}
%}

View file

@ -0,0 +1,93 @@
%module(directors="1") director_unwrap_result
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Storage;
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) StorageTmpl;
%feature("director") Element;
%feature("director") Storage;
%feature("director") StorageTmpl;
%inline %{
class Element {
Element* self;
Element** selfptr;
public:
Element() {
self = this;
selfptr = &self;
}
virtual ~Element() {}
Element **getPtrPtr() {
return &self;
}
Element ***getPtrPtrPtr() {
return &selfptr;
}
};
typedef Element * element_ptr_t;
typedef Element & element_ref_t;
class Storage {
public:
virtual ~Storage() {}
virtual Element **getIt() = 0;
Element getElement() {
return **getIt();
}
Element* const getElementPtr() {
return *getIt();
}
Element& getElementRef() {
return **getIt();
}
Element* const *getElementPtrPtr() {
return getIt();
}
Element *&getElementPtrRef() {
return *getIt();
}
element_ref_t getElementRefTypedef() {
return **getIt();
}
element_ptr_t getElementPtrTypedef() {
return *getIt();
}
element_ptr_t &getElementPtrRefTypedef() {
return *getIt();
}
};
template<class T> class StorageTmpl {
public:
virtual ~StorageTmpl() {}
virtual T &getIt() = 0;
T getVal() {
return getIt();
}
T *getPtr() {
return &getIt();
}
T &getRef() {
return getIt();
}
};
%}
%template(ElementStorage) StorageTmpl<Element>;
%template(ElementPtrStorage) StorageTmpl<Element *>;
%template(ElementPtrPtrStorage) StorageTmpl<Element *const *>;
%inline %{
template<class T> T getParam(T t) {
return t;
}
%}
%template(getIntParam) getParam<int>;
%template(getIntPtrParam) getParam<int*>;
%template(getElementPtrParam) getParam<Element *>;

View file

@ -95,13 +95,68 @@
class ClassWithNestedEnum {
public:
/**
* Enum description.
* ENested description.
*/
typedef enum {ONE, ///< desc of one
TWO, ///< desc of two
THREE ///< desc of three
} ENested;
/**
* ENestedOdd description.
*/
typedef enum {ODD_ONE ///< desc of odd_one
,ODD_TWO ///< desc of odd_two
,ODD_THREE ///< desc of odd_three
} ENestedOdd;
/**
* ENestedOddPartial1 description.
*/
typedef enum {ODD_PARTIAL1_ONE
,ODD_PARTIAL1_TWO ///< desc of odd_partial1_two
,ODD_PARTIAL1_THREE ///< desc of odd_partial1_three
} ENestedOddPartial1;
/**
* ENestedOddPartial3 description.
*/
typedef enum {ODD_PARTIAL3_ONE ///< desc of odd_partial3_one
,ODD_PARTIAL3_TWO ///< desc of odd_partial3_two
,ODD_PARTIAL3_THREE
} ENestedOddPartial3;
/** Description for TESTENUM. */
enum TESTENUM
{
/** something for none */
TEST_NONE = 0,
/** something for one */
TEST_ONE,
/** something for two */
TEST_TWO /** something more for two */
};
};
/// SIOBeam struct description
struct SIOBeam {
/** testfunction - testing extra trailing doc comment */
void testfunction(
/** testfunction aaa parm */
int testf_aaa,
/** testfunction bbb parm */
double testf_bbb,
/** testfunction ccc parm */
bool testf_ccc /** testfunction more for two parm */
) {}
/// Constructor for input from an existing SIO file
explicit SIOBeam(
const char * filename, ///< Name of input SIO file.
int elevationOrder=1, ///< Interpolation order (0-3) in elevation
int bearingOrder=1 ///< Interpolation order (0-3) in bearing
) {}
};
/// @return This is a bad place for this tag, but it should be ignored.
@ -121,6 +176,13 @@
*/
void showList() { }
/** Incorrectly documented members, these should be post document comments, Github issue #1636 */
struct IncorrectlyDocumentedMembers
{
int aaaa; //! really for bbbb value
int bbbb; //! not for bbbb value, is quietly ignored by Doxygen and SWIG
};
#include "doxygen_misc_constructs.h"
%}

View file

@ -133,6 +133,16 @@ struct SomeAnotherStruct
}
};
struct Foo1636
{
///@{
/// groupmember1 description
int groupmember1;
/// groupmember2 description
int groupmember2;
///@}
};
struct Foo1750
{
/// @name Group name

View file

@ -59,6 +59,7 @@
* \endif
*
* \image html testImage.bmp "Hello, world!" width=10cm
* \image html "test image.jpg" "Test jpeg" width=10cm
*
* <ul>
*

View file

@ -0,0 +1,88 @@
%module duplicate_class_name_in_ns
%rename(XA) A::X;
%rename(XB) B::X;
%inline %{
namespace A
{
class X
{
public:
X(){};
};
template<typename T>
class Foo
{
public:
Foo(){};
};
class Bar
{
public:
Bar(){};
};
template<typename T>
class Baz
{
public:
Baz(){};
};
}
namespace B
{
// non-template derived from non-template
class X : public A::X
{
public:
X(){};
A::X do_x(){return A::X();}
};
// template derived from template with different template args
template<typename T, typename U>
class Foo : public A::Foo<U>
{
public:
Foo(){};
A::Foo<U> do_foo(){return A::Foo<U>();}
};
// template derived from non-template
template<typename T, typename U>
class Bar : public A::Bar
{
public:
Bar(){};
A::Bar do_bar(){return A::Bar();}
};
// template derived from template with same template args
template<typename T>
class Baz : public A::Baz<T>
{
public:
Baz(){};
A::Baz<T> do_baz(){return A::Baz<T>();}
};
}
%}
%template(AFoo) A::Foo<double>;
%template(ABaz) A::Baz<double>;
%template(BFoo) B::Foo<int, double>;
%template(BBar) B::Bar<int, double>;
%template(BBaz) B::Baz<double>;
%inline %{
A::X get_a_x() {B::X x; return x.do_x();}
A::Foo<double> get_a_foo() {B::Foo<int, double> x; return x.do_foo();}
A::Bar get_a_bar() {B::Bar<int, double> x; return x.do_bar();}
A::Baz<double> get_a_baz() {B::Baz<double> x; return x.do_baz();}
%}

View file

@ -1,5 +1,5 @@
%module xxx
/* Note: needs -Wextra to see these warnings */
/* Spaceship operator doesn't seem to be allowed in preprocessor expressions. */
#if (4 <=> 2) < 0

View file

@ -0,0 +1,34 @@
%module xxx
template<typename T> struct A {};
%template(Aint) A<int>;
%template(Aint2) A<int>; // Now ignored and issues a warning
template<typename T> struct B {};
%template() B<int>;
%template(Bint) B<int>; // OK
template<typename T> struct C {};
%template() C<int>;
%template() C<int>; // Quietly ignored now
%template(Cint) C<int>; // OK
template <typename T, typename U = short> struct D {};
%template(Dint) D<int>;
%template(Dintshort) D<int, short>;
template<typename T> struct E {};
%template(Eint) E<int>;
%template(Eint) E<int>; // Always has been ignored as a redefined identifier
template<typename T> struct F {};
%template(Fint) F<int>;
%template() F<int>; // Quietly ignored
%template() F<int>; // Quietly ignored
template<typename T> struct G {};
%template() G<int>;
%template() G<int>; // Quietly ignored
%template(Gint) G<int>;
%template() G<int>; // Quietly ignored

View file

@ -0,0 +1,6 @@
cpp_template_class_repeat.i:5: Warning 404: Duplicate template instantiation of 'A< int >' with name 'Aint2' ignored,
cpp_template_class_repeat.i:4: Warning 404: previous instantiation of 'A< int >' with name 'Aint'.
cpp_template_class_repeat.i:18: Warning 404: Duplicate template instantiation of 'D< int,short >' with name 'Dintshort' ignored,
cpp_template_class_repeat.i:17: Warning 404: previous instantiation of 'D< int >' with name 'Dint'.
cpp_template_class_repeat.i:22: Warning 404: Duplicate template instantiation of 'E< int >' with name 'Eint' ignored,
cpp_template_class_repeat.i:21: Warning 404: previous instantiation of 'E< int >' with name 'Eint'.

View file

@ -2,13 +2,13 @@ cpp_template_duplicate_names.i:14: Warning 302: Identifier 'Duplicate1' redefine
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:14: Warning 302: Identifier 'Duplicate1' redefined (ignored),
cpp_template_duplicate_names.i:13: Warning 302: previous definition of 'Duplicate1'.
cpp_template_duplicate_names.i:25: Warning 302: Identifier 'Duplicate2_0' redefined (ignored) (Renamed from 'Duplicate2< 0 >'),
cpp_template_duplicate_names.i:24: Warning 302: previous definition of 'Duplicate2_0' (Renamed from 'Duplicate2< 0 >').
cpp_template_duplicate_names.i:35: Warning 302: Identifier 'Duplicate3' redefined (ignored) (Renamed from 'Duplicate3< 0 >'),
cpp_template_duplicate_names.i:31: Warning 302: previous definition of 'Duplicate3'.
cpp_template_duplicate_names.i:25: Warning 404: Duplicate template instantiation of 'Duplicate2< 0 >' with name 'Duplicate2_0' ignored,
cpp_template_duplicate_names.i:24: Warning 404: previous instantiation of 'Duplicate2< 0 >' with name 'Duplicate2_0'.
cpp_template_duplicate_names.i:35: Warning 404: Duplicate template instantiation of 'Duplicate3< 0 >' with name 'Duplicate3' ignored,
cpp_template_duplicate_names.i:34: Warning 404: previous instantiation of 'Duplicate3< 0 >' with name 'Duplicate3'.
cpp_template_duplicate_names.i:47: Warning 302: Identifier 'Duplicate4' redefined (ignored),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:47: Warning 302: Identifier 'Duplicate4' redefined (ignored),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:50: Warning 302: Identifier 'Duplicate4' redefined (ignored) (Renamed from 'Duplicate4< 0 >'),
cpp_template_duplicate_names.i:46: Warning 302: previous definition of 'Duplicate4'.
cpp_template_duplicate_names.i:50: Warning 404: Duplicate template instantiation of 'Duplicate4< 0 >' with name 'Duplicate4' ignored,
cpp_template_duplicate_names.i:49: Warning 404: previous instantiation of 'Duplicate4< 0 >' with name 'Duplicate4'.

View file

@ -4,4 +4,15 @@ 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
// empty template instantiations for template functions warn (unlike for template classes)
%template() blah<double>;
%template() blah<double>;
%template() blah<double>;
%template(sblah) blah<short>;
%template(sblah) blah<short>;
%template() blah<const char *>;
%template() blah<const char *>;
%template(sblah) blah<const char *>;

View file

@ -0,0 +1,6 @@
cpp_template_repeat.i:6: Warning 404: Duplicate template instantiation of 'blah< int >' with name 'iiblah' ignored,
cpp_template_repeat.i:5: Warning 404: previous instantiation of 'blah< int >' with name 'iblah'.
cpp_template_repeat.i:14: Warning 404: Duplicate template instantiation of 'blah< short >' with name 'sblah' ignored,
cpp_template_repeat.i:13: Warning 404: previous instantiation of 'blah< short >' with name 'sblah'.
cpp_template_repeat.i:9: Warning 519: %template() contains no name. Template method ignored: blah< double >(double)
cpp_template_repeat.i:16: Warning 519: %template() contains no name. Template method ignored: blah< char const * >(char const *)

View file

@ -1,5 +1,5 @@
%module xxx
/* Note: needs -Wextra to see these warnings */
/* Divide by zero */
#define ZERO 0

View file

@ -1,6 +1,7 @@
%module exception_memory_leak
%include <std_string.i>
%include <exception.i>
%typemap(in) Foo* foo
{
@ -11,12 +12,23 @@
Foo::inc_freearg_count();
delete $1;
}
%typemap(out) Foo* verify_no_memory_leak
%typemap(out) Foo* trigger_internal_swig_exception
{
if ($1 == NULL)
SWIG_exception_fail(SWIG_RuntimeError, "Let's see how the bindings manage this exception!");
if ($1 == NULL) {
SWIG_exception(SWIG_RuntimeError, "Let's see how the bindings manage this exception!");
#ifdef SWIG_fail
SWIG_fail;
#endif
}
$1 = NULL;
}
%typemap(out) Foo trigger_internal_swig_exception
{
SWIG_exception(SWIG_RuntimeError, "Let's see how the bindings manage this exception!");
#ifdef SWIG_fail
SWIG_fail;
#endif
}
%inline %{
#include <string>
@ -42,4 +54,9 @@
return (message == "null") ? NULL : foo;
}
static Foo trigger_internal_swig_exception(const std::string& message)
{
return Foo();
}
%}

View file

@ -0,0 +1,13 @@
%module final_c
%warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final'
%inline %{
struct Y {
int yval;
};
struct Y final;
void init() {
final.yval = 123;
}
%}

View file

@ -1,7 +1,7 @@
%module global_immutable_vars
// Test immutable and mutable global variables,
// see http://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_readonly_variables
// see https://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_readonly_variables
%inline %{
int default_mutable_var = 40;

View file

@ -1,7 +1,7 @@
%module global_immutable_vars_cpp
// Test immutable and mutable global variables,
// see http://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_readonly_variables
// see https://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_readonly_variables
%inline %{
int default_mutable_var = 40;

View file

@ -0,0 +1,32 @@
package main
import "strings"
import . "swigtests/catches_strings"
func main() {
{
exception_thrown := false
func() {
defer func() {
exception_thrown = strings.Index(recover().(string), "charstring message") == 0
}()
StringsThrowerCharstring()
}()
if !exception_thrown {
panic(0)
}
}
{
exception_thrown := false
func() {
defer func() {
exception_thrown = strings.Index(recover().(string), "stdstring message") == 0
}()
StringsThrowerStdstring()
}()
if !exception_thrown {
panic(0)
}
}
}

View file

@ -28,4 +28,9 @@ func main() {
if x != "Grok::blah" {
panic(x)
}
x = d.Far()
if x != "Spam::far" {
panic(x)
}
}

View file

@ -0,0 +1,3 @@
(dynamic-call "scm_init_catches_strings_module" (dynamic-link "./libcatches_strings"))
(load "testsuite.scm")
(load "../schemerunme/catches_strings.scm")

View file

@ -0,0 +1,41 @@
import catches_strings.*;
public class catches_strings_runme {
static {
try {
System.loadLibrary("catches_strings");
} 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
{
{
boolean exception_thrown = false;
try {
StringsThrower.charstring();
} catch (RuntimeException e) {
if (!e.getMessage().contains("charstring message"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new RuntimeException("Should have thrown an exception");
}
{
boolean exception_thrown = false;
try {
StringsThrower.stdstring();
} catch (RuntimeException e) {
if (!e.getMessage().contains("stdstring message"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new RuntimeException("Should have thrown an exception");
}
}
}

View file

@ -0,0 +1,19 @@
import cpp17_enable_if_t.*;
public class cpp17_enable_if_t_runme {
static {
try {
System.loadLibrary("cpp17_enable_if_t");
} 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[])
{
if (cpp17_enable_if_t.enableif5(10, 20) != 30)
throw new RuntimeException("enableif5 not working");
}
}

View file

@ -97,7 +97,7 @@ public class doxygen_misc_constructs_runme {
"\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENested",
" Enum description.\n" +
" ENested description.\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENested.ONE",
@ -109,6 +109,81 @@ public class doxygen_misc_constructs_runme {
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENested.THREE",
" desc of three\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOdd",
" ENestedOdd description.\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOdd.ODD_ONE",
" desc of odd_one\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOdd.ODD_TWO",
" desc of odd_two\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOdd.ODD_THREE",
" desc of odd_three\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOddPartial1",
" ENestedOddPartial1 description.\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOddPartial1.ODD_PARTIAL1_THREE",
" desc of odd_partial1_three\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOddPartial1.ODD_PARTIAL1_TWO",
" desc of odd_partial1_two\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOddPartial3",
" ENestedOddPartial3 description.\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOddPartial3.ODD_PARTIAL3_ONE",
" desc of odd_partial3_one\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.ENestedOddPartial3.ODD_PARTIAL3_TWO",
" desc of odd_partial3_two\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.TESTENUM",
" Description for TESTENUM.\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.TESTENUM.TEST_NONE",
" something for none\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.TESTENUM.TEST_ONE",
" something for one\n");
wantedComments.put("doxygen_misc_constructs.ClassWithNestedEnum.TESTENUM.TEST_TWO",
" something for two something more for two\n");
wantedComments.put("doxygen_misc_constructs.SIOBeam",
" SIOBeam struct description\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.SIOBeam.testfunction(int, double, boolean)",
" testfunction - testing extra trailing doc comment <br>\n" +
" @param testf_aaa testfunction aaa parm <br>\n" +
" @param testf_bbb testfunction bbb parm <br>\n" +
" @param testf_ccc testfunction ccc parm testfunction more for two parm\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.SIOBeam(java.lang.String, int, int)",
" Constructor for input from an existing SIO file<br>\n" +
" @param filename Name of input SIO file.<br>\n" +
" @param elevationOrder Interpolation order (0-3) in elevation<br>\n" +
" @param bearingOrder Interpolation order (0-3) in bearing\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.SIOBeam(java.lang.String, int)",
" Constructor for input from an existing SIO file<br>\n" +
" @param filename Name of input SIO file.<br>\n" +
" @param elevationOrder Interpolation order (0-3) in elevation<br>\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.SIOBeam(java.lang.String)",
" Constructor for input from an existing SIO file<br>\n" +
" @param filename Name of input SIO file.<br>\n" +
"\n");
wantedComments.put("doxygen_misc_constructs.StructWithReturnComment",
" @return This is a bad place for this tag, but it should be ignored.");
@ -124,6 +199,16 @@ public class doxygen_misc_constructs_runme {
" <br>\n" +
" And this is not a list item any more.\n" +
"");
wantedComments.put("doxygen_misc_constructs.IncorrectlyDocumentedMembers",
" Incorrectly documented members, these should be post document comments, Github issue #1636");
wantedComments.put("doxygen_misc_constructs.IncorrectlyDocumentedMembers.setBbbb(int)",
" really for bbbb value");
wantedComments.put("doxygen_misc_constructs.IncorrectlyDocumentedMembers.getBbbb()",
" really for bbbb value");
wantedComments.put("doxygen_misc_constructs.doxygen_misc_constructs.isNoSpaceValidA()",
" This comment without space after '*' is valid in Doxygen.\n" +
"\n" +

View file

@ -132,6 +132,14 @@ public class doxygen_parsing_runme {
wantedComments.put("doxygen_parsing.doxygen_parsingConstants.CONSTANT_VALUE",
"The constant comment \n" +
"");
wantedComments.put("doxygen_parsing.Foo1636.getGroupmember1()",
"groupmember1 description");
wantedComments.put("doxygen_parsing.Foo1636.setGroupmember1(int)",
"groupmember1 description");
wantedComments.put("doxygen_parsing.Foo1636.getGroupmember2()",
"groupmember2 description");
wantedComments.put("doxygen_parsing.Foo1636.setGroupmember2(int)",
"groupmember2 description");
wantedComments.put("doxygen_parsing.Foo1750.getA()",
"");
wantedComments.put("doxygen_parsing.Foo1750.getB()",

View file

@ -81,7 +81,7 @@ public class doxygen_translate_all_tags_runme {
" If not: SOMECONDITION {\n" +
" This is printed if not \n" +
" }\n" +
" <img src=testImage.bmp alt=\"Hello, world!\" />\n" +
" <img src=\"testImage.bmp\" alt=\"Hello, world!\"/>\n" +
" Some text \n" +
" describing invariant. \n");

View file

@ -69,7 +69,8 @@ public class doxygen_translate_runme {
" This is printed if not}\n" +
" \n" +
" \n" +
" <img src=testImage.bmp alt=\"Hello, world!\"/>\n" +
" <img src=\"testImage.bmp\" alt=\"Hello, world!\"/>\n" +
" <img src=\"test image.jpg\" alt=\"Test jpeg\"/>\n" +
" \n" +
" <ul> \n" +
" \n" +

View file

@ -0,0 +1,25 @@
import template_function_parm.*;
public class template_function_parm_runme {
static {
try {
System.loadLibrary("template_function_parm");
} 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[]) {
VectorInt vi = new VectorInt();
vi.add(10);
vi.add(20);
vi.add(30);
MyC myc = new MyC();
int sum = myc.take_function(template_function_parmConstants.accumulate_integers, vi);
if (sum != 60)
throw new RuntimeException("Expected sum of 60, got " + sum);
}
}

View file

@ -12,12 +12,15 @@ public class template_partial_specialization_typedef_runme {
}
public static void main(String argv[]) {
double dub = 11.1;
Concrete concrete = new Concrete();
// One parameter tests
new A().a();
new B().b();
new C().c();
new D().d();
new E().e();
new B().b(); new B().bb(dub);
new C().c(); new C().cc(dub);
new D().d(); new D().dd(dub);
new E().e(); new E().ee(dub);
new F().f();
new G().g();
@ -28,10 +31,10 @@ public class template_partial_specialization_typedef_runme {
new M().m();
new N().n();
new BB().b();
new BBB().b();
new BBBB().b();
new BBBBB().b();
new BB().b(); new BB().bb(true);
new BBB().b(); new BBB().bb('A');
new BBBB().b(); new BBBB().bb((short)12);
new BBBBB().b(); new BBBBB().bb(123);
new B1().b();
new B2().b();
@ -40,18 +43,18 @@ public class template_partial_specialization_typedef_runme {
// Two parameter tests
new A_().a();
new B_().b();
new C_().c();
new D_().d();
new B_().b(); new B_().bbb(dub);
new C_().c(); new C_().ccc(dub);
new D_().d(); new D_().ddd(123);
new E_().e();
new F_().f();
new G_().g();
new C1_().c();
new C2_().c();
new C3_().c();
new C4_().c();
new B1_().b();
new C1_().c(); new C1_().ccc(concrete);
new C2_().c(); new C2_().ccc(concrete);
new C3_().c(); new C3_().ccc(concrete);
new C4_().c(); new C4_().ccc(concrete);
new B1_().b(); new B1_().bbb(concrete);
new E1_().e();
new E2_().e();
}

View file

@ -14,7 +14,7 @@ public class template_template_parameters_runme {
}
public static void main(String argv[]) {
// Test first part
// Test part 1
ListFastBool listBool = new ListFastBool();
listBool.setItem(true);
boolean x_boolean = listBool.getAllotype();
@ -27,7 +27,7 @@ public class template_template_parameters_runme {
if (listDouble.getItem() != 10.2)
throw new RuntimeException("Failed");
// Test second part
// Test part 2
FloatTestStruct floatTestStruct = new FloatTestStruct();
FloatContainer2 floatContainer2 = floatTestStruct.getX();
floatContainer2.setX(8.1f);
@ -41,6 +41,10 @@ public class template_template_parameters_runme {
IntTestStruct intTestStructReturned = template_template_parameters.TestStructContainer1Method(intTestStruct);
if (intTestStructReturned.getX().getX() != 101)
throw new RuntimeException("Failed");
// Test part 3
MyFootInt99 mfi99 = new MyFootInt99();
mfi99.OperatorPlusEquals(mfi99);
}
}

View file

@ -0,0 +1,36 @@
import template_template_template_parameters.*;
public class template_template_template_parameters_runme {
static {
try {
System.loadLibrary("template_template_template_parameters");
} 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[]) {
CustomAttrs custom_attrs = new CustomAttrs();
AC ac = new AC();
BAC bac = new BAC();
CBAC cbac = new CBAC();
DBAC dbac = new DBAC();
custom_attrs = ac.getAttributes();
custom_attrs = bac.getAttributes();
custom_attrs = cbac.getAttributes();
custom_attrs = dbac.getAttributes();
bac.BMethod(custom_attrs, ac);
cbac.BMethod(custom_attrs, ac);
dbac.BMethod(custom_attrs, ac);
cbac.CMethod(custom_attrs, bac);
dbac.DMethod(custom_attrs, bac);
}
}

View file

@ -8,6 +8,7 @@ NODEJS = @NODEJS@
SCRIPTSUFFIX = _runme.js
OBJEXT = @OBJEXT@
SO = @SO@
GYP_CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@
HAVE_CXX11 = @HAVE_CXX11@
HAVE_CXX14 = @HAVE_CXX14@
@ -59,10 +60,11 @@ ifeq (node,$(JSENGINE))
director_basic.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
member_funcptr_galore.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
director_unwrap_result.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
setup_node = \
test -d $* || mkdir $* && \
sed -e 's|$$testcase|$*|g; s|$$cflags|$(GYP_CFLAGS)|g; s|$$srcdir|$(srcdir)|g' \
sed -e 's|$$testcase|$*|g; s|$$cflags|$(GYP_CFLAGS)|g; s|$$cxxflags|"$(GYP_CXXFLAGS)"|g; s|$$srcdir|$(srcdir)|g' \
$(srcdir)/node_template/binding.gyp.in > $*/binding.gyp && \
sed -e 's|$$testcase|$*|g;' \
$(srcdir)/node_template/index.js.in > $*/index.js

View file

@ -0,0 +1,23 @@
var catches_strings = require("catches_strings");
exception_thrown = false;
try {
catches_strings.StringsThrower.charstring();
} catch (e) {
if (!e.message.includes("charstring message"))
throw new Error("incorrect exception message " + e.message);
exception_thrown = true;
}
if (!exception_thrown)
throw new Error("Should have thrown an exception");
exception_thrown = false;
try {
catches_strings.StringsThrower.stdstring();
} catch (e) {
if (!e.message.includes("stdstring message"))
throw new Error("incorrect exception message " + e.message);
exception_thrown = true;
}
if (!exception_thrown)
throw new Error("Should have thrown an exception");

View file

@ -1,18 +1,24 @@
var integers = require("integers");
var val = 3902408827
ret = integers.signed_long_identity(val)
if (ret != val)
throw "Incorrect value: " + ret
function checkOne(val, signed, typeName) {
typeName = (signed ? 'signed_' : 'unsigned_') + typeName
ret = integers.unsigned_long_identity(val)
if (ret != val)
throw "Incorrect value: " + ret
var size = integers[typeName + '_size']()
if ((!signed && val < 0) || (size < 8))
return // out of range, skip test
ret = integers.signed_long_long_identity(val)
if (ret != val)
throw "Incorrect value: " + ret
ret = integers[typeName + '_identity'](val)
if (ret !== val)
throw "Incorrect value: expected " + val + ", got " + ret
}
ret = integers.unsigned_long_long_identity(val)
if (ret != val)
throw "Incorrect value: " + ret
function checkAll(val) {
checkOne(val, true, 'long')
checkOne(val, false, 'long')
checkOne(val, true, 'long_long')
checkOne(val, false, 'long_long')
}
checkAll(3902408827)
checkAll(Number.MAX_SAFE_INTEGER)
checkAll(Number.MIN_SAFE_INTEGER)

View file

@ -19,7 +19,7 @@
['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"',
{
'cflags': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags],
'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags],
'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cxxflags, $cflags],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions', '-fno-rtti' ]
}

View file

@ -21,3 +21,7 @@ if (x != "Spam::blah")
x = typedef_inherit.do_blah2(d);
if (x != "Grok::blah")
print ("Whoa! Bad return" + x);
x = d.far();
if (x != "Spam::far")
print ("Whoa! Bad return" + x);

View file

@ -44,7 +44,7 @@
# define SWIG_SHARED_PTR_NAMESPACE SwigBoost
#endif
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif
@ -268,6 +268,7 @@ long use_count(const SwigBoost::shared_ptr<KlassDerived>& sptr) {
long use_count(const SwigBoost::shared_ptr<Klass>& sptr) {
return sptr.use_count();
}
const SwigBoost::shared_ptr<Klass>& ref_1() {
static SwigBoost::shared_ptr<Klass> sptr;
return sptr;

View file

@ -0,0 +1,68 @@
%module li_std_vector_vector
%include <std_string.i>
%include <std_vector.i>
namespace std {
%template(VectorInt) vector<int>;
%template(VectorString) vector<string>;
%template(VectorVectorInt) vector<vector<int>>;
%template(VectorVectorString) vector<vector<string>>;
};
%inline %{
std::vector<std::string> make_vector_int() {
std::string x[5] = {"1", "2", "3", "4", "5"};
std::vector<std::string> v;
for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]);
return v;
}
std::vector<std::vector<int> > make_vector_vector_int() {
int x[5] = {1, 2, 3, 4, 5};
std::vector<std::vector<int> > vv;
std::vector<int> v;
for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]);
vv.push_back(v);
return vv;
}
std::vector<bool> make_vector_bool() {
bool x[5] = {true, false, false, false, true};
std::vector<bool> v;
for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]);
return v;
}
std::vector<std::vector<bool> > make_vector_vector_bool() {
bool x[5] = {false, true, true, true, false};
std::vector<std::vector<bool> > vv;
std::vector<bool> v;
for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]);
vv.push_back(v);
return vv;
}
std::vector<std::string> make_vector_string() {
std::string x[5] = {"aa", "bb", "cc", "dd", "ee"};
std::vector<std::string> v;
for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]);
return v;
}
std::vector<std::vector<std::string> > make_vector_vector_string() {
std::string x[5] = {"1", "2", "3", "4", "5"};
std::vector<std::vector<std::string> > vv;
std::vector<std::string> v;
for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]);
vv.push_back(v);
return vv;
}
%}

View file

@ -0,0 +1,13 @@
require("import") -- the import fn
import("catches_strings") -- import code
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
s, msg = pcall(function() catches_strings.StringsThrower.charstring() end)
assert(s == false and msg:find("charstring message", 1, true))
s, msg = pcall(function() catches_strings.StringsThrower.stdstring() end)
assert(s == false and msg:find("stdstring message", 1, true))

View file

@ -0,0 +1,29 @@
require("import") -- the import fn
import("exception_memory_leak") -- import code
eml=exception_memory_leak --alias
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
a = eml.Foo()
assert(eml.Foo_get_count() == 1)
b = eml.Foo()
assert(eml.Foo_get_count() == 2)
-- Normal behaviour
eml.trigger_internal_swig_exception("no problem", a)
assert(eml.Foo_get_count() == 2)
assert(eml.Foo_get_freearg_count() == 1)
-- SWIG exception triggered and handled (return new object case)
ok,ex=pcall(eml.trigger_internal_swig_exception, "null", b)
assert(ok==false)
assert(eml.Foo_get_count() == 2)
assert(eml.Foo_get_freearg_count() == 2)
-- SWIG exception triggered and handled (return by value case).
ok,ex=pcall(eml.trigger_internal_swig_exception, "null")
assert(ok==false)
assert(eml.Foo_get_count() == 2)

View file

@ -0,0 +1,12 @@
require("import") -- the import fn
import("mod_a") -- import lib
import("mod_b") -- import lib
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
c = mod_b.C()
d = mod_b.D()
d:DoSomething(c)

View file

@ -0,0 +1,18 @@
(load-extension "catches_strings.so")
(require (lib "defmacro.ss"))
(define exception_thrown "no exception thrown for kin")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(StringsThrower-charstring))
(unless (string-contains? exception_thrown "charstring message")
(error (format "incorrect exception message: ~a" exception_thrown)))
(define exception_thrown "no exception thrown for kin")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(StringsThrower-stdstring))
(unless (string-contains? exception_thrown "stdstring message")
(error (format "incorrect exception message: ~a" exception_thrown)))
(exit 0)

View file

@ -0,0 +1,14 @@
open Swig
open Catches_strings
let _ =
try
ignore (_StringsThrower_charstring (C_void)); assert false
with Failure s ->
assert (s = "charstring message")
let _ =
try
ignore (_StringsThrower_stdstring (C_void)); assert false
with Failure s ->
assert (s = "stdstring message")

View file

@ -0,0 +1,10 @@
open Swig
open Enum_rename
let mydec = C_enum `M_Dec
let _ = assert (((enum_to_int `Month mydec)) = C_int 2)
let _ = assert (((int_to_enum `Month 2)) = C_enum `M_Dec)
let mymay = C_enum `May
let _ = assert (((enum_to_int `Month mymay)) = C_int 1)
let _ = assert (((int_to_enum `Month 1)) = C_enum `May)

View file

@ -0,0 +1,7 @@
open Swig
open Mod_a
open Mod_b
let c = new_C '()
let d = new_D '()
let _ = d -> "DoSomething" (c)

View file

@ -0,0 +1,7 @@
open Swig
open Rename_rstrip_encoder
let s = new_SomeThing '()
let a = new_AnotherThing '() in
assert (a -> DoClsX () = C_void);
;;

View file

@ -7,5 +7,6 @@ let _ =
assert (_do_blah (b) as string = "Bar::blah");
let c = new_Spam '() and d = new_Grok '() in
assert (_do_blah2 (c) as string = "Spam::blah");
assert (_do_blah2 (d) as string = "Grok::blah")
assert (_do_blah2 (d) as string = "Grok::blah");
assert (d -> far() as string = "Spam::far")
;;

View file

@ -0,0 +1,4 @@
open Swig
open Using2
let _ = assert (_spam '(37) as int = 37)

View file

@ -0,0 +1,32 @@
# do not dump Octave core
if exist("crash_dumps_octave_core", "builtin")
crash_dumps_octave_core(0);
endif
catches_strings
exception_thrown = false;
try
StringsThrower.charstring();
catch e
if (isempty(strfind(e.message, "charstring message")))
error("incorrect exception message: %s", e.message)
endif
exception_thrown = true;
end_try_catch
if (!exception_thrown)
error("Should have thrown an exception");
endif
exception_thrown = false;
try
StringsThrower.stdstring();
catch e
if (isempty(strfind(e.message, "stdstring message")))
error("incorrect exception message: %s", e.message)
endif
exception_thrown = true;
end_try_catch
if (!exception_thrown)
error("Should have thrown an exception");
endif

View file

@ -30,3 +30,8 @@ x = typedef_inherit.do_blah2(d);
if (!strcmp(x,"Grok::blah"))
error("Whoa! Bad return", x)
endif
x = d.far();
if (!strcmp(x,"Spam::far"))
error("Whoa! Bad return", x)
endif

View file

@ -0,0 +1,15 @@
use strict;
use warnings;
use Test::More tests => 4;
BEGIN { use_ok('catches_strings') }
require_ok('catches_strings');
eval {
catches_strings::StringsThrower::charstring();
};
like($@, qr/\bcharstring message/, "Should have thrown an exception");
eval {
catches_strings::StringsThrower::stdstring();
};
like($@, qr/\bstdstring message/, "Should have thrown an exception");

View file

@ -57,10 +57,18 @@ missingtests: missingcpptests missingctests
+$(swig_and_compile_c)
+$(run_testcase)
# Trying to load the modules for imports.multicpptest fails with:
#
# Warning: Function registration failed - duplicate name - global_test in Unknown on line 0
# Segmentation fault
#
# This was previously hidden because we didn't even try to load the modules for
# .multicpptest testcases, so for now just do the parts of the test we did
# before. FIXME: Fix this!
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
+$(run_testcase)
+[ "$*" = "imports" ] || $(run_multi_testcase)
# Smart target
%.test:
@ -72,14 +80,23 @@ missingtests: missingcpptests missingctests
$(MAKE) $*.multicpptest
# Runs the testcase. Tries to run testcase_runme.php, and if that's not found,
# at least test that the module loads without errors, except for multicpptests.
# at least test that the module loads without errors.
run_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION=$(TARGETPREFIX)$*@PHP_SO@ PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php_run; \
elif [ ! -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \
else \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION=$(TARGETPREFIX)$*@PHP_SO@ PHP_SCRIPT= RUNTOOL='$(RUNTOOL)' php_run; \
fi
# Runs a multicpptest testcase. Tries to run testcase_runme.php, and if that's
# not found, at least test that the modules load without errors.
run_multi_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION_LIST=$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list PHP_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php_run_multi; \
else \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP_EXTENSION_LIST=$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list PHP_SCRIPT= RUNTOOL='$(RUNTOOL)' php_run_multi; \
fi
# Clean: remove the generated PHP-specific files
%.clean:
@rm -f php_$*.h

View file

@ -0,0 +1,23 @@
<?php
require "tests.php";
$exception_thrown = false;
try {
StringsThrower::charstring();
} catch (Exception $e) {
check::str_contains($e->getMessage(), "charstring message", "incorrect exception message: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "Should have thrown an exception");
$exception_thrown = false;
try {
StringsThrower::stdstring();
} catch (Exception $e) {
check::str_contains($e->getMessage(), "stdstring message", "incorrect exception message: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "Should have thrown an exception");
check::done();

View file

@ -90,23 +90,23 @@ function makeCalls($caller, $base) {
check::equal($caller->PtrCall($dh)->val, $dh->val, "$bname.Ptr");
check::equal($caller->ConstPtrRefCall($dh)->val, $dh->val, "$bname.ConstPtrRef");
check::equal($caller->FullyOverloadedCall(1),
"${bname}::FullyOverloaded(int)",
"{$bname}::FullyOverloaded(int)",
"$bname.FullyOverloaded(int)");
check::equal($caller->FullyOverloadedCall(false),
"${bname}::FullyOverloaded(bool)",
"{$bname}::FullyOverloaded(bool)",
"$bname.FullyOverloaded(bool)");
// This next one is TODO for Perl with PerlDerived.
check::equal($caller->SemiOverloadedCall(-678),
"${bname}::SemiOverloaded(int)",
"{$bname}::SemiOverloaded(int)",
"$bname.SemiOverloaded(int)");
check::equal($caller->SemiOverloadedCall(false),
"Base::SemiOverloaded(bool)",
"$bname.SemiOverloaded(bool)");
check::equal($caller->DefaultParmsCall(10, 2.2),
"${bname}::DefaultParms(int, double)",
"{$bname}::DefaultParms(int, double)",
"$bname.DefaultParms(int, double)");
check::equal($caller->DefaultParmsCall(10),
"${bname}::DefaultParms(int)",
"{$bname}::DefaultParms(int)",
"$bname.DefaultParms(int)");
$caller->reset();
}

View file

@ -10,6 +10,8 @@ check::classes(array('A','Foo','Bar'));
check::globals(array());
class MyBar extends Bar {
public $val;
function __construct($val = 2) {
parent::__construct();
$this->val = $val;

View file

@ -10,6 +10,8 @@ check::classes(array('director_exception','Foo','Exception1','Exception2','Base'
check::globals(array());
class MyException extends Exception {
public $msg;
function __construct($a, $b) {
$this->msg = $a . $b;
}

View file

@ -10,6 +10,8 @@ check::classes(array('A','StringVector'));
check::globals(array());
class B extends A {
public $smem;
function get_first() {
return parent::get_first() . " world!";
}

View file

@ -17,7 +17,19 @@ trigger_internal_swig_exception("no problem", $a);
check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
check::equal(Foo::get_freearg_count(), 1, "freearg should have been used once");
// SWIG exception triggered and handled.
trigger_internal_swig_exception("null", $b);
// SWIG exception triggered and handled (return new object case).
try {
trigger_internal_swig_exception("null", $b);
check::fail("Expected exception not thrown");
} catch (Exception $e) {
}
check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
check::equal(Foo::get_freearg_count(), 2, "freearg should have been used twice");
// SWIG exception triggered and handled (return by value case).
try {
trigger_internal_swig_exception("null");
check::fail("Expected exception not thrown");
} catch (Exception $e) {
}
check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");

View file

@ -0,0 +1,9 @@
<?php
require "tests.php";
$c = new C();
$d = new D();
$d->DoSomething($c);
check::done();

View file

@ -9,18 +9,19 @@ class check {
private static $_werror = false;
// This is called automatically at the end of this file.
static function init() {
foreach(get_included_files() as $f) {
$module_name = preg_filter('/.*\/([^\/]+)_runme\.php$/', '\1', $f);
if ($module_name !== null) break;
static function get_extension() {
if (self::$_extension === null) {
foreach(get_included_files() as $f) {
$module_name = preg_filter('/.*\/([^\/]+)_runme\.php$/', '\1', $f);
if ($module_name !== null) break;
}
if ($module_name === null) {
print("Failed to determine module name from get_included_files()\n");
exit(1);
}
self::$_extension = new ReflectionExtension($module_name);
}
if ($module_name === null) {
print("Failed to determine module name from get_included_files()\n");
exit(1);
}
self::$_extension = new ReflectionExtension($module_name);
return self::$_extension;
}
static function werror($v) {
@ -92,7 +93,7 @@ class check {
if (! is_array($classes)) $classes=array($classes);
$message=array();
$missing=array();
$extra = array_flip(array_filter(self::$_extension->getClassNames(),
$extra = array_flip(array_filter(self::get_extension()->getClassNames(),
function ($e) { return !preg_match('/^SWIG\\\\/', $e); }));
foreach($classes as $class) {
if (! class_exists($class)) $missing[]=$class;
@ -109,7 +110,7 @@ class check {
if (! is_array($functions)) $functions=array($functions);
$message=array();
$missing=array();
$extra = self::$_extension->getFunctions();
$extra = self::get_extension()->getFunctions();
foreach ($functions as $func) {
if (! function_exists($func)) $missing[]=$func;
else unset($extra[$func]);
@ -127,7 +128,7 @@ class check {
if (! is_array($globals)) $globals=array($globals);
$message=array();
$missing=array();
$extra = self::$_extension->getFunctions();
$extra = self::get_extension()->getFunctions();
foreach ($globals as $glob) {
if (! function_exists($glob . "_get") && ! function_exists($glob . "_set")) $missing[]=$glob;
else {
@ -149,7 +150,7 @@ class check {
if (! is_array($constants)) $constants=array($constants);
$message=array();
$missing=array();
$extra = self::$_extension->getConstants();
$extra = self::get_extension()->getConstants();
unset($extra['swig_runtime_data_type_pointer']);
foreach($constants as $constant) {
if (! defined($constant)) $missing[]=$constant;
@ -213,5 +214,3 @@ class check {
# print $_SERVER[argv][0]." ok\n";
}
}
check::init();

View file

@ -86,7 +86,7 @@ struct Defined {
void defined_not(TYPE);
#endif
#if !( defined(AAA) \
#if !( defined(AAA) &&\
defined(BBB) \\
&& defined(CCC) )
void bumpf_not(TYPE);

View file

@ -0,0 +1,27 @@
/* This list will need updating when new target languages are added. */
#if (0\
+defined(SWIGCSHARP)\
+defined(SWIGD)\
+defined(SWIGGO)\
+defined(SWIGGUILE)\
+defined(SWIGJAVA)\
+defined(SWIGJAVASCRIPT)\
+defined(SWIGLUA)\
+defined(SWIGMZSCHEME)\
+defined(SWIGOCAML)\
+defined(SWIGOCTAVE)\
+defined(SWIGPERL)\
+defined(SWIGPHP)\
+defined(SWIGPYTHON)\
+defined(SWIGR)\
+defined(SWIGRUBY)\
+defined(SWIGSCILAB)\
+defined(SWIGTCL)\
+defined(SWIGXML)\
) != 1
# ifdef SWIG
# error Did not detect exactly one target-language-specific macro defined at SWIG time.
# else
# error Did not detect exactly one target-language-specific macro defined in the generated wrapper.
# endif
#endif

View file

@ -0,0 +1,62 @@
%module preproc_predefined
/* Test that SWIG_VERSION is defined at SWIG-time and in the wrapper. */
#ifndef SWIG_VERSION
# error SWIG_VERSION not defined at SWIG-time
#endif
%{
#ifndef SWIG_VERSION
# error SWIG_VERSION not defined in the generated wrapper
#endif
%}
/* Test that SWIG_VERSION has a plausible value - in particular catch if
* it isn't defined to a numeric value (which will get replaced by 0).
*/
#if SWIG_VERSION < 0x040100
# error SWIG_VERSION value not plausible at SWIG-time
#endif
%{
#if SWIG_VERSION < 0x040100
# error SWIG_VERSION value not plausible in the generated wrapper
#endif
%}
%define %generate_swig_version_from_preprocessor()%#define SWIG_VERSION_FROM_SWIG_PREPROCESSOR SWIG_VERSION %enddef
%insert("header") {
%generate_swig_version_from_preprocessor()
}
%insert("header") %{
#if SWIG_VERSION != SWIG_VERSION_FROM_SWIG_PREPROCESSOR
# error SWIG_VERSION in SWIG preprocessor does not match SWIG_VERSION from C preprocessor
#endif
%}
/* Test that SWIGVERSION is NOT defined at SWIG-time or in the wrapper.
* It used to be defined in the wrapper as a side-effect of how SWIG_VERSION
* was defined in the wrapper but was never documented and is redundant.
*/
#ifdef SWIGVERSION
# error SWIGVERSION should not be defined at SWIG-time
#endif
%{
#ifdef SWIGVERSION
# error SWIGVERSION should not be defined in the generated wrapper
#endif
%}
/* Test that SWIG is defined at SWIG-time but not in the wrapper. */
#ifndef SWIG
# error SWIG not defined at SWIG-time
#endif
%{
#ifdef SWIG
# error SWIG should not be defined in the generated wrapper
#endif
%}
/* Test that SWIGxxx is defined at SWIG-time and in the wrapper. */
%include "preproc_predefined.h"
%{
#include "preproc_predefined.h"
%}

View file

@ -0,0 +1,21 @@
from catches_strings import *
exception_thrown = False
try:
StringsThrower.charstring()
except RuntimeError as e:
if "charstring message" not in str(e):
raise RuntimeError("incorrect exception message:" + str(e))
exception_thrown = True
if not exception_thrown:
raise RuntimeError("Should have thrown an exception")
exception_thrown = False
try:
StringsThrower.stdstring()
except RuntimeError as e:
if "stdstring message" not in str(e):
raise RuntimeError("incorrect exception message:" + str(e))
exception_thrown = True
if not exception_thrown:
raise RuntimeError("Should have thrown an exception")

View file

@ -9,10 +9,10 @@ a.j = 10
if a.j != 10:
raise RuntimeError("Assignment to a.j failed.")
b = a.foo(5)
b = a.get_number(5)
if b != 10:
raise RuntimeError("foo(5) should return 10.")
raise RuntimeError("get_number(5) should return 10.")
b = a.foo(6)
b = a.get_number(6)
if b != 0:
raise RuntimeError("foo(6) should return 0.")
raise RuntimeError("get_number(6) should return 0.")

View file

@ -0,0 +1,65 @@
from cpp11_final_class import *
fc1 = FinalClass1()
fc1.method1()
fc2 = FinalClass2()
fc2.method2()
fc3 = FinalClass3()
fc3.method3()
fc4 = FinalClass4()
fc4.method4()
fc4final = cvar.final
cvar.final.method4()
fc5 = FinalClass5()
fc5.method5()
fc5.final_member_var.finalmethod()
fc5final = fc5.get_final_member()
fc5final.finalmethod()
fc5final = fc5.get_final_member2()
fc5final.finalmethod()
fc6 = FinalClass6()
fc6.method6()
fc6.final()
o = override()
o.omethod();
y = Y()
fv4 = FinalVar4()
yy = fv4.final
fv5 = FinalVar5()
yy = fv5.final
fv6 = FinalVar6()
yy = fv6.final
fv7 = FinalVar7()
yy = fv7.final
fv8 = FinalVar8()
yy = fv8.final
fv9 = FinalVar9()
yy = fv9.final
fv10 = FinalVar10()
fv10.b10(y)
# Removed due to Visual C++ compiler limitations
# fv11 = FinalVar11()
# fv11.a11(y)
#
# fe1 = FinalEnum1()
# fe1.enum_in(FinalEnum1.final)
#
# fe2 = FinalEnum2()
# fe2f = fe2.final
s3f = Space3_final()
s3f.fmethod();

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