Browse Source

Align memory alloc.

pull/1879/head
Joao Matos 2 years ago
parent
commit
05eb5f31de
  1. 1719
      src/CppParser/Bindings/CSharp/arm64-apple-darwin/CppSharp.CppParser.cs
  2. 17
      src/CppParser/Bindings/CSharp/arm64-apple-darwin/Std.cs
  3. 1719
      src/CppParser/Bindings/CSharp/i686-apple-darwin/CppSharp.CppParser.cs
  4. 17
      src/CppParser/Bindings/CSharp/i686-apple-darwin/Std.cs
  5. 1719
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin/CppSharp.CppParser.cs
  6. 17
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin/Std.cs
  7. 1719
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  8. 17
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs
  9. 1719
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  10. 17
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs
  11. 13
      src/Generator/Generators/CSharp/CSharpSources.cs

1719
src/CppParser/Bindings/CSharp/arm64-apple-darwin/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

17
src/CppParser/Bindings/CSharp/arm64-apple-darwin/Std.cs

@ -8,6 +8,7 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention; using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr; using __IntPtr = global::System.IntPtr;
@ -110,7 +111,7 @@ namespace Std
private static void* __CopyValue(global::Std.CharTraits.__Internal native) private static void* __CopyValue(global::Std.CharTraits.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.CharTraits.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.CharTraits.__Internal), 16);
*(global::Std.CharTraits.__Internal*) ret = native; *(global::Std.CharTraits.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -143,7 +144,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -243,7 +244,7 @@ namespace Std
private static void* __CopyValue(global::Std.Allocator.__Internal native) private static void* __CopyValue(global::Std.Allocator.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
*(global::Std.Allocator.__Internal*) ret = native; *(global::Std.Allocator.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -267,7 +268,7 @@ namespace Std
var ___Tp = typeof(_Tp); var ___Tp = typeof(_Tp);
if (___Tp.IsAssignableFrom(typeof(sbyte))) if (___Tp.IsAssignableFrom(typeof(sbyte)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance); global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance);
@ -290,7 +291,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -439,7 +440,7 @@ namespace Std
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native) private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C), 16);
*(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C*) ret = native; *(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -465,7 +466,7 @@ namespace Std
var ___Allocator = typeof(_Allocator); var ___Allocator = typeof(_Allocator);
if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>))) if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C.ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C(__Instance); global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C.ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C(__Instance);
@ -499,7 +500,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_CharT, _Traits, _Allocator", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Allocator).FullName }), "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>."); throw new ArgumentOutOfRangeException("_CharT, _Traits, _Allocator", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Allocator).FullName }), "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }

1719
src/CppParser/Bindings/CSharp/i686-apple-darwin/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

17
src/CppParser/Bindings/CSharp/i686-apple-darwin/Std.cs

@ -8,6 +8,7 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention; using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr; using __IntPtr = global::System.IntPtr;
@ -110,7 +111,7 @@ namespace Std
private static void* __CopyValue(global::Std.CharTraits.__Internal native) private static void* __CopyValue(global::Std.CharTraits.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.CharTraits.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.CharTraits.__Internal), 16);
*(global::Std.CharTraits.__Internal*) ret = native; *(global::Std.CharTraits.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -143,7 +144,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -243,7 +244,7 @@ namespace Std
private static void* __CopyValue(global::Std.Allocator.__Internal native) private static void* __CopyValue(global::Std.Allocator.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
*(global::Std.Allocator.__Internal*) ret = native; *(global::Std.Allocator.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -267,7 +268,7 @@ namespace Std
var ___Tp = typeof(_Tp); var ___Tp = typeof(_Tp);
if (___Tp.IsAssignableFrom(typeof(sbyte))) if (___Tp.IsAssignableFrom(typeof(sbyte)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance); global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance);
@ -290,7 +291,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -474,7 +475,7 @@ namespace Std
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native) private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C), 16);
*(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C*) ret = native; *(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -500,7 +501,7 @@ namespace Std
var ___Allocator = typeof(_Allocator); var ___Allocator = typeof(_Allocator);
if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>))) if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C.ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C(__Instance); global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C.ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C(__Instance);
@ -535,7 +536,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_CharT, _Traits, _Allocator", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Allocator).FullName }), "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>."); throw new ArgumentOutOfRangeException("_CharT, _Traits, _Allocator", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Allocator).FullName }), "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }

