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;
}
}
In case if I remap the function pointer type, ClangSharpPInvokeGenerator uses remapped typename instead of
IntPtrat the place where function pointer type is used within the C code. As result I get following warning:Steps to reproduce
# 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=PFooExpected
Actual generated file