From 31bc3beb222b0c36b5a5ffb84beebd8e761dbdc2 Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Tue, 15 Oct 2019 10:11:09 -0300 Subject: [PATCH] csharp: Avoid direct usage of some dllimport funcs Summary: Instead of accessing them directly, generated code should access them only through proper managed wrappers. JIT should take care of inline them. This would allow D10338 without depending on the friendly assembly feature. Reviewers: YOhoho, felipealmeida, brunobelo, woohyun, segfaultxavi Reviewed By: YOhoho Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10366 --- src/bin/eolian_mono/eolian/mono/events.hh | 4 +- .../eolian/mono/function_definition.hh | 4 +- src/bindings/mono/eo_mono/iwrapper.cs | 42 +++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh index ea37c9ccfe..5ca6b1b1ea 100644 --- a/src/bin/eolian_mono/eolian/mono/events.hh +++ b/src/bin/eolian_mono/eolian/mono/events.hh @@ -127,7 +127,7 @@ struct pack_event_info_and_call_visitor Context const* context; attributes::type_def const& type; - static auto constexpr native_call = "Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, info);\n"; + static auto constexpr native_call = "Efl.Eo.Globals.CallEventCallback(this.NativeHandle, desc, info);\n"; typedef pack_event_info_and_call_visitor visitor_type; typedef bool result_type; @@ -381,7 +381,7 @@ struct event_definition_generator if (!etype.is_engaged()) { auto event_call_site_sink = std::back_inserter(event_native_call); - if (!as_generator(indent.inc().inc() << "Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, IntPtr.Zero);\n") + if (!as_generator(indent.inc().inc() << "Efl.Eo.Globals.CallEventCallback(this.NativeHandle, desc, IntPtr.Zero);\n") .generate(event_call_site_sink, attributes::unused, context)) return false; } diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh index df72f2ce6c..301f5417f3 100644 --- a/src/bin/eolian_mono/eolian/mono/function_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh @@ -102,7 +102,7 @@ struct native_function_definition_generator else klass_cast_name = name_helpers::klass_inherit_name(*klass); - std::string self = "Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj))"; + std::string self = "Efl.Eo.Globals.Super(obj, Efl.Eo.Globals.GetClass(obj))"; if (f.is_static) self = ""; @@ -198,7 +198,7 @@ struct function_definition_generator // IsGeneratedBindingClass is set in the constructor, true if this // instance is from a pure C# class (not generated). if (do_super && !f.is_static) - self = "(IsGeneratedBindingClass ? " + self + " : Efl.Eo.Globals.efl_super(" + self + ", this.NativeClass))"; + self = "(IsGeneratedBindingClass ? " + self + " : Efl.Eo.Globals.Super(" + self + ", this.NativeClass))"; else if (f.is_static) self = ""; diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index 8fe4b0623f..ae39b6139a 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs @@ -188,9 +188,37 @@ public class Globals public delegate IntPtr efl_data_scope_get_delegate(IntPtr obj, IntPtr klass); [DllImport(efl.Libs.Eo)] public static extern IntPtr efl_data_scope_get(IntPtr obj, IntPtr klass); public delegate IntPtr efl_super_delegate(IntPtr obj, IntPtr klass); + + /// Gets a native pointer to obj that forwards the method call to its parent + /// implementation. + /// + /// For generated code use only. + /// Since EFL 1.23. + /// + /// The native pointer to be prepared. + /// The current class. + /// The native pointer to obj prepared to call the parent implementation of klass. + public static IntPtr Super(IntPtr obj, IntPtr klass) + { + return efl_super(obj, klass); + } + [DllImport(efl.Libs.Eo)] public static extern IntPtr efl_super(IntPtr obj, IntPtr klass); public delegate IntPtr efl_class_get_delegate(IntPtr obj); [DllImport(efl.Libs.Eo)] public static extern IntPtr efl_class_get(IntPtr obj); + + /// Gets the native EO class pointer for the given object. + /// For generated code use only. + /// Since EFL 1.23. + /// + /// The native pointer to the instance to get the native class + /// from. + /// The native class pointer or if no such class existis. + public static IntPtr GetClass(IntPtr obj) + { + return efl_class_get(obj); + } + [DllImport(efl.Libs.Eo)] public static extern EflClassType efl_class_type_get(IntPtr klass); public delegate IntPtr dlerror_delegate(); [DllImport(efl.Libs.Evil)] public static extern IntPtr dlerror(); @@ -208,6 +236,20 @@ public class Globals [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool efl_event_callback_call(IntPtr obj, IntPtr desc, IntPtr event_info); + /// Calls the callbacks associated to an event. + /// For generated code use only. + /// Since EFL 1.23. + /// + /// The native pointer to the instance that will be the emitter + /// of the event. + /// The native event description. + /// The native payload of the event. + /// false if one of the callbacks aborted the call. true otherwise. + public static bool CallEventCallback(IntPtr obj, IntPtr desc, IntPtr event_info) + { + return efl_event_callback_call(obj, desc, event_info); + } + public const int RTLD_NOW = 2; public delegate byte class_initializer(IntPtr klass);