diff options
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-03-15 20:35:17 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2018-03-16 11:12:49 -0300
commit7c543d3c860c8c2d6979c55a0460d4ad3c983291 (patch)
parenteolian_cxx: Add 'unknown' to parameter direction (diff)
csharp: Change policy on ptr(struct) owned calls
When transferring the ownership of a ptr(struct) from Unamanaged to managed, we should marshal the reference-typed fields or they can point to Managed memory that would make no sense to access from C (for example, strings would return garbage). The downside is that it can cause potential leaks if the receiver of the memory do not free it. In the current state of the EFL api this can happen in two places: - Efl.Ui.List.SegArray::remove return -> ptr(Efl.Ui.List.LayoutItem) @owned - Efl.Ui.Focus.Manager::fetch return -> ptr(Efl.Ui.Focus.Relations) @owned The resources copied by both structs may leak when those functions are overriden in C# and the values returned to the C code. Also hide some internal stuff instead of exporting it and generate implicit conversion operators for struct external/internal.
1 files changed, 3 insertions, 5 deletions
diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs
index 4bd93ce25b..8bccc06ea4 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -110,11 +110,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;