summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-06-09 15:33:38 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 18:25:44 -0300
commit5315ce15edb8d3dc800a6f4d290a92dc5e2404a0 (patch)
tree6fce7dc85006d780bc8c3ae10996e4f6912c5cce
parent2624e91cbaa2045117c91688974f973c1bdf2bf5 (diff)
eolian_mono eina_mono: add missing traits and corrections
Still missing eolian keyword for Eina Inarray
-rw-r--r--src/bin/eolian_mono/eolian/mono/parameter.hh2
-rw-r--r--src/bindings/mono/eina_mono/eina_container_common.cs119
-rw-r--r--src/bindings/mono/eina_mono/eina_inarray.cs38
-rw-r--r--src/lib/efl_mono/efl_custom_exports_mono.c6
4 files changed, 141 insertions, 24 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh b/src/bin/eolian_mono/eolian/mono/parameter.hh
index 1080f992d9..c2b7de6e4f 100644
--- a/src/bin/eolian_mono/eolian/mono/parameter.hh
+++ b/src/bin/eolian_mono/eolian/mono/parameter.hh
@@ -716,7 +716,7 @@ struct convert_out_assign_generator
716 || param_is_acceptable(param, "Eina_Inarray *", WANT_OWN, WANT_OUT) 716 || param_is_acceptable(param, "Eina_Inarray *", WANT_OWN, WANT_OUT)
717 || param_is_acceptable(param, "Eina_Inarray *", !WANT_OWN, WANT_OUT) 717 || param_is_acceptable(param, "Eina_Inarray *", !WANT_OWN, WANT_OUT)
718 || param_is_acceptable(param, "const Eina_Inarray *", WANT_OWN, WANT_OUT) 718 || param_is_acceptable(param, "const Eina_Inarray *", WANT_OWN, WANT_OUT)
719 || param_is_acceptable(param, "const Eina_Inarray *", !WANT_OWN, WANT_OUT 719 || param_is_acceptable(param, "const Eina_Inarray *", !WANT_OWN, WANT_OUT)
720 || param_is_acceptable(param, "Eina_List *", WANT_OWN, WANT_OUT) 720 || param_is_acceptable(param, "Eina_List *", WANT_OWN, WANT_OUT)
721 || param_is_acceptable(param, "Eina_List *", !WANT_OWN, WANT_OUT) 721 || param_is_acceptable(param, "Eina_List *", !WANT_OWN, WANT_OUT)
722 || param_is_acceptable(param, "const Eina_List *", WANT_OWN, WANT_OUT) 722 || param_is_acceptable(param, "const Eina_List *", WANT_OWN, WANT_OUT)
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs
index 67ee4d6748..f9c6f082fe 100644
--- a/src/bindings/mono/eina_mono/eina_container_common.cs
+++ b/src/bindings/mono/eina_mono/eina_container_common.cs
@@ -6,6 +6,7 @@ using eina.Callbacks;
6using static eina.HashNativeFunctions; 6using static eina.HashNativeFunctions;
7using static eina.InarrayNativeFunctions; 7using static eina.InarrayNativeFunctions;
8using static eina.NativeCustomExportFunctions; 8using static eina.NativeCustomExportFunctions;
9using static eina.ContainerCommonData;
9 10
10namespace eina { 11namespace eina {
11 12
@@ -16,6 +17,8 @@ public static class NativeCustomExportFunctions
16{ 17{
17 [DllImport("eflcustomexportsmono")] public static extern void 18 [DllImport("eflcustomexportsmono")] public static extern void
18 efl_mono_native_free(IntPtr ptr); 19 efl_mono_native_free(IntPtr ptr);
20 [DllImport("eflcustomexportsmono")] public static extern void
21 efl_mono_native_free_ref(IntPtr ptr);
19 [DllImport("eflcustomexportsmono")] public static extern IntPtr 22 [DllImport("eflcustomexportsmono")] public static extern IntPtr
20 efl_mono_native_alloc_copy(IntPtr val, uint size); 23 efl_mono_native_alloc_copy(IntPtr val, uint size);
21 [DllImport("eflcustomexportsmono")] public static extern IntPtr 24 [DllImport("eflcustomexportsmono")] public static extern IntPtr
@@ -32,6 +35,11 @@ public static class NativeCustomExportFunctions
32 efl_mono_native_efl_unref_addr_get(); 35 efl_mono_native_efl_unref_addr_get();
33} 36}
34 37
38public static class ContainerCommonData
39{
40 public static IBaseElementTraits<IntPtr> intPtrTraits = null;
41}
42
35[StructLayout(LayoutKind.Sequential)] 43[StructLayout(LayoutKind.Sequential)]
36public struct ConvertWrapper<T> 44public struct ConvertWrapper<T>
37{ 45{
@@ -58,9 +66,13 @@ public interface IBaseElementTraits<T>
58{ 66{
59 IntPtr ManagedToNativeAlloc(T man); 67 IntPtr ManagedToNativeAlloc(T man);
60 IntPtr ManagedToNativeAllocRef(T man, bool refs = false); 68 IntPtr ManagedToNativeAllocRef(T man, bool refs = false);
69 IntPtr ManagedToNativeAllocInplace(T man);
61 void NativeFree(IntPtr nat); 70 void NativeFree(IntPtr nat);
62 void NativeFreeRef(IntPtr nat, bool unrefs = false); 71 void NativeFreeRef(IntPtr nat, bool unrefs = false);
72 void NativeFreeInplace(IntPtr nat);
73 void ResidueFreeInplace(IntPtr nat);
63 T NativeToManaged(IntPtr nat); 74 T NativeToManaged(IntPtr nat);
75 T NativeToManagedInplace(IntPtr nat);
64 IntPtr EinaCompareCb(); 76 IntPtr EinaCompareCb();
65 IntPtr EinaFreeCb(); 77 IntPtr EinaFreeCb();
66 IntPtr EinaHashNew(); 78 IntPtr EinaHashNew();
@@ -69,6 +81,13 @@ public interface IBaseElementTraits<T>
69 81
70public class StringElementTraits<T> : IBaseElementTraits<T> 82public class StringElementTraits<T> : IBaseElementTraits<T>
71{ 83{
84
85 public StringElementTraits()
86 {
87 if (intPtrTraits == null)
88 intPtrTraits = TraitFunctions.GetTypeTraits<IntPtr>();
89 }
90
72 public IntPtr ManagedToNativeAlloc(T man) 91 public IntPtr ManagedToNativeAlloc(T man)
73 { 92 {
74 return efl_mono_native_strdup((string)(object)man); 93 return efl_mono_native_strdup((string)(object)man);
@@ -80,6 +99,11 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
80 return ManagedToNativeAlloc(man); 99 return ManagedToNativeAlloc(man);
81 } 100 }
82 101
102 public IntPtr ManagedToNativeAllocInplace(T man)
103 {
104 return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man));
105 }
106
83 public void NativeFree(IntPtr nat) 107 public void NativeFree(IntPtr nat)
84 { 108 {
85 if (nat != IntPtr.Zero) 109 if (nat != IntPtr.Zero)
@@ -91,6 +115,16 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
91 NativeFree(nat); 115 NativeFree(nat);
92 } 116 }
93 117
118 public void NativeFreeInplace(IntPtr nat)
119 {
120 efl_mono_native_free_ref(nat);
121 }
122
123 public void ResidueFreeInplace(IntPtr nat)
124 {
125 intPtrTraits.NativeFree(nat);
126 }
127
94 public T NativeToManaged(IntPtr nat) 128 public T NativeToManaged(IntPtr nat)
95 { 129 {
96 if (nat == IntPtr.Zero) 130 if (nat == IntPtr.Zero)
@@ -98,6 +132,13 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
98 return (T)(object)Marshal.PtrToStringAuto(nat); 132 return (T)(object)Marshal.PtrToStringAuto(nat);
99 } 133 }
100 134
135 public T NativeToManagedInplace(IntPtr nat)
136 {
137 if (nat == IntPtr.Zero)
138 return default(T);
139 return NativeToManaged(intPtrTraits.NativeToManaged(nat));
140 }
141
101 public IntPtr EinaCompareCb() 142 public IntPtr EinaCompareCb()
102 { 143 {
103 return efl_mono_native_str_compare_addr_get(); 144 return efl_mono_native_str_compare_addr_get();
@@ -115,14 +156,13 @@ public class StringElementTraits<T> : IBaseElementTraits<T>
115 156
116 public IntPtr EinaInarrayNew(uint step) 157 public IntPtr EinaInarrayNew(uint step)
117 { 158 {
118 return eina_inarray_new(Marshal.SizeOf<IntPtr>(), step); 159 return eina_inarray_new((uint)Marshal.SizeOf<IntPtr>(), step);
119 } 160 }
120} 161}
121 162
122public class EflObjectElementTraits<T> : IBaseElementTraits<T> 163public class EflObjectElementTraits<T> : IBaseElementTraits<T>
123{ 164{
124 private System.Type concreteType = null; 165 private System.Type concreteType = null;
125 private static IBaseElementTraits<IntPtr> intPtrTraits = null;
126 166
127 public EflObjectElementTraits(System.Type concrete) 167 public EflObjectElementTraits(System.Type concrete)
128 { 168 {
@@ -146,6 +186,11 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
146 return intPtrTraits.ManagedToNativeAlloc(h); 186 return intPtrTraits.ManagedToNativeAlloc(h);
147 } 187 }
148 188
189 public IntPtr ManagedToNativeAllocInplace(T man)
190 {
191 return intPtrTraits.ManagedToNativeAlloc(ManagedToNativeAlloc(man));
192 }
193
149 public void NativeFree(IntPtr nat) 194 public void NativeFree(IntPtr nat)
150 { 195 {
151 if (nat != IntPtr.Zero) 196 if (nat != IntPtr.Zero)
@@ -159,6 +204,16 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
159 intPtrTraits.NativeFree(nat); 204 intPtrTraits.NativeFree(nat);
160 } 205 }
161 206
207 public void NativeFreeInplace(IntPtr nat)
208 {
209 NativeFree(intPtrTraits.NativeToManaged(nat));
210 }
211
212 public void ResidueFreeInplace(IntPtr nat)
213 {
214 intPtrTraits.NativeFree(nat);
215 }
216
162 public T NativeToManaged(IntPtr nat) 217 public T NativeToManaged(IntPtr nat)
163 { 218 {
164 if (nat == IntPtr.Zero) 219 if (nat == IntPtr.Zero)
@@ -166,6 +221,13 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
166 return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat)); 221 return (T) Activator.CreateInstance(concreteType, efl.eo.Globals.efl_ref(nat));
167 } 222 }
168 223
224 public T NativeToManagedInplace(IntPtr nat)
225 {
226 if (nat == IntPtr.Zero)
227 return default(T);
228 return NativeToManaged(intPtrTraits.NativeToManaged(nat));
229 }
230
169 public IntPtr EinaCompareCb() 231 public IntPtr EinaCompareCb()
170 { 232 {
171 return efl_mono_native_ptr_compare_addr_get(); 233 return efl_mono_native_ptr_compare_addr_get();
@@ -183,7 +245,7 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
183 245
184 public IntPtr EinaInarrayNew(uint step) 246 public IntPtr EinaInarrayNew(uint step)
185 { 247 {
186 return eina_inarray_new(Marshal.SizeOf<IntPtr>(), step); 248 return eina_inarray_new((uint)Marshal.SizeOf<IntPtr>(), step);
187 } 249 }
188} 250}
189 251
@@ -191,6 +253,15 @@ public abstract class PrimitiveElementTraits<T>
191{ 253{
192 private Eina_Compare_Cb dlgt = null; 254 private Eina_Compare_Cb dlgt = null;
193 255
256 public PrimitiveElementTraits()
257 {
258 if (intPtrTraits == null)
259 if (typeof(T) == typeof(IntPtr)) // avoid infinite recursion
260 intPtrTraits = (IBaseElementTraits<IntPtr>)this;
261 else
262 intPtrTraits = TraitFunctions.GetTypeTraits<IntPtr>();
263 }
264
194 public IntPtr ManagedToNativeAlloc(T man) 265 public IntPtr ManagedToNativeAlloc(T man)
195 { 266 {
196 GCHandle pinnedData = GCHandle.Alloc(man, GCHandleType.Pinned); 267 GCHandle pinnedData = GCHandle.Alloc(man, GCHandleType.Pinned);
@@ -200,11 +271,26 @@ public abstract class PrimitiveElementTraits<T>
200 return nat; 271 return nat;
201 } 272 }
202 273
274 public IntPtr ManagedToNativeAllocInplace(T man)
275 {
276 return ManagedToNativeAlloc(man);
277 }
278
203 public void NativeFree(IntPtr nat) 279 public void NativeFree(IntPtr nat)
204 { 280 {
205 efl_mono_native_free(nat); 281 efl_mono_native_free(nat);
206 } 282 }
207 283
284 public void NativeFreeInplace(IntPtr nat)
285 {
286 // Do nothing
287 }
288
289 public void ResidueFreeInplace(IntPtr nat)
290 {
291 NativeFree(nat);
292 }
293
208 public T NativeToManaged(IntPtr nat) 294 public T NativeToManaged(IntPtr nat)
209 { 295 {
210 if (nat == IntPtr.Zero) 296 if (nat == IntPtr.Zero)
@@ -216,6 +302,11 @@ public abstract class PrimitiveElementTraits<T>
216 return w.Val; 302 return w.Val;
217 } 303 }
218 304
305 public T NativeToManagedInplace(IntPtr nat)
306 {
307 return NativeToManaged(nat);
308 }
309
219 private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2) 310 private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2)
220 { 311 {
221 var m1 = (IComparable) NativeToManaged(ptr1); 312 var m1 = (IComparable) NativeToManaged(ptr1);
@@ -237,7 +328,7 @@ public abstract class PrimitiveElementTraits<T>
237 328
238 public IntPtr EinaInarrayNew(uint step) 329 public IntPtr EinaInarrayNew(uint step)
239 { 330 {
240 return eina_inarray_new(Marshal.SizeOf<T>(), step); 331 return eina_inarray_new((uint)Marshal.SizeOf<T>(), step);
241 } 332 }
242} 333}
243 334
@@ -384,6 +475,11 @@ public static class TraitFunctions
384 return GetTypeTraits<T>().ManagedToNativeAllocRef(man, refs); 475 return GetTypeTraits<T>().ManagedToNativeAllocRef(man, refs);
385 } 476 }
386 477
478 public static IntPtr ManagedToNativeAllocInplace<T>(T man)
479 {
480 return GetTypeTraits<T>().ManagedToNativeAllocInplace(man);
481 }
482
387 public static void NativeFree<T>(IntPtr nat) 483 public static void NativeFree<T>(IntPtr nat)
388 { 484 {
389 GetTypeTraits<T>().NativeFree(nat); 485 GetTypeTraits<T>().NativeFree(nat);
@@ -394,11 +490,26 @@ public static class TraitFunctions
394 GetTypeTraits<T>().NativeFreeRef(nat, unrefs); 490 GetTypeTraits<T>().NativeFreeRef(nat, unrefs);
395 } 491 }
396 492
493 public static void NativeFreeInplace<T>(IntPtr nat)
494 {
495 GetTypeTraits<T>().NativeFreeInplace(nat);
496 }
497
498 public static void ResidueFreeInplace<T>(IntPtr nat)
499 {
500 GetTypeTraits<T>().ResidueFreeInplace(nat);
501 }
502
397 public static T NativeToManaged<T>(IntPtr nat) 503 public static T NativeToManaged<T>(IntPtr nat)
398 { 504 {
399 return GetTypeTraits<T>().NativeToManaged(nat); 505 return GetTypeTraits<T>().NativeToManaged(nat);
400 } 506 }
401 507
508 public static T NativeToManagedInplace<T>(IntPtr nat)
509 {
510 return GetTypeTraits<T>().NativeToManagedInplace(nat);
511 }
512
402 // Misc // 513 // Misc //
403 514
404 public static IntPtr EinaCompareCb<T>() 515 public static IntPtr EinaCompareCb<T>()
diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs
index 1daf7dd9f8..b2c55254be 100644
--- a/src/bindings/mono/eina_mono/eina_inarray.cs
+++ b/src/bindings/mono/eina_mono/eina_inarray.cs
@@ -128,7 +128,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
128 uint len = eina_inarray_count(h); 128 uint len = eina_inarray_count(h);
129 for(uint i = 0; i < len; ++i) 129 for(uint i = 0; i < len; ++i)
130 { 130 {
131 InarrayNativeFree<T>(eina_inarray_nth(h, i)); 131 NativeFreeInplace<T>(eina_inarray_nth(h, i));
132 } 132 }
133 } 133 }
134 134
@@ -161,7 +161,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
161 int len = Length; 161 int len = Length;
162 for (int i = 0; i < len; ++i) 162 for (int i = 0; i < len; ++i)
163 { 163 {
164 InarrayNativeFree<T>(eina_inarray_nth(Handle, i)); 164 NativeFreeInplace<T>(eina_inarray_nth(Handle, (uint)i));
165 } 165 }
166 } 166 }
167 } 167 }
@@ -191,12 +191,12 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
191 191
192 public int Push(T val) 192 public int Push(T val)
193 { 193 {
194 IntPtr ele = InarrayManagedToNativeAlloc(val); 194 IntPtr ele = ManagedToNativeAllocInplace(val);
195 var r = eina_inarray_push(Handle, ele); 195 var r = eina_inarray_push(Handle, ele);
196 if (r == -1) 196 if (r == -1)
197 InarrayNativeFree<T>(ele); 197 NativeFreeInplace<T>(ele);
198 else 198 else
199 InarrayTempFree<T>(ele); 199 ResidueFreeInplace<T>(ele);
200 return r; 200 return r;
201 } 201 }
202 202
@@ -210,16 +210,16 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
210 public T Pop() 210 public T Pop()
211 { 211 {
212 IntPtr ele = eina_inarray_pop(Handle); 212 IntPtr ele = eina_inarray_pop(Handle);
213 var r = InarrayNativeToManaged<T>(ele); 213 var r = NativeToManagedInplace<T>(ele);
214 if (OwnContent && ele != IntPtr.Zero) 214 if (OwnContent && ele != IntPtr.Zero)
215 InarrayNativeFree<T>(ele); 215 NativeFreeInplace<T>(ele);
216 return r; 216 return r;
217 } 217 }
218 218
219 public T Nth(uint idx) 219 public T Nth(uint idx)
220 { 220 {
221 IntPtr ele = eina_inarray_nth(Handle, idx); 221 IntPtr ele = eina_inarray_nth(Handle, idx);
222 return InarrayNativeToManaged<T>(ele); 222 return NativeToManagedInplace<T>(ele);
223 } 223 }
224 224
225 public T At(int idx) 225 public T At(int idx)
@@ -229,12 +229,12 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
229 229
230 public bool InsertAt(uint idx, T val) 230 public bool InsertAt(uint idx, T val)
231 { 231 {
232 IntPtr ele = InarrayManagedToNativeAlloc(val); 232 IntPtr ele = ManagedToNativeAllocInplace(val);
233 var r = eina_inarray_insert_at(Handle, idx, ele); 233 var r = eina_inarray_insert_at(Handle, idx, ele);
234 if (r) 234 if (r)
235 InarrayTempFree<T>(ele); 235 ResidueFreeInplace<T>(ele);
236 else 236 else
237 InarrayNativeFree<T>(ele); 237 NativeFreeInplace<T>(ele);
238 return r; 238 return r;
239 } 239 }
240 240
@@ -244,13 +244,13 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
244 if (ele == IntPtr.Zero) 244 if (ele == IntPtr.Zero)
245 return false; 245 return false;
246 if (OwnContent) 246 if (OwnContent)
247 InarrayNativeFree<T>(ele); 247 NativeFreeInplace<T>(ele);
248 ele = InarrayManagedToNativeAlloc(val); 248 ele = ManagedToNativeAllocInplace(val);
249 var r = eina_inarray_insert_at(Handle, idx, ele); 249 var r = eina_inarray_insert_at(Handle, idx, ele);
250 if (r) 250 if (r)
251 InarrayTempFree<T>(ele); 251 ResidueFreeInplace<T>(ele);
252 else 252 else
253 InarrayNativeFree<T>(ele); 253 NativeFreeInplace<T>(ele);
254 return r; 254 return r;
255 } 255 }
256 256
@@ -262,7 +262,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
262 } 262 }
263 set 263 set
264 { 264 {
265 ReplaceAt(idx, value); 265 ReplaceAt((uint)idx, value);
266 } 266 }
267 } 267 }
268 268
@@ -272,12 +272,12 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
272 if (ele == IntPtr.Zero) 272 if (ele == IntPtr.Zero)
273 return false; 273 return false;
274 if (OwnContent) 274 if (OwnContent)
275 InarrayNativeFree<T>(ele); 275 NativeFreeInplace<T>(ele);
276 276
277 return eina_inarray_remove_at(Handle, idx); 277 return eina_inarray_remove_at(Handle, idx);
278 } 278 }
279 279
280 public bool Reverse() 280 public void Reverse()
281 { 281 {
282 eina_inarray_reverse(Handle); 282 eina_inarray_reverse(Handle);
283 } 283 }
@@ -288,7 +288,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
288 var managed = new T[len]; 288 var managed = new T[len];
289 for(int i = 0; i < len; ++i) 289 for(int i = 0; i < len; ++i)
290 { 290 {
291 managed[i] = DataGet(i); 291 managed[i] = At(i);
292 } 292 }
293 return managed; 293 return managed;
294 } 294 }
diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c
index c61927de2e..efc5fe6745 100644
--- a/src/lib/efl_mono/efl_custom_exports_mono.c
+++ b/src/lib/efl_mono/efl_custom_exports_mono.c
@@ -32,6 +32,12 @@ EAPI void efl_mono_native_free(void *ptr)
32 free(ptr); 32 free(ptr);
33} 33}
34 34
35EAPI void efl_mono_native_free_ref(void **ptr)
36{
37 if (!ptr) return;
38 free(*ptr);
39}
40
35EAPI void *efl_mono_native_alloc_copy(const void *val, unsigned int size) 41EAPI void *efl_mono_native_alloc_copy(const void *val, unsigned int size)
36{ 42{
37 if (!val) return NULL; 43 if (!val) return NULL;