Browse Source

Merge pull request #336 from ddobrev/master

Ensured the UnmanagedFunctionPointerAttribute is always set on generated delegates
pull/338/head
João Matos 11 years ago
parent
commit
1043be1743
  1. 18
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 6
      tests/Basic/Basic.Tests.cs
  3. 4
      tests/Basic/Basic.cpp
  4. 1
      tests/Basic/Basic.h

18
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -2651,17 +2651,15 @@ namespace CppSharp.Generators.CSharp @@ -2651,17 +2651,15 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(CSharpBlockKind.Typedef);
var attributedType = typedef.Type.GetPointee() as AttributedType;
if (attributedType != null)
{
var equivalentFunctionType = attributedType.Equivalent.Type as FunctionType;
var callingConvention = equivalentFunctionType.CallingConvention.ToInteropCallConv();
if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi)
{
WriteLine("[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
callingConvention);
}
}
var callingConvention = attributedType == null
? functionType.CallingConvention
: ((FunctionType) attributedType.Equivalent.Type).CallingConvention;
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
var interopCallConv = callingConvention.ToInteropCallConv();
if (interopCallConv != System.Runtime.InteropServices.CallingConvention.Winapi)
WriteLine(
"[UnmanagedFunctionPointerAttribute(global::System.Runtime.InteropServices.CallingConvention.{0})]",
interopCallConv);
WriteLine("{0}unsafe {1};",
Helpers.GetAccess(typedef.Access),
string.Format(TypePrinter.VisitDelegate(functionType).Type,

6
tests/Basic/Basic.Tests.cs

@ -418,5 +418,11 @@ public class BasicTests : GeneratorTestFixture @@ -418,5 +418,11 @@ public class BasicTests : GeneratorTestFixture
Assert.AreEqual(bar.A << 2, result.valueTypeField.A);
Assert.AreEqual(bar.B, result.valueTypeField.B);
}
[Test]
public void TestMarshalUnattributedDelegate()
{
new TestDelegates().MarshalUnattributedDelegate(i => i);
}
}

4
tests/Basic/Basic.cpp

@ -304,3 +304,7 @@ Bar::Item operator |(Bar::Item left, Bar::Item right) @@ -304,3 +304,7 @@ Bar::Item operator |(Bar::Item left, Bar::Item right)
void va_listFunction(va_list v)
{
}
void TestDelegates::MarshalUnattributedDelegate(DelegateInGlobalNamespace del)
{
}

1
tests/Basic/Basic.h

@ -292,6 +292,7 @@ struct DLL_API TestDelegates @@ -292,6 +292,7 @@ struct DLL_API TestDelegates
int StdCall(DelegateStdCall del) { return del(1); }
int CDecl(DelegateCDecl del) { return del(1); }
void MarshalUnattributedDelegate(DelegateInGlobalNamespace del);
DelegateInClass A;
DelegateInGlobalNamespace B;

Loading…
Cancel
Save