Permalink
Browse files

Fixed the binding of multiple identical function pointers with a call…

…ing convention.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 25, 2017
1 parent 16aa74a commit 046c428852b33865a43d101300ce2a6344f1a60a
@@ -89,7 +89,14 @@ public virtual string VisitPointerType(PointerType pointer, TypeQualifiers quals
if (arguments.Count > 0)
args = VisitParameters(function.Parameters, hasNames: false);
return string.Format("{0} (*)({1})", returnType.Visit(this), args);
var callingConvention = string.Empty;
if (function.CallingConvention != CallingConvention.Default &&
function.CallingConvention != CallingConvention.C)
{
string conventionString = function.CallingConvention.ToString();
callingConvention = $"__{conventionString.ToLowerInvariant()} ";
}
return $"{returnType.Visit(this)} ({callingConvention}*)({args})";
}
var qual = GetStringQuals(quals, false);
@@ -488,7 +488,7 @@ public override bool VisitFunctionType(FunctionType function, TypeQualifiers qua
return returnType.Visit(this);
}
public bool VisitDelegateType(FunctionType function, string type)
public bool VisitDelegateType(string type)
{
// We marshal function pointer types by calling
// GetFunctionPointerForDelegate to get a native function
@@ -533,7 +533,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
var cppTypePrinter = new CppTypePrinter();
var cppTypeName = pointer.Visit(cppTypePrinter, quals);
return VisitDelegateType(function, cppTypeName);
return VisitDelegateType(cppTypeName);
}
Enumeration @enum;
@@ -631,7 +631,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
cppTypeName = decl.Type.Visit(cppTypePrinter, quals);
}
VisitDelegateType(func, cppTypeName);
VisitDelegateType(cppTypeName);
return true;
}
@@ -115,7 +115,10 @@ private TypedefDecl GetDelegate(QualifiedType type, ITypedDecl decl)
return existingDelegate;
// Add a new delegate with the calling convention appended to its name
delegateName += newFunctionType.CallingConvention;
delegateName += '_' + newFunctionType.CallingConvention.ToString();
existingDelegate = delegates.SingleOrDefault(t => t.Name == delegateName);
if (existingDelegate != null)
return existingDelegate;
}
var namespaceDelegates = GetDeclContextForDelegates(((Declaration) decl).Namespace);
@@ -562,6 +562,10 @@ public void TestPassAnonymousDelegate()
var testDelegates = new TestDelegates();
int value = testDelegates.MarshalAnonymousDelegate(i => i * 2);
Assert.AreEqual(2, value);
int value5 = testDelegates.MarshalAnonymousDelegate5(i => i * 2);
Assert.AreEqual(4, value5);
int value6 = testDelegates.MarshalAnonymousDelegate6(i => i * 2);
Assert.AreEqual(6, value6);
}
[Test]
@@ -434,6 +434,16 @@ int (*TestDelegates::MarshalAnonymousDelegate4())(int n)
return f;
}
int TestDelegates::MarshalAnonymousDelegate5(int (STDCALL *del)(int))
{
return del(2);
}
int TestDelegates::MarshalAnonymousDelegate6(int (STDCALL *del)(int))
{
return del(3);
}
ClassA::ClassA(int value)
{
Value = value;
@@ -387,6 +387,8 @@ struct DLL_API TestDelegates
void MarshalAnonymousDelegate2(int (*del)(int n));
void MarshalAnonymousDelegate3(float (*del)(float n));
int (*MarshalAnonymousDelegate4())(int n);
int MarshalAnonymousDelegate5(int (STDCALL *del)(int n));
int MarshalAnonymousDelegate6(int (STDCALL *del)(int n));
void MarshalDelegateInAnotherUnit(DelegateInAnotherUnit del);

0 comments on commit 046c428

Please sign in to comment.