template template parameters patch tidyup

- Document change in CHANGES file
- Minor tweaks and whitespace fixes in stype.c
- Enhance testcase
- Synchronise Java and Python runt test in testcase
This commit is contained in:
William S Fulton 2021-03-22 00:58:07 +00:00
parent cbfc0d15b1
commit b3bc87d551
5 changed files with 59 additions and 31 deletions

View File

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress) Version 4.1.0 (in progress)
=========================== ===========================
2021-03-22: goto40
#1977 Fix handling of template template parameters.
2021-03-21: olly 2021-03-21: olly
#1929, #1978 [PHP] Add support for PHP 8. #1929, #1978 [PHP] Add support for PHP 8.

View File

@ -34,7 +34,12 @@ public class template_template_parameters_runme {
IntTestStruct intTestStruct = new IntTestStruct(); IntTestStruct intTestStruct = new IntTestStruct();
IntContainer1 intContainer1 = intTestStruct.getX(); IntContainer1 intContainer1 = intTestStruct.getX();
intContainer1.setX(91); intContainer1.setX(91);
if (intContainer1.getX()!=91) if (intContainer1.getX() != 91)
throw new RuntimeException("Failed");
if (intTestStruct.getX().getX() != 91)
throw new RuntimeException("Failed");
IntTestStruct intTestStructReturned = template_template_parameters.TestStructContainer1Method(intTestStruct);
if (intTestStructReturned.getX().getX() != 101)
throw new RuntimeException("Failed"); throw new RuntimeException("Failed");
} }
} }

View File

@ -1,5 +1,18 @@
from template_template_parameters import * from template_template_parameters import *
# Test first part
listBool = ListFastBool()
listBool.item = True
x_boolean = listBool.allotype
if listBool.item != True:
raise RuntimeError("Failed")
listDouble = ListDefaultDouble()
listDouble.item = 10.2
x_double = listDouble.allotype
if listDouble.item != 10.2:
raise RuntimeError("Failed")
# Test second part # Test second part
floatTestStruct = FloatTestStruct() floatTestStruct = FloatTestStruct()
floatContainer2 = floatTestStruct.x floatContainer2 = floatTestStruct.x
@ -7,8 +20,11 @@ floatContainer2.x = 8.1
intTestStruct = IntTestStruct() intTestStruct = IntTestStruct()
intContainer1 = intTestStruct.x intContainer1 = intTestStruct.x
intContainer1.x = 91 intContainer1.x = 91
if intContainer1.x!=91: if intContainer1.x != 91:
raise RuntimeError("Failed") raise RuntimeError("Failed")
if intTestStruct.x.x!=91: if intTestStruct.x.x != 91:
raise RuntimeError("Failed")
intTestStructReturned = TestStructContainer1Method(intTestStruct)
if intTestStructReturned.x.x != 101:
raise RuntimeError("Failed") raise RuntimeError("Failed")

View File

@ -48,6 +48,11 @@ struct TestStruct {
TemplateTemplateT<BaseT> x; TemplateTemplateT<BaseT> x;
}; };
TestStruct<int, Container1> TestStructContainer1Method(TestStruct<int, Container1> ts1) {
ts1.x.x += 10;
return ts1;
}
%} %}
/* part 1 */ /* part 1 */
@ -61,8 +66,8 @@ struct TestStruct {
%template(DoubleAllocFast) pfc::alloc_fast<double>; %template(DoubleAllocFast) pfc::alloc_fast<double>;
/* part 2 */ /* part 2 */
%template(IntTestStruct) TestStruct<int, Container1>;
%template(FloatTestStruct) TestStruct<float, Container2>;
%template(IntContainer1) Container1<int>; %template(IntContainer1) Container1<int>;
%template(FloatContainer2) Container2<float>; %template(FloatContainer2) Container2<float>;
%template(IntTestStruct) TestStruct<int, Container1>;
%template(FloatTestStruct) TestStruct<float, Container2>;

View File

@ -1296,22 +1296,21 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
* with "pat=TemplateTemplateT" * with "pat=TemplateTemplateT"
* we need to compare only the first part of the string e. * we need to compare only the first part of the string e.
*/ */
int len = DohLen(pat); int len = Len(pat);
/* DohLen(e) > len, not >= (because we expecte at least a /* Len(e) > len, not >= (because we expect at least a
* character '<' following the template typename) * character '<' following the template typename)
*/ */
if (DohLen(e)>len) { if (Len(e) > len) {
String *firstPartOfType = NewStringWithSize(e, len); String *firstPartOfType = NewStringWithSize(e, len);
const char* e_as_char = DohData(e); const char* e_as_char = Char(e);
if (Equal(firstPartOfType, pat) && e_as_char[len]=='<') { if (Equal(firstPartOfType, pat) && e_as_char[len] == '<') {
String *repbase = SwigType_templateprefix(rep); String *repbase = SwigType_templateprefix(rep);
Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST); Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST);
Delete(repbase); Delete(repbase);
} }
Delete(firstPartOfType); Delete(firstPartOfType);
} }
} }