Skip to content

Incorrect function pointer mapping in case of remapping #462

Description

@dovdiienko-el3

In case if I remap the function pointer type, ClangSharpPInvokeGenerator uses remapped typename instead of IntPtr at the place where function pointer type is used within the C code. As result I get following warning:

warning CS8500: This takes the address of, gets the size of, or declares a pointer to a managed type

Steps to reproduce

// api.h
typedef void (ApiPFoo)(int);

struct ApiCallbacks
{
  ApiPFoo* Foo;
};
// pinvoke-header.txt
using ClangSharp.Interop;
# pinvoke.rsp
--file
api.h
--output
PInvoke.cs
--namespace
PInvoke
--language
c
--methodClassName
Native
--prefixStrip
api_
--libraryPath
api.dll
--config
compatible-codegen
--headerFile
pinvoke-header.txt
--remap
ApiCallbacks=Callbacks
ApiPFoo=PFoo
rem generate.cmd
ClangSharpPInvokeGenerator @pinvoke.rsp

Expected

using ClangSharp.Interop;
using System;
using System.Runtime.InteropServices;

namespace PInvoke
{
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate void PFoo(int param0);

    public partial struct Callbacks
    {
        [NativeTypeName("ApiPFoo *")]
        public IntPtr Foo;
    }
}

Actual generated file

using ClangSharp.Interop;
using System.Runtime.InteropServices;

namespace PInvoke
{
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate void PFoo(int param0);

    public unsafe partial struct Callbacks
    {
        [NativeTypeName("ApiPFoo *")]
        public PFoo* Foo;
    }
}

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