Applying shared_ptr template upcast fix to CSharp, adding CSharp test, and cleanup

This commit is contained in:
etse 2019-05-02 13:29:22 -04:00
parent 24f974bb0c
commit 3359b4ccab
5 changed files with 25 additions and 21 deletions

View File

@ -33,6 +33,7 @@ CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_template_upcast \
cpp11_shared_ptr_upcast \
cpp11_strongly_typed_enumerations_simple \

View File

@ -0,0 +1,15 @@
// 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.
// For this case, the expected behavior is: given a cptr with underlying type shared_ptr<Printable<Derived> >, PrintableDerived_SWIGSmartPtrUpcast returns a cptr with
// underlying type std::shared_ptr< Derived >, where Printable<Derived> inherits from Derived.
using System;
using cpp11_shared_ptr_template_upcastNamespace;
public class cpp11_shared_ptr_template_upcast_runme
{
static void Main()
{
PrintableDerived pd = cpp11_shared_ptr_template_upcast.MakePrintableDerived(20);
pd.GetResult();
pd.GetFormatted();
}
}

View File

@ -1,7 +1,6 @@
// 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.
// In this case, the expected behavior is that given a cptr (underlying type shared_ptr<Printable<Derived> >), PrintableDerived_SWIGSmartPtrUpcast returns a cptr
// (underlying type std::shared_ptr< Derived >).
// 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.
// For this case, the expected behavior is: given a cptr with underlying type shared_ptr<Printable<Derived> >, PrintableDerived_SWIGSmartPtrUpcast returns a cptr with
// underlying type std::shared_ptr< Derived >, where Printable<Derived> inherits from Derived.
import cpp11_shared_ptr_template_upcast.*;

View File

@ -1758,21 +1758,22 @@ public:
Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name);
if (smart) {
SwigType *bsmart = Copy(smart);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(smart);
SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
Replaceall(bsmart, rclassname, rbaseclass);
Replaceall(bsmartnamestr, rclassname, rbaseclass);
Delete(rclassname);
Delete(rbaseclass);
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
Printv(upcasts_code,
"SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", wname, "(", smartnamestr, " *jarg1) {\n",
" return jarg1 ? new ", bsmartnamestr, "(*jarg1) : 0;\n"
"}\n", "\n", NIL);
Delete(bsmartnamestr);
Delete(smartnamestr);
Delete(bsmart);
} else {
Printv(upcasts_code,
"SWIGEXPORT ", c_baseclass, " * SWIGSTDCALL ", wname, "(", c_classname, " *jarg1) {\n",

View File

@ -1893,8 +1893,6 @@ public:
* ----------------------------------------------------------------------------- */
void upcastsCode(SwigType *smart, String *upcast_method_name, String *c_classname, String *c_baseclass) {
Swig_warning(0, NULL, NULL, "******************************************\n");
Swig_warning(0, NULL, NULL, "Smart: %s, Class name: '%s', baseclass: '%s' \n", smart, c_classname, c_baseclass);
String *jniname = makeValidJniName(upcast_method_name);
String *wname = Swig_name_wrapper(jniname);
Printf(imclass_cppcasts_code, " public final static native long %s(long jarg1);\n", upcast_method_name);
@ -1903,21 +1901,12 @@ public:
String *bsmartnamestr = SwigType_namestr(smart);
SwigType *rclassname = SwigType_typedef_resolve_all(c_classname);
Swig_warning(0, NULL, NULL, "SwigType_typedef_resolve_all - c_classname(%s): '%s'\n", c_classname, rclassname);
SwigType *rbaseclass = SwigType_typedef_resolve_all(c_baseclass);
Swig_warning(0, NULL, NULL, "SwigType_typedef_resolve_all - c_baseclass(%s): '%s'\n", c_baseclass, rbaseclass);
Swig_warning(0, NULL, NULL, "Replaceall - PRE(%s, %s, %s)\n", bsmartnamestr, rclassname, rbaseclass);
Replaceall(bsmartnamestr, rclassname, rbaseclass);
Swig_warning(0, NULL, NULL, "Replaceall - POST(%s, %s, %s)\n", bsmartnamestr, rclassname, rbaseclass);
Delete(rclassname);
Delete(rbaseclass);
//String *smartnamestr = SwigType_namestr(smart);
//String *bsmartnamestr = SwigType_namestr(bsmart);
Swig_warning(0, NULL, NULL, "bsmartnamestr: '%s', smartnamestr: '%s' \n", bsmartnamestr, smartnamestr);
Printv(upcasts_code,
"SWIGEXPORT jlong JNICALL ", wname, "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n",
@ -1941,7 +1930,6 @@ public:
" return baseptr;\n"
"}\n", "\n", NIL);
}
Swig_warning(0, NULL, NULL, "******************************************\n");
Delete(wname);
Delete(jniname);