Permalink
Browse files

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>
  • Loading branch information...
ddobrev committed Aug 3, 2017
1 parent db522c0 commit 46b40bbe054e488af62186265b0408d2b4370bd3
@@ -2959,9 +2959,9 @@ public override bool VisitTypedefNameDecl(TypedefNameDecl typedef)
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;
@@ -320,8 +320,8 @@ public static bool IsConstCharString(QualifiedType qualType)
}
}
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;
@@ -143,9 +143,10 @@ private void AddDelegatesToDictionary(Declaration decl, Module module)
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;
@@ -856,10 +856,10 @@ public void TestVoidPtrReturningIndexer()
}
}
[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));
}
}
@@ -1355,9 +1355,9 @@ void useStdStringJustAsParameter(std::string s)
{
}
int funcWithTypedefedFuncPtrAsParam(typedefedFuncPtr *func)
int funcWithTypedefedFuncPtrAsParam(typedefedFuncPtr* func)
{
Foo* a = 0;
Bar b;
return func(a, b);
}
}
@@ -1218,5 +1218,5 @@ extern const ComplexArrayElement ArrayOfVariableSize[];
void useStdStringJustAsParameter(std::string s);
typedef int (typedefedFuncPtr)(Foo *a, Bar b);
int DLL_API funcWithTypedefedFuncPtrAsParam(typedefedFuncPtr *func);
typedef int (typedefedFuncPtr)(Foo* a, Bar b);
int DLL_API funcWithTypedefedFuncPtrAsParam(typedefedFuncPtr* func);

0 comments on commit 46b40bb

Please sign in to comment.