csharp: fix EFL# by updating it to reflect the newest changes in Eolian
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>
Fri, 26 Jul 2019 17:40:38 +0000 (14:40 -0300)
committerWooHyun Jung <wh0705.jung@samsung.com>
Mon, 5 Aug 2019 01:48:27 +0000 (10:48 +0900)
Summary:
`Efl.Event` became a builtin type that is no longer declared in `efl_object.eo`,
and therefore it is no longer automatically generated in EFL#.
Given that, we define a struct manually to reflect the memory layout of the
native struct.

Containers of value types are now allowed in eolian, so tests that were disabled
because of the restriction on `ptr` were re-enabled using the plain type.

But since these containers have just arrived, handling of ownership for value
types is currently undefined in bindings.
Hence, tests that used `ptr(int) @owned` as elements were left disable.
This will be solved in a future patch.

`void_pr` is now deprecated, so we remove it from tests also.

Reviewers: q66, segfaultxavi, lauromoura, felipealmeida

Reviewed By: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D9417

src/bindings/mono/eo_mono/workaround.cs
src/tests/efl_mono/Eina.cs
src/tests/efl_mono/StructHelpers.cs
src/tests/efl_mono/dummy_test_object.c
src/tests/efl_mono/dummy_test_object.eo

index 80c6bdc..fdaa621 100644 (file)
@@ -108,6 +108,88 @@ public struct EventDescription
     }
 };
 
+/// <summary>
+/// A parameter passed in event callbacks holding extra event parameters.
+/// This is the full event information passed to callbacks in C.
+/// (Since EFL 1.22)
+/// </summary>
+[StructLayout(LayoutKind.Sequential)]
+[Efl.Eo.BindingEntity]
+public struct Event
+{
+    /// <summary>The object the callback was called on.
+    /// (Since EFL 1.22)</summary>
+    public Efl.Object Object;
+
+    /// <summary>The event description.
+    /// (Since EFL 1.22)</summary>
+    public Efl.EventDescription Desc;
+
+    /// <summary>Extra event information passed by the event caller.
+    /// Must be cast to the event type declared in the EO file. Keep in mind that:
+    /// 1) Objects are passed as a normal Eo*. Event subscribers can call functions on these objects.
+    /// 2) Structs, built-in types and containers are passed as const pointers, with one level of indirection.
+    /// (Since EFL 1.22)</summary>
+    public System.IntPtr Info;
+
+    /// <summary>Constructor for Event.</summary>
+    public Event(
+        Efl.Object obj = default(Efl.Object),
+        Efl.EventDescription desc = default(Efl.EventDescription),
+        System.IntPtr info = default(System.IntPtr))
+    {
+        this.Object = obj;
+        this.Desc = desc;
+        this.Info = info;
+    }
+
+    /// <summary>Implicit conversion to the managed representation from a native pointer.</summary>
+    /// <param name="ptr">Native pointer to be converted.</param>
+    public static implicit operator Event(IntPtr ptr)
+    {
+        var tmp = (Event.NativeStruct) Marshal.PtrToStructure(ptr, typeof(Event.NativeStruct));
+        return tmp;
+    }
+
+    /// <summary>Internal wrapper for struct Event.</summary>
+    [StructLayout(LayoutKind.Sequential)]
+    public struct NativeStruct
+    {
+        /// <summary>Internal wrapper for field Object</summary>
+        public System.IntPtr Object;
+
+        /// <summary>Internal wrapper for field Desc</summary>
+        public System.IntPtr Desc;
+
+        /// <summary>Internal wrapper for field Info</summary>
+        public System.IntPtr Info;
+
+        /// <summary>Implicit conversion to the internal/marshalling representation.</summary>
+        /// <param name="externalStruct">Managed struct to be converted.</param>
+        /// <returns>Native representation of the managed struct.</returns>
+        public static implicit operator Event.NativeStruct(Event externalStruct)
+        {
+            var internalStruct = new Event.NativeStruct();
+            internalStruct.Object = externalStruct.Object?.NativeHandle ?? System.IntPtr.Zero;
+            internalStruct.Desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(externalStruct.Desc);
+            internalStruct.Info = externalStruct.Info;
+            return internalStruct;
+        }
+
+        /// <summary>Implicit conversion to the managed representation.</summary>
+        /// <param name="internalStruct">Native struct to be converted.</param>
+        /// <returns>Managed representation of the native struct.</returns>
+        public static implicit operator Event(Event.NativeStruct internalStruct)
+        {
+            var externalStruct = new Event();
+            externalStruct.Object = (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(internalStruct.Object);
+            externalStruct.Desc = Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(internalStruct.Desc);
+            externalStruct.Info = internalStruct.Info;
+            return externalStruct;
+        }
+    }
+}
+
 public delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt);
 public delegate void FreeWrapperSupervisorCb(System.IntPtr obj);
 
