Skip to content

Commit ab7f526

Browse files
committed
Applying shared_ptr template upcast fix to CSharp, adding CSharp test, and cleanup
1 parent e7d228b commit ab7f526

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

Examples/test-suite/csharp/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CPP11_TEST_CASES = \
3333
cpp11_shared_ptr_const \
3434
cpp11_shared_ptr_nullptr_in_containers \
3535
cpp11_shared_ptr_overload \
36+
cpp11_shared_ptr_template_upcast \
3637
cpp11_shared_ptr_upcast \
3738
cpp11_strongly_typed_enumerations_simple \
3839

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This is the cpp11_shared_ptr_template_upcast runtime testcase. It checks that SWIG generates the appropriate upcasted shared_ptr type for a template instantiation deriving from a base class.
2+
// For this case, the expected behavior is: given a cptr with underlying type shared_ptr<Printable<Derived> >, PrintableDerived_SWIGSmartPtrUpcast returns a cptr with
3+
// underlying type std::shared_ptr< Derived >, where Printable<Derived> inherits from Derived.
4+
using System;
5+
using cpp11_shared_ptr_template_upcastNamespace;
6+
7+
public class cpp11_shared_ptr_template_upcast_runme
8+
{
9+
static void Main()
10+
{
11+
PrintableDerived pd = cpp11_shared_ptr_template_upcast.MakePrintableDerived(20);
12+
pd.GetResult();
13+
pd.GetFormatted();
14+
}
15+
}

Examples/test-suite/java/cpp11_shared_ptr_template_upcast_runme.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
2-
// This is the cpp11_shared_ptr_template_upcast runtime testcase. It checks that SWIG generates the appropriate, upcasted shared_ptr type for a template instantiation deriving from a base class.
3-
// In this case, the expected behavior is that given a cptr (underlying type shared_ptr<Printable<Derived> >), PrintableDerived_SWIGSmartPtrUpcast returns a cptr
4-
// (underlying type std::shared_ptr< Derived >).
1+
// This is the cpp11_shared_ptr_template_upcast runtime testcase. It checks that SWIG generates the appropriate upcasted shared_ptr type for a template instantiation deriving from a base class.
2+
// For this case, the expected behavior is: given a cptr with underlying type shared_ptr<Printable<Derived> >, PrintableDerived_SWIGSmartPtrUpcast returns a cptr with
3+
// underlying type std::shared_ptr< Derived >, where Printable<Derived> inherits from Derived.
54

65
import cpp11_shared_ptr_template_upcast.*;
76

Source/Modules/csharp.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,21 +1758,22 @@ class CSHARP:public Language {
17581758
Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name);
17591759

17601760
if (smart) {
1761-
SwigType *bsmart = Copy(smart);
1761+
String *smartnamestr = SwigType_namestr(smart);
1762+
String *bsmartnamestr = SwigType_namestr(smart);
1763+
17621764
SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
17631765
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
1764-
Replaceall(bsmart, rclassname, rbaseclass);
1766+
Replaceall(bsmartnamestr, rclassname, rbaseclass);
1767+
17651768
Delete(rclassname);
17661769
Delete(rbaseclass);
1767-
String *smartnamestr = SwigType_namestr(smart);
1768-
String *bsmartnamestr = SwigType_namestr(bsmart);
1770+
17691771
Printv(upcasts_code,
17701772
"SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", wname, "(", smartnamestr, " *jarg1) {\n",
17711773
" return jarg1 ? new ", bsmartnamestr, "(*jarg1) : 0;\n"
17721774
"}\n", "\n", NIL);
17731775
Delete(bsmartnamestr);
17741776
Delete(smartnamestr);
1775-
Delete(bsmart);
17761777
} else {
17771778
Printv(upcasts_code,
17781779
"SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname, "(", c_classname, " *jarg1) {\n",

Source/Modules/java.cxx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,8 +1893,6 @@ class JAVA:public Language {
18931893
* ----------------------------------------------------------------------------- */
18941894

18951895
void upcastsCode(SwigType *smart, String *upcast_method_name, String *c_classname, String *c_baseclass) {
1896-
Swig_warning(0, NULL, NULL, "******************************************\n");
1897-
Swig_warning(0, NULL, NULL, "Smart: %s, Class name: '%s', baseclass: '%s' \n", smart, c_classname, c_baseclass);
18981896
String *jniname = makeValidJniName(upcast_method_name);
18991897
String *wname = Swig_name_wrapper(jniname);
19001898
Printf(imclass_cppcasts_code, " public final static native long %s(long jarg1);\n", upcast_method_name);
@@ -1903,21 +1901,12 @@ class JAVA:public Language {
19031901
String *bsmartnamestr = SwigType_namestr(smart);
19041902

19051903
SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
1906-
Swig_warning(0, NULL, NULL, "SwigType_typedef_resolve_all - c_classname(%s): '%s'\n", c_classname, rclassname);
1907-
19081904
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
1909-
Swig_warning(0, NULL, NULL, "SwigType_typedef_resolve_all - c_baseclass(%s): '%s'\n", c_baseclass, rbaseclass);
19101905

1911-
Swig_warning(0, NULL, NULL, "Replaceall - PRE(%s, %s, %s)\n", bsmartnamestr, rclassname, rbaseclass);
19121906
Replaceall(bsmartnamestr, rclassname, rbaseclass);
1913-
Swig_warning(0, NULL, NULL, "Replaceall - POST(%s, %s, %s)\n", bsmartnamestr, rclassname, rbaseclass);
19141907

19151908
Delete(rclassname);
19161909
Delete(rbaseclass);
1917-
//String *smartnamestr = SwigType_namestr(smart);
1918-
//String *bsmartnamestr = SwigType_namestr(bsmart);
1919-
Swig_warning(0, NULL, NULL, "bsmartnamestr: '%s', smartnamestr: '%s' \n", bsmartnamestr, smartnamestr);
1920-
19211910

19221911
Printv(upcasts_code,
19231912
"SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
@@ -1941,7 +1930,6 @@ class JAVA:public Language {
19411930
" return baseptr;\n"
19421931
"}\n", "\n", NIL);
19431932
}
1944-
Swig_warning(0, NULL, NULL, "******************************************\n");
19451933

19461934
Delete(wname);
19471935
Delete(jniname);

0 commit comments

Comments
 (0)