diff --git a/Examples/test-suite/csharp/special_variable_macros_runme.cs b/Examples/test-suite/csharp/special_variable_macros_runme.cs index 1c0939a1f..bd6fd4b04 100644 --- a/Examples/test-suite/csharp/special_variable_macros_runme.cs +++ b/Examples/test-suite/csharp/special_variable_macros_runme.cs @@ -14,6 +14,8 @@ public class runme { throw new Exception("test failed"); if (special_variable_macros.testJim(name) != "multiname num") throw new Exception("test failed"); + if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123) + throw new Exception("test failed"); NewName newName = NewName.factory("factoryname"); name = newName.getStoredName(); } diff --git a/Examples/test-suite/java/special_variable_macros_runme.java b/Examples/test-suite/java/special_variable_macros_runme.java index dee629666..d7f8070b3 100644 --- a/Examples/test-suite/java/special_variable_macros_runme.java +++ b/Examples/test-suite/java/special_variable_macros_runme.java @@ -24,6 +24,8 @@ public class special_variable_macros_runme { throw new RuntimeException("test failed"); if (!special_variable_macros.testJim(name).equals("multiname num")) throw new RuntimeException("test failed"); + if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123) + throw new RuntimeException("test failed"); NewName newName = NewName.factory("factoryname"); name = newName.getStoredName(); } diff --git a/Examples/test-suite/python/special_variable_macros_runme.py b/Examples/test-suite/python/special_variable_macros_runme.py index a1d3308ed..07e60dfa2 100644 --- a/Examples/test-suite/python/special_variable_macros_runme.py +++ b/Examples/test-suite/python/special_variable_macros_runme.py @@ -11,4 +11,6 @@ if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap": raise "test failed" if special_variable_macros.testJim(name) != "multiname num": raise "test failed" +if special_variable_macros.testJohn(special_variable_macros.PairIntBool(10, False)) != 123: + raise "test failed" diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index 85adf7af1..3f0cd724a 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -110,6 +110,40 @@ const char * testJim(Name *jim, int count) { } %} +////////////////////////////////////////////////////////////////////////////////////// +// Template types with more than one template parameter + +// check $1 and $input get expanded properly when used from $typemap() +%typemap(in) Space::Pair PAIR_INT_BOOL ($1_type temp) +%{ + /*%typemap(in) Name *GENERIC start */ + temp = Space::Pair(123, true); + (void)$input; + $1 = ($1_ltype)temp; + /*%typemap(in) Name *GENERIC end */ +%} + +%typemap(in) Space::Pair john { +// %typemap(in) Name *john start +$typemap(in, Space::Pair PAIR_INT_BOOL) +// %typemap(in) Name *john end +} + +%inline %{ +namespace Space { + template struct Pair { + Pair(T1 f, T2 s) : first(f), second(s) {} + Pair() {} + T1 first; + T2 second; + }; + int testJohn(Space::Pair john) { + return john.first; + } +} +%} +%template(PairIntBool) Space::Pair; + ////////////////////////////////////////////////////////////////////////////////////// // A real use case for $typemap diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 0fae2344e..9fcbb38e0 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1699,9 +1699,10 @@ static List *split_embedded_typemap(String *s) { List *args = 0; char *c, *start; int level = 0; + int angle_level = 0; int leading = 1; - args = NewList(); + args = NewList(); c = strchr(Char(s), '('); assert(c); c++; @@ -1720,7 +1721,7 @@ static List *split_embedded_typemap(String *s) { c++; } } - if ((level == 0) && ((*c == ',') || (*c == ')'))) { + if ((level == 0) && angle_level == 0 && ((*c == ',') || (*c == ')'))) { String *tmp = NewStringWithSize(start, c - start); Append(args, tmp); Delete(tmp); @@ -1735,6 +1736,10 @@ static List *split_embedded_typemap(String *s) { level++; if (*c == ')') level--; + if (*c == '<') + angle_level++; + if (*c == '>') + angle_level--; if (isspace((int) *c) && leading) start++; if (!isspace((int) *c)) @@ -1901,6 +1906,7 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper } Delete(l); } + if (syntax_error) { String *dtypemap = NewString(dollar_typemap); Replaceall(dtypemap, "$TYPEMAP", "$typemap");