ClangSharp
ClangSharp copied to clipboard
Incorrect function pointer mapping in case of remapping
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;
}
}
Will take a look. It's probably a bad interplay between the function pointer support that exists for .NET 5+ and the compatible handling that exists for .NET Standard