From c010a0d9a9acb25141d68cece9f56999a6df7869 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 7 Nov 2016 19:28:52 +0200 Subject: [PATCH] Restored the STD allocator in the OS X parser bindings. Signed-off-by: Dimitar Dobrev --- .../CSharp/i686-apple-darwin12.4.0/Std.cs | 81 +++++++++++++++++++ .../CSharp/x86_64-apple-darwin12.4.0/Std.cs | 81 +++++++++++++++++++ .../Passes/StripUnusedSystemTypesPass.cs | 2 +- src/Generator/Types/Std/Stdlib.cs | 2 +- 4 files changed, 164 insertions(+), 2 deletions(-) diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs index 58076915..b6af75d8 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs @@ -139,6 +139,87 @@ namespace Std { namespace __1 { + public unsafe partial class Allocator : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 0)] + public unsafe partial struct __Internal + { + [SuppressUnmanagedCodeSecurity] + [DllImport("Std-templates", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZNSt3__19allocatorIcEC2Ev")] + internal static extern void ctor_0(global::System.IntPtr instance); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static Allocator __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new Allocator(native.ToPointer(), skipVTables); + } + + public static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false) + { + return new Allocator(native, skipVTables); + } + + private static void* __CopyValue(Allocator.__Internal native) + { + var ret = Marshal.AllocHGlobal(0); + *(Allocator.__Internal*) ret = native; + return ret.ToPointer(); + } + + private Allocator(Allocator.__Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected Allocator(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public Allocator() + { + __Instance = Marshal.AllocHGlobal(0); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + __Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + public virtual void Dispose(bool disposing) + { + global::Std.__1.Allocator __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + } + + + public unsafe partial class Rebind + { + [StructLayout(LayoutKind.Explicit, Size = 0)] + public partial struct __Internal + { + } + + } namespace CompressedPair { [StructLayout(LayoutKind.Explicit, Size = 12)] diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs index d28c88d3..705a5e6d 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs @@ -139,6 +139,87 @@ namespace Std { namespace __1 { + public unsafe partial class Allocator : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 0)] + public unsafe partial struct __Internal + { + [SuppressUnmanagedCodeSecurity] + [DllImport("Std-templates", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, + EntryPoint="_ZNSt3__19allocatorIcEC2Ev")] + internal static extern void ctor_0(global::System.IntPtr instance); + } + + public global::System.IntPtr __Instance { get; protected set; } + + protected int __PointerAdjustment; + public static readonly System.Collections.Concurrent.ConcurrentDictionary NativeToManagedMap = new System.Collections.Concurrent.ConcurrentDictionary(); + protected void*[] __OriginalVTables; + + protected bool __ownsNativeInstance; + + public static Allocator __CreateInstance(global::System.IntPtr native, bool skipVTables = false) + { + return new Allocator(native.ToPointer(), skipVTables); + } + + public static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false) + { + return new Allocator(native, skipVTables); + } + + private static void* __CopyValue(Allocator.__Internal native) + { + var ret = Marshal.AllocHGlobal(0); + *(Allocator.__Internal*) ret = native; + return ret.ToPointer(); + } + + private Allocator(Allocator.__Internal native, bool skipVTables = false) + : this(__CopyValue(native), skipVTables) + { + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + } + + protected Allocator(void* native, bool skipVTables = false) + { + if (native == null) + return; + __Instance = new global::System.IntPtr(native); + } + + public Allocator() + { + __Instance = Marshal.AllocHGlobal(0); + __ownsNativeInstance = true; + NativeToManagedMap[__Instance] = this; + __Internal.ctor_0((__Instance + __PointerAdjustment)); + } + + public void Dispose() + { + Dispose(disposing: true); + } + + public virtual void Dispose(bool disposing) + { + global::Std.__1.Allocator __dummy; + NativeToManagedMap.TryRemove(__Instance, out __dummy); + if (__ownsNativeInstance) + Marshal.FreeHGlobal(__Instance); + } + } + + + public unsafe partial class Rebind + { + [StructLayout(LayoutKind.Explicit, Size = 0)] + public partial struct __Internal + { + } + + } namespace CompressedPair { [StructLayout(LayoutKind.Explicit, Size = 24)] diff --git a/src/Generator/Passes/StripUnusedSystemTypesPass.cs b/src/Generator/Passes/StripUnusedSystemTypesPass.cs index db8beae4..79120bf3 100644 --- a/src/Generator/Passes/StripUnusedSystemTypesPass.cs +++ b/src/Generator/Passes/StripUnusedSystemTypesPass.cs @@ -27,7 +27,7 @@ namespace CppSharp.Passes { // we need this one for marshalling std::string foreach (var allocator in context.FindClass("allocator", false, true).Where( - a => a.Namespace.Name == "std")) + a => a.TranslationUnit.IsSystemHeader)) usedStdTypes.Add(allocator); var result = base.VisitASTContext(context); diff --git a/src/Generator/Types/Std/Stdlib.cs b/src/Generator/Types/Std/Stdlib.cs index 343cb96a..69bb9bad 100644 --- a/src/Generator/Types/Std/Stdlib.cs +++ b/src/Generator/Types/Std/Stdlib.cs @@ -67,7 +67,7 @@ namespace CppSharp.Types.Std ctx.Return.Write("*({0}*) ", basicString.Visit(typePrinter)); typePrinter.PopContext(); var allocator = ctx.Context.ASTContext.FindClass("allocator", false, true).First( - a => a.IsDependent); + a => a.IsDependent && a.TranslationUnit.IsSystemHeader); if (type.IsPointer() || (type.IsReference() && ctx.Declaration is Field)) { ctx.Return.Write("new {0}({1}, new {2}()).{3}",