1719
src/CppParser/Bindings/CSharp/x86_64-apple-darwin/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

17
src/CppParser/Bindings/CSharp/x86_64-apple-darwin/Std.cs

@ -8,6 +8,7 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention; using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr; using __IntPtr = global::System.IntPtr;
@ -110,7 +111,7 @@ namespace Std
private static void* __CopyValue(global::Std.CharTraits.__Internal native) private static void* __CopyValue(global::Std.CharTraits.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.CharTraits.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.CharTraits.__Internal), 16);
*(global::Std.CharTraits.__Internal*) ret = native; *(global::Std.CharTraits.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -143,7 +144,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -243,7 +244,7 @@ namespace Std
private static void* __CopyValue(global::Std.Allocator.__Internal native) private static void* __CopyValue(global::Std.Allocator.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
*(global::Std.Allocator.__Internal*) ret = native; *(global::Std.Allocator.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -267,7 +268,7 @@ namespace Std
var ___Tp = typeof(_Tp); var ___Tp = typeof(_Tp);
if (___Tp.IsAssignableFrom(typeof(sbyte))) if (___Tp.IsAssignableFrom(typeof(sbyte)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance); global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance);
@ -290,7 +291,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -474,7 +475,7 @@ namespace Std
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native) private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C), 16);
*(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C*) ret = native; *(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -500,7 +501,7 @@ namespace Std
var ___Allocator = typeof(_Allocator); var ___Allocator = typeof(_Allocator);
if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>))) if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C.ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C(__Instance); global::Std.BasicString.__Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C.ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C(__Instance);
@ -535,7 +536,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_CharT, _Traits, _Allocator", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Allocator).FullName }), "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>."); throw new ArgumentOutOfRangeException("_CharT, _Traits, _Allocator", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Allocator).FullName }), "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }

1719
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

17
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs

@ -8,6 +8,7 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention; using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr; using __IntPtr = global::System.IntPtr;
@ -79,7 +80,7 @@ namespace Std
private static void* __CopyValue(global::Std.Allocator.__Internal native) private static void* __CopyValue(global::Std.Allocator.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
*(global::Std.Allocator.__Internal*) ret = native; *(global::Std.Allocator.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -103,7 +104,7 @@ namespace Std
var ___Tp = typeof(_Tp); var ___Tp = typeof(_Tp);
if (___Tp.IsAssignableFrom(typeof(sbyte))) if (___Tp.IsAssignableFrom(typeof(sbyte)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.Allocator.__Internal.ctorc__N_std_S_allocator__C(__Instance); global::Std.Allocator.__Internal.ctorc__N_std_S_allocator__C(__Instance);
@ -136,7 +137,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_Tp", string.Join(", ", new[] { typeof(_Tp).FullName }), "global::Std.Allocator<_Tp> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte>."); throw new ArgumentOutOfRangeException("_Tp", string.Join(", ", new[] { typeof(_Tp).FullName }), "global::Std.Allocator<_Tp> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -285,7 +286,7 @@ namespace Std
private static void* __CopyValue(global::Std.CharTraits.__Internal native) private static void* __CopyValue(global::Std.CharTraits.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.CharTraits.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.CharTraits.__Internal), 16);
*(global::Std.CharTraits.__Internal*) ret = native; *(global::Std.CharTraits.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -318,7 +319,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -421,7 +422,7 @@ namespace Std
private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native) private static void* __CopyValue(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C), 16);
*(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C*) ret = native; *(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -447,7 +448,7 @@ namespace Std
var ___Alloc = typeof(_Alloc); var ___Alloc = typeof(_Alloc);
if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Alloc.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>))) if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Alloc.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C.ctorc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__Instance); global::Std.BasicString.__Internalc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C.ctorc__N_std_N___cxx11_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__Instance);
@ -482,7 +483,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_CharT, _Traits, _Alloc", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Alloc).FullName }), "global::Std.BasicString<_CharT, _Traits, _Alloc> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>."); throw new ArgumentOutOfRangeException("_CharT, _Traits, _Alloc", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Alloc).FullName }), "global::Std.BasicString<_CharT, _Traits, _Alloc> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }

