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.
This commit is contained in:
parent
78251aa0d2
commit
7c543d3c86
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue