Skip to content

Generated code incorrect for typedef'd function pointers #253

@ThadHouse

Description

@ThadHouse

In a lot of Windows API's, when a callback is passed to a function, usually the function pointer itself is declared as a function type, with a typedef into a function pointer. ClangSharp doesn't seem to like this, and generates a double function pointer instead, which is incorrect.

#pragma once

typedef
int
(__cdecl Callback)(
    int Input
);

typedef Callback *CallbackHandler;


typedef struct Thing {
    CallbackHandler CB;
} Thing;

This code should generate

namespace TestNS
{
    public unsafe partial struct Thing
    {
        [NativeTypeName("CallbackHandler")]
        public delegate* unmanaged[Cdecl]<int, int> CB;
    }
}

But insteads generates as

namespace TestNS
{
    public unsafe partial struct Thing
    {
        [NativeTypeName("CallbackHandler")]
        public delegate* unmanaged[Cdecl]<int, int>* CB;
    }
}

Which is incorrect because of the extra indirection on CB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions