Browse Source

Fixed the generated C# for a case of a typedef of a function pointer.

Typedefs of function pointers can be written in two ways:

typedef void (*typedefedFuncPtr)();
int f(typedefedFuncPtr fptr);

typedef void (typedefedFuncPtr)();
int f(typedefedFuncPtr* fptr);

Up until now we only supported the former.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/890/head
Dimitar Dobrev 9 years ago
parent
commit
46b40bbe05
  1. 4
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 3
      src/Generator/Passes/DelegatesPass.cs
  4. 4
      tests/CSharp/CSharp.Tests.cs

4
src/Generator/Generators/CSharp/CSharpSources.cs

@ -2959,9 +2959,9 @@ namespace CppSharp.Generators.CSharp @@ -2959,9 +2959,9 @@ namespace CppSharp.Generators.CSharp
GenerateDeclarationCommon(typedef);
FunctionType functionType;
var functionType = typedef.Type as FunctionType;
if (typedef.Type.IsPointerTo(out functionType))
if (functionType != null || typedef.Type.IsPointerTo(out functionType))
{
PushBlock(BlockKind.Typedef);
var attributedType = typedef.Type.GetPointee() as AttributedType;

4
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -320,8 +320,8 @@ namespace CppSharp.Generators.CSharp @@ -320,8 +320,8 @@ namespace CppSharp.Generators.CSharp
}
}
FunctionType func;
if (decl.Type.IsPointerTo(out func))
FunctionType func = decl.Type as FunctionType;
if (func != null || decl.Type.IsPointerTo(out func))
{
if (ContextKind == TypePrinterContextKind.Native)
return IntPtrType;

3
src/Generator/Passes/DelegatesPass.cs

@ -143,9 +143,10 @@ namespace CppSharp.Passes @@ -143,9 +143,10 @@ namespace CppSharp.Passes
private void VisitFunctionTypeParameters(Function function)
{
foreach (var param in from param in function.Parameters
where !(param.Type is TypedefType)
let paramType = param.Type.Desugar()
where paramType.IsAddress() &&
paramType.GetFinalPointee().Desugar() is FunctionType
paramType.GetPointee() is FunctionType
select param)
{
var module = function.TranslationUnit.Module;

4
tests/CSharp/CSharp.Tests.cs

@ -856,10 +856,10 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -856,10 +856,10 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test, Platform(Exclude = "Win", Reason = "This test crashes our Windows build, possibly a problem with the NUnit runner there.")]
[Test]
public void TestFuncWithTypedefedFuncPtrAsParam()
{
Func_int_IntPtr_CSharp_Bar___Internal function = (a, b) => 5;
TypedefedFuncPtr function = (a, b) => 5;
Assert.That(CSharp.CSharp.FuncWithTypedefedFuncPtrAsParam(function), Is.EqualTo(5));
}
}

Loading…
Cancel
Save