diff options
author | Nishant Gupta <nish.gupta01@gmail.com> | 2016-07-30 12:47:53 +0530 |
---|---|---|
committer | Nishant Gupta <nish.gupta01@gmail.com> | 2016-07-30 12:47:53 +0530 |
commit | 6e8ba0be53a84373f04e05b18e96a13d8bfeb2de (patch) | |
tree | c5549e8e3bb3cd927ec3e6840b774830a41b29e4 | |
parent | a1e52520a12e1b53edaa2d79e4f9930172aaada5 (diff) | |
parent | d0a45be1ebfe125d51696b48cb5d359bc7431052 (diff) | |
download | swig-6e8ba0be53a84373f04e05b18e96a13d8bfeb2de.tar.gz |
Merge remote-tracking branch 'upstream/master'
35 files changed, 318 insertions, 96 deletions
diff --git a/CCache/ccache.c b/CCache/ccache.c index e7dd1d30a..c5c510388 100644 --- a/CCache/ccache.c +++ b/CCache/ccache.c @@ -130,6 +130,7 @@ static void failed(void) exit(1); } args_add_prefix(orig_args, p); + free(p); } if (ccache_verbose) { @@ -490,7 +491,9 @@ static void find_hash(ARGS *args) /* also include the hash of the compiler name - as some compilers use hard links and behave differently depending on the real name */ if (st.st_nlink > 1) { - hash_string(str_basename(args->argv[0])); + char *path = str_basename(args->argv[0]); + hash_string(path); + free(path); } hash_int(st.st_size); @@ -523,6 +526,7 @@ static void find_hash(ARGS *args) input_base, tmp_string(), i_extension); x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", temp_dir, tmp_string()); + free(input_base); if (!direct_i_file) { /* run cpp on the input file to obtain the .i */ @@ -781,6 +785,7 @@ static void find_compiler(int argc, char **argv) /* support user override of the compiler */ if ((path=getenv("CCACHE_CC"))) { + free(base); base = x_strdup(path); } @@ -791,8 +796,10 @@ static void find_compiler(int argc, char **argv) stats_update(STATS_COMPILER); cc_log("could not find compiler (%s)\n", base); perror(base); + free(base); exit(1); } + free(base); } @@ -1076,6 +1083,7 @@ static void process_args(int argc, char **argv) if (strlen(p) < 2) { cc_log("badly formed dependency file %s\n", output_file); stats_update(STATS_ARGS); + free(default_depfile_name); failed(); return; } @@ -1093,6 +1101,7 @@ static void process_args(int argc, char **argv) strcat(default_depfile_name, ".d"); args_add(stripped_args, "-MF"); args_add(stripped_args, default_depfile_name); + free(default_depfile_name); } if (!dependency_target_specified) { @@ -1117,6 +1126,7 @@ static void process_args(int argc, char **argv) exit(1); } args_add_prefix(stripped_args, p); + free(p); } } @@ -1305,6 +1315,7 @@ static void setup_uncached_err(void) if (putenv(buf) == -1) { cc_log("putenv failed\n"); + close(uncached_fd); stats_update(STATS_ERROR); failed(); } diff --git a/CCache/execute.c b/CCache/execute.c index 165b91e66..6df025e95 100644 --- a/CCache/execute.c +++ b/CCache/execute.c @@ -267,6 +267,7 @@ char *find_executable(const char *name, const char *exclude_name) } free(fname); } + free(path); return NULL; #endif diff --git a/CCache/stats.c b/CCache/stats.c index d2122bcd3..4d01d2afa 100644 --- a/CCache/stats.c +++ b/CCache/stats.c @@ -138,7 +138,10 @@ static void stats_update_size(enum stats stat, size_t size, size_t numfiles) memset(counters, 0, sizeof(counters)); - if (lock_fd(fd) != 0) return; + if (lock_fd(fd) != 0) { + close(fd); + return; + } /* read in the old stats */ stats_read_fd(fd, counters); diff --git a/CCache/unify.c b/CCache/unify.c index a93d48a02..7a36476a1 100644 --- a/CCache/unify.c +++ b/CCache/unify.c @@ -281,6 +281,7 @@ int unify_hash(const char *fname) fd = open(fname, O_RDONLY|O_BINARY); if (fd == -1 || fstat(fd, &st) != 0) { cc_log("Failed to open preprocessor output %s\n", fname); + if (fd != -1) close(fd); stats_update(STATS_PREPROCESSOR); return -1; } @@ -289,12 +290,12 @@ int unify_hash(const char *fname) lines in preprocessor output. I have seen lines of over 100k in length, so this is well worth it */ map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (map == (char *)-1) { cc_log("Failed to mmap %s\n", fname); stats_update(STATS_PREPROCESSOR); return -1; } - close(fd); /* pass it through the unifier */ unify((unsigned char *)map, st.st_size); diff --git a/CCache/util.c b/CCache/util.c index 66f9823b9..ef90e2336 100644 --- a/CCache/util.c +++ b/CCache/util.c @@ -189,9 +189,11 @@ void copy_fd(int fd_in, int fd_out) { while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) { if (write(fd_out, buf, n) != n) { + gzclose(gz_in); fatal("Failed to copy fd"); } } + gzclose(gz_in); } static int _copy_file(const char *src, const char *dest, int mode) { @@ -248,9 +250,11 @@ static int _copy_file(const char *src, const char *dest, int mode) { } if (mode == COPY_TO_CACHE) { - gz_out = gzdopen(dup(fd_out), "wb"); + int dup_fd_out = dup(fd_out); + gz_out = gzdopen(dup_fd_out, "wb"); if (!gz_out) { gzclose(gz_in); + close(dup_fd_out); close(fd_out); free(tmp_name); return -1; @@ -459,6 +463,7 @@ int create_cachedirtag(const char *dir) f = fopen(filename, "w"); if (!f) goto error; if (fwrite(CACHEDIR_TAG, sizeof(CACHEDIR_TAG)-1, 1, f) != 1) { + fclose(f); goto error; } if (fclose(f)) goto error; @@ -485,7 +490,7 @@ void x_asprintf(char **ptr, const char *format, ...) } va_end(ap); - if (!ptr) fatal("out of memory in x_asprintf"); + if (!*ptr) fatal("out of memory in x_asprintf"); } /* diff --git a/CHANGES.current b/CHANGES.current index 312343f56..075c00ef6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,3 +4,26 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.11 (in progress) ============================ + +2016-06-26: wkalinin + [Java, C#] Patch #681 Fix seg fault when ignoring nested classes. + +2016-06-25: mromberg + [Python] #711 Fix -castmode and conversion of signed and unsigned integer types. + See 2015-12-23 CHANGES entry for details of these improvements when they were + implemented for the default options (ie not using -castmode). + +2016-06-25: ahnolds + Patch #730 - Fix %implicitconv for overloaded functions when using + -castmode or -fastdispatch options. + + The result is that in all overload cases where there are multiple possibilities + with the same number of arguments, the dispatch function will first check for + exact (aka non implicit) matches, and then subsequently check for implicit + casting matches. This was already happening in the normal dispatch situation, + and in the -fastdispatch case two passes through the candidates were happening, + just with SWIG_POINTER_IMPLICIT_CONV always set. After this patch, it is not set + on the first pass, and then set on the second pass. + +2016-06-25: liorgold + Patch #727 - Add support for C++11 type aliasing. diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 714845bba..c825d8426 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -29,7 +29,7 @@ <li><a href="#CPlusPlus11_strongly_typed_enumerations">Strongly typed enumerations</a> <li><a href="#CPlusPlus11_double_angle_brackets">Double angle brackets</a> <li><a href="#CPlusPlus11_explicit_conversion_operators">Explicit conversion operators</a> -<li><a href="#CPlusPlus11_alias_templates">Alias templates</a> +<li><a href="#CPlusPlus11_alias_templates">Type alias and alias templates</a> <li><a href="#CPlusPlus11_unrestricted_unions">Unrestricted unions</a> <li><a href="#CPlusPlus11_variadic_templates">Variadic templates</a> <li><a href="#CPlusPlus11_new_string_literals">New string literals</a> @@ -52,7 +52,7 @@ <li><a href="#CPlusPlus11_general_purpose_smart_pointers">General-purpose smart pointers</a> <li><a href="#CPlusPlus11_extensible_random_number_facility">Extensible random number facility</a> <li><a href="#CPlusPlus11_wrapper_reference">Wrapper reference</a> -<li><a href="#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphous wrappers for function objects</a> +<li><a href="#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphic wrappers for function objects</a> <li><a href="#CPlusPlus11_type_traits_for_metaprogramming">Type traits for metaprogramming</a> <li><a href="#CPlusPlus11_uniform_method_for_computing_return_type_of_function_objects">Uniform method for computing return type of function objects</a> </ul> @@ -603,10 +603,30 @@ Conversion operators either with or without <tt>explicit</tt> need renaming to a them available as a normal proxy method. </p> -<H3><a name="CPlusPlus11_alias_templates">7.2.16 Alias templates</a></H3> +<H3><a name="CPlusPlus11_alias_templates">7.2.16 Type alias and alias templates</a></H3> <p> +A type alias is a statement of the form: +</p> + +<div class="code"><pre> +using PFD = void (*)(double); // New introduced syntax +</pre></div> + +<p> +which is equivalent to the old style typedef: +</p> + +<div class="code"><pre> +typedef void (*PFD)(double); // The old style +</pre></div> + +<p> +SWIG supports type aliasing. +</p> + +<p> The following is an example of an alias template: <div class="code"><pre> @@ -632,31 +652,6 @@ example.i:13: Warning 342: The 'using' keyword in template aliasing is not fully </pre> </div> -<p> -Similarly for non-template type aliasing: -</p> - -<div class="code"><pre> -using PFD = void (*)(double); // New introduced syntax -</pre></div> - -<p> -A warning will be issued: -</p> - -<div class="shell"> -<pre> -example.i:17: Warning 341: The 'using' keyword in type aliasing is not fully supported yet. -</pre> -</div> - - -<p>The equivalent old style typedefs can be used as a workaround:</p> - -<div class="code"><pre> -typedef void (*PFD)(double); // The old style -</pre></div> - <H3><a name="CPlusPlus11_unrestricted_unions">7.2.17 Unrestricted unions</a></H3> @@ -1034,7 +1029,7 @@ Users would need to write their own typemaps if wrapper references are being use </p> -<H3><a name="CPlusPlus11_polymorphous_wrappers_for_function_objects">7.3.8 Polymorphous wrappers for function objects</a></H3> +<H3><a name="CPlusPlus11_polymorphous_wrappers_for_function_objects">7.3.8 Polymorphic wrappers for function objects</a></H3> <p> diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 7107384c8..0b456fca7 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -287,7 +287,7 @@ <li><a href="CPlusPlus11.html#CPlusPlus11_strongly_typed_enumerations">Strongly typed enumerations</a> <li><a href="CPlusPlus11.html#CPlusPlus11_double_angle_brackets">Double angle brackets</a> <li><a href="CPlusPlus11.html#CPlusPlus11_explicit_conversion_operators">Explicit conversion operators</a> -<li><a href="CPlusPlus11.html#CPlusPlus11_alias_templates">Alias templates</a> +<li><a href="CPlusPlus11.html#CPlusPlus11_alias_templates">Type alias and alias templates</a> <li><a href="CPlusPlus11.html#CPlusPlus11_unrestricted_unions">Unrestricted unions</a> <li><a href="CPlusPlus11.html#CPlusPlus11_variadic_templates">Variadic templates</a> <li><a href="CPlusPlus11.html#CPlusPlus11_new_string_literals">New string literals</a> diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index d3c592674..20ffb1a91 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -3359,20 +3359,20 @@ There is more than one macro in order to provide a choice for choosing the Java </tr> <tr> <td><tt>%interface(CTYPE)</tt></td> - <td>Proxy class name is unchanged, interface name has <tt>SwigInterface</tt> added as a suffix for C++ class <tt>CTYPE</tt>.</td> + <td>For C++ class <tt>CTYPE</tt>, proxy class name is unchanged without any suffix added, interface name has <tt>SwigInterface</tt> added as a suffix.</td> </tr> <tr> <td><tt>%interface_impl(CTYPE)</tt></td> - <td>Proxy class name has <tt>SwigImpl</tt> as a suffix, interface name has <tt>SwigInterface</tt> added as a suffix for C++ class <tt>CTYPE</tt>.</td> + <td>For C++ class <tt>CTYPE</tt>, proxy class name has <tt>SwigImpl</tt> added as a suffix, interface name has no added suffix.</td> </tr> <tr> <td><tt>%interface_custom("PROXY", "INTERFACE", CTYPE)</tt></td> - <td>Proxy class name is given by the string <tt>PROXY</tt>, interface name is given by the string <tt>INTERFACE</tt> for C++ class <tt>CTYPE</tt>. The <tt>PROXY</tt> and <tt>INTERFACE</tt> names can use the <a href="SWIG.html#SWIG_advanced_renaming">string formatting functions</a> used in <tt>%rename</tt>.</td> + <td>For C++ class <tt>CTYPE</tt>, proxy class name is given by the string <tt>PROXY</tt>, interface name is given by the string <tt>INTERFACE</tt>. The <tt>PROXY</tt> and <tt>INTERFACE</tt> names can use the <a href="SWIG.html#SWIG_advanced_renaming">string formatting functions</a> used in <tt>%rename</tt>.</td> </tr> </table> <p> -The table below has a few examples showing the resulting proxy and interface names. +The table below has a few examples showing the resulting proxy and interface names for a C++ class called <tt>Base</tt>. </p> <table BORDER summary="Java interface macro examples"> diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index a6747a080..1658e509b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -308,6 +308,7 @@ CPP_TEST_CASES += \ nested_class \ nested_directors \ nested_comment \ + nested_ignore \ nested_scope \ nested_template_base \ nested_workaround \ diff --git a/Examples/test-suite/cpp11_type_aliasing.i b/Examples/test-suite/cpp11_type_aliasing.i index 87443633a..2f6ea3aa7 100644 --- a/Examples/test-suite/cpp11_type_aliasing.i +++ b/Examples/test-suite/cpp11_type_aliasing.i @@ -2,15 +2,6 @@ // Type aliasing seg fault : Github issue #424 -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Target; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Int; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRef; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntPtrRef; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRValueRef; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntArray; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr1; -%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr2; - %inline %{ namespace Halide { @@ -53,14 +44,69 @@ public: %inline %{ -using Int = int; -using IntRef = int&; -using IntPtrRef = int*&; -using IntRValueRef = int&&; -using IntArray = int[]; - using HalideTargetPtr1 = Halide::Target*; namespace Halide { using HalideTargetPtr2 = Target*; } %} + +// Define some types + +%inline %{ +using Int = int; +using IntPtr = Int*; +using IntRef = Int&; +using IntPtrRef = Int*&; +using IntRValueRef = Int&&; +using IntArray = Int[]; +%} + +// Test that SWIG understands these new types + +%callback("%s_cb"); +Int mult2(Int x); +%nocallback; + +%inline %{ +Int mult2(Int x) { return x * 2; } +IntPtr allocate_int() { return new Int(12); } +void free_int(int* ptr) { delete ptr; } +void inplace_mult2(IntRef x) { x *= 2; } +Int read_int(IntPtr ptr) { return *ptr; } + +template <typename T> class Pair { +public: + using data_t = T; + + data_t a, b; + + Pair() : a(), b() { } + Pair(data_t a, data_t b) : a(a), b(b) { } + data_t first() { return a; } + data_t second() { return b; } +}; +%} + +%template(int_pair) Pair<Int>; + +%inline %{ +using PairInt = Pair<Int>; + +class PairSubclass : public PairInt { +public: + PairSubclass(data_t a, data_t b) : PairInt(a, b) { } + + using const_ref_data_t = const data_t&; +}; + +PairSubclass::data_t plus1(PairSubclass::const_ref_data_t x) { return x + 1; } +%} + +// Test function pointers + +%inline %{ +using callback_t = int(*)(int); + +callback_t get_callback() { return mult2; } +int call(callback_t func, int param) { return func(param); } +%} diff --git a/Examples/test-suite/errors/cpp_using_type_aliasing.stderr b/Examples/test-suite/errors/cpp_using_type_aliasing.stderr index 3f256652f..e69de29bb 100644 --- a/Examples/test-suite/errors/cpp_using_type_aliasing.stderr +++ b/Examples/test-suite/errors/cpp_using_type_aliasing.stderr @@ -1,3 +0,0 @@ -cpp_using_type_aliasing.i:8: Warning 341: The 'using' keyword in type aliasing is not fully supported yet. -cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'. -cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'. diff --git a/Examples/test-suite/li_boost_shared_ptr_template.i b/Examples/test-suite/li_boost_shared_ptr_template.i index e3b735c24..3965a976e 100644 --- a/Examples/test-suite/li_boost_shared_ptr_template.i +++ b/Examples/test-suite/li_boost_shared_ptr_template.i @@ -67,7 +67,7 @@ INTEGER bar_getter(Base<INTEGER>& foo) { // 2nd test - templates with default template parameters #if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) -%shared_ptr(Space::BaseDefault<short>) +%shared_ptr(Space::BaseDefault<short, int>) %shared_ptr(Space::DerivedDefault<short>) %shared_ptr(Space::DerivedDefault2<short>) diff --git a/Examples/test-suite/nested_ignore.i b/Examples/test-suite/nested_ignore.i new file mode 100644 index 000000000..e271eca7d --- /dev/null +++ b/Examples/test-suite/nested_ignore.i @@ -0,0 +1,24 @@ +%module nested_ignore +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) B::C::D; + +%rename($ignore) B::C; + +%inline %{ +namespace B { + class C { + public: + struct D { + }; + }; + + class E { + public: + typedef C::D D; + }; + + struct F + { + const E::D foo(){ return E::D(); } + }; +} +%} diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index ce0aae0eb..af04c8c0e 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -15,11 +15,19 @@ def check(got, expected, expected_builtin=None, skip=False): def is_new_style_class(cls): return hasattr(cls, "__class__") +def is_fastproxy(module): + return "new_instancemethod" in module + if not is_new_style_class(A): # Missing static methods make this hard to test... skip if -classic is # used! sys.exit(0) +if is_fastproxy(dir()): + # Detect when -fastproxy is specified and skip test as it changes the function names making it + # hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved + sys.exit(0) + # skip builtin check - the autodoc is missing, but it probably should not be skip = True diff --git a/Examples/test-suite/python/cpp11_type_aliasing_runme.py b/Examples/test-suite/python/cpp11_type_aliasing_runme.py new file mode 100644 index 000000000..52cc81d1c --- /dev/null +++ b/Examples/test-suite/python/cpp11_type_aliasing_runme.py @@ -0,0 +1,32 @@ +from cpp11_type_aliasing import * + +if get_host_target().bits != 32: + raise RuntimeError("get_host_target().bits should return 32") + +if mult2(10) != 20: + raise RuntimeError("mult2(10) should return 20") + +int_ptr = allocate_int() +inplace_mult2(int_ptr) +if read_int(int_ptr) != 24: + raise RuntimeError("read_int should return 24") +free_int(int_ptr) + +pair = PairSubclass(3, 4) +if pair.first() != 3: + raise RuntimeError("pair.first() should return 3") + +if pair.second() != 4: + raise RuntimeError("pair.second() should return 4") + +if pair.a != 3: + raise RuntimeError("pair.a should be 3") + +if plus1(5) != 6: + raise RuntimeError("plus1(5) should return 6") + +if call(mult2_cb, 7) != 14: + raise RuntimeError("call(mult2_cb, 7) should return 14") + +if call(get_callback(), 7) != 14: + raise RuntimeError("call(get_callback(), 7) should return 14") diff --git a/Examples/test-suite/python/cpp_static_runme.py b/Examples/test-suite/python/cpp_static_runme.py index b742de285..1c7705f3e 100644 --- a/Examples/test-suite/python/cpp_static_runme.py +++ b/Examples/test-suite/python/cpp_static_runme.py @@ -14,4 +14,5 @@ else: StaticFunctionTest().static_func_2(1) StaticFunctionTest().static_func_3(1, 2) StaticMemberTest.static_int = 10 -assert StaticMemberTest.static_int == 10 +if not StaticMemberTest.static_int == 10: + raise RuntimeError("static_int not 10") diff --git a/Examples/test-suite/python/exception_classname_runme.py b/Examples/test-suite/python/exception_classname_runme.py index c78f4e68b..9a82c9105 100644 --- a/Examples/test-suite/python/exception_classname_runme.py +++ b/Examples/test-suite/python/exception_classname_runme.py @@ -1,4 +1,5 @@ import exception_classname a = exception_classname.Exception() -assert a.testfunc() == 42 +if a.testfunc() != 42: + raise RuntimeError("Not 42!") diff --git a/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py index 6b56ec479..eab7e282a 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_template_runme.py @@ -8,9 +8,8 @@ if d.bar() != 2: raise RuntimeError if bar_getter(b) != 1: raise RuntimeError -# Fix reverted in rev 12953 -# if bar_getter(d) != 2: -# raise RuntimeError +if bar_getter(d) != 2: + raise RuntimeError b = BaseDefaultInt() d = DerivedDefaultInt() @@ -23,8 +22,11 @@ if d2.bar2() != 4: raise RuntimeError if bar2_getter(b) != 3: raise RuntimeError -# Fix reverted in rev 12953 -# if bar2_getter(d) != 4: -# raise RuntimeError -# if bar2_getter(d2) != 4: -# raise RuntimeError +# SWIG fix reverted in Subversion rev 12953 +# Testcase has now been modified to mask the problem by providing the default parameter 'int' in: +# %shared_ptr(Space::BaseDefault<short, int>) +# If this is not done then d fails to convert to BaseDefault<short>& +if bar2_getter(d) != 4: + raise RuntimeError +if bar2_getter(d2) != 4: + raise RuntimeError diff --git a/Examples/test-suite/python/operbool_runme.py b/Examples/test-suite/python/operbool_runme.py index 708dea786..cdef85abc 100644 --- a/Examples/test-suite/python/operbool_runme.py +++ b/Examples/test-suite/python/operbool_runme.py @@ -1,3 +1,4 @@ #!/usr/bin/env python import operbool -assert not operbool.Test() +if operbool.Test(): + raise RuntimeError("operbool failed") diff --git a/Examples/test-suite/python/python_destructor_exception_runme.py b/Examples/test-suite/python/python_destructor_exception_runme.py index 671eff3cc..ee71ab33b 100644 --- a/Examples/test-suite/python/python_destructor_exception_runme.py +++ b/Examples/test-suite/python/python_destructor_exception_runme.py @@ -26,8 +26,10 @@ def test1(): sys.stderr.flush() sys.stderr = stderr_saved - assert attributeErrorOccurred - assert buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1 + if not attributeErrorOccurred: + raise RuntimeError("attributeErrorOccurred failed") + if not buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1: + raise RuntimeError("ClassWithThrowingDestructor dtor doing bad things failed") class VectorHolder(object): def __init__(self, v): diff --git a/Examples/test-suite/python/unicode_strings_runme.py b/Examples/test-suite/python/unicode_strings_runme.py index 3ce98bcdb..fa9c51437 100644 --- a/Examples/test-suite/python/unicode_strings_runme.py +++ b/Examples/test-suite/python/unicode_strings_runme.py @@ -13,11 +13,15 @@ if sys.version_info[0:2] >= (3, 1): if unicode_strings.non_utf8_std_string() != test_string: raise ValueError('Test comparison mismatch') +def check(s1, s2): + if s1 != s2: + raise RuntimeError("{} != {}".format(s1, s2)) + # Testing SWIG_PYTHON_2_UNICODE flag which allows unicode strings to be passed to C if sys.version_info[0:2] < (3, 0): - assert unicode_strings.charstring("hello1") == "hello1" - assert unicode_strings.charstring(str(u"hello2")) == "hello2" - assert unicode_strings.charstring(u"hello3") == "hello3" - assert unicode_strings.charstring(unicode("hello4")) == "hello4" + check(unicode_strings.charstring("hello1"), "hello1") + check(unicode_strings.charstring(str(u"hello2")), "hello2") + check(unicode_strings.charstring(u"hello3"), "hello3") + check(unicode_strings.charstring(unicode("hello4")), "hello4") unicode_strings.charstring(u"hell\xb05") unicode_strings.charstring(u"hell\u00f66") diff --git a/Examples/test-suite/scilab/Makefile.in b/Examples/test-suite/scilab/Makefile.in index 9ddd8f1aa..483ed2439 100644 --- a/Examples/test-suite/scilab/Makefile.in +++ b/Examples/test-suite/scilab/Makefile.in @@ -13,7 +13,6 @@ top_builddir = ../@top_builddir@ C_TEST_CASES += \ scilab_consts \ - scilab_enums \ scilab_identifier_name \ CPP_TEST_CASES += \ @@ -21,6 +20,7 @@ CPP_TEST_CASES += \ primitive_types \ scilab_li_matrix \ scilab_multivalue \ + scilab_enums \ scilab_pointer_conversion_functions \ CPP_STD_TEST_CASES += \ diff --git a/Examples/test-suite/scilab/scilab_enums_runme.sci b/Examples/test-suite/scilab/scilab_enums_runme.sci index 3e9fb7ae0..2776bee1e 100644 --- a/Examples/test-suite/scilab/scilab_enums_runme.sci +++ b/Examples/test-suite/scilab/scilab_enums_runme.sci @@ -24,4 +24,13 @@ checkEnum(TYPEDEF_ENUM_1_2, 22); checkEnum(TYPEDEF_ENUM_2_1, 31); checkEnum(TYPEDEF_ENUM_2_2, 32); +checkEnum(ENUM_REF_1, 1); +checkEnum(ENUM_REF_2, 10); + +checkEnum(clsEnum_CLS_ENUM_1, 100); +checkEnum(clsEnum_CLS_ENUM_2, 101); + +checkEnum(clsEnum_CLS_ENUM_REF_1, 101); +checkEnum(clsEnum_CLS_ENUM_REF_2, 110); + exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab_enums.i b/Examples/test-suite/scilab_enums.i index 32d5a34de..9c2e393e0 100644 --- a/Examples/test-suite/scilab_enums.i +++ b/Examples/test-suite/scilab_enums.i @@ -35,4 +35,21 @@ typedef enum TYPEDEF_ENUM_2 { TYPEDEF_ENUM_2_2 = 32 } TYPEDEF_ENUM_2; +enum ENUM_REF { + ENUM_REF_1 = 1, + ENUM_REF_2 = ENUM_REF_1 + 9 +}; + +class clsEnum { +public: + enum CLS_ENUM { + CLS_ENUM_1 = 100, + CLS_ENUM_2 = 101 + }; + enum CLS_ENUM_REF { + CLS_ENUM_REF_1 = 101, + CLS_ENUM_REF_2 = CLS_ENUM_REF_1 + 9 + }; +}; + %} diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index fb5bbf6df..575b6db88 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -223,6 +223,8 @@ SWIG_AsVal_dec(long long)(PyObject *obj, long long *val) const double mant_min = -mant_max; double d; res = SWIG_AsVal(double)(obj,&d); + if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, mant_min, mant_max)) + return SWIG_OverflowError; if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, mant_min, mant_max)) { if (val) *val = (long long)(d); return SWIG_AddCast(res); @@ -280,6 +282,8 @@ SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val) const double mant_max = 1LL << DBL_MANT_DIG; double d; res = SWIG_AsVal(double)(obj,&d); + if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max)) + return SWIG_OverflowError; if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) { if (val) *val = (unsigned long long)(d); return SWIG_AddCast(res); diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 51cd5b553..784187c28 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2899,16 +2899,15 @@ c_declaration : c_decl { SWIG_WARN_NODE_END($$); } | USING idcolon EQUAL type plain_declarator SEMI { - $$ = new_node("using"); - Setattr($$,"name",$2); + /* Convert using statement to a typedef statement */ + $$ = new_node("cdecl"); SwigType_push($4,$5.type); - Setattr($$,"uname",$4); + Setattr($$,"type",$4); + Setattr($$,"storage","typedef"); + Setattr($$,"name",$2); + Setattr($$,"decl",""); + SetFlag($$,"typealias"); add_symbols($$); - SWIG_WARN_NODE_BEGIN($$); - Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line, "The 'using' keyword in type aliasing is not fully supported yet.\n"); - SWIG_WARN_NODE_END($$); - - $$ = 0; /* TODO - ignored for now */ } | TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL type plain_declarator SEMI { $$ = new_node("using"); diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 12a502586..01fd5435b 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -188,8 +188,12 @@ public: String *symname = Copy(Getattr(n, "sym:name")); if (symname && !GetFlag(n, "feature:flatnested")) { for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { - Push(symname, "."); - Push(symname, Getattr(outer_class, "sym:name")); + if (String* name = Getattr(outer_class, "sym:name")) { + Push(symname, "."); + Push(symname, name); + } + else + return NULL; } } if (nspace) { diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 6013fa15b..7fa9b2670 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -4176,7 +4176,6 @@ private: Wrapper *dummy = NewWrapper(); emit_attach_parmmaps(parms, dummy); - DelWrapper(dummy); Swig_typemap_attach_parms("gotype", parms, NULL); Swig_typemap_attach_parms("imtype", parms, NULL); @@ -4233,6 +4232,8 @@ private: Swig_typemap_attach_parms("goin", parms, dummy); Swig_typemap_attach_parms("goargout", parms, dummy); + DelWrapper(dummy); + if (!is_ignored) { // We use an interface to see if this method is defined in Go. Printv(f_go_wrappers, "type ", interface_name, " interface {\n", NULL); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index b7a5ebbfe..eb809ff59 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -210,10 +210,14 @@ public: String *nspace = Getattr(n, "sym:nspace"); String *symname = Copy(Getattr(n, "sym:name")); if (symname && !GetFlag(n, "feature:flatnested")) { - for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { - Push(symname, jnidescriptor ? "$" : "."); - Push(symname, Getattr(outer_class, "sym:name")); - } + for (Node *outer_class = Getattr(n, "nested:outer"); outer_class; outer_class = Getattr(outer_class, "nested:outer")) { + if (String* name = Getattr(outer_class, "sym:name")) { + Push(symname, jnidescriptor ? "$" : "."); + Push(symname, name); + } + else + return NULL; + } } if (nspace) { if (package && !jnidescriptor) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 1b4c8f617..80ea47f3f 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -856,6 +856,9 @@ public: //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); if (!luaAddSymbol(lua_name, n)) { + DelWrapper(f); + Delete(dispatch); + Delete(tmp); return SWIG_ERROR; } diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index dd3ca4972..330294efd 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -433,6 +433,7 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int * int fn = 0; Node *ni = Getitem(dispatch, i); Parm *pi = Getattr(ni, "wrap:parms"); + bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0; int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); if (num_arguments > *maxargs) @@ -476,6 +477,7 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int * String *tm = Getattr(pj, "tmap:typecheck"); if (tm) { + tm = Copy(tm); /* normalise for comparison later */ Replaceid(tm, Getattr(pj, "lname"), "_v"); @@ -528,13 +530,14 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int * String *tmp = NewStringf(argv_template_string, j); String *conv = Getattr(pj, "implicitconv"); - if (conv) { + if (conv && !implicitconvtypecheckoff) { Replaceall(tm, "$implicitconv", conv); } else { Replaceall(tm, "$implicitconv", "0"); } Replaceall(tm, "$input", tmp); Printv(f, "{\n", tm, "}\n", NIL); + Delete(tm); fn = i + 1; Printf(f, "if (!_v) goto check_%d;\n", fn); Printf(f, "_ranki += _v*_pi;\n"); @@ -574,6 +577,9 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int * if (fn) Printf(f, "check_%d:\n\n", fn); + if (implicitconvtypecheckoff) + Delattr(ni, "implicitconvtypecheckoff"); + Delete(lfmt); Delete(coll); } @@ -607,6 +613,7 @@ String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int * int fn = 0; Node *ni = Getitem(dispatch, i); Parm *pi = Getattr(ni, "wrap:parms"); + bool implicitconvtypecheckoff = GetFlag(ni, "implicitconvtypecheckoff") != 0; int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); if (num_arguments > *maxargs) @@ -646,6 +653,7 @@ String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int * String *tm = Getattr(pj, "tmap:typecheck"); if (tm) { + tm = Copy(tm); /* normalise for comparison later */ Replaceid(tm, Getattr(pj, "lname"), "_v"); @@ -699,13 +707,14 @@ String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int * String *tmp = NewStringf(argv_template_string, j); String *conv = Getattr(pj, "implicitconv"); - if (conv) { + if (conv && !implicitconvtypecheckoff) { Replaceall(tm, "$implicitconv", conv); } else { Replaceall(tm, "$implicitconv", "0"); } Replaceall(tm, "$input", tmp); Printv(f, "{\n", tm, "}\n", NIL); + Delete(tm); fn = i + 1; Printf(f, "if (!_v) goto check_%d;\n", fn); } @@ -737,6 +746,9 @@ String *Swig_overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int * if (fn) Printf(f, "check_%d:\n\n", fn); + if (implicitconvtypecheckoff) + Delattr(ni, "implicitconvtypecheckoff"); + Delete(lfmt); Delete(coll); } diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 42df12f7c..c44c92d6c 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -326,6 +326,7 @@ public: bool isLastOverloaded = isOverloaded && !Getattr(node, "sym:nextSibling"); if (!isOverloaded && !addSymbol(functionName, node)) { + DelWrapper(wrapper); return SWIG_ERROR; } @@ -633,7 +634,10 @@ public: /* Add function to builder table */ addFunctionToScilab(scilabSetFunctionName, setFunctionName); + + DelWrapper(setFunctionWrapper); } + DelWrapper(getFunctionWrapper); return SWIG_OK; } @@ -660,7 +664,7 @@ public: if (isConstant || isEnum) { if (isEnum) { Setattr(node, "type", "double"); - constantValue = Getattr(node, "enumvalue"); + constantValue = Getattr(node, "value"); } constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0); @@ -1026,7 +1030,7 @@ public: Printf(gatewayHeaderV5, ",\n"); Printf(gatewayHeaderV5, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}", wrapperFunctionName, scilabFunctionName); - Printf(gatewayHeaderV6, "if (wcscmp(pwstFuncName, L\"%s\") == 0) { addCFunction((wchar_t *)L\"%s\", &%s, (wchar_t *)MODULE_NAME); }\n", scilabFunctionName, scilabFunctionName, wrapperFunctionName); + Printf(gatewayHeaderV6, "if (wcscmp(pwstFuncName, L\"%s\") == 0) { addCStackFunction((wchar_t *)L\"%s\", &%s, (wchar_t *)MODULE_NAME); }\n", scilabFunctionName, scilabFunctionName, wrapperFunctionName); } /* ----------------------------------------------------------------------- diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 847f5b4f9..dc4d02bdd 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -265,7 +265,13 @@ class TypePass:private Dispatcher { SwigType *bsmart = Copy(smart); SwigType *rclsname = SwigType_typedef_resolve_all(clsname); SwigType *rbname = SwigType_typedef_resolve_all(bname); - Replaceall(bsmart, rclsname, rbname); + int replace_count = Replaceall(bsmart, rclsname, rbname); + if (replace_count == 0) { + // If no replacement made, it will be because rclsname is fully resolved, but the + // type in the smartptr feature used a typedef or not fully resolved name. + String *firstname = Getattr(first, "name"); + Replaceall(bsmart, firstname, rbname); + } Delete(rclsname); Delete(rbname); String *smartnamestr = SwigType_namestr(smart); diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 08226a25c..94df338f0 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -291,6 +291,7 @@ int Swig_insert_file(const_String_or_char_ptr filename, File *outfile) { while ((nbytes = Read(f, buffer, 4096)) > 0) { Write(outfile, buffer, nbytes); } + fclose(f); return 0; } |