1719
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

17
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs

@ -8,6 +8,7 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention; using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr; using __IntPtr = global::System.IntPtr;
@ -79,7 +80,7 @@ namespace Std
private static void* __CopyValue(global::Std.Allocator.__Internal native) private static void* __CopyValue(global::Std.Allocator.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
*(global::Std.Allocator.__Internal*) ret = native; *(global::Std.Allocator.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -103,7 +104,7 @@ namespace Std
var ___Tp = typeof(_Tp); var ___Tp = typeof(_Tp);
if (___Tp.IsAssignableFrom(typeof(sbyte))) if (___Tp.IsAssignableFrom(typeof(sbyte)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.Allocator.__Internal.ctorc__N_std_S_allocator__C(__Instance); global::Std.Allocator.__Internal.ctorc__N_std_S_allocator__C(__Instance);
@ -136,7 +137,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_Tp", string.Join(", ", new[] { typeof(_Tp).FullName }), "global::Std.Allocator<_Tp> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte>."); throw new ArgumentOutOfRangeException("_Tp", string.Join(", ", new[] { typeof(_Tp).FullName }), "global::Std.Allocator<_Tp> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -285,7 +286,7 @@ namespace Std
private static void* __CopyValue(global::Std.CharTraits.__Internal native) private static void* __CopyValue(global::Std.CharTraits.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.CharTraits.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.CharTraits.__Internal), 16);
*(global::Std.CharTraits.__Internal*) ret = native; *(global::Std.CharTraits.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -318,7 +319,7 @@ namespace Std
NativeToManagedMap.TryRemove(__Instance, out _); NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing); DisposePartial(disposing);
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }
@ -397,7 +398,7 @@ namespace Std
private static void* __CopyValue(global::Std.BasicString.__Internal native) private static void* __CopyValue(global::Std.BasicString.__Internal native)
{ {
var ret = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internal)); var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internal), 16);
*(global::Std.BasicString.__Internal*) ret = native; *(global::Std.BasicString.__Internal*) ret = native;
return ret.ToPointer(); return ret.ToPointer();
} }
@ -423,7 +424,7 @@ namespace Std
var ___Alloc = typeof(_Alloc); var ___Alloc = typeof(_Alloc);
if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Alloc.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>))) if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Alloc.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>)))
{ {
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.BasicString.__Internal)); __Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.BasicString.__Internal), 16);
__ownsNativeInstance = true; __ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this); __RecordNativeToManagedMapping(__Instance, this);
global::Std.BasicString.__Internal.ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__Instance); global::Std.BasicString.__Internal.ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__Instance);
@ -458,7 +459,7 @@ namespace Std
throw new ArgumentOutOfRangeException("_CharT, _Traits, _Alloc", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Alloc).FullName }), "global::Std.BasicString<_CharT, _Traits, _Alloc> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>."); throw new ArgumentOutOfRangeException("_CharT, _Traits, _Alloc", string.Join(", ", new[] { typeof(_CharT).FullName, typeof(_Traits).FullName, typeof(_Alloc).FullName }), "global::Std.BasicString<_CharT, _Traits, _Alloc> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>.");
} }
if (__ownsNativeInstance) if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance); __NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero; __Instance = IntPtr.Zero;
} }
} }

13
src/Generator/Generators/CSharp/CSharpSources.cs

