From 2e7b508312bf7dc6bd884475513f7d799d2f285d Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Tue, 24 Sep 2019 11:36:34 -0300 Subject: [PATCH] csharp: Fix wrapping of private classes Summary: Sometimes, valid Eo objects of private classes can be returned from methods. Currently we try to wrap in a minimal `Efl.Object` instance, but as it is an abstract class, we can't instantiate directly. This commits adds a dummy `Efl.ObjectRealized` to be instantiated when wrapping such classes alongside a test case. Fixes: T8258 Reviewers: felipealmeida, brunobelo, segfaultxavi, Jaehyun_Cho Reviewed By: brunobelo Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10101 --- src/bindings/mono/eo_mono/EoWrapper.cs | 11 +++++++++++ src/bindings/mono/eo_mono/iwrapper.cs | 2 +- src/tests/efl_mono/Eo.cs | 11 +++++++++++ src/tests/efl_mono/dummy_hidden_object.c | 8 ++++++++ src/tests/efl_mono/dummy_hidden_object.eo | 2 ++ src/tests/efl_mono/dummy_test_object.c | 8 ++++++++ src/tests/efl_mono/dummy_test_object.eo | 8 ++++++++ src/tests/efl_mono/libefl_mono_native_test.h | 1 + src/tests/efl_mono/meson.build | 7 ++++++- 9 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/tests/efl_mono/dummy_hidden_object.c create mode 100644 src/tests/efl_mono/dummy_hidden_object.eo diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs index 1805071175..79d597c7b6 100644 --- a/src/bindings/mono/eo_mono/EoWrapper.cs +++ b/src/bindings/mono/eo_mono/EoWrapper.cs @@ -413,4 +413,15 @@ public abstract class EoWrapper : IWrapper, IDisposable } // namespace Eo +/// Concrete realization of Efl.Object. +/// +/// Some legacy classes (like Evas.Canvas) may be returned by some methods. As these classes are not bound, we +/// allow minimal interaction with them through . +/// +/// But as is abstract, whis realized class will allow us to create C# instances of it. +internal class ObjectRealized : Efl.Object +{ + protected ObjectRealized(Efl.Eo.Globals.WrappingHandle ch) : base(ch) { } +} + } // namespace Efl diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index a03e48a326..8fe4b0623f 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs @@ -843,7 +843,7 @@ public static class ClassRegister if (t == null) { - return typeof(Efl.Object); + return typeof(Efl.ObjectRealized); } } diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs index 4c7196ec5b..a2e178adbb 100644 --- a/src/tests/efl_mono/Eo.cs +++ b/src/tests/efl_mono/Eo.cs @@ -621,4 +621,15 @@ class TestStaticInterfaceMembers } } +class TestHiddenClasses +{ + public static void test_hidden_class() + { + var obj = new Dummy.TestObject(); + var hidden = obj.HiddenObject; + + Test.AssertEquals(hidden.Name, "hidden_object"); + } +} + } diff --git a/src/tests/efl_mono/dummy_hidden_object.c b/src/tests/efl_mono/dummy_hidden_object.c new file mode 100644 index 0000000000..cf9c9cde5b --- /dev/null +++ b/src/tests/efl_mono/dummy_hidden_object.c @@ -0,0 +1,8 @@ +#include "libefl_mono_native_test.h" + +typedef struct Dummy_Hidden_Object_Data +{ +} Dummy_Hidden_Object_Data; + + +#include "dummy_hidden_object.eo.c" diff --git a/src/tests/efl_mono/dummy_hidden_object.eo b/src/tests/efl_mono/dummy_hidden_object.eo new file mode 100644 index 0000000000..1b29472a1c --- /dev/null +++ b/src/tests/efl_mono/dummy_hidden_object.eo @@ -0,0 +1,2 @@ +class Dummy.Hidden_Object extends Efl.Object { +} diff --git a/src/tests/efl_mono/dummy_test_object.c b/src/tests/efl_mono/dummy_test_object.c index 0406dd3f53..7f158430a2 100644 --- a/src/tests/efl_mono/dummy_test_object.c +++ b/src/tests/efl_mono/dummy_test_object.c @@ -22,6 +22,7 @@ typedef struct Dummy_Test_Object_Data Eo *iface_provider; int prop1; int prop2; + Eo *hidden_object; // Containers passed to C# as iterator/accessors Eina_Array *out_array; @@ -75,6 +76,8 @@ _dummy_test_object_efl_object_constructor(Eo *obj, Dummy_Test_Object_Data *pd) { efl_constructor(efl_super(obj, DUMMY_TEST_OBJECT_CLASS)); pd->provider = efl_add(DUMMY_NUMBERWRAPPER_CLASS, obj); + pd->hidden_object = efl_add(DUMMY_HIDDEN_OBJECT_CLASS, obj); + efl_name_set(pd->hidden_object, "hidden_object"); if (efl_parent_get(obj) == NULL) { // Avoid recursion pd->iface_provider = efl_add(DUMMY_TEST_OBJECT_CLASS, obj); @@ -4738,6 +4741,11 @@ int _dummy_test_object_dummy_test_iface_call_method_protected(const Eo *obj, EIN return dummy_test_iface_method_protected(obj, x); } +Eo *_dummy_test_object_hidden_object_get(EINA_UNUSED const Eo *obj, Dummy_Test_Object_Data *pd) +{ + return pd->hidden_object; +} + // Inherit int _dummy_inherit_helper_receive_dummy_and_call_int_out(Dummy_Test_Object *x) { diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo index a63c822375..44a7c97464 100644 --- a/src/tests/efl_mono/dummy_test_object.eo +++ b/src/tests/efl_mono/dummy_test_object.eo @@ -1646,6 +1646,14 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface { } return: const(ptr(Eina.Value_Type)); } + + @property hidden_object { + get {} + + values { + obj: Efl.Object; + } + } } implements { Efl.Object.constructor; diff --git a/src/tests/efl_mono/libefl_mono_native_test.h b/src/tests/efl_mono/libefl_mono_native_test.h index b726bd05c1..87abefe5e2 100644 --- a/src/tests/efl_mono/libefl_mono_native_test.h +++ b/src/tests/efl_mono/libefl_mono_native_test.h @@ -56,6 +56,7 @@ #include "dummy_part_holder.eo.h" #include "dummy_event_manager.eo.h" #include "dummy_constructible_object.eo.h" +#include "dummy_hidden_object.eo.h" #include diff --git a/src/tests/efl_mono/meson.build b/src/tests/efl_mono/meson.build index 202c09fbb0..d7cd6bbff7 100644 --- a/src/tests/efl_mono/meson.build +++ b/src/tests/efl_mono/meson.build @@ -10,9 +10,13 @@ eo_files = [ 'dummy_constructible_object.eo', ] +private_eo_files = [ + 'dummy_hidden_object.eo' +] + eo_file_targets = [] -foreach eo_file : eo_files +foreach eo_file : eo_files + private_eo_files eo_file_targets += custom_target('eolian_gen_' + eo_file, input : eo_file, output : [eo_file + '.h'], @@ -35,6 +39,7 @@ efl_mono_native_test = library('efl_mono_native_test', 'dummy_test_object.c', 'dummy_event_manager.c', 'dummy_constructible_object.c', + 'dummy_hidden_object.c', ], dependencies : [ecore, eo, efl], )