summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2021-03-22 00:58:07 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2021-03-22 01:08:05 +0000
commitb3bc87d5514be00f7d9c601650c0430d6de58b51 (patch)
treebfe677cbd7e93df1ee98ff50e1ba3ad85b470085
parentcbfc0d15b1f5fcef1ee9a65dbee97f7859bd837f (diff)
downloadswig-b3bc87d5514be00f7d9c601650c0430d6de58b51.tar.gz
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
-rw-r--r--CHANGES.current3
-rw-r--r--Examples/test-suite/java/template_template_parameters_runme.java11
-rw-r--r--Examples/test-suite/python/template_template_parameters_runme.py24
-rw-r--r--Examples/test-suite/template_template_parameters.i9
-rw-r--r--Source/Swig/stype.c47
5 files changed, 61 insertions, 33 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 473db0696..b97d7709d 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -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)
===========================
+2021-03-22: goto40
+ #1977 Fix handling of template template parameters.
+
2021-03-21: olly
#1929, #1978 [PHP] Add support for PHP 8.
diff --git a/Examples/test-suite/java/template_template_parameters_runme.java b/Examples/test-suite/java/template_template_parameters_runme.java
index 6ccc858ac..613f9087c 100644
--- a/Examples/test-suite/java/template_template_parameters_runme.java
+++ b/Examples/test-suite/java/template_template_parameters_runme.java
@@ -29,12 +29,17 @@ public class template_template_parameters_runme {
// Test second part
FloatTestStruct floatTestStruct = new FloatTestStruct();
- FloatContainer2 floatContainer2 = floatTestStruct.getX();
+ FloatContainer2 floatContainer2 = floatTestStruct.getX();
floatContainer2.setX(8.1f);
IntTestStruct intTestStruct = new IntTestStruct();
- IntContainer1 intContainer1 = intTestStruct.getX();
+ IntContainer1 intContainer1 = intTestStruct.getX();
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");
}
}
diff --git a/Examples/test-suite/python/template_template_parameters_runme.py b/Examples/test-suite/python/template_template_parameters_runme.py
index 4c018176e..4b0e27d9c 100644
--- a/Examples/test-suite/python/template_template_parameters_runme.py
+++ b/Examples/test-suite/python/template_template_parameters_runme.py
@@ -1,5 +1,18 @@
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
floatTestStruct = FloatTestStruct()
floatContainer2 = floatTestStruct.x
@@ -7,8 +20,11 @@ floatContainer2.x = 8.1
intTestStruct = IntTestStruct()
intContainer1 = intTestStruct.x
intContainer1.x = 91
-if intContainer1.x!=91:
- raise RuntimeError("Failed")
-if intTestStruct.x.x!=91:
- raise RuntimeError("Failed")
+if intContainer1.x != 91:
+ raise RuntimeError("Failed")
+if intTestStruct.x.x != 91:
+ raise RuntimeError("Failed")
+intTestStructReturned = TestStructContainer1Method(intTestStruct)
+if intTestStructReturned.x.x != 101:
+ raise RuntimeError("Failed")
diff --git a/Examples/test-suite/template_template_parameters.i b/Examples/test-suite/template_template_parameters.i
index 3d8825697..53b18b0b0 100644
--- a/Examples/test-suite/template_template_parameters.i
+++ b/Examples/test-suite/template_template_parameters.i
@@ -48,6 +48,11 @@ struct TestStruct {
TemplateTemplateT<BaseT> x;
};
+TestStruct<int, Container1> TestStructContainer1Method(TestStruct<int, Container1> ts1) {
+ ts1.x.x += 10;
+ return ts1;
+}
+
%}
/* part 1 */
@@ -61,8 +66,8 @@ struct TestStruct {
%template(DoubleAllocFast) pfc::alloc_fast<double>;
/* part 2 */
-%template(IntTestStruct) TestStruct<int, Container1>;
-%template(FloatTestStruct) TestStruct<float, Container2>;
%template(IntContainer1) Container1<int>;
%template(FloatContainer2) Container2<float>;
+%template(IntTestStruct) TestStruct<int, Container1>;
+%template(FloatTestStruct) TestStruct<float, Container2>;
diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c
index 1c7f6cc00..5f876ff04 100644
--- a/Source/Swig/stype.c
+++ b/Source/Swig/stype.c
@@ -1290,30 +1290,29 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
/* Replaces a type of the form 'pat' with 'rep<args>' */
Replace(e, pat, rep, DOH_REPLACE_ANY);
} else if (SwigType_istemplate(e)) {
- /* Replaces a type of the form 'pat<args>' with 'rep' */
- {
- /* To match "e=TemplateTemplateT<(float)>"
- * with "pat=TemplateTemplateT"
- * we need to compare only the first part of the string e.
- */
- int len = DohLen(pat);
-
- /* DohLen(e) > len, not >= (because we expecte at least a
- * character '<' following the template typename)
- */
- if (DohLen(e)>len) {
- String *firstPartOfType = NewStringWithSize(e, len);
- const char* e_as_char = DohData(e);
-
- if (Equal(firstPartOfType, pat) && e_as_char[len]=='<') {
- String *repbase = SwigType_templateprefix(rep);
- Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST);
- Delete(repbase);
- }
- Delete(firstPartOfType);
-
- }
- }
+ /* Replaces a type of the form 'pat<args>' with 'rep' */
+ {
+ /* To match "e=TemplateTemplateT<(float)>"
+ * with "pat=TemplateTemplateT"
+ * we need to compare only the first part of the string e.
+ */
+ int len = Len(pat);
+
+ /* Len(e) > len, not >= (because we expect at least a
+ * character '<' following the template typename)
+ */
+ if (Len(e) > len) {
+ String *firstPartOfType = NewStringWithSize(e, len);
+ const char* e_as_char = Char(e);
+
+ if (Equal(firstPartOfType, pat) && e_as_char[len] == '<') {
+ String *repbase = SwigType_templateprefix(rep);
+ Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST);
+ Delete(repbase);
+ }
+ Delete(firstPartOfType);
+ }
+ }
{
String *tsuffix;