From 0a102e28462200039a281014ce94d66b026714f0 Mon Sep 17 00:00:00 2001
From: Rokas Kupstys
Date: Thu, 6 Sep 2018 12:43:51 +0300
Subject: [PATCH] Fix class having method `Connect()` creating a name collision
with `SwigDirectorConnect()`.
Issue is fixed by prepending director methods with `SwigDirectorMethod` instead of `SwigDirector`.
---
Doc/Manual/CSharp.html | 14 +++++++-------
Examples/test-suite/director_basic.i | 3 +++
Source/Modules/csharp.cxx | 4 ++--
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
index d74707708..a4e0be799 100644
--- a/Doc/Manual/CSharp.html
+++ b/Doc/Manual/CSharp.html
@@ -1575,9 +1575,9 @@ public class Base : global::System.IDisposable {
private void SwigDirectorConnect() {
if (SwigDerivedClassHasMethod("UIntMethod", swigMethodTypes0))
- swigDelegate0 = new SwigDelegateBase_0(SwigDirectorUIntMethod);
+ swigDelegate0 = new SwigDelegateBase_0(SwigDirectorMethodUIntMethod);
if (SwigDerivedClassHasMethod("BaseBoolMethod", swigMethodTypes1))
- swigDelegate1 = new SwigDelegateBase_1(SwigDirectorBaseBoolMethod);
+ swigDelegate1 = new SwigDelegateBase_1(SwigDirectorMethodBaseBoolMethod);
examplePINVOKE.Base_director_connect(swigCPtr, swigDelegate0, swigDelegate1);
}
@@ -1587,11 +1587,11 @@ public class Base : global::System.IDisposable {
return hasDerivedMethod;
}
- private uint SwigDirectorUIntMethod(uint x) {
+ private uint SwigDirectorMethodUIntMethod(uint x) {
return UIntMethod(x);
}
- private void SwigDirectorBaseBoolMethod(global::System.IntPtr b, bool flag) {
+ private void SwigDirectorMethodBaseBoolMethod(global::System.IntPtr b, bool flag) {
BaseBoolMethod(new Base(b, false), flag);
}
@@ -1620,9 +1620,9 @@ It uses a support method, SwigDerivedClassHasMethod(), which simply use
BaseBoolMethod, with the list of required parameter types, exists in a subclass.
If it does not exist, the delegate is not initialised as there is no need for unmanaged code to call back into managed C# code.
However, if there is an overridden method in any subclass, the delegate is required.
-It is then initialised to the SwigDirectorBaseBoolMethod which in turn will call BaseBoolMethod if invoked.
+It is then initialised to the SwigDirectorMethodBaseBoolMethod which in turn will call BaseBoolMethod if invoked.
The delegate is not initialised to the BaseBoolMethod directly as quite often types will need marshalling from the unmanaged type
-to the managed type in which case an intermediary method (SwigDirectorBaseBoolMethod) is required for the marshalling.
+to the managed type in which case an intermediary method (SwigDirectorMethodBaseBoolMethod) is required for the marshalling.
In this case, the C# Base class needs to be created from the unmanaged IntPtr type.
@@ -2497,7 +2497,7 @@ The generated proxy class code will then contain the following wrapper for calli
...
- private void SwigDirectorsomeCallback(global::System.IntPtr date) {
+ private void SwigDirectorMethodsomeCallback(global::System.IntPtr date) {
System.DateTime tempdate = new System.DateTime();
try {
someCallback(out tempdate);
diff --git a/Examples/test-suite/director_basic.i b/Examples/test-suite/director_basic.i
index 4c258b097..5ab66288e 100644
--- a/Examples/test-suite/director_basic.i
+++ b/Examples/test-suite/director_basic.i
@@ -121,6 +121,9 @@ public:
static Bar * call_pmethod(MyClass *myclass, Bar *b) {
return myclass->pmethod(b);
}
+
+ // Collisions with generated method names
+ virtual void Connect() { }
};
template
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index c48a0a1f6..bd00ffaf3 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -1935,7 +1935,7 @@ public:
String *methid = Getattr(udata, "class_methodidx");
String *overname = Getattr(udata, "overname");
Printf(proxy_class_code, " if (SwigDerivedClassHasMethod(\"%s\", swigMethodTypes%s))\n", method, methid);
- Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirector%s);\n", methid, proxy_class_name, methid, overname);
+ Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirectorMethod%s);\n", methid, proxy_class_name, methid, overname);
}
String *director_connect_method_name = Swig_name_member(getNSpace(), getClassPrefix(), "director_connect");
Printf(proxy_class_code, " %s.%s(swigCPtr", imclass_name, director_connect_method_name);
@@ -3864,7 +3864,7 @@ public:
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
}
- Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name);
+ Printf(callback_def, " private %s SwigDirectorMethod%s(", tm, overloaded_name);
if (!ignored_method) {
const String *csdirectordelegatemodifiers = Getattr(n, "feature:csdirectordelegatemodifiers");
String *modifiers = (csdirectordelegatemodifiers ? NewStringf("%s%s", csdirectordelegatemodifiers, Len(csdirectordelegatemodifiers) > 0 ? " " : "") : NewStringf("public "));