index d71d6c8..07dfd1b 100644 (file)
@@ -826,7 +826,6 @@ class TestEinaArray
 
     // Integer //
 
-    /*
     public static void test_eina_array_int_in()
     {
         var t = new Dummy.TestObject();
@@ -839,6 +838,7 @@ class TestEinaArray
         Test.Assert(arr.Handle == IntPtr.Zero);
     }
 
+    /*
     public static void test_eina_array_int_in_own()
     {
         var t = new Dummy.TestObject();
@@ -851,6 +851,7 @@ class TestEinaArray
         Test.Assert(arr.Handle == IntPtr.Zero);
         Test.Assert(t.CheckEinaArrayIntInOwn());
     }
+    */
 
     public static void test_eina_array_int_out()
     {
@@ -865,6 +866,7 @@ class TestEinaArray
         Test.Assert(t.CheckEinaArrayIntOut());
     }
 
+    /*
     public static void test_eina_array_int_out_own()
     {
         var t = new Dummy.TestObject();
@@ -876,6 +878,7 @@ class TestEinaArray
         arr.Dispose();
         Test.Assert(arr.Handle == IntPtr.Zero);
     }
+    */
 
     public static void test_eina_array_int_return()
     {
@@ -889,6 +892,7 @@ class TestEinaArray
         Test.Assert(t.CheckEinaArrayIntReturn());
     }
 
+    /*
     public static void test_eina_array_int_return_own()
     {
         var t = new Dummy.TestObject();
@@ -1886,7 +1890,6 @@ class TestEinaList
 
     // Integer //
 
-    /*
     public static void test_eina_list_int_in()
     {
         var t = new Dummy.TestObject();
@@ -1899,6 +1902,7 @@ class TestEinaList
         Test.Assert(lst.Handle == IntPtr.Zero);
     }
 
+    /*
     public static void test_eina_list_int_in_own()
     {
         var t = new Dummy.TestObject();
@@ -1910,6 +1914,7 @@ class TestEinaList
         Test.Assert(lst.Handle == IntPtr.Zero);
         Test.Assert(t.CheckEinaListIntInOwn());
     }
+    */
 
     public static void test_eina_list_int_out()
     {
@@ -1923,6 +1928,7 @@ class TestEinaList
         Test.Assert(t.CheckEinaListIntOut());
     }
 
+    /*
     public static void test_eina_list_int_out_own()
     {
         var t = new Dummy.TestObject();
@@ -1934,6 +1940,7 @@ class TestEinaList
         lst.Dispose();
         Test.Assert(lst.Handle == IntPtr.Zero);
     }
+    */
 
     public static void test_eina_list_int_return()
     {
@@ -1946,6 +1953,7 @@ class TestEinaList
         Test.Assert(t.CheckEinaListIntReturn());
     }
 
+    /*
     public static void test_eina_list_int_return_own()
     {
         var t = new Dummy.TestObject();
@@ -2666,7 +2674,6 @@ class TestEinaHash
 
     // Integer //
 
-    /*
     public static void test_eina_hash_int_in()
     {
         var t = new Dummy.TestObject();
@@ -2680,6 +2687,7 @@ class TestEinaHash
         Test.Assert(hsh.Handle == IntPtr.Zero);
     }
 
+    /*
     public static void test_eina_hash_int_in_own()
     {
         var t = new Dummy.TestObject();
@@ -2694,6 +2702,7 @@ class TestEinaHash
         Test.Assert(hsh.Handle == IntPtr.Zero);
         Test.Assert(t.CheckEinaHashIntInOwn());
     }
+    */
 
     public static void test_eina_hash_int_out()
     {
@@ -2709,6 +2718,7 @@ class TestEinaHash
         Test.Assert(t.CheckEinaHashIntOut());
     }
 
