summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2020-01-14 17:17:04 +0900
committerJaehyun Cho <jae_hyun.cho@samsung.com>2020-01-14 17:17:05 +0900
commitae30d3c57bc28bddd9e3a6c18163719fd8958f06 (patch)
tree094665590e1f799fecf6418b472739c09da8fd6a /src/bindings
parente894c9bff8b1a0a7c2e6b18a9e0b0f707400eee4 (diff)
eina_mono: replace eina_list and eina_array with IList
Summary: Eina.List<T> => System.Collections.Generic.IList<T> Eina.Array<T> => System.Collections.Generic.IList<T> ref T8486 Depends On D10785 Test Plan: meson build -Dbindings=mono,cxx -Dmono-beta=true Reviewers: felipealmeida, Jaehyun_Cho Reviewed By: Jaehyun_Cho Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8486, T8488 Differential Revision: https://phab.enlightenment.org/D10902
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_application.cs3
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs98
2 files changed, 87 insertions, 14 deletions
diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs
index 8493abd6ab..9c2f7f0f06 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_application.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs
@@ -198,7 +198,7 @@ public abstract class Application
198 { 198 {
199 Init(components); 199 Init(components);
200 Efl.App app = Efl.App.AppMain; 200 Efl.App app = Efl.App.AppMain;
201 var command_line = new Eina.Array<Eina.Stringshare>(); 201 var command_line = new List<Eina.Stringshare>();
202 //command_line.Add(List.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s)); 202 //command_line.Add(List.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s));
203 //command_line.AddRange(Environment.GetCommandLineArgs()); 203 //command_line.AddRange(Environment.GetCommandLineArgs());
204#if EFL_BETA 204#if EFL_BETA
@@ -234,7 +234,6 @@ public abstract class Application
234 OnTerminate(); 234 OnTerminate();
235 }; 235 };
236 app.Begin(); 236 app.Begin();
237 command_line.Dispose();
238 Shutdown(); 237 Shutdown();
239 } 238 }
240} 239}
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 2a8ebf0620..780735fcca 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -875,33 +875,107 @@ internal static class Globals
875 return ret; 875 return ret;
876 } 876 }
877 877
878 internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list) 878 internal static IList<T> NativeListToIList<T>(IntPtr nativeList)
879 { 879 {
880 if (list == IntPtr.Zero) 880 if (nativeList == IntPtr.Zero)
881 throw new ArgumentException("list is null", nameof(list)); 881 throw new ArgumentException("nativeList is null", nameof(nativeList));
882 882
883 IntPtr l; 883 IntPtr l;
884 884 List<T> list = new List<T>();
885 for (l = list; l != IntPtr.Zero; l = Eina.ListNativeFunctions.eina_list_next_custom_export_mono(l)) 885 for (l = nativeList; l != IntPtr.Zero; l = Eina.ListNativeFunctions.eina_list_next_custom_export_mono(l))
886 { 886 {
887 yield return Eina.TraitFunctions.NativeToManaged<T>(Eina.ListNativeFunctions.eina_list_data_get_custom_export_mono(l)); 887 list.Add(Eina.TraitFunctions.NativeToManaged<T>(Eina.ListNativeFunctions.eina_list_data_get_custom_export_mono(l)));
888 } 888 }
889 return list;
889 } 890 }
890 891
891 internal static IntPtr IEnumerableToList<T>(IEnumerable<T> enumerable) 892 internal static IntPtr IListToNativeList<T>(IList<T> list, bool isMoved)
892 { 893 {
893 if (enumerable == null) 894 if (list == null)
894 throw new ArgumentException("enumerable is null", nameof(enumerable)); 895 throw new ArgumentException("list is null", nameof(list));
895 896
896 IntPtr list = IntPtr.Zero; 897 // If we are a wrapper around an existing Eina.List, we can just forward
897 foreach (T data in enumerable) 898 // it and avoid unnecessary copying in non-owning transfers.
899 var wrappedList = list as Eina.List<T>;
900
901 if (wrappedList != null && !isMoved)
902 {
903 return wrappedList.Handle;
904 }
905
906 IntPtr nativeList = IntPtr.Zero;
907 foreach (T data in list)
898 { 908 {
899 list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data)); 909 nativeList = Eina.ListNativeFunctions.eina_list_append(nativeList, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free
900 } 910 }
911
912 if (!isMoved)
913 {
914 // FIXME Need to free ret and unpin pinnedArray in the future.
915 }
916
917 return nativeList;
918 }
919
920 internal static IList<T> NativeArrayToIList<T>(IntPtr nativeArray)
921 {
922 if (nativeArray == IntPtr.Zero)
923 throw new ArgumentException("nativeArray is null", nameof(nativeArray));
924
925 List<T> list = new List<T>();
926 UpdateListFromNativeArray(list, nativeArray);
927
901 // FIXME need to free `list` if the returned list is not @moved 928 // FIXME need to free `list` if the returned list is not @moved
902 return list; 929 return list;
903 } 930 }
904 931
932 internal static IntPtr IListToNativeArray<T>(IList<T> list, bool isMoved)
933 {
934 if (list == null)
935 throw new ArgumentException("list is null", nameof(list));
936
937 // If we are a wrapper around an existing Eina.Array, we can just forward
938 // it and avoid unnecessary copying in non-owning transfers.
939 var wrappedArray = list as Eina.Array<T>;
940
941 if (wrappedArray != null && !isMoved)
942 {
943 return wrappedArray.Handle;
944 }
945
946 IntPtr nativeArray = Eina.ArrayNativeFunctions.eina_array_new(4);
947 foreach (T data in list)
948 {
949 Eina.ArrayNativeFunctions.eina_array_push_custom_export_mono(nativeArray, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free
950 }
951
952 if (!isMoved)
953 {
954 // FIXME Need to free ret and unpin pinnedArray in the future.
955 }
956
957 return nativeArray;
958 }
959
960 internal static void UpdateListFromNativeArray<T>(IList<T> list, IntPtr nativeArray)
961 {
962 // Do not update if list Handle is same to nativeArray. They already updated in native code.
963 var wrappedArray = list as Eina.Array<T>;
964 if (wrappedArray != null && wrappedArray.Handle == nativeArray)
965 return;
966
967 list.Clear();
968 if (nativeArray == IntPtr.Zero)
969 {
970 return;
971 }
972
973 uint count = Eina.ArrayNativeFunctions.eina_array_count_custom_export_mono(nativeArray);
974 for (uint i = 0; i < count; i++)
975 {
976 list.Add(Eina.TraitFunctions.NativeToManaged<T>(Eina.ArrayNativeFunctions.eina_array_data_get_custom_export_mono(nativeArray, i)));
977 }
978 }
905 979
906} // Globals 980} // Globals
907 981