From 678937db247e4fceadbdc8f68d2c1220fe6c9067 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Tue, 2 Jun 2015 07:27:03 +0100
Subject: [PATCH 01/15] Appveyor upgrade to cygwin on stable server
Appveyor now has cygwin on their stable OS
---
appveyor.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/appveyor.yml b/appveyor.yml
index e84bf6c88..aa69719d8 100755
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,5 +1,5 @@
os:
-- Unstable
+- Windows Server 2012 R2
platform:
- x86
From 117f6d0026ae0e52286c1e1a3750c682d081b53c Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Tue, 9 Jun 2015 07:49:25 +0100
Subject: [PATCH 02/15] Fix C++11 type aliasing seg fault.
Closes #424
---
CHANGES.current | 3 ++
Examples/test-suite/common.mk | 1 +
Examples/test-suite/cpp11_type_aliasing.i | 46 +++++++++++++++++++
.../java/cpp11_type_aliasing_runme.java | 20 ++++++++
Source/CParse/parser.y | 4 +-
5 files changed, 72 insertions(+), 2 deletions(-)
create mode 100644 Examples/test-suite/cpp11_type_aliasing.i
create mode 100644 Examples/test-suite/java/cpp11_type_aliasing_runme.java
diff --git a/CHANGES.current b/CHANGES.current
index a9847ac6f..542f6c1a5 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress)
===========================
+2015-06-09: wsfulton
+ Fix seg fault processing C++11 type aliasing. Issue #424.
+
2015-05-28: wsfulton
[Python] Add new feature "python:cdefaultargs" to control default argument
code generation. By default, SWIG attempts to convert C/C++ default argument values
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 5fd09566e..4e3b52fe0 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -543,6 +543,7 @@ CPP11_TEST_CASES = \
cpp11_template_explicit \
cpp11_template_typedefs \
cpp11_type_traits \
+ cpp11_type_aliasing \
cpp11_uniform_initialization \
cpp11_unrestricted_unions \
cpp11_userdefined_literals \
diff --git a/Examples/test-suite/cpp11_type_aliasing.i b/Examples/test-suite/cpp11_type_aliasing.i
new file mode 100644
index 000000000..8ddbc3bdc
--- /dev/null
+++ b/Examples/test-suite/cpp11_type_aliasing.i
@@ -0,0 +1,46 @@
+%module cpp11_type_aliasing
+
+// Type aliasing seg fault : Github issue #424
+
+%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Target;
+
+%inline %{
+
+namespace Halide {
+
+struct Target {
+ int bits;
+ Target(int bits=32) : bits(bits) {}
+};
+
+class NamesInterface {
+public:
+ using Target = Halide::Target;
+};
+
+Target get_host_target() {
+ return Target();
+}
+
+namespace Internal {
+
+template class GeneratorParam {
+ T value;
+public:
+ GeneratorParam(const char *name, const T &v) : value(v) {}
+
+ T getValue() {
+ return value;
+ }
+};
+
+class GeneratorBase : public NamesInterface {
+public:
+ GeneratorParam target{ "target", Halide::get_host_target() };
+};
+
+}
+}
+%}
+
+%template(Halide_Target) Halide::Internal::GeneratorParam;
diff --git a/Examples/test-suite/java/cpp11_type_aliasing_runme.java b/Examples/test-suite/java/cpp11_type_aliasing_runme.java
new file mode 100644
index 000000000..0db1df372
--- /dev/null
+++ b/Examples/test-suite/java/cpp11_type_aliasing_runme.java
@@ -0,0 +1,20 @@
+import cpp11_type_aliasing.*;
+
+public class cpp11_type_aliasing_runme {
+
+ static {
+ try {
+ System.loadLibrary("cpp11_type_aliasing");
+ } 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[]) {
+ Halide_Target ht = new GeneratorBase().getTarget();
+ Target x = ht.getValue();
+ if (x.getBits() != 32)
+ throw new RuntimeException("Incorrect bits");
+ }
+}
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 39b859d68..c6b1d5ee4 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -2850,10 +2850,10 @@ c_declaration : c_decl {
Swig_warning(WARN_CPP11_LAMBDA, cparse_file, cparse_line, "Lambda expressions and closures are not fully supported yet.\n");
SWIG_WARN_NODE_END($$);
}
- | USING idcolon EQUAL {
- skip_decl();
+ | USING idcolon EQUAL idcolon {
$$ = new_node("using");
Setattr($$,"name",$2);
+ Setattr($$,"uname",$4);
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");
From efa84dab7cd9caae1175546558c49b8662384f0d Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Tue, 9 Jun 2015 07:54:47 +0100
Subject: [PATCH 03/15] Fix warning display of types associated with 'using'
and templates.
---
.../test-suite/errors/cpp_using_type_aliasing.i | 13 +++++++++++++
.../errors/cpp_using_type_aliasing.stderr | 3 +++
Source/Swig/symbol.c | 8 ++++----
3 files changed, 20 insertions(+), 4 deletions(-)
create mode 100644 Examples/test-suite/errors/cpp_using_type_aliasing.i
create mode 100644 Examples/test-suite/errors/cpp_using_type_aliasing.stderr
diff --git a/Examples/test-suite/errors/cpp_using_type_aliasing.i b/Examples/test-suite/errors/cpp_using_type_aliasing.i
new file mode 100644
index 000000000..df65dbd3d
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_using_type_aliasing.i
@@ -0,0 +1,13 @@
+%module cpp_using_type_aliasing
+
+namespace Space {
+ template struct Okay {
+ };
+ struct User {
+ protected:
+ using OkayInt = Okay;
+ };
+ struct Derived : User {
+ Okay ff();
+ };
+};
diff --git a/Examples/test-suite/errors/cpp_using_type_aliasing.stderr b/Examples/test-suite/errors/cpp_using_type_aliasing.stderr
new file mode 100644
index 000000000..3f256652f
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_using_type_aliasing.stderr
@@ -0,0 +1,3 @@
+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/Source/Swig/symbol.c b/Source/Swig/symbol.c
index 2202f61c6..d72451a14 100644
--- a/Source/Swig/symbol.c
+++ b/Source/Swig/symbol.c
@@ -1149,7 +1149,7 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
Symtab *un = Getattr(s, "sym:symtab");
Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */
if (!ss) {
- Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
+ Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
@@ -1221,7 +1221,7 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
Node *ss;
ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
if (!ss && !checkfunc) {
- Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
+ Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
@@ -1272,7 +1272,7 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
while (s && Checkattr(s, "nodeType", "using")) {
Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
if (!ss) {
- Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
+ Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
@@ -1320,7 +1320,7 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
while (s && Checkattr(s, "nodeType", "using")) {
Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc);
if (!ss && !checkfunc) {
- Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
+ Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
}
s = ss;
}
From 2b9b007027961cf79088af2f38398e8c33dc3c4c Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 11 Jun 2015 07:42:50 +0100
Subject: [PATCH 04/15] C# -outfile cosmetic code fixes
---
Source/Modules/csharp.cxx | 57 +++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 29 deletions(-)
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index ad27a5bea..38afc7357 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -248,16 +248,16 @@ public:
} else if (strcmp(argv[i], "-oldvarnames") == 0) {
Swig_mark_arg(i);
old_variable_names = true;
- } else if (strcmp(argv[i], "-outfile") == 0) {
- if (argv[i + 1]) {
- output_file = NewString("");
- Printf(output_file, argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else {
- Swig_arg_error();
- }
+ } else if (strcmp(argv[i], "-outfile") == 0) {
+ if (argv[i + 1]) {
+ output_file = NewString("");
+ Printf(output_file, argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
} else if (strcmp(argv[i], "-help") == 0) {
Printf(stdout, "%s\n", usage);
}
@@ -465,7 +465,7 @@ public:
Printf(f_im, "}\n");
addCloseNamespace(0, f_im);
- if(f_im != f_single_out)
+ if (f_im != f_single_out)
Delete(f_im);
f_im = NULL;
}
@@ -508,7 +508,7 @@ public:
Printf(f_module, "}\n");
addCloseNamespace(0, f_module);
- if(f_module != f_single_out)
+ if (f_module != f_single_out)
Delete(f_module);
f_module = NULL;
}
@@ -609,7 +609,7 @@ public:
f_directors_h = NULL;
}
- if(f_single_out) {
+ if (f_single_out) {
Dump(f_single_out, f_begin);
Delete(f_single_out);
f_single_out = NULL;
@@ -649,12 +649,12 @@ public:
* /.cs
* ----------------------------------------------------------------------------- */
- File *getOutputFile(const String* dir, String* name) {
- if(output_file) {
- if(!f_single_out) {
+ File *getOutputFile(const String *dir, const String *name) {
+ if (output_file) {
+ if (!f_single_out) {
String *filen = NewStringf("%s%s", SWIG_output_directory(), output_file);
f_single_out = NewFile(filen, "w", SWIG_output_files());
- if(!f_single_out) {
+ if (!f_single_out) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
@@ -668,7 +668,7 @@ public:
} else {
String *filen = NewStringf("%s%s.cs", dir, name);
File *f = NewFile(filen, "w", SWIG_output_files());
- if(!f) {
+ if (!f) {
FileErrorDisplay(f);
SWIG_exit(EXIT_FAILURE);
}
@@ -1132,7 +1132,7 @@ public:
scope = NewString("");
if (nspace)
Printf(scope, "%s", nspace);
- if (Node* cls = getCurrentClass()) {
+ if (Node *cls = getCurrentClass()) {
if (Node *outer = Getattr(cls, "nested:outer")) {
String *outerClassesPrefix = Copy(Getattr(outer, "sym:name"));
for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) {
@@ -1252,7 +1252,7 @@ public:
"\n", enum_code, "\n", NIL);
addCloseNamespace(nspace, f_enum);
- if(f_enum != f_single_out)
+ if (f_enum != f_single_out)
Delete(f_enum);
f_enum = NULL;
Delete(output_directory);
@@ -1954,7 +1954,6 @@ public:
}
}
- // Each outer proxy class goes into a separate file
if (!has_outerclass) {
String *output_directory = outputDirectory(nspace);
f_proxy = getOutputFile(output_directory, proxy_class_name);
@@ -2017,7 +2016,7 @@ public:
if (!has_outerclass) {
Printf(f_proxy, "}\n");
addCloseNamespace(nspace, f_proxy);
- if(f_proxy != f_single_out)
+ if (f_proxy != f_single_out)
Delete(f_proxy);
f_proxy = NULL;
} else {
@@ -3278,7 +3277,7 @@ public:
Printv(f_swigtype, swigtype, NIL);
addCloseNamespace(0, f_swigtype);
- if(f_swigtype != f_single_out)
+ if (f_swigtype != f_single_out)
Delete(f_swigtype);
f_swigtype = NULL;
Delete(swigtype);
@@ -4297,10 +4296,10 @@ extern "C" Language *swig_csharp(void) {
const char *CSHARP::usage = "\
C# Options (available with -csharp)\n\
- -dllimport - Override DllImport attribute name to \n\
- -namespace - Generate wrappers into C# namespace \n\
- -noproxy - Generate the low-level functional interface instead\n\
- of proxy classes\n\
- -oldvarnames - Old intermediary method names for variable wrappers\n\
- -outfile - Write all C# to a single file located in the output directory\n\
+ -dllimport - Override DllImport attribute name to \n\
+ -namespace - Generate wrappers into C# namespace \n\
+ -noproxy - Generate the low-level functional interface instead\n\
+ of proxy classes\n\
+ -oldvarnames - Old intermediary method names for variable wrappers\n\
+ -outfile - Write all C# into a single located in the output directory\n\
\n";
From c1a18992ccc56bb85cb33e0a4e366608929b68de Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 11 Jun 2015 07:43:26 +0100
Subject: [PATCH 05/15] Add in all C# command line options to the docs
---
Doc/Manual/CSharp.html | 66 +++++++++++++++++++++++++++++++-----------
1 file changed, 49 insertions(+), 17 deletions(-)
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
index 28d6d2b2e..0c0d98c0e 100644
--- a/Doc/Manual/CSharp.html
+++ b/Doc/Manual/CSharp.html
@@ -14,7 +14,7 @@
- SWIG 2 Compatibility
Differences to the Java module
- Void pointers
@@ -37,7 +37,7 @@
- Directors implementation
- Director caveats
-
- Multiples modules
+
- Multiple modules
- C# Typemap examples
- Memory management when returning references to member variables
@@ -82,26 +82,58 @@ Monodoc, available from the Mono project, has a very useful section titled using directives in generated code. This breaks backwards compatibility with typemaps, pragmas, etc written for use with SWIG 2 that assume the presence of using System; or using System.Runtime.InteropServices; directives in the intermediate class imports, module imports, or proxy imports. SWIG 3 supports backwards compatibility though the use of the SWIG2_CSHARP macro. If SWIG2_CSHARP is defined, SWIG 3 generates using directives in the intermediate class, module class, and proxy class code similar to those generated by SWIG 2. This can be done without modifying any of the input code by passing the -DSWIG2_CSHARP commandline parameter when executing swig.
-20.1.2 C# Command Line Options
-
-Additional command line options that can be used to control code generation:
+20.1.2 Additional command line options
--outfile <filename>
-This command line will instruct the C# module to write all generated C# code to <filename> (located in the output directory) instead of creating separate files for generated classes.
-Caveats:
-
+The following table lists the additional commandline options available for the C# module. They can also be seen by using:
+
--
-The file extension (.cs) will not be automatically be added and needs to be provided.
-
+
--
-Due to possible compiler limits it is not advisable to use -outfile when generating wrappers for big projects.
-
+
-
+
+
+| C# specific options |
+
+
+
+| -dllimport <dl> |
+Override DllImport attribute name to <dl> |
+
+
+
+| -namespace <nm> |
+Generate wrappers into C# namespace <nm> |
+
+
+
+| -noproxy |
+Generate the low-level functional interface instead of proxy classes |
+
+
+
+| -oldvarnames |
+Old intermediary method names for variable wrappers |
+
+
+
+| -outfile <file> |
+Write all C# into a single <file> located in the output directory
+ |
+
+
+
+
+
+The -outfile option combines all the generated C# code into a single output file instead of creating multiple C# files.
+The default, when this option is not provided, is to generate separate .cs files for the module class,
+intermediary class and each of the generated proxy and type wrapper classes.
+Note that the file extension (.cs) will not be automatically added and needs to be provided.
+Due to possible compiler limits it is not advisable to use -outfile for large projects.
20.2 Differences to the Java module
@@ -1707,7 +1739,7 @@ However, a call from C# to CSharpDefaults.DefaultMethod() will of cours
should pass the call on to CSharpDefaults.DefaultMethod(int)using the C++ default value, as shown above.
-20.7 Multiples modules
+20.7 Multiple modules
From 50b7a0410cc2ff44825b1860b203373725346d79 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 11 Jun 2015 07:47:42 +0100
Subject: [PATCH 06/15] changes file update for -outfile
---
CHANGES.current | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/CHANGES.current b/CHANGES.current
index a9847ac6f..94ed20271 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress)
===========================
+2015-06-11: sghirate
+ [C#] Patch #427 adds in new command line option -outfile to combine all the
+ generated C# code into a single file.
+
2015-05-28: wsfulton
[Python] Add new feature "python:cdefaultargs" to control default argument
code generation. By default, SWIG attempts to convert C/C++ default argument values
From 8bd6e596d1eabca437f78e980c4fc8227f07adcd Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 11 Jun 2015 07:57:37 +0100
Subject: [PATCH 07/15] Cosmetics - remove references to Java in C# module
---
Source/Modules/csharp.cxx | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index 38afc7357..9193cd34b 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -636,7 +636,7 @@ public:
Swig_banner_target_lang(f, "//");
Printf(f, "//------------------------------------------------------------------------------\n\n");
}
-
+
/* -----------------------------------------------------------------------------
* getOutputFile()
*
@@ -3375,7 +3375,7 @@ public:
/* -----------------------------------------------------------------------------
* outputDirectory()
*
- * Return the directory to use for generating Java classes/enums and create the
+ * Return the directory to use for generating C# classes/enums and create the
* subdirectory (does not create if language specific outdir does not exist).
* ----------------------------------------------------------------------------- */
@@ -3515,7 +3515,7 @@ public:
* classDirectorMethod()
*
* Emit a virtual director method to pass a method call on to the
- * underlying Java object.
+ * underlying C# object.
*
* --------------------------------------------------------------- */
@@ -3676,7 +3676,7 @@ public:
if (!ignored_method)
Printf(w->code, "} else {\n");
- /* Go through argument list, convert from native to Java */
+ /* Go through argument list, convert from native to C# */
for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
From 85c02b172d1aeb52bf67cb95906355684c38745e Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 11 Jun 2015 20:13:09 +0100
Subject: [PATCH 08/15] Expand section on code generation philosophy.
We avoid introducing 3rd party dependencies in the generated code
including the STL.
---
Doc/Manual/Introduction.html | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html
index 9cc4277c9..02a41169a 100644
--- a/Doc/Manual/Introduction.html
+++ b/Doc/Manual/Introduction.html
@@ -457,6 +457,12 @@ be used on any platform. Again, this is an important part of staying out
of the programmer's way----the last thing any developer wants to do is
to spend their time debugging the output of a tool that relies on
non-portable or unreliable programming features.
+Dependencies are often a source of incompatibilities and problems and so
+additional third party libraries are not used in the generated code.
+SWIG will also generally avoid generating code that introduces a dependency
+on the C++ Standard Template Library (STL).
+SWIG will generate code that depends on the C libraries though.
+