Fix C++11 type aliasing seg fault.

Closes #424
This commit is contained in:
William S Fulton 2015-06-09 07:49:25 +01:00
parent 678937db24
commit 117f6d0026
5 changed files with 72 additions and 2 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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 <typename T> 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{ "target", Halide::get_host_target() };
};
}
}
%}
%template(Halide_Target) Halide::Internal::GeneratorParam<Halide::Target>;

View File

@ -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");
}
}

View File

@ -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");