mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.12k stars 513 forks source link

Method with custom class parameters are not generated in osx #1195

Open hs3366677 opened 5 years ago

hs3366677 commented 5 years ago
Brief Description

OS: OS X CppSharp Version: 0.8.23

0.8.23 works well for me on Windows. But when I use my compilation on mac osx, member methods involving custom class as passing parameters are not generated. Neither is singleton method. For example,

class A {
public:
    int testInt(int i);
};

class B
{
public:
    int testB(bool _b);
    int testA(A& _a);
};

class A and B are both correctly generated. But testA() does not appear in the generated file.

// ----------------------------------------------------------------------------
// <auto-generated>
// This is autogenerated code by CppSharp.
// Do not edit this file or all your changes will be lost after re-generation.
// </auto-generated>
// ----------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("testDLL")]

namespace testDLL
{
    public unsafe partial class A : IDisposable
    {
        [StructLayout(LayoutKind.Explicit, Size = 0)]
        public partial struct __Internal
        {
            [SuppressUnmanagedCodeSecurity]
            [DllImport("TestDLL", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
                EntryPoint="_ZN1A7testIntEi")]
            internal static extern int TestInt(global::System.IntPtr instance, int i);
        }

        public global::System.IntPtr __Instance { get; protected set; }

        protected int __PointerAdjustment;
        internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::testDLL.A> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::testDLL.A>();
        protected internal void*[] __OriginalVTables;

        protected bool __ownsNativeInstance;

        internal static global::testDLL.A __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
        {
            return new global::testDLL.A(native.ToPointer(), skipVTables);
        }

        internal static global::testDLL.A __CreateInstance(global::testDLL.A.__Internal native, bool skipVTables = false)
        {
            return new global::testDLL.A(native, skipVTables);
        }

        private static void* __CopyValue(global::testDLL.A.__Internal native)
        {
            var ret = Marshal.AllocHGlobal(sizeof(global::testDLL.A.__Internal));
            *(global::testDLL.A.__Internal*) ret = native;
            return ret.ToPointer();
        }

        private A(global::testDLL.A.__Internal native, bool skipVTables = false)
            : this(__CopyValue(native), skipVTables)
        {
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
        }

        protected A(void* native, bool skipVTables = false)
        {
            if (native == null)
                return;
            __Instance = new global::System.IntPtr(native);
        }

        public A()
        {
            __Instance = Marshal.AllocHGlobal(sizeof(global::testDLL.A.__Internal));
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
        }

        public void Dispose()
        {
            Dispose(disposing: true);
        }

        public virtual void Dispose(bool disposing)
        {
            if (__Instance == IntPtr.Zero)
                return;
            global::testDLL.A __dummy;
            NativeToManagedMap.TryRemove(__Instance, out __dummy);
            if (__ownsNativeInstance)
                Marshal.FreeHGlobal(__Instance);
            __Instance = IntPtr.Zero;
        }

        public int TestInt(int i)
        {
            var __ret = __Internal.TestInt((__Instance + __PointerAdjustment), i);
            return __ret;
        }
    }

    public unsafe partial class B : IDisposable
    {
        [StructLayout(LayoutKind.Explicit, Size = 0)]
        public partial struct __Internal
        {
            [SuppressUnmanagedCodeSecurity]
            [DllImport("testDLL", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
                EntryPoint="_ZN1B5testBEb")]
            internal static extern int TestB(global::System.IntPtr instance, bool _b);
        }

        public global::System.IntPtr __Instance { get; protected set; }

        protected int __PointerAdjustment;
        internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::testDLL.B> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::testDLL.B>();
        protected internal void*[] __OriginalVTables;

        protected bool __ownsNativeInstance;

        internal static global::testDLL.B __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
        {
            return new global::testDLL.B(native.ToPointer(), skipVTables);
        }

        internal static global::testDLL.B __CreateInstance(global::testDLL.B.__Internal native, bool skipVTables = false)
        {
            return new global::testDLL.B(native, skipVTables);
        }

        private static void* __CopyValue(global::testDLL.B.__Internal native)
        {
            var ret = Marshal.AllocHGlobal(sizeof(global::testDLL.B.__Internal));
            *(global::testDLL.B.__Internal*) ret = native;
            return ret.ToPointer();
        }

        private B(global::testDLL.B.__Internal native, bool skipVTables = false)
            : this(__CopyValue(native), skipVTables)
        {
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
        }

        protected B(void* native, bool skipVTables = false)
        {
            if (native == null)
                return;
            __Instance = new global::System.IntPtr(native);
        }

        public B()
        {
            __Instance = Marshal.AllocHGlobal(sizeof(global::testDLL.B.__Internal));
            __ownsNativeInstance = true;
            NativeToManagedMap[__Instance] = this;
        }

        public void Dispose()
        {
            Dispose(disposing: true);
        }

        public virtual void Dispose(bool disposing)
        {
            if (__Instance == IntPtr.Zero)
                return;
            global::testDLL.B __dummy;
            NativeToManagedMap.TryRemove(__Instance, out __dummy);
            if (__ownsNativeInstance)
                Marshal.FreeHGlobal(__Instance);
            __Instance = IntPtr.Zero;
        }

        public int TestB(bool _b)
        {
            var __ret = __Internal.TestB((__Instance + __PointerAdjustment), _b);
            return __ret;
        }
    }
}
Used headers
Used settings

Target: MSVC/GCC/Clang

Other settings

Stack trace or incompilable generated code
tritao commented 5 years ago

Do you have symbols checking enabled? It's the only thing that comes to mind that could explain this behavior.

tritao commented 5 years ago

Did you figure it out meanwhile?

tritao commented 5 years ago

Any update?

hs3366677 commented 5 years ago

no, it still didn't work out for me with symbols checking enabled. I commented out if (output.TranslationUnit.Module != Options.SystemModule) in Driver.cs and it worked. Seems that the custom class was reckoned as system module ?