summaryrefslogtreecommitdiff
path: root/src/lib/efl_mono
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-05 19:57:29 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-05 19:58:19 -0300
commit1c22a3d8190fd85570418a076356547f3eda606f (patch)
treec22410a67a3b7263b495ce9ae0ae24d5e8b1daf9 /src/lib/efl_mono
parent1e22db1150049e313bcba7906fc5ffc9a745eaf0 (diff)
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
Diffstat (limited to 'src/lib/efl_mono')
-rw-r--r--src/lib/efl_mono/efl_custom_exports_mono.c49
1 files changed, 48 insertions, 1 deletions
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 @@
1#include "Eo.h" 1#include "Eo.h"
2#include "Eina.h" 2#include "Eina.h"
3#include "Ecore.h"
3 4
4#include <stdlib.h> 5#include <stdlib.h>
5#include <string.h> 6#include <string.h>
@@ -22,6 +23,52 @@
22# endif 23# endif
23#endif /* ! _WIN32 */ 24#endif /* ! _WIN32 */
24 25
26static void _efl_mono_unref_cb(void *obj)
27{
28 efl_unref(obj);
29}
30
31EAPI void efl_mono_thread_safe_efl_unref(Eo* obj)
32{
33 ecore_main_loop_thread_safe_call_async(_efl_mono_unref_cb, obj);
34}
35
36EAPI void efl_mono_thread_safe_free_cb_exec(Eina_Free_Cb free_cb, void* cb_data)
37{
38 ecore_main_loop_thread_safe_call_async(free_cb, cb_data);
39}
40
41static void _efl_mono_list_free_cb(void *l)
42{
43 eina_list_free(l);
44}
45
46EAPI void efl_mono_thread_safe_eina_list_free(Eina_List* list)
47{
48 ecore_main_loop_thread_safe_call_async(_efl_mono_list_free_cb, list);
49}
50
51typedef struct _Efl_Mono_Promise_Reject_Data
52{
53 Eina_Promise *promise;
54 Eina_Error err;
55} Efl_Mono_Promise_Reject_Data;
56
57static void _efl_mono_promise_reject_cb(void *data)
58{
59 Efl_Mono_Promise_Reject_Data *d = data;
60 eina_promise_reject(d->promise, d->err);
61 free(d);
62}
63
64EAPI void efl_mono_thread_safe_promise_reject(Eina_Promise *p, Eina_Error err)
65{
66 Efl_Mono_Promise_Reject_Data *d = malloc(sizeof(Efl_Mono_Promise_Reject_Data));
67 d->promise = p;
68 d->err = err;
69 ecore_main_loop_thread_safe_call_async(_efl_mono_promise_reject_cb, d);
70}
71
25EAPI void *efl_mono_native_alloc(unsigned int size) 72EAPI void *efl_mono_native_alloc(unsigned int size)
26{ 73{
27 return malloc(size); 74 return malloc(size);
@@ -81,7 +128,7 @@ EAPI Eina_Free_Cb efl_mono_native_free_addr_get()
81 128
82EAPI Eina_Free_Cb efl_mono_native_efl_unref_addr_get() 129EAPI Eina_Free_Cb efl_mono_native_efl_unref_addr_get()
83{ 130{
84 return (Eina_Free_Cb)efl_unref; 131 return (Eina_Free_Cb)efl_mono_thread_safe_efl_unref;
85} 132}
86 133
87// Iterator Wrapper // 134// Iterator Wrapper //