From 1c22a3d8190fd85570418a076356547f3eda606f Mon Sep 17 00:00:00 2001 From: Vitor Sousa Date: Fri, 5 Apr 2019 19:57:29 -0300 Subject: efl-csharp: fix resource deallocation causing errors everywhere Summary: This commit mainly fixes errors caused by deallocating resources in the garbage collector thread. Using `ecore_main_loop_thread_safe_call_async` to queue resource deallocation in the main thread seems to solve it. Also, some `efl_ref` calls are added in places they were missing, mainly objects that unref in the destructor thus taking ownership if efl_ref is not called. Also fix improper resource deallocation in tests that were causing it to crash, enabling it to call Efl.All.Shutdown again. This allocation and the deallocation process was moved from the Eo class constructor to static class methods that are called in the test 'set up' and 'tear down' methods. Queuing resource deallocation in the main thread make it mandatory that tests call `Efl.App.AppMain.Iterate()` if they want to check proper resource deallocation (like TestFunctionPointers.set_callback_inherited_called_from_c). Extras: Remove duplicated declaration of 'eflcustomexportsmono' in meson in order to fix some linking problems. Remove some unused code around deallocation functions that had to be reworked. Object allocation is now supplied with the call site information it expects (file name and line for _efl_add_start). Depends on D8550 Test Plan: meson test Reviewers: felipealmeida, lauromoura, cedric, segfaultxavi Reviewed By: lauromoura Subscribers: segfaultxavi Tags: #efl_language_bindings, #do_not_merge Differential Revision: https://phab.enlightenment.org/D8431 --- src/lib/efl_mono/efl_custom_exports_mono.c | 49 +++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/lib/efl_mono') diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c index fce3a43a1e..669625969e 100644 --- a/src/lib/efl_mono/efl_custom_exports_mono.c +++ b/src/lib/efl_mono/efl_custom_exports_mono.c @@ -1,5 +1,6 @@ #include "Eo.h" #include "Eina.h" +#include "Ecore.h" #include #include @@ -22,6 +23,52 @@ # endif #endif /* ! _WIN32 */ +static void _efl_mono_unref_cb(void *obj) +{ + efl_unref(obj); +} + +EAPI void efl_mono_thread_safe_efl_unref(Eo* obj) +{ + ecore_main_loop_thread_safe_call_async(_efl_mono_unref_cb, obj); +} + +EAPI void efl_mono_thread_safe_free_cb_exec(Eina_Free_Cb free_cb, void* cb_data) +{ + ecore_main_loop_thread_safe_call_async(free_cb, cb_data); +} + +static void _efl_mono_list_free_cb(void *l) +{ + eina_list_free(l); +} + +EAPI void efl_mono_thread_safe_eina_list_free(Eina_List* list) +{ + ecore_main_loop_thread_safe_call_async(_efl_mono_list_free_cb, list); +} + +typedef struct _Efl_Mono_Promise_Reject_Data +{ + Eina_Promise *promise; + Eina_Error err; +} Efl_Mono_Promise_Reject_Data; + +static void _efl_mono_promise_reject_cb(void *data) +{ + Efl_Mono_Promise_Reject_Data *d = data; + eina_promise_reject(d->promise, d->err); + free(d); +} + +EAPI void efl_mono_thread_safe_promise_reject(Eina_Promise *p, Eina_Error err) +{ + Efl_Mono_Promise_Reject_Data *d = malloc(sizeof(Efl_Mono_Promise_Reject_Data)); + d->promise = p; + d->err = err; + ecore_main_loop_thread_safe_call_async(_efl_mono_promise_reject_cb, d); +} + EAPI void *efl_mono_native_alloc(unsigned int size) { return malloc(size); @@ -81,7 +128,7 @@ EAPI Eina_Free_Cb efl_mono_native_free_addr_get() EAPI Eina_Free_Cb efl_mono_native_efl_unref_addr_get() { - return (Eina_Free_Cb)efl_unref; + return (Eina_Free_Cb)efl_mono_thread_safe_efl_unref; } // Iterator Wrapper // -- cgit v1.2.1