From c2c3f968df9e62a6b809712452c63f2aecb02fc4 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 17:46:20 -0500 Subject: [PATCH 01/13] "Include what you use" for tests Using strcpy/strlen in global namespace requires ``. Include explicitly instead of assuming another SWIG or library header brings it in. --- Examples/test-suite/director_binary_string.i | 1 + Examples/test-suite/kwargs_feature.i | 5 +++++ Examples/test-suite/typemap_various.i | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/Examples/test-suite/director_binary_string.i b/Examples/test-suite/director_binary_string.i index 17bdc1b64..40d899fe1 100644 --- a/Examples/test-suite/director_binary_string.i +++ b/Examples/test-suite/director_binary_string.i @@ -8,6 +8,7 @@ %inline %{ #include +#include #define BUFFER_SIZE_AA 8 #define BUFFER_SIZE_BB 5 diff --git a/Examples/test-suite/kwargs_feature.i b/Examples/test-suite/kwargs_feature.i index 6db4d407b..5b9418129 100644 --- a/Examples/test-suite/kwargs_feature.i +++ b/Examples/test-suite/kwargs_feature.i @@ -128,6 +128,11 @@ struct ExtendingOptArgs1 {}; struct ExtendingOptArgs2 {}; %} +// For strlen/strcpy +%{ +#include +%} + // Varargs %warnfilter(SWIGWARN_LANG_VARARGS_KEYWORD) VarargConstructor::VarargConstructor; // Can't wrap varargs with keyword arguments enabled %warnfilter(SWIGWARN_LANG_VARARGS_KEYWORD) VarargConstructor::vararg_method; // Can't wrap varargs with keyword arguments enabled diff --git a/Examples/test-suite/typemap_various.i b/Examples/test-suite/typemap_various.i index 2caff97dc..d619aabaa 100644 --- a/Examples/test-suite/typemap_various.i +++ b/Examples/test-suite/typemap_various.i @@ -58,6 +58,10 @@ void CheckRetTypemapUsed() { /* hello */ delete[] result; } +%{ +#include +%} + %inline { class FFoo { public: From fc2b90acd10b6de98213c775e238fc43eddd6224 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 18:06:56 -0500 Subject: [PATCH 02/13] Add a "diamond" pattern to multi-impmort test This tests whether multiple modules can correctly import the same common module. ``` a -> d -> b -> c -> d* ``` --- Examples/test-suite/go/Makefile.in | 3 ++- Examples/test-suite/javascript/Makefile.in | 2 +- Examples/test-suite/multi_import.list | 3 ++- Examples/test-suite/multi_import_a.i | 3 ++- Examples/test-suite/multi_import_c.i | 2 ++ Examples/test-suite/multi_import_d.i | 3 +++ Examples/test-suite/ocaml/Makefile.in | 2 +- Examples/test-suite/php/Makefile.in | 2 +- Examples/test-suite/python/Makefile.in | 2 +- Examples/test-suite/template_typedef_cplx2.h | 2 ++ 10 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 Examples/test-suite/multi_import_d.i diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 75debc538..e905a1060 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -67,7 +67,7 @@ multi_import.multicpptest: if ! test -d gopath/multi_import/src/swigtests; then \ (cd gopath/multi_import/src && ln -s . swigtests); \ fi - for f in multi_import_b multi_import_a; do \ + for f in multi_import_d multi_import_b multi_import_a; do \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ @@ -181,6 +181,7 @@ clean: rm -f mod_a.go mod_a.gox mod_b.go mod_b.gox rm -f multi_import_a.go multi_import_a.gox rm -f multi_import_b.go multi_import_b.gox + rm -f multi_import_d.go multi_import_d.gox rm -f packageoption_a.go packageoption_a.gox rm -f packageoption_b.go packageoption_b.gox rm -f packageoption_c.go packageoption_c.gox diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index c0c73e242..4f2d450e5 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -134,7 +134,7 @@ clean: rm -f imports_a$${ext} imports_b$${ext}; \ rm -f import_stl_a$${ext} import_stl_b$${ext}; \ rm -f mod_a$${ext} mod_b$${ext}; \ - rm -f multi_import_a$${ext} multi_import_b$${ext}; \ + rm -f multi_import_a$${ext} multi_import_b$${ext} multi_import_d$${ext}; \ rm -f packageoption_a$${ext} packageoption_b$${ext} packageoption_c$${ext}; \ rm -f template_typedef_cplx2$${ext}; \ done diff --git a/Examples/test-suite/multi_import.list b/Examples/test-suite/multi_import.list index 6f7f98cae..a42944f48 100644 --- a/Examples/test-suite/multi_import.list +++ b/Examples/test-suite/multi_import.list @@ -1,2 +1,3 @@ -multi_import_a +multi_import_d multi_import_b +multi_import_a diff --git a/Examples/test-suite/multi_import_a.i b/Examples/test-suite/multi_import_a.i index 62d7cc0b8..0630f1df2 100644 --- a/Examples/test-suite/multi_import_a.i +++ b/Examples/test-suite/multi_import_a.i @@ -2,7 +2,8 @@ %module multi_import_a -%import multi_import_b.i +%import multi_import_d.i +%import "multi_import_b.i" %{ #include "multi_import.h" diff --git a/Examples/test-suite/multi_import_c.i b/Examples/test-suite/multi_import_c.i index 854e6b136..9aca70029 100644 --- a/Examples/test-suite/multi_import_c.i +++ b/Examples/test-suite/multi_import_c.i @@ -1,3 +1,5 @@ +%import "multi_import_d.i" + class XXX { public: diff --git a/Examples/test-suite/multi_import_d.i b/Examples/test-suite/multi_import_d.i new file mode 100644 index 000000000..01e4760f7 --- /dev/null +++ b/Examples/test-suite/multi_import_d.i @@ -0,0 +1,3 @@ +%module multi_import_d + +%constant int myval = 1234; diff --git a/Examples/test-suite/ocaml/Makefile.in b/Examples/test-suite/ocaml/Makefile.in index c44f02a72..10b537e4c 100644 --- a/Examples/test-suite/ocaml/Makefile.in +++ b/Examples/test-suite/ocaml/Makefile.in @@ -106,6 +106,6 @@ clean: rm -f import_stl_a.ml import_stl_b.ml rm -f imports_a.ml imports_b.ml rm -f mod_a.ml mod_b.ml - rm -f multi_import_a.ml multi_import_b.ml + rm -f multi_import_a.ml multi_import_b.ml multi_import_d.ml rm -f packageoption_a.ml packageoption_b.ml packageoption_c.ml rm -f template_typedef_cplx2.ml diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index b64918df7..a31eedbee 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -86,6 +86,6 @@ clean: rm -f import_stl_a.php import_stl_b.php php_import_stl_a.h php_import_stl_b.h rm -f imports_a.php imports_b.php php_imports_a.h php_imports_b.h rm -f mod_a.php mod_b.php php_mod_a.h php_mod_b.h - rm -f multi_import_a.php multi_import_b.php php_multi_import_a.h php_multi_import_b.h + rm -f multi_import_a.php multi_import_b.php multi_import_d.php php_multi_import_a.h php_multi_import_b.h php_multi_import_d.h rm -f packageoption_a.php packageoption_b.php packageoption_c.php php_packageoption_a.h php_packageoption_b.h php_packageoption_c.h rm -f template_typedef_cplx2.php php_template_typedef_cplx2.h diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index a5f2670d8..c10d9abf7 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -146,7 +146,7 @@ clean: rm -f clientdata_prop_a.py clientdata_prop_b.py import_stl_a.py import_stl_b.py rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py rm -f imports_a.py imports_b.py mod_a.py mod_b.py multi_import_a.py - rm -f multi_import_b.py packageoption_a.py packageoption_b.py packageoption_c.py + rm -f multi_import_b.py multi_import_d.py packageoption_a.py packageoption_b.py packageoption_c.py rm -f template_typedef_cplx2.py hugemod_runme = hugemod$(SCRIPTPREFIX) diff --git a/Examples/test-suite/template_typedef_cplx2.h b/Examples/test-suite/template_typedef_cplx2.h index 17d065252..a6ee3c673 100644 --- a/Examples/test-suite/template_typedef_cplx2.h +++ b/Examples/test-suite/template_typedef_cplx2.h @@ -113,6 +113,8 @@ namespace vfncs { #ifndef SWIG // Initialize these static class members +// XXX Since this is a header file, the following creates the symbols in *each* SWIG _wrap.cxx file. Linking the resulting SWIG modules together may result in +// duplicate symbol link errors. const char* const arith_traits< double, double >::arg_type = "double"; const char* const arith_traits< double, double >::res_type = "double"; From a8e73e3ad7a617c387407ff1da795f4a6723ea93 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 18:08:22 -0500 Subject: [PATCH 03/13] Test scope resolution of global struct A --- Examples/test-suite/class_scope_namespace.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/class_scope_namespace.i b/Examples/test-suite/class_scope_namespace.i index 47d918157..a24932a6e 100644 --- a/Examples/test-suite/class_scope_namespace.i +++ b/Examples/test-suite/class_scope_namespace.i @@ -15,6 +15,7 @@ namespace Space1 { void aaa(Space1::SubSpace1::A, SubSpace1::A, A) {} } } +void global_namespace_a(A*) {} namespace Space2 { struct B; From c9fbb81e4a824801e76d196ff8dc108d5d024346 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 18:09:32 -0500 Subject: [PATCH 04/13] Mark in-header function definitions as "inline" Otherwise, generating the `clientdata_prop` modules will duplicate symbols, leading to linker errors if the resulting modules are linked (or possibly loaded) simultaneously. --- Examples/test-suite/clientdata_prop_a.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/clientdata_prop_a.h b/Examples/test-suite/clientdata_prop_a.h index 5f82e98bc..52c54066d 100644 --- a/Examples/test-suite/clientdata_prop_a.h +++ b/Examples/test-suite/clientdata_prop_a.h @@ -6,7 +6,7 @@ class A { typedef A tA; -void test_A(A *a) {} -void test_tA(tA *a) {} +inline void test_A(A *a) {} +inline void test_tA(tA *a) {} -tA *new_tA() { return new tA(); } +inline tA *new_tA() { return new tA(); } From fb0cddfd2b686b14719cbb785516ab02f4305545 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 18:13:20 -0500 Subject: [PATCH 05/13] Add C "contract" test Tests that the `%contract` code (viz., each target language's implementation of SWIG_contract_assert) compiles in C as expected. Update the note in the source code since `%contract` is in the official documentation. --- Examples/test-suite/common.mk | 1 + Examples/test-suite/contract.i | 3 ++- Examples/test-suite/contract_c.i | 5 +++++ Lib/swig.swg | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/contract_c.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 25ca2d512..20d358d80 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -695,6 +695,7 @@ C_TEST_CASES += \ command_line_define \ const_const \ constant_expr_c \ + contract_c \ default_args_c \ empty_c \ enums \ diff --git a/Examples/test-suite/contract.i b/Examples/test-suite/contract.i index 0ad7e8e7c..de662c108 100644 --- a/Examples/test-suite/contract.i +++ b/Examples/test-suite/contract.i @@ -48,6 +48,7 @@ int test_prepost(int x, int y) { } %} +#ifdef __cplusplus /* Class tests */ %contract Foo::test_preassert(int x, int y) { @@ -235,4 +236,4 @@ class myClass }; } - +#endif diff --git a/Examples/test-suite/contract_c.i b/Examples/test-suite/contract_c.i new file mode 100644 index 000000000..465a7ded6 --- /dev/null +++ b/Examples/test-suite/contract_c.i @@ -0,0 +1,5 @@ +%module contract_c; + +%include + +%include "contract.i" diff --git a/Lib/swig.swg b/Lib/swig.swg index d719a139c..94c6e93e1 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -172,7 +172,7 @@ #define %novaluewrapper %feature("novaluewrapper") #define %clearnovaluewrapper %feature("novaluewrapper","") -/* Contract support - Experimental and undocumented */ +/* Contract support - Experimental */ #define %contract %feature("contract") #define %nocontract %feature("contract","0") #define %clearcontract %feature("contract","") From 0da8a9bb44ba3703393b7f03a358b5d4357a68d5 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 18:43:02 -0500 Subject: [PATCH 06/13] Test ability to manipulate a daughter class from its base class wrapper Even in the case of just creating a `DerivedClass` this test says: ``` swig/python detected a memory leak of type 'DerivedClass *', no destructor found. ``` even though the destructor is defined in the base class. --- Examples/test-suite/abstract_basecast.i | 20 +++++++++++++++++++ Examples/test-suite/common.mk | 1 + .../python/abstract_basecast_runme.py | 15 ++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 Examples/test-suite/abstract_basecast.i create mode 100644 Examples/test-suite/python/abstract_basecast_runme.py diff --git a/Examples/test-suite/abstract_basecast.i b/Examples/test-suite/abstract_basecast.i new file mode 100644 index 000000000..b6a21aa64 --- /dev/null +++ b/Examples/test-suite/abstract_basecast.i @@ -0,0 +1,20 @@ +%module abstract_basecast + +%inline %{ +class BaseClass { +public: + virtual ~BaseClass() { } + + virtual void g() = 0; +}; + +class DerivedClass : public BaseClass { +public: + + virtual void g() { } + + BaseClass& f() { + return *this; + } +}; +%} diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 20d358d80..4a7855efb 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -102,6 +102,7 @@ C_TEST_BROKEN += \ # C++ test cases. (Can be run individually using: make testcase.cpptest) CPP_TEST_CASES += \ abstract_access \ + abstract_basecast \ abstract_inherit \ abstract_inherit_ok \ abstract_signature \ diff --git a/Examples/test-suite/python/abstract_basecast_runme.py b/Examples/test-suite/python/abstract_basecast_runme.py new file mode 100644 index 000000000..4a3f4a9e1 --- /dev/null +++ b/Examples/test-suite/python/abstract_basecast_runme.py @@ -0,0 +1,15 @@ +from abstract_basecast import * + +def check(flag): + if not flag: + raise RuntimeError("Test failed") + +derived = DerivedClass() +derived.g() +check(isinstance(derived, BaseClass)) +check(isinstance(derived, DerivedClass)) + +base = derived.f() +base.g() +check(isinstance(base, BaseClass)) +check(not isinstance(base, DerivedClass)) From 266766d7c75d8cf28c69934ed0d404e8dcad8656 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 18:44:43 -0500 Subject: [PATCH 07/13] Test identity operation on class references --- Examples/test-suite/cpp_basic.i | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Examples/test-suite/cpp_basic.i b/Examples/test-suite/cpp_basic.i index ddccfa727..c39206b13 100644 --- a/Examples/test-suite/cpp_basic.i +++ b/Examples/test-suite/cpp_basic.i @@ -45,6 +45,9 @@ class FooSubSub : public FooSub { const char* __str__() const { return "FooSubSub"; } }; +Foo& get_reference(Foo& other) { return other; } +const Foo& get_const_reference(const Foo& other) { return other; } + %} %{ From 77cdba81adecc882ea167417d0c0401f672c1859 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 19:19:31 -0500 Subject: [PATCH 08/13] Add test case for very simple director classes Test both abstract and concrete base classes, with simple int/bool data. This level of complexity is very helpful when setting up director functionality for a new target language. --- Examples/test-suite/common.mk | 1 + Examples/test-suite/director_simple.i | 42 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Examples/test-suite/director_simple.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 4a7855efb..61a5fcddc 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -214,6 +214,7 @@ CPP_TEST_CASES += \ director_protected_overloaded \ director_redefined \ director_ref \ + director_simple \ director_smartptr \ director_thread \ director_unroll \ diff --git a/Examples/test-suite/director_simple.i b/Examples/test-suite/director_simple.i new file mode 100644 index 000000000..0883cae12 --- /dev/null +++ b/Examples/test-suite/director_simple.i @@ -0,0 +1,42 @@ +%module(directors="1") director_simple + +%feature("director") IntBase; +%feature("director") BoolBase; + +%inline %{ +class IntBase { + public: + virtual ~IntBase() {} + IntBase(int i = 3) { (void)i; } + virtual int apply(int x) const { return x * 2; } +}; + +class IntDerived : public IntBase { + public: + virtual int apply(int x) const { return x * 3; } +}; + +int apply(const IntBase& b, int x) +{ + return b.apply(x); +} + +class BoolBase { + public: + virtual ~BoolBase() {} + BoolBase() {} + virtual bool apply(bool a, bool b) const = 0; +}; + +class BoolDerived : public BoolBase { + public: + virtual bool apply(bool a, bool b) const { return a != b; } +}; + +bool apply(const BoolBase& base, bool a, bool b) +{ + return base.apply(a, b); +} + +%} + From ef112087cc22d4d7d6041d159834c27d56eb7984 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 19:23:44 -0500 Subject: [PATCH 09/13] Add test of callback with enum argument This is an odd use case often with numerical solver flags that's not covered in the existing test suite. --- Examples/test-suite/callback.i | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Examples/test-suite/callback.i b/Examples/test-suite/callback.i index 4db63353b..e406615bb 100644 --- a/Examples/test-suite/callback.i +++ b/Examples/test-suite/callback.i @@ -13,6 +13,7 @@ %callback("%s") A::foom; #endif %callback("%(uppercase)s_Cb_Ptr") foo_T; // this works in Python too +%callback("%s_cb") identity_finger; %inline %{ @@ -85,6 +86,15 @@ const T& ident(const T& x) { return x; } + + // Test callbacks for enum types + typedef enum {One, Two, Three, Four, Five} finger; + typedef finger (*finger_finger)(finger); + finger identity_finger(finger f) { return f; } + finger apply_finger_cb(finger f, finger_finger cb) { + return cb(f); + } + %} %template(foo_i) foo_T; From 47eb9c8078625cbbb49c11985b2f37a4da59b9c3 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 19:25:34 -0500 Subject: [PATCH 10/13] Extend "ignore" parameter test - Ensure that `argout` is called even when a parameter is ignored - Ensure that ignored parameters with default arguments are handled correctly --- Examples/test-suite/ignore_parameter.i | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/ignore_parameter.i b/Examples/test-suite/ignore_parameter.i index 604ee3b84..b3633bd97 100644 --- a/Examples/test-suite/ignore_parameter.i +++ b/Examples/test-suite/ignore_parameter.i @@ -3,14 +3,19 @@ %module ignore_parameter %typemap(in,numinputs=0) char* a "static const char* hi = \"hello\"; $1 = const_cast(hi);"; -%typemap(in,numinputs=0) int bb "$1 = 101;"; +%typemap(in,numinputs=0) int bb "$1 = 101; called_argout = 0;"; %typemap(in,numinputs=0) double ccc "$1 = 8.8;"; %typemap(freearg) char* a ""; // ensure freearg is not generated (needed for Java at least) +%typemap(argout) int bb "called_argout = 1;" + %ignore unignorable; %inline %{ +// constant for detecting correct "argout" call +int called_argout = 0; + // global function tests char* jaguar(char* a, int b, double c) { return a; } int lotus(char* aa, int bb, double cc) { return bb; } @@ -25,6 +30,7 @@ struct SportsCars { double bugatti(char* aaa, int bbb, double ccc) { return ccc; } int lamborghini(int bb) { return bb; } int maseratti(int unignorable) { return unignorable; } + double audi(double ccc=9.5) { return ccc; } }; // constructor tests From 01995ec14f3f3af4becae0bc633e0774957f6852 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 19:30:41 -0500 Subject: [PATCH 11/13] Add test cases for reference/const-reference of integers --- Examples/test-suite/integers.i | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Examples/test-suite/integers.i b/Examples/test-suite/integers.i index 6a9ede4bc..9569df767 100644 --- a/Examples/test-suite/integers.i +++ b/Examples/test-suite/integers.i @@ -17,6 +17,41 @@ signed long long signed_long_long_identity(signed long long x) { return x; } unsigned long long unsigned_long_long_identity(unsigned long long x) { return x; } +#ifdef __cplusplus + signed char & signed_char_ref_identity( signed char & x) { return x; } + unsigned char & unsigned_char_ref_identity( unsigned char & x) { return x; } + signed short & signed_short_ref_identity( signed short & x) { return x; } + unsigned short & unsigned_short_ref_identity( unsigned short & x) { return x; } + signed int & signed_int_ref_identity( signed int & x) { return x; } + unsigned int & unsigned_int_ref_identity( unsigned int & x) { return x; } + signed long & signed_long_ref_identity( signed long & x) { return x; } + unsigned long & unsigned_long_ref_identity( unsigned long & x) { return x; } + signed long long & signed_long_long_ref_identity( signed long long & x) { return x; } + unsigned long long & unsigned_long_long_ref_identity(unsigned long long & x) { return x; } + + const signed char & const_signed_char_ref_identity( const signed char & x) { return x; } + const unsigned char & const_unsigned_char_ref_identity( const unsigned char & x) { return x; } + const signed short & const_signed_short_ref_identity( const signed short & x) { return x; } + const unsigned short & const_unsigned_short_ref_identity( const unsigned short & x) { return x; } + const signed int & const_signed_int_ref_identity( const signed int & x) { return x; } + const unsigned int & const_unsigned_int_ref_identity( const unsigned int & x) { return x; } + const signed long & const_signed_long_ref_identity( const signed long & x) { return x; } + const unsigned long & const_unsigned_long_ref_identity( const unsigned long & x) { return x; } + const signed long long & const_signed_long_long_ref_identity( const signed long long & x) { return x; } + const unsigned long long & const_unsigned_long_long_ref_identity(const unsigned long long & x) { return x; } +#endif + + signed char * signed_char_ptr() { return NULL; } + unsigned char * unsigned_char_ptr() { return NULL; } + signed short * signed_short_ptr() { return NULL; } + unsigned short * unsigned_short_ptr() { return NULL; } + signed int * signed_int_ptr() { return NULL; } + unsigned int * unsigned_int_ptr() { return NULL; } + signed long * signed_long_ptr() { return NULL; } + unsigned long * unsigned_long_ptr() { return NULL; } + signed long long * signed_long_long_ptr() { return NULL; } + unsigned long long * unsigned_long_long_ptr() { return NULL; } + size_t signed_char_size() { return sizeof (signed char); } size_t unsigned_char_size() { return sizeof (unsigned char); } size_t signed_short_size() { return sizeof (signed short); } From b08713f09f0e1b041f8f3e8493d06fdb99cbf47d Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sat, 12 Feb 2022 19:39:35 -0500 Subject: [PATCH 12/13] Add test of null shared pointers emitted from C++ This tests nulls emitted as pointers and values of shared pointers, created from null, from references, and from default constructors. --- Examples/test-suite/li_boost_shared_ptr.i | 4 ++++ .../test-suite/python/li_boost_shared_ptr_runme.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index b64197be1..001eacb78 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -242,6 +242,10 @@ std::string nullsmartpointerpointertest(SwigBoost::shared_ptr* k) { else return "also not null"; } + +SwigBoost::shared_ptr* sp_pointer_null() { return NULL; } +SwigBoost::shared_ptr* null_sp_pointer() { static SwigBoost::shared_ptr static_sp; return &static_sp; } +SwigBoost::shared_ptr sp_value_null() { return SwigBoost::shared_ptr(); } // $owner Klass *pointerownertest() { return new Klass("pointerownertest"); diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index 2e241d590..bde79fd61 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -168,6 +168,19 @@ class li_boost_shared_ptr_runme: except ValueError: pass + # test null pointers emitted from C++ + k = li_boost_shared_ptr.sp_pointer_null() + if (li_boost_shared_ptr.smartpointertest(k) != None): + raise RuntimeError("return was not null") + + k = li_boost_shared_ptr.null_sp_pointer() + if (li_boost_shared_ptr.smartpointertest(k) != None): + raise RuntimeError("return was not null") + + k = li_boost_shared_ptr.sp_value_null() + if (li_boost_shared_ptr.smartpointertest(k) != None): + raise RuntimeError("return was not null") + # $owner k = li_boost_shared_ptr.pointerownertest() val = k.getValue() From 0268dde2014db1e47e45ce0c0a3e15afaab2c511 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Sun, 13 Feb 2022 14:19:52 -0500 Subject: [PATCH 13/13] Extend diamond multi test to fix go --- Examples/test-suite/multi_import.h | 10 ++++++++++ Examples/test-suite/multi_import_a.i | 4 ++++ Examples/test-suite/multi_import_b.i | 4 ++++ Examples/test-suite/multi_import_c.i | 3 +++ Examples/test-suite/multi_import_d.i | 9 +++++++++ 5 files changed, 30 insertions(+) diff --git a/Examples/test-suite/multi_import.h b/Examples/test-suite/multi_import.h index fa7a460e9..f893e3de0 100644 --- a/Examples/test-suite/multi_import.h +++ b/Examples/test-suite/multi_import.h @@ -1,3 +1,11 @@ +#ifndef MULTI_IMPORT_H +#define MULTI_IMPORT_H + +class WWW { + public: + void nullop() const {} +}; + class XXX { public: @@ -15,3 +23,5 @@ class ZZZ : public XXX public: int testz() { return 2;} }; + +#endif /* MULTI_IMPORT_H */ diff --git a/Examples/test-suite/multi_import_a.i b/Examples/test-suite/multi_import_a.i index 0630f1df2..7cb311051 100644 --- a/Examples/test-suite/multi_import_a.i +++ b/Examples/test-suite/multi_import_a.i @@ -14,3 +14,7 @@ class ZZZ : public XXX public: int testz(); }; + +%inline %{ +void use_www_a(const WWW& w) {w.nullop();} +%} diff --git a/Examples/test-suite/multi_import_b.i b/Examples/test-suite/multi_import_b.i index a2be27055..f19608292 100644 --- a/Examples/test-suite/multi_import_b.i +++ b/Examples/test-suite/multi_import_b.i @@ -11,3 +11,7 @@ class YYY : public XXX public: int testy(); }; + +%inline %{ +void use_www_b(const WWW& w) {w.nullop();} +%} diff --git a/Examples/test-suite/multi_import_c.i b/Examples/test-suite/multi_import_c.i index 9aca70029..0e5a02e74 100644 --- a/Examples/test-suite/multi_import_c.i +++ b/Examples/test-suite/multi_import_c.i @@ -1,5 +1,8 @@ %import "multi_import_d.i" +// NB: this module is only imported, never compiled, so it's not necessary to +// include the header for testing purposes. + class XXX { public: diff --git a/Examples/test-suite/multi_import_d.i b/Examples/test-suite/multi_import_d.i index 01e4760f7..bb9cf0137 100644 --- a/Examples/test-suite/multi_import_d.i +++ b/Examples/test-suite/multi_import_d.i @@ -1,3 +1,12 @@ %module multi_import_d %constant int myval = 1234; + +%{ +#include "multi_import.h" +%} + +class WWW { + public: + void nullop() const; +};