+    /*
     public static void test_eina_hash_int_out_own()
     {
         var t = new Dummy.TestObject();
@@ -2722,6 +2732,7 @@ class TestEinaHash
         Test.Assert(hsh.Handle == IntPtr.Zero);
         Test.Assert(t.CheckEinaHashIntOutOwn());
     }
+    */
 
     public static void test_eina_hash_int_return()
     {
@@ -2736,6 +2747,7 @@ class TestEinaHash
         Test.Assert(t.CheckEinaHashIntReturn());
     }
 
+    /*
     public static void test_eina_hash_int_return_own()
     {
         var t = new Dummy.TestObject();
index 110432f..7af3529 100644 (file)
@@ -41,7 +41,6 @@ internal class StructHelpers
         simple.Ffloat = -16777216.0f;
         simple.Fdouble = -9007199254740992.0;
         simple.Fbool = true;
-        simple.Fvoid_ptr = (IntPtr) 0xFE;
         simple.Fenum = Dummy.SampleEnum.V2;
         simple.Fstring = "test/string";
         simple.Fmstring = "test/mstring";
@@ -78,7 +77,6 @@ internal class StructHelpers
         Test.Assert(simple.Ffloat == -16777216.0f);
         Test.Assert(simple.Fdouble == -9007199254740992.0);
         Test.Assert(simple.Fbool == true);
-        Test.Assert(simple.Fvoid_ptr == (IntPtr) 0xFE);
         Test.Assert(simple.Fenum == Dummy.SampleEnum.V2);
         Test.Assert(simple.Fstring == "test/string");
         Test.Assert(simple.Fmstring == "test/mstring");
@@ -113,7 +111,6 @@ internal class StructHelpers
         Test.Assert(simple.Ffloat == 0);
         Test.Assert(simple.Fdouble == 0);
         Test.Assert(simple.Fbool == false);
-        Test.Assert(simple.Fvoid_ptr == IntPtr.Zero);
         Test.Assert(simple.Fenum == Dummy.SampleEnum.V0);
         Test.Assert(simple.Fstring == null);
         Test.Assert(simple.Fmstring == null);
index e6bec29..6717b12 100644 (file)
@@ -4040,7 +4040,6 @@ void struct_simple_with_values(Dummy_StructSimple *simple)
    simple->ffloat = -16777216.0;
    simple->fdouble = -9007199254740992.0;
    simple->fbool = EINA_TRUE;
-   simple->fvoid_ptr = (void*) 0xFE;
    simple->fenum = DUMMY_SAMPLEENUM_V2;
    simple->fstring = "test/string";
    simple->fmstring = strdup("test/mstring");
@@ -4077,7 +4076,6 @@ Eina_Bool check_and_modify_struct_simple(Dummy_StructSimple *simple)
      && EQUAL(simple->ffloat, -16777216.0)
      && EQUAL(simple->fdouble, -9007199254740992.0)
      && EQUAL(simple->fbool, EINA_TRUE)
-     && EQUAL(simple->fvoid_ptr, (void*) 0xFE)
      && EQUAL(simple->fenum, DUMMY_SAMPLEENUM_V2)
      && STR_EQUAL(simple->fstring, "test/string")
      && STR_EQUAL(simple->fmstring, "test/mstring")
index 97b7cf6..2273c23 100644 (file)
@@ -51,7 +51,6 @@ struct @free(free) Dummy.StructSimple
    ffloat: float;
    fdouble: double;
    fbool: bool;
-   fvoid_ptr: void_ptr;
    fenum: Dummy.SampleEnum;
    // fboolptr: ptr(bool); // TODO
    // fbyteptr: ptr(byte);
@@ -379,27 +378,28 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
       /* Eina Array */
 
       /* Integer */
