summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_common.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_common.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_common.cs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs
index 4bd93ce25b..2a9766cd4d 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -23,6 +23,8 @@ internal static class NativeCustomExportFunctions
[DllImport(efl.Libs.CustomExports)] public static extern IntPtr
efl_mono_native_alloc(uint count);
[DllImport(efl.Libs.CustomExports)] public static extern IntPtr
+ efl_mono_native_memset(IntPtr ptr, uint fill, uint count);
+ [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
efl_mono_native_alloc_copy(IntPtr val, uint size);
[DllImport(efl.Libs.CustomExports)] public static extern IntPtr
efl_mono_native_strdup(string str);
@@ -56,6 +58,11 @@ public static class MemoryNative {
return NativeCustomExportFunctions.efl_mono_native_alloc(Convert.ToUInt32(count));
}
+ public static void Memset(IntPtr ptr, int fill, int count)
+ {
+ NativeCustomExportFunctions.efl_mono_native_memset(ptr, Convert.ToUInt32(fill), Convert.ToUInt32(count));
+ }
+
public static IntPtr AllocCopy(IntPtr ptr, int count)
{
return NativeCustomExportFunctions.efl_mono_native_alloc_copy(ptr, Convert.ToUInt32(count));
@@ -110,11 +117,9 @@ public static class PrimitiveConversion
public static IntPtr ManagedToPointerAlloc<T>(T man)
{
- GCHandle pinnedData = GCHandle.Alloc(man, GCHandleType.Pinned);
- IntPtr ptr = pinnedData.AddrOfPinnedObject();
- IntPtr nat = MemoryNative.AllocCopy(ptr, Marshal.SizeOf<T>());
- pinnedData.Free();
- return nat;
+ IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<T>());
+ Marshal.StructureToPtr(man, ptr, false);
+ return ptr;
}
}
@@ -147,18 +152,12 @@ public static class StringConversion
}
}
-public struct Unicode {
- private uint val;
-
- public static implicit operator Unicode(uint x)
- {
- return new Unicode{val=x};
- }
- public static implicit operator uint(Unicode x)
- {
- return x.val;
- }
+/// <summary>Enum to handle resource ownership between managed and unmanaged code.</summary>
+public enum Ownership {
+ /// <summary> The resource is owned by the managed code. It should free the handle on disposal.</summary>
+ Managed,
+ /// <summary> The resource is owned by the unmanaged code. It won't be freed on disposal.</summary>
+ Unmanaged
}
-
}