@ -172,6 +172,7 @@ namespace CppSharp.Generators.CSharp
foreach (var @namespace in requiredNameSpaces.Union(Options.DependentNameSpaces).OrderBy(x => x)) foreach (var @namespace in requiredNameSpaces.Union(Options.DependentNameSpaces).OrderBy(x => x))
WriteLine($"using {@namespace};"); WriteLine($"using {@namespace};");
WriteLine("using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;");
WriteLine("using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;"); WriteLine("using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;");
WriteLine("using __IntPtr = global::System.IntPtr;"); WriteLine("using __IntPtr = global::System.IntPtr;");
@ -2394,7 +2395,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
{ {
string name = prop.Field.OriginalName; string name = prop.Field.OriginalName;
WriteLine($"if (__{name}_OwnsNativeMemory)"); WriteLine($"if (__{name}_OwnsNativeMemory)");
WriteLineIndent($"Marshal.FreeHGlobal({ptr}->{name});"); WriteLineIndent($"__NativeMemory.AlignedFree((void*){ptr}->{name});");
} }
if (@class.IsValueType) if (@class.IsValueType)
@ -2404,7 +2405,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
else else
{ {
WriteLine("if ({0})", Helpers.OwnsNativeInstanceIdentifier); WriteLine("if ({0})", Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier); WriteLineIndent("__NativeMemory.AlignedFree((void*){0});", Helpers.InstanceIdentifier);
WriteLine("{0} = IntPtr.Zero;", Helpers.InstanceIdentifier); WriteLine("{0} = IntPtr.Zero;", Helpers.InstanceIdentifier);
} }
@ -2606,14 +2607,14 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
string defaultValue = string.Empty; string defaultValue = string.Empty;
if (copyCtorMethod.Parameters.Count > 1) if (copyCtorMethod.Parameters.Count > 1)
defaultValue = $", {ExpressionPrinter.VisitParameter(copyCtorMethod.Parameters.Last())}"; defaultValue = $", {ExpressionPrinter.VisitParameter(copyCtorMethod.Parameters.Last())}";
WriteLine($@"var ret = Marshal.AllocHGlobal(sizeof({@internal}));"); WriteLine($@"var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof({@internal}), 16);");
WriteLine($@"{printed}.{GetFunctionNativeIdentifier(copyCtorMethod)}(ret, new {TypePrinter.IntPtrType}(&native){defaultValue});", WriteLine($@"{printed}.{GetFunctionNativeIdentifier(copyCtorMethod)}(ret, new {TypePrinter.IntPtrType}(&native){defaultValue});",
printed, GetFunctionNativeIdentifier(copyCtorMethod)); printed, GetFunctionNativeIdentifier(copyCtorMethod));
WriteLine("return ret.ToPointer();"); WriteLine("return ret.ToPointer();");
} }
else else
{ {
WriteLine($"var ret = Marshal.AllocHGlobal(sizeof({@internal}));"); WriteLine($"var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof({@internal}), 16);");
WriteLine($"*({@internal}*) ret = native;"); WriteLine($"*({@internal}*) ret = native;");
WriteLine("return ret.ToPointer();"); WriteLine("return ret.ToPointer();");
} }
@ -3041,7 +3042,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
var @internal = TypePrinter.PrintNative( var @internal = TypePrinter.PrintNative(
@class.IsAbstractImpl ? @class.BaseClass : @class); @class.IsAbstractImpl ? @class.BaseClass : @class);
WriteLine($"{Helpers.InstanceIdentifier} = Marshal.AllocHGlobal(sizeof({@internal}));"); WriteLine($"{Helpers.InstanceIdentifier} = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof({@internal}), 16);");
WriteLine($"{Helpers.OwnsNativeInstanceIdentifier} = true;"); WriteLine($"{Helpers.OwnsNativeInstanceIdentifier} = true;");
if (generateNativeToManaged) if (generateNativeToManaged)
@ -3223,7 +3224,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
if (method != null && !method.IsConstructor && method.OriginalFunction != null && if (method != null && !method.IsConstructor && method.OriginalFunction != null &&
((Method)method.OriginalFunction).IsConstructor) ((Method)method.OriginalFunction).IsConstructor)
{ {
WriteLine($@"Marshal.AllocHGlobal({((Class)method.OriginalNamespace).Layout.Size});"); WriteLine($@"(nint)__NativeMemory.AlignedAlloc((nuint){((Class)method.OriginalNamespace).Layout.Size}, 16);");
names.Insert(0, Helpers.ReturnIdentifier); names.Insert(0, Helpers.ReturnIdentifier);
} }
WriteLine("{0}({1});", functionName, string.Join(", ", names)); WriteLine("{0}({1});", functionName, string.Join(", ", names));

Loading…
Cancel
Save