-      /*
       eina_array_int_in {
          params {
-            @in arr: array<ptr(int)>;
+            @in arr: array<int>;
          }
          return: bool;
       }
 
+      /*
       eina_array_int_in_own {
          params {
-            @in arr: array<free(ptr(int),free) @owned> @owned;
+            @in arr: array<int> @owned; // <int @owned>
          }
          return: bool;
       }
       check_eina_array_int_in_own {
          return: bool;
       }
+      */
 
       eina_array_int_out {
          params {
-            @out arr: array<ptr(int)>;
+            @out arr: array<int>;
          }
          return: bool;
       }
@@ -407,22 +407,25 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
          return: bool;
       }
 
+      /*
       eina_array_int_out_own {
          params {
-            @out arr: array<free(ptr(int),free) @owned> @owned;
+            @out arr: array<int> @owned; // <int @owned>
          }
          return: bool;
       }
+      */
 
       eina_array_int_return {
-         return: array<ptr(int)>;
+         return: array<int>;
       }
       check_eina_array_int_return {
          return: bool;
       }
 
+      /*
       eina_array_int_return_own {
-         return: array<free(ptr(int),free) @owned> @owned;
+         return: array<int> @owned; // <int @owned>
       }
       */
 
@@ -574,27 +577,28 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
       /* Eina List */
 
       /* Integer */
-      /*
       eina_list_int_in {
          params {
-            @in lst: list<ptr(int)>;
+            @in lst: list<int>;
          }
          return: bool;
       }
 
+      /*
       eina_list_int_in_own {
          params {
-            @in lst: list<free(ptr(int),free) @owned> @owned;
+            @in lst: list<int> @owned; // <int @owned>
          }
          return: bool;
       }
       check_eina_list_int_in_own {
          return: bool;
       }
+      */
 
       eina_list_int_out {
          params {
-            @out lst: list<ptr(int)>;
+            @out lst: list<int>;
          }
          return: bool;
       }
@@ -602,22 +606,25 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
          return: bool;
       }
 
+      /*
       eina_list_int_out_own {
          params {
-            @out lst: list<free(ptr(int),free) @owned> @owned;
+            @out lst: list<int> @owned; // <int @owned>
          }
          return: bool;
       }
+      */
 
       eina_list_int_return {
-         return: list<ptr(int)>;
+         return: list<int>;
       }
       check_eina_list_int_return {
          return: bool;
       }
 
+      /*
       eina_list_int_return_own {
-         return: list<free(ptr(int),free) @owned> @owned;
+         return: list<int> @owned; // <int @owned>
       }
       */
 
@@ -769,27 +776,28 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
       // Eina Hash //
 
       // Integer //
-      /*
       eina_hash_int_in {
          params {
-            @in hsh: hash<ptr(int), ptr(int)>;
+            @in hsh: hash<int, int>;
          }
          return: bool;
       }
 
+      /*
       eina_hash_int_in_own {
          params {
-            @in hsh: hash<ptr(int), free(ptr(int),free) @owned> @owned;
+            @in hsh: hash<int, int> @owned; // <, int @owned>
          }
          return: bool;
       }
       check_eina_hash_int_in_own {
          return: bool;
       }
+      */
 
       eina_hash_int_out {
          params {
-            @out hsh: hash<ptr(int), ptr(int)>;
+            @out hsh: hash<int, int>;
          }
          return: bool;
       }
@@ -797,25 +805,28 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
          return: bool;
       }
 
+      /*
       eina_hash_int_out_own {
          params {
-            @out hsh: hash<ptr(int), free(ptr(int),free) @owned> @owned;
+            @out hsh: hash<int, int> @owned; // <, int @owned>
          }
          return: bool;
       }
       check_eina_hash_int_out_own {
          return: bool;
       }
+      */
 
       eina_hash_int_return {
-         return: hash<ptr(int), ptr(int)>;
+         return: hash<int, int>;
       }
       check_eina_hash_int_return {
          return: bool;
       }
 
+      /*
       eina_hash_int_return_own {
-         return: hash<ptr(int), free(ptr(int),free) @owned> @owned;
+         return: hash<int, int> @owned; // <, int @owned>
       }
       check_eina_hash_int_return_own {
          return: bool;