mirror of https://github.com/swig/swig
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:
parent
cbfc0d15b1
commit
b3bc87d551
|
@ -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.
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,17 @@ public class template_template_parameters_runme {
|
||||||
|
|
||||||
// Test second part
|
// Test second part
|
||||||
FloatTestStruct floatTestStruct = new FloatTestStruct();
|
FloatTestStruct floatTestStruct = new FloatTestStruct();
|
||||||
FloatContainer2 floatContainer2 = floatTestStruct.getX();
|
FloatContainer2 floatContainer2 = floatTestStruct.getX();
|
||||||
floatContainer2.setX(8.1f);
|
floatContainer2.setX(8.1f);
|
||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
raise RuntimeError("Failed")
|
||||||
|
intTestStructReturned = TestStructContainer1Method(intTestStruct)
|
||||||
|
if intTestStructReturned.x.x != 101:
|
||||||
|
raise RuntimeError("Failed")
|
||||||
|
|
||||||
|
|
|
@ -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>;
|
||||||
|
|
||||||
|
|
|
@ -1290,30 +1290,29 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
|
||||||
/* Replaces a type of the form 'pat' with 'rep<args>' */
|
/* Replaces a type of the form 'pat' with 'rep<args>' */
|
||||||
Replace(e, pat, rep, DOH_REPLACE_ANY);
|
Replace(e, pat, rep, DOH_REPLACE_ANY);
|
||||||
} else if (SwigType_istemplate(e)) {
|
} else if (SwigType_istemplate(e)) {
|
||||||
/* Replaces a type of the form 'pat<args>' with 'rep' */
|
/* Replaces a type of the form 'pat<args>' with 'rep' */
|
||||||
{
|
{
|
||||||
/* To match "e=TemplateTemplateT<(float)>"
|
/* To match "e=TemplateTemplateT<(float)>"
|
||||||
* 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
String *tsuffix;
|
String *tsuffix;
|
||||||
|
|
Loading…
Reference in New Issue