diff --git a/CHANGES.current b/CHANGES.current index 398022036..b1070d3c7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,16 @@ Version 1.3.41 (in progress) ============================ +2010-01-28: wsfulton + Fix typemap matching bug when a templated type has a typemap both specialized and not + specialized. For example: + + template struct XX { ... }; + %typemap(in) const XX & "..." + %typemap(in) const XX< int > & "..." + + resulted in the 2nd typemap being applied for all T in XX< T >. + 2010-01-22: wsfulton Fix #2933129 - typemaps not being found when the unary scope operator (::) is used to denote global scope, the typemap is now used in situations like this: diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 7fe932828..d2db34432 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -1025,6 +1025,11 @@ checks are made:
  • Typemaps that match the stripped TYPE only. +

    +If TYPE is a C++ template, the matching rules above are repeated with the template parameterization removed. +For example if TYPE is X< double > , then repeat with the type simply as X. +

    +

    If TYPE is an array. The following transformation is made:

    diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 9830d6e7f..0dfe73939 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -386,6 +386,7 @@ CPP_TEST_CASES += \ typemap_namespace \ typemap_ns_using \ typemap_numinputs \ + typemap_template \ typemap_out_optimal \ typemap_variables \ typemap_various \ diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 42ee042d4..b9d53d5d1 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -78,16 +78,7 @@ static Hash *get_typemap(int tm_scope, const SwigType *type) { hashtype = SwigType_remove_global_scope_prefix(type); tm = Getattr(typemaps[tm_scope], hashtype); - if (dtype) { - if (!tm) { - String *t_name = SwigType_templateprefix(hashtype); - if (!Equal(t_name, hashtype)) { - tm = Getattr(typemaps[tm_scope], t_name); - } - Delete(t_name); - } - Delete(dtype); - } + Delete(dtype); Delete(hashtype); return tm; @@ -105,7 +96,7 @@ static void set_typemap(int tm_scope, const SwigType *type, Hash *tm) { hashtype = SwigType_remove_global_scope_prefix(type); } - /* note that the unary scope operator (::) prefix indicating global scope has been removed for storing in the hashmap */ + /* note that the unary scope operator (::) prefix indicating global scope has been removed from the type */ Setattr(typemaps[tm_scope], hashtype, tm); Delete(hashtype); @@ -653,6 +644,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type SwigType *noarrays = 0; SwigType *primitive = 0; SwigType *ctype = 0; + SwigType *template_prefix = 0; int ts; int isarray; const String *cname = 0; @@ -710,6 +702,48 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type if (result) backup = result; } + + /* look for the type reduced to just the template prefix */ + Delete(template_prefix); + template_prefix = SwigType_templateprefix(ctype); + tm = get_typemap(ts, template_prefix); + if (template_prefix) { + if (debug_display && cqualifiedname) + Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, cqualifiedname)); + if (tm && cqualifiedname) { + tm1 = Getattr(tm, cqualifiedname); + if (tm1) { + result = Getattr(tm1, tm_method); /* See if there is a type - qualified name match */ + if (result && Getattr(result, "code")) + goto ret_result; + if (result) + backup = result; + } + } + if (debug_display && cname) + Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, cname)); + if (tm && cname) { + tm1 = Getattr(tm, cname); + if (tm1) { + result = Getattr(tm1, tm_method); /* See if there is a type - name match */ + if (result && Getattr(result, "code")) + goto ret_result; + if (result) + backup = result; + } + } + if (debug_display) + Printf(stdout, " Looking for: %s\n", SwigType_str(template_prefix, 0)); + if (tm) { + result = Getattr(tm, tm_method); /* See if there is simply a type match */ + if (result && Getattr(result, "code")) + goto ret_result; + if (result) + backup = result; + } + } + + /* look for [ANY] arrays */ isarray = SwigType_isarray(ctype); if (isarray) { /* If working with arrays, strip away all of the dimensions and replace with "ANY". @@ -828,6 +862,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type result = backup; ret_result: + Delete(template_prefix); Delete(noarrays); Delete(primitive); if ((unstripped) && (unstripped != type))