efl-csharp: Fix event struct marshalling.
authorLauro Moura <lauromoura@gmail.com>
Wed, 26 Sep 2018 15:01:49 +0000 (12:01 -0300)
committerYeongjong Lee <yj34.lee@samsung.com>
Fri, 28 Sep 2018 01:38:25 +0000 (10:38 +0900)
Summary:
The efl.Event struct has a class field that gets generated normally but
can be problematic when marshalling the struct back from C to C#. The
compilation works fine but when C# runtime tries to marshall the C data
(e.g. accessing the Event.Info field), it becomes erratic, either
complaining about missing references to object or even segfault.

This commit changes the event handling code to use the
"Event_StructInternal" struct as is already done when receiving structs
from C code.

In order to work with other assemblies, the _StructInternal fields were
made publit too.

Fixes the events tests and the text editor app.

Test Plan: make check and run the text editor app in examples repo.

Reviewers: segfaultxavi, vitor.sousa

Reviewed By: vitor.sousa

Subscribers: cedric, #reviewers, #committers

Tags: #efl

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

src/bin/eolian_mono/eolian/mono/events.hh
src/bin/eolian_mono/eolian/mono/struct_definition.hh
src/bindings/mono/eo_mono/workaround.cs

index 2da287b..a5fe8ec 100644 (file)
@@ -211,7 +211,7 @@ struct event_definition_generator
             << scope_tab << scope_tab << "}\n"
             << scope_tab << scope_tab << "if (evt != null) { evt(this, e); }\n"
             << scope_tab << "}\n"
-            << scope_tab << "private void on_" << wrapper_evt_name << "_NativeCallback(System.IntPtr data, ref efl.Event evt)\n"
+            << scope_tab << "private void on_" << wrapper_evt_name << "_NativeCallback(System.IntPtr data, ref efl.Event_StructInternal evt)\n"
             << scope_tab << "{\n"
             << scope_tab << scope_tab << event_args
             << scope_tab << scope_tab << "try {\n"
index 42d2f0d..58007a2 100644 (file)
@@ -115,11 +115,12 @@ struct struct_internal_definition_generator
                               || regular->base_type == "stringshare"
                               || regular->base_type == "any_value_ptr")))
             {
-               if (!as_generator(" internal System.IntPtr " << string << ";\n")
-                   .generate(sink, field_name, context))
+               if (!as_generator("///<summary>Internal wrapper for field " << field_name << "</summary>\n"
+                                 << "public System.IntPtr " << field_name << ";\n")
+                   .generate(sink, nullptr, context))
                  return false;
             }
-          else if (!as_generator(eolian_mono::marshall_annotation(false) << " internal " << eolian_mono::marshall_type(false) << " " << string << ";\n")
+          else if (!as_generator(eolian_mono::marshall_annotation(false) << " public " << eolian_mono::marshall_type(false) << " " << string << ";\n")
                    .generate(sink, std::make_tuple(field.type, field.type, field_name), context))
             return false;
        }
@@ -368,9 +369,10 @@ struct struct_binding_conversion_functions_generator
      // Open conversion class
      if (!as_generator
          (
-          "public static class " << string << "_StructConversion\n{\n"
+          "/// <summary>Conversion class for struct " << struct_.cxx_name << "</summary>\n"
+          "public static class " << struct_.cxx_name << "_StructConversion\n{\n"
          )
-         .generate(sink, struct_.cxx_name, context))
+         .generate(sink, nullptr, context))
        return false;
 
      // to internal
index 26afcef..253e375 100644 (file)
@@ -106,7 +106,7 @@ public struct Event_Description {
 };
 
 
-public delegate void Event_Cb(System.IntPtr data, ref Event evt);
+public delegate void Event_Cb(System.IntPtr data, ref Event_StructInternal evt);
 #pragma warning disable 0169
 public struct Dbg_Info {
     IntPtr name;