Fix typemap matching bug when a templated type has a typemap both specialized and not specialized - the wrong typemap would sometimes be used

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11831 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-01-28 07:25:59 +00:00
commit d02f543dbc
4 changed files with 62 additions and 11 deletions

View file

@ -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<typename T> 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:

View file

@ -1025,6 +1025,11 @@ checks are made:
<Li>Typemaps that match the stripped <tt>TYPE</tt> only.
</ul>
<p>
If <tt>TYPE</tt> is a C++ template, the matching rules above are repeated with the template parameterization removed.
For example if <tt>TYPE</tt> is <tt>X&lt; double &gt; </tt>, then repeat with the type simply as <tt>X</tt>.
</p>
<p>
If <tt>TYPE</tt> is an array. The following transformation is made:
</p>

View file

@ -386,6 +386,7 @@ CPP_TEST_CASES += \
typemap_namespace \
typemap_ns_using \
typemap_numinputs \
typemap_template \
typemap_out_optimal \
typemap_variables \
typemap_various \

View file

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