From 8a4bac15e7a0a0a9f0901eee1dc7b23fc990d18e Mon Sep 17 00:00:00 2001 From: Lauro Moura Date: Wed, 26 Sep 2018 12:01:49 -0300 Subject: [PATCH] efl-csharp: Fix event struct marshalling. 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 | 2 +- src/bin/eolian_mono/eolian/mono/struct_definition.hh | 12 +++++++----- src/bindings/mono/eo_mono/workaround.cs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh index 2da287b8e7..a5fe8ec788 100644 --- a/src/bin/eolian_mono/eolian/mono/events.hh +++ b/src/bin/eolian_mono/eolian/mono/events.hh @@ -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" diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh index 42d2f0d711..58007a2cdd 100644 --- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh +++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh @@ -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("///Internal wrapper for field " << field_name << "\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" + "/// Conversion class for struct " << struct_.cxx_name << "\n" + "public static class " << struct_.cxx_name << "_StructConversion\n{\n" ) - .generate(sink, struct_.cxx_name, context)) + .generate(sink, nullptr, context)) return false; // to internal diff --git a/src/bindings/mono/eo_mono/workaround.cs b/src/bindings/mono/eo_mono/workaround.cs index 26afcefcb6..253e3758f3 100644 --- a/src/bindings/mono/eo_mono/workaround.cs +++ b/src/bindings/mono/eo_mono/workaround.cs @@ -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;