summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-05 13:36:48 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-05 13:36:48 -0300
commit0e55612280baca435ceaec3e67cbd24c79ff88f0 (patch)
tree84cd6063d136bf17a182b98fc84b19664096b659
parentf131e55f396ca142e466f6bba50aca1618a187ca (diff)
efl_mono: avoid C# making many handles for event delegates, so we can unregister themdevs/vitorsousa/csharp_end_error_fix
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh11
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs11
2 files changed, 12 insertions, 10 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index bec470efef..c2c885ec3e 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -472,7 +472,7 @@ struct klass
472 return true; 472 return true;
473 473
474 if (cls.get_all_events().size() > 0) 474 if (cls.get_all_events().size() > 0)
475 if (!as_generator(scope_tab << visibility << "Dictionary<(IntPtr desc, object evtDelegate), Efl.EventCb> eoEvents = new Dictionary<(IntPtr desc, object evtDelegate), Efl.EventCb>();\n" 475 if (!as_generator(scope_tab << visibility << "Dictionary<(IntPtr desc, object evtDelegate), (IntPtr evtCallerPtr, Efl.EventCb evtCaller)> eoEvents = new Dictionary<(IntPtr desc, object evtDelegate), (IntPtr evtCallerPtr, Efl.EventCb evtCaller)>();\n"
476 << scope_tab << visibility << "readonly object eventLock = new object();\n") 476 << scope_tab << visibility << "readonly object eventLock = new object();\n")
477 .generate(sink, attributes::unused, context)) 477 .generate(sink, attributes::unused, context))
478 return false; 478 return false;
@@ -667,13 +667,14 @@ struct klass
667 << scope_tab << scope_tab << scope_tab << "return;\n" 667 << scope_tab << scope_tab << scope_tab << "return;\n"
668 << scope_tab << scope_tab << "}\n\n" 668 << scope_tab << scope_tab << "}\n\n"
669 669
670 << scope_tab << scope_tab << "if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCaller, IntPtr.Zero))\n" 670 << scope_tab << scope_tab << "IntPtr evtCallerPtr = Marshal.GetFunctionPointerForDelegate(evtCaller);\n"
671 << scope_tab << scope_tab << "if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCallerPtr, IntPtr.Zero))\n"
671 << scope_tab << scope_tab << "{\n" 672 << scope_tab << scope_tab << "{\n"
672 << scope_tab << scope_tab << scope_tab << "Eina.Log.Error($\"Failed to add event proxy for event {key}\");\n" 673 << scope_tab << scope_tab << scope_tab << "Eina.Log.Error($\"Failed to add event proxy for event {key}\");\n"
673 << scope_tab << scope_tab << scope_tab << "return;\n" 674 << scope_tab << scope_tab << scope_tab << "return;\n"
674 << scope_tab << scope_tab << "}\n\n" 675 << scope_tab << scope_tab << "}\n\n"
675 676
676 << scope_tab << scope_tab << "eoEvents[(desc, evtDelegate)] = evtCaller;\n" 677 << scope_tab << scope_tab << "eoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller);\n"
677 << scope_tab << scope_tab << "Eina.Error.RaiseIfUnhandledException();\n" 678 << scope_tab << scope_tab << "Eina.Error.RaiseIfUnhandledException();\n"
678 << scope_tab << "}\n\n" 679 << scope_tab << "}\n\n"
679 680
@@ -692,10 +693,10 @@ struct klass
692 << scope_tab << scope_tab << "}\n\n" 693 << scope_tab << scope_tab << "}\n\n"
693 694
694 << scope_tab << scope_tab << "var evtPair = (desc, evtDelegate);\n" 695 << scope_tab << scope_tab << "var evtPair = (desc, evtDelegate);\n"
695 << scope_tab << scope_tab << "if (eoEvents.TryGetValue(evtPair, out var evtCaller))\n" 696 << scope_tab << scope_tab << "if (eoEvents.TryGetValue(evtPair, out var caller))\n"
696 << scope_tab << scope_tab << "{\n" 697 << scope_tab << scope_tab << "{\n"
697 698
698 << scope_tab << scope_tab << scope_tab << "if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, evtCaller, IntPtr.Zero))\n" 699 << scope_tab << scope_tab << scope_tab << "if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, caller.evtCallerPtr, IntPtr.Zero))\n"
699 << scope_tab << scope_tab << scope_tab << "{\n" 700 << scope_tab << scope_tab << scope_tab << "{\n"
700 << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error($\"Failed to remove event proxy for event {key}\");\n" 701 << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error($\"Failed to remove event proxy for event {key}\");\n"
701 << scope_tab << scope_tab << scope_tab << scope_tab << "return;\n" 702 << scope_tab << scope_tab << scope_tab << scope_tab << "return;\n"
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 77e3cfd75a..efec393d8e 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -175,10 +175,10 @@ public class Globals {
175 [DllImport(efl.Libs.Evil)] public static extern IntPtr dlerror(); 175 [DllImport(efl.Libs.Evil)] public static extern IntPtr dlerror();
176 176
177 [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 177 [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
178 efl_event_callback_priority_add(IntPtr obj, IntPtr desc, short priority, Efl.EventCb cb, IntPtr data); 178 efl_event_callback_priority_add(IntPtr obj, IntPtr desc, short priority, IntPtr cb, IntPtr data);
179 179
180 [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 180 [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
181 efl_event_callback_del(IntPtr obj, IntPtr desc, Efl.EventCb cb, IntPtr data); 181 efl_event_callback_del(IntPtr obj, IntPtr desc, IntPtr cb, IntPtr data);
182 182
183 [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 183 [DllImport(efl.Libs.Eo)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
184 efl_event_callback_call(IntPtr obj, IntPtr desc, IntPtr event_info); 184 efl_event_callback_call(IntPtr obj, IntPtr desc, IntPtr event_info);
@@ -509,17 +509,18 @@ public class Globals {
509 try 509 try
510 { 510 {
511 GCHandle gcHandle = GCHandle.FromIntPtr(gcHandlePtr); 511 GCHandle gcHandle = GCHandle.FromIntPtr(gcHandlePtr);
512 var eoEvents = gcHandle.Target as Dictionary<(IntPtr desc, object evtDelegate), Efl.EventCb>; 512 var eoEvents = gcHandle.Target as Dictionary<(IntPtr desc, object evtDelegate), (IntPtr evtCallerPtr, Efl.EventCb evtCaller)>;
513 if (eoEvents == null) 513 if (eoEvents == null)
514 { 514 {
515 Eina.Log.Error($"Invalid event dictionary [GCHandle pointer: {gcHandlePtr}]");
515 return; 516 return;
516 } 517 }
517 518
518 foreach (var item in eoEvents) 519 foreach (var item in eoEvents)
519 { 520 {
520 if (!efl_event_callback_del(obj, item.Key.desc, item.Value, IntPtr.Zero)) 521 if (!efl_event_callback_del(obj, item.Key.desc, item.Value.evtCallerPtr, IntPtr.Zero))
521 { 522 {
522 Eina.Log.Error($"Failed to remove event proxy for event {item.Key.desc}"); 523 Eina.Log.Error($"Failed to remove event proxy for event {item.Key.desc} [cb: {item.Value.evtCallerPtr}]");
523 } 524 }
524 } 525 }
525 } 526 }