summaryrefslogtreecommitdiff
path: root/src/lib/efl_mono
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-05 19:59:34 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-05 19:59:47 -0300
commit7c28762f15f9935d5ca08ef87ee7ddfaf1df4815 (patch)
tree3b602d7fb867e91c202f262b7aaa215c8245856b /src/lib/efl_mono
parent1c22a3d8190fd85570418a076356547f3eda606f (diff)
efl-csharp: fix crash when events trigger after C# object `Dispose`
Summary: Rework general event handling to check individually each event call, if the object is not alive then the event will not be propagated. WeakReferences (and lambdas capturing those WeakRefs) are used to ensure this. Dispose methods in object now take care of checking if efl libraries are still initialized and thread-safely unregister each event before performing an efl_unref on the Eo object. Event handling in C# is now centered around a single dictionary inside the object: `EoEvents`. C# event triggers now properly trigger events on C too. Standardize C# event-triggering methods names (remove underscores). Some diminished use of static memory due events no longer requiring static key objects to be registered/unregistered. Some fixing of white space generation for generated events. Depends on D8431 Reviewers: lauromoura, felipealmeida, segfaultxavi Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8564
Diffstat (limited to 'src/lib/efl_mono')
-rw-r--r--src/lib/efl_mono/efl_custom_exports_mono.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c
index 669625969e..c4a3b54bc5 100644
--- a/src/lib/efl_mono/efl_custom_exports_mono.c
+++ b/src/lib/efl_mono/efl_custom_exports_mono.c
@@ -23,6 +23,46 @@
23# endif 23# endif
24#endif /* ! _WIN32 */ 24#endif /* ! _WIN32 */
25 25
26typedef void (*Efl_Mono_Free_GCHandle_Cb)(void *gchandle);
27typedef void (*Efl_Mono_Remove_Events_Cb)(Eo *obj, void *gchandle);
28
29static Efl_Mono_Free_GCHandle_Cb _efl_mono_free_gchandle_call = NULL;
30static Efl_Mono_Remove_Events_Cb _efl_mono_remove_events_call = NULL;
31
32EAPI void efl_mono_gchandle_callbacks_set(Efl_Mono_Free_GCHandle_Cb free_gchandle_cb, Efl_Mono_Remove_Events_Cb remove_events_cb)
33{
34 _efl_mono_free_gchandle_call = free_gchandle_cb;
35 _efl_mono_remove_events_call = remove_events_cb;
36}
37
38EAPI void efl_mono_native_dispose(Eo *obj, void* gchandle)
39{
40 if (gchandle) _efl_mono_remove_events_call(obj, gchandle);
41 efl_unref(obj);
42 if (gchandle) _efl_mono_free_gchandle_call(gchandle);
43}
44
45typedef struct _Efl_Mono_Native_Dispose_Data
46{
47 Eo *obj;
48 void *gchandle;
49} Efl_Mono_Native_Dispose_Data;
50
51static void _efl_mono_native_dispose_cb(void *data)
52{
53 Efl_Mono_Native_Dispose_Data *dd = data;
54 efl_mono_native_dispose(dd->obj, dd->gchandle);
55 free(dd);
56}
57
58EAPI void efl_mono_thread_safe_native_dispose(Eo *obj, void* gchandle)
59{
60 Efl_Mono_Native_Dispose_Data *dd = malloc(sizeof(Efl_Mono_Native_Dispose_Data));
61 dd->obj = obj;
62 dd->gchandle = gchandle;
63 ecore_main_loop_thread_safe_call_async(_efl_mono_native_dispose_cb, dd);
64}
65
26static void _efl_mono_unref_cb(void *obj) 66static void _efl_mono_unref_cb(void *obj)
27{ 67{
28 efl_unref(obj); 68 efl_unref(obj);