summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-09-05 14:25:11 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-09-05 14:47:19 -0300
commit4c53151096cf0e4e9e0f451b9d90ec0848aadd36 (patch)
tree7b8b95fe99aa15bb7bdf21ca57da7bd595444502
parent5e107aa19dc944e38624a0fa5a61a54db7f8035c (diff)
downloadefl-4c53151096cf0e4e9e0f451b9d90ec0848aadd36.tar.gz
efl-csharp: Fix event callback removal.
Summary: Use the native event loaded from dlsym directly instead of wrapping it in a Event_Description structure. Fixes: T7355 Reviewers: felipealmeida, vitor.sousa, segfaultxavi Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl_language_bindings Differential Revision: https://phab.enlightenment.org/D6981
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh12
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs2
-rw-r--r--src/bindings/mono/eo_mono/workaround.cs14
-rw-r--r--src/tests/efl_mono/Events.cs25
4 files changed, 45 insertions, 8 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 4eea1e852f..ef2c58f757 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -484,7 +484,11 @@ struct klass
<< scope_tab << scope_tab << "if (!event_cb_count.TryGetValue(key, out event_count))\n"
<< scope_tab << scope_tab << scope_tab << "event_cb_count[key] = event_count;\n"
<< scope_tab << scope_tab << "if (event_count == 0) {\n"
- << scope_tab << scope_tab << scope_tab << "IntPtr desc = efl.eo.Globals.dlsym(efl.eo.Globals.RTLD_DEFAULT, key);\n"
+ << scope_tab << scope_tab << scope_tab << "IntPtr desc = efl.Event_Description.GetNative(key);\n"
+ << scope_tab << scope_tab << scope_tab << "if (desc == IntPtr.Zero) {\n"
+ << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error($\"Failed to get native event {key}\");\n"
+ << scope_tab << scope_tab << scope_tab << scope_tab << "return false;\n"
+ << scope_tab << scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << scope_tab << "bool result = efl.eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evt_delegate, System.IntPtr.Zero);\n"
<< scope_tab << scope_tab << scope_tab << "if (!result) {\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error($\"Failed to add event proxy for event {key}\");\n"
@@ -500,7 +504,11 @@ struct klass
<< scope_tab << scope_tab << "if (!event_cb_count.TryGetValue(key, out event_count))\n"
<< scope_tab << scope_tab << scope_tab << "event_cb_count[key] = event_count;\n"
<< scope_tab << scope_tab << "if (event_count == 1) {\n"
- << scope_tab << scope_tab << scope_tab << "efl.Event_Description desc = new efl.Event_Description(key);\n"
+ << scope_tab << scope_tab << scope_tab << "IntPtr desc = efl.Event_Description.GetNative(key);\n"
+ << scope_tab << scope_tab << scope_tab << "if (desc == IntPtr.Zero) {\n"
+ << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error($\"Failed to get native event {key}\");\n"
+ << scope_tab << scope_tab << scope_tab << scope_tab << "return false;\n"
+ << scope_tab << scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << scope_tab << "bool result = efl.eo.Globals.efl_event_callback_del(handle, desc, evt_delegate, System.IntPtr.Zero);\n"
<< scope_tab << scope_tab << scope_tab << "if (!result) {\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Error($\"Failed to remove event proxy for event {key}\");\n"
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 499b1cc000..90f7f9b5ae 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -59,7 +59,7 @@ public class Globals {
System.IntPtr data);
[DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_del(
System.IntPtr obj,
- efl.Event_Description desc,
+ IntPtr desc,
efl.Event_Cb cb,
System.IntPtr data);
[DllImport(efl.Libs.Eo)] public static extern IntPtr
diff --git a/src/bindings/mono/eo_mono/workaround.cs b/src/bindings/mono/eo_mono/workaround.cs
index 207f5cab52..26afcefcb6 100644
--- a/src/bindings/mono/eo_mono/workaround.cs
+++ b/src/bindings/mono/eo_mono/workaround.cs
@@ -83,6 +83,14 @@ public struct Event_Description {
public Event_Description(string name)
{
+ this.Name = GetNative(name);
+ this.Unfreezable = false;
+ this.Legacy_is = false;
+ this.Restart = false;
+ }
+
+ public static IntPtr GetNative(string name)
+ {
if (!descriptions.ContainsKey(name))
{
IntPtr data = efl.eo.Globals.dlsym(efl.eo.Globals.RTLD_DEFAULT, name);
@@ -93,11 +101,7 @@ public struct Event_Description {
}
descriptions.Add(name, data);
}
-
- this.Name = descriptions[name];
- this.Unfreezable = false;
- this.Legacy_is = false;
- this.Restart = false;
+ return descriptions[name];
}
};
diff --git a/src/tests/efl_mono/Events.cs b/src/tests/efl_mono/Events.cs
index a08cd8b367..9cf7795dca 100644
--- a/src/tests/efl_mono/Events.cs
+++ b/src/tests/efl_mono/Events.cs
@@ -165,4 +165,29 @@ class TestEoEvents
Test.AssertEquals(sent, received);
}
}
+
+class TestEventAddRemove
+{
+ public static void test_add_remove_event()
+ {
+ test.ITesting obj = new test.Testing();
+ bool called = true;
+
+ EventHandler<test.Testing.EvtWithIntEvt_Args> evtCb = (object sender, EvtWithIntEvt_Args e) => {
+ called = true;
+ };
+
+ obj.EvtWithIntEvt += evtCb;
+ obj.EmitEventWithInt(42);
+ Test.Assert(called);
+
+ called = false;
+ obj.EvtWithIntEvt -= evtCb;
+ obj.EmitEventWithInt(42);
+ Test.Assert(!called);
+
+
+
+ }
+}
}