diff --git a/CHANGES.current b/CHANGES.current index 848dd25dd..e8f8f9a35 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.5 (in progress) =========================== +2011-06-19: wsfulton + Fix incorrect typemaps being used for a symbol within a templated type, eg: + A::value_type would incorrectly use a typemap for type A. + 2011-06-18: olly [Tcl] Fix variable declarations in middle of blocks which isn't permitted in C90 (issue probably introduced in 2.0.3 by patch #3224663). diff --git a/Examples/test-suite/typemap_template.i b/Examples/test-suite/typemap_template.i index ad35371cc..7ef77c79d 100644 --- a/Examples/test-suite/typemap_template.i +++ b/Examples/test-suite/typemap_template.i @@ -2,8 +2,8 @@ /* Test bug in 1.3.40 where the presence of a generic/unspecialized typemap caused the incorrect specialized typemap to be used */ -%typemap(in) SWIGTYPE "/*_this_will_not_compile_SWIGTYPE_ \"$type\" */ " -%typemap(in) const SWIGTYPE & "/*_this_will_not_compile_const_SWIGTYPE_REF_\"$type\" */ " +%typemap(in) SWIGTYPE "_this_will_not_compile_SWIGTYPE_ \"$type\" " +%typemap(in) const SWIGTYPE & "_this_will_not_compile_const_SWIGTYPE_REF_\"$type\" " %typemap(in) const TemplateTest1 & {$1 = (TemplateTest1 *)0; /* in typemap generic for $type */} %typemap(in) const TemplateTest1< ZZ > & {$1 = (TemplateTest1 *)0; /* in typemap ZZ for $type */} @@ -12,6 +12,7 @@ %inline %{ template struct TemplateTest1 { void setT(const TemplateTest1& t) {} + typedef double Double; }; %} @@ -32,3 +33,8 @@ template struct TemplateTest1 { {} %} +%typemap(in) TemplateTest1 "_this_will_not_compile_TemplateTest_ \"$type\" " + +%inline %{ + void wasbug(TemplateTest1< int >::Double wbug) {} +%} diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index db6144ce6..c5b1a7ce3 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -166,6 +166,7 @@ extern "C" { extern String *SwigType_templateprefix(const SwigType *t); extern String *SwigType_templatesuffix(const SwigType *t); extern String *SwigType_istemplate_templateprefix(const SwigType *t); + extern String *SwigType_istemplate_only_templateprefix(const SwigType *t); extern String *SwigType_templateargs(const SwigType *t); extern String *SwigType_prefix(const SwigType *t); extern int SwigType_array_ndim(const SwigType *t); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index fe6a33641..412db3f93 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -728,8 +728,8 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type goto ret_result; { - /* Look for the type reduced to just the template prefix */ - SwigType *template_prefix = SwigType_istemplate_templateprefix(ctype); + /* Look for the type reduced to just the template prefix - for templated types without the template parameter list being specified */ + SwigType *template_prefix = SwigType_istemplate_only_templateprefix(ctype); if (template_prefix) { tm = get_typemap(ts, template_prefix); result = typemap_search_helper(debug_display, tm, tm_method, template_prefix, cqualifiedname, cname, &backup); diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index dd8d901e0..b8ecf6e6a 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -927,6 +927,32 @@ String *SwigType_istemplate_templateprefix(const SwigType *t) { return c ? NewStringWithSize(s, c - s) : 0; } +/* ----------------------------------------------------------------------------- + * SwigType_istemplate_only_templateprefix() + * + * Similar to SwigType_istemplate_templateprefix() but only returns the template + * prefix if the type is just the template and not a subtype/symbol within the template. + * Returns NULL if not a template or is a template with a symbol within the template. + * For example: + * + * Foo<(p.int)> => Foo + * Foo<(p.int)>::bar => NULL + * r.q(const).Foo<(p.int)> => r.q(const).Foo + * r.q(const).Foo<(p.int)>::bar => NULL + * Foo => NULL + * ----------------------------------------------------------------------------- */ + +String *SwigType_istemplate_only_templateprefix(const SwigType *t) { + int len = Len(t); + const char *s = Char(t); + if (len >= 4 && strcmp(s + len - 2, ")>") == 0) { + const char *c = strstr(s, "<("); + return c ? NewStringWithSize(s, c - s) : 0; + } else { + return 0; + } +} + /* ----------------------------------------------------------------------------- * SwigType_templateargs() *