csharp: Avoid direct usage of some dllimport funcs
authorLauro Moura <lauromoura@expertisesolutions.com.br>
Tue, 15 Oct 2019 13:11:09 +0000 (10:11 -0300)
committerWonki Kim <wonki_.kim@samsung.com>
Mon, 11 Nov 2019 02:18:25 +0000 (11:18 +0900)
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
src/bin/eolian_mono/eolian/mono/function_definition.hh
src/bindings/mono/eo_mono/iwrapper.cs

index ea37c9c..5ca6b1b 100644 (file)
@@ -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<OutputIterator, Context> 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;
         }
index df72f2c..301f541 100644 (file)
@@ -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 = "";
 
index 8fe4b06..ae39b61 100644 (file)
@@ -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);
+
+    /// <summary>Gets a native pointer to <c>obj</c> that forwards the method call to its parent
+    /// implementation.
+    ///
+    /// <para>For generated code use only.</para>
+    /// <para>Since EFL 1.23.</para>
+    /// </summary>
+    /// <param name="obj">The native pointer to be prepared.</param>
+    /// <param name="klass">The current class.</param>
+    /// <returns>The native pointer to <c>obj</c> prepared to call the parent implementation of <c>klass</c>.</returns>
+    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);
+
+    /// <summary>Gets the native EO class pointer for the given object.
+    /// <para>For generated code use only.</para>
+    /// <para>Since EFL 1.23.</para>
+    /// </summary>
+    /// <param name="obj">The native pointer to the <see cref="Efl.Object" /> instance to get the native class
+    /// from.</param>
+    /// <returns>The native class pointer or <see cref="IntPtr.Zero" /> if no such class existis.</returns>
+    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);
 
+    /// <summary>Calls the callbacks associated to an event.
+    /// <para>For generated code use only.</para>
+    /// <para>Since EFL 1.23.</para>
+    /// </summary>
+    /// <param name="obj">The native pointer to the <see cref="Efl.Object" /> instance that will be the emitter
+    /// of the event.</param>
+    /// <param name="desc">The native event description.</param>
+    /// <param name="event_info">The native payload of the event.</param>
+    /// <returns><c>false</c> if one of the callbacks aborted the call. <c>true</c> otherwise.</returns>
+    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);