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)
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
774 } 774 }
775 } 775 }
776 776
777 internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable) 777 internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable, bool isMoved)
778 { 778 {
779 if (enumerable == null) 779 if (enumerable == null)
780 {
780 throw new ArgumentException("enumerable is null", nameof(enumerable)); 781 throw new ArgumentException("enumerable is null", nameof(enumerable));
781 IntPtr[] intPtrs = new IntPtr[enumerable.Count()]; 782 }
782 783
783 int i = 0; 784 // If we are a wrapper around an existing Eina.Accessor, we can just forward
785 // it and avoid unnecessary copying in non-owning transfers.
786 var wrappedAccessor = enumerable as Eina.Accessor<T>;
787
788 if (wrappedAccessor != null && !isMoved)
789 {
790 return wrappedAccessor.Handle;
791 }
792
793 var list = new List<IntPtr>();
784 foreach (T data in enumerable) 794 foreach (T data in enumerable)
785 { 795 {
786 intPtrs[i] = Eina.TraitFunctions.ManagedToNativeAlloc<T>(data); 796 list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data));
787 i++;
788 } 797 }
789 IntPtr[] dataArray = intPtrs.ToArray(); 798 IntPtr[] dataArray = list.ToArray();
790 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free. 799 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
791 return Eina.AccessorNativeFunctions.eina_carray_length_accessor_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length); 800 IntPtr ret = Eina.AccessorNativeFunctions.eina_carray_length_accessor_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
801
802 if (!isMoved)
803 {
804 // FIXME Need to free ret and unpin pinnedArray in the future.
805 }
806
807 return ret;
792 } 808 }
793 809
794 internal static IEnumerable<T> IteratorToIEnumerable<T>(IntPtr iterator) 810 internal static IEnumerable<T> IteratorToIEnumerable<T>(IntPtr iterator)
@@ -802,22 +818,38 @@ public static class Globals
802 } 818 }
803 } 819 }
804 820
805 internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable) 821 internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable, bool isMoved)
806 { 822 {
807 if (enumerable == null) 823 if (enumerable == null)
824 {
808 throw new ArgumentException("enumerable is null", nameof(enumerable)); 825 throw new ArgumentException("enumerable is null", nameof(enumerable));
826 }
809 827
810 var list = new List<IntPtr>(); 828 // If we are a wrapper around an existing Eina.Iterator, we can just forward
811 //IntPtr[] intPtrs = new IntPtr[enumerable.Count()]; 829 // it and avoid unnecessary copying in non-owning transfers.
830 var wrappedIterator = enumerable as Eina.Iterator<T>;
812 831
832 if (wrappedIterator != null && !isMoved)
833 {
834 return wrappedIterator.Handle;
835 }
836
837 var list = new List<IntPtr>();
813 foreach (T data in enumerable) 838 foreach (T data in enumerable)
814 { 839 {
815 list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data)); 840 list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data));
816 } 841 }
817 842
818 IntPtr[] dataArray = list.ToArray(); 843 IntPtr[] dataArray = list.ToArray();
819 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free. 844 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned);
820 return Eina.IteratorNativeFunctions.eina_carray_length_iterator_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length); 845 IntPtr ret = Eina.IteratorNativeFunctions.eina_carray_length_iterator_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
846
847 if (!isMoved)
848 {
849 // FIXME Need to free ret and unpin pinnedArray in the future.
850 }
851
852 return ret;
821 } 853 }
822 854
823 internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list) 855 internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list)
@@ -841,8 +873,9 @@ public static class Globals
841 IntPtr list = IntPtr.Zero; 873 IntPtr list = IntPtr.Zero;
842 foreach (T data in enumerable) 874 foreach (T data in enumerable)
843 { 875 {
844 list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free 876 list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data));
845 } 877 }
878 // FIXME need to free `list` if the returned list is not @moved
846 return list; 879 return list;
847 } 880 }
848 881