From c6f2ea9eba9e36fa964f60b8b7c32d0dfad16cf4 Mon Sep 17 00:00:00 2001 From: Vitor Sousa Date: Fri, 26 Jul 2019 14:40:38 -0300 Subject: [PATCH] csharp: fix EFL# by updating it to reflect the newest changes in Eolian 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 | 82 +++++++++++++++++++++++++++++++++ src/tests/efl_mono/Eina.cs | 18 ++++++-- src/tests/efl_mono/StructHelpers.cs | 3 -- src/tests/efl_mono/dummy_test_object.c | 2 - src/tests/efl_mono/dummy_test_object.eo | 55 +++++++++++++--------- 5 files changed, 130 insertions(+), 30 deletions(-) diff --git a/src/bindings/mono/eo_mono/workaround.cs b/src/bindings/mono/eo_mono/workaround.cs index 80c6bdc..fdaa621 100644 --- a/src/bindings/mono/eo_mono/workaround.cs +++ b/src/bindings/mono/eo_mono/workaround.cs @@ -108,6 +108,88 @@ public struct EventDescription } }; +/// +/// 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) +/// +[StructLayout(LayoutKind.Sequential)] +[Efl.Eo.BindingEntity] +public struct Event +{ + /// The object the callback was called on. + /// (Since EFL 1.22) + public Efl.Object Object; + + /// The event description. + /// (Since EFL 1.22) + public Efl.EventDescription Desc; + + /// 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) + public System.IntPtr Info; + + /// Constructor for Event. + 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; + } + + /// Implicit conversion to the managed representation from a native pointer. + /// Native pointer to be converted. + public static implicit operator Event(IntPtr ptr) + { + var tmp = (Event.NativeStruct) Marshal.PtrToStructure(ptr, typeof(Event.NativeStruct)); + return tmp; + } + + /// Internal wrapper for struct Event. + [StructLayout(LayoutKind.Sequential)] + public struct NativeStruct + { + /// Internal wrapper for field Object + public System.IntPtr Object; + + /// Internal wrapper for field Desc + public System.IntPtr Desc; + + /// Internal wrapper for field Info + public System.IntPtr Info; + + /// Implicit conversion to the internal/marshalling representation. + /// Managed struct to be converted. + /// Native representation of the managed struct. + 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; + } + + /// Implicit conversion to the managed representation. + /// Native struct to be converted. + /// Managed representation of the native struct. + 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(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); diff --git a/src/tests/efl_mono/Eina.cs b/src/tests/efl_mono/Eina.cs index d71d6c8..07dfd1b 100644 --- a/src/tests/efl_mono/Eina.cs +++ b/src/tests/efl_mono/Eina.cs @@ -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(); diff --git a/src/tests/efl_mono/StructHelpers.cs b/src/tests/efl_mono/StructHelpers.cs index 110432f..7af3529 100644 --- a/src/tests/efl_mono/StructHelpers.cs +++ b/src/tests/efl_mono/StructHelpers.cs @@ -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); diff --git a/src/tests/efl_mono/dummy_test_object.c b/src/tests/efl_mono/dummy_test_object.c index e6bec29..6717b12 100644 --- a/src/tests/efl_mono/dummy_test_object.c +++ b/src/tests/efl_mono/dummy_test_object.c @@ -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") diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo index 97b7cf6..2273c23 100644 --- a/src/tests/efl_mono/dummy_test_object.eo +++ b/src/tests/efl_mono/dummy_test_object.eo @@ -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; + @in arr: array; } return: bool; } + /* eina_array_int_in_own { params { - @in arr: array @owned; + @in arr: array @owned; // } return: bool; } check_eina_array_int_in_own { return: bool; } + */ eina_array_int_out { params { - @out arr: array; + @out arr: array; } 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 @owned; + @out arr: array @owned; // } return: bool; } + */ eina_array_int_return { - return: array; + return: array; } check_eina_array_int_return { return: bool; } + /* eina_array_int_return_own { - return: array @owned; + return: array @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; + @in lst: list; } return: bool; } + /* eina_list_int_in_own { params { - @in lst: list @owned; + @in lst: list @owned; // } return: bool; } check_eina_list_int_in_own { return: bool; } + */ eina_list_int_out { params { - @out lst: list; + @out lst: list; } 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 @owned; + @out lst: list @owned; // } return: bool; } + */ eina_list_int_return { - return: list; + return: list; } check_eina_list_int_return { return: bool; } + /* eina_list_int_return_own { - return: list @owned; + return: list @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; + @in hsh: hash; } return: bool; } + /* eina_hash_int_in_own { params { - @in hsh: hash @owned; + @in hsh: hash @owned; // <, int @owned> } return: bool; } check_eina_hash_int_in_own { return: bool; } + */ eina_hash_int_out { params { - @out hsh: hash; + @out hsh: hash; } 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 @owned; + @out hsh: hash @owned; // <, int @owned> } return: bool; } check_eina_hash_int_out_own { return: bool; } + */ eina_hash_int_return { - return: hash; + return: hash; } check_eina_hash_int_return { return: bool; } + /* eina_hash_int_return_own { - return: hash @owned; + return: hash @owned; // <, int @owned> } check_eina_hash_int_return_own { return: bool; -- 2.7.4