summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-12-17 11:34:41 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-17 11:34:42 -0300
commit8e951504f584f124ba88471fc46f1e7b6d2d3639 (patch)
tree3839fc7a7e31b744cf6ed9b9b1d5acfda0ab6d55 /src/bindings
parentf90a97470d54edb20116e55739025e71cdfbbd92 (diff)
downloadefl-8e951504f584f124ba88471fc46f1e7b6d2d3639.tar.gz
csharp : add move tag info to EinaAccessor, EinaIterator converter
Summary: Included commits in devs/lauromoura/remove_eina_mono-rebased ``` commit ed6679db1901c710cc6ddb50e7001cfd20caa77a Author: Lauro Moura <lauromoura@expertisesolutions.com.br> Date: Mon Dec 2 13:58:04 2019 -0300 csharp: add move information to EnumerableToAccessor Still need to fix the converted accessor ownership, maybe by creating a custom accessor class that released the pinned memory when is freed. ``` ref T8486 Depends On D10878 Co-authored-by: Lauro Moura <lauromoura@expertisesolutions.com.br> Test Plan: meson build -Dbindings=mono,cxx -Dmono-beta=true Reviewers: YOhoho Reviewed By: YOhoho Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8486 Differential Revision: https://phab.enlightenment.org/D10879
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 32ed323113..8ba8c964bd 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -774,21 +774,37 @@ public static class Globals
}
}
- internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable)
+ internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable, bool isMoved)
{
if (enumerable == null)
+ {
throw new ArgumentException("enumerable is null", nameof(enumerable));
- IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
+ }
- int i = 0;
+ // If we are a wrapper around an existing Eina.Accessor, we can just forward
+ // it and avoid unnecessary copying in non-owning transfers.
+ var wrappedAccessor = enumerable as Eina.Accessor<T>;
+
+ if (wrappedAccessor != null && !isMoved)
+ {
+ return wrappedAccessor.Handle;
+ }
+
+ var list = new List<IntPtr>();
foreach (T data in enumerable)
{
- intPtrs[i] = Eina.TraitFunctions.ManagedToNativeAlloc<T>(data);
- i++;
+ list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data));
}
- IntPtr[] dataArray = intPtrs.ToArray();
+ IntPtr[] dataArray = list.ToArray();
GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
- return Eina.AccessorNativeFunctions.eina_carray_length_accessor_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
+ IntPtr ret = Eina.AccessorNativeFunctions.eina_carray_length_accessor_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
+
+ if (!isMoved)
+ {
+ // FIXME Need to free ret and unpin pinnedArray in the future.
+ }
+
+ return ret;
}
internal static IEnumerable<T> IteratorToIEnumerable<T>(IntPtr iterator)
@@ -802,22 +818,38 @@ public static class Globals
}
}
- internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable)
+ internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable, bool isMoved)
{
if (enumerable == null)
+ {
throw new ArgumentException("enumerable is null", nameof(enumerable));
+ }
- var list = new List<IntPtr>();
- //IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
+ // If we are a wrapper around an existing Eina.Iterator, we can just forward
+ // it and avoid unnecessary copying in non-owning transfers.
+ var wrappedIterator = enumerable as Eina.Iterator<T>;
+ if (wrappedIterator != null && !isMoved)
+ {
+ return wrappedIterator.Handle;
+ }
+
+ var list = new List<IntPtr>();
foreach (T data in enumerable)
{
list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data));
}
IntPtr[] dataArray = list.ToArray();
- GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
- return Eina.IteratorNativeFunctions.eina_carray_length_iterator_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
+ GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned);
+ IntPtr ret = Eina.IteratorNativeFunctions.eina_carray_length_iterator_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
+
+ if (!isMoved)
+ {
+ // FIXME Need to free ret and unpin pinnedArray in the future.
+ }
+
+ return ret;
}
internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list)
@@ -841,8 +873,9 @@ public static class Globals
IntPtr list = IntPtr.Zero;
foreach (T data in enumerable)
{
- list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free
+ list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data));
}
+ // FIXME need to free `list` if the returned list is not @moved
return list;
}