From b3da344765625f22847bd56ee22b392dd16c4c84 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 24 Jan 2020 19:46:39 +0000 Subject: [PATCH] Add some comments about shared_ptr upcast code --- Source/Modules/csharp.cxx | 1 + Source/Modules/d.cxx | 1 + Source/Modules/java.cxx | 1 + Source/Modules/typepass.cxx | 8 ++++++++ 4 files changed, 11 insertions(+) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index aa0fece36..27cc65b32 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1762,6 +1762,7 @@ public: String *smartnamestr = SwigType_namestr(smart); String *bsmartnamestr = SwigType_namestr(smart); + // TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates SwigType *rclassname = SwigType_typedef_resolve_all(classname); SwigType *rbaseclassname = SwigType_typedef_resolve_all(baseclassname); Replaceall(bsmartnamestr, rclassname, rbaseclassname); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 683686ea1..b7283eac2 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -3381,6 +3381,7 @@ private: String *smartnamestr = SwigType_namestr(smart); String *bsmartnamestr = SwigType_namestr(smart); + // TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates SwigType *rclassname = SwigType_typedef_resolve_all(classname); SwigType *rbaseclassname = SwigType_typedef_resolve_all(baseclassname); Replaceall(bsmartnamestr, rclassname, rbaseclassname); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 0c3b5bf3c..7734c6471 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1904,6 +1904,7 @@ public: String *smartnamestr = SwigType_namestr(smart); String *bsmartnamestr = SwigType_namestr(smart); + // TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates SwigType *rclassname = SwigType_typedef_resolve_all(classname); SwigType *rbaseclassname = SwigType_typedef_resolve_all(baseclassname); Replaceall(bsmartnamestr, rclassname, rbaseclassname); diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 8dbf0865e..dc84cf94a 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -267,6 +267,8 @@ class TypePass:private Dispatcher { and smart pointer to base class, so that smart pointer upcasts are automatically generated. */ SwigType *bsmart = Copy(smart); + + // TODO: SwigType_typedef_resolve_all on a String instead of SwigType is incorrect for templates SwigType *rclsname = SwigType_typedef_resolve_all(clsname); SwigType *rbname = SwigType_typedef_resolve_all(bname); int replace_count = Replaceall(bsmart, rclsname, rbname); @@ -276,6 +278,12 @@ class TypePass:private Dispatcher { String *firstname = Getattr(first, "name"); Replaceall(bsmart, firstname, rbname); } + // The code above currently creates a smartptr of the base class by substitution, replacing Derived + // with Base resulting in something like: 'smartptr< Derived >' from 'smartptr< Base >'. Instead + // the feature:smartptr should be used as it also contains 'smartptr< Base >' as specified by the user. + // A similar fix should also be done in upcastsCode in java.cxx, csharp.cxx and writeClassUpcast in d.cxx. + // Printf(stdout, "smartcomparison %s <=> %s\n", SwigType_namestr(bsmart), Getattr(bclass, "feature:smartptr")); + Delete(rclsname); Delete(rbname); String *smartnamestr = SwigType_namestr(smart);