summaryrefslogtreecommitdiff
path: root/src/bin
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/bin
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/bin')
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_pointer.hh27
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh9
2 files changed, 33 insertions, 3 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_pointer.hh b/src/bin/eolian_mono/eolian/mono/function_pointer.hh
index aa99601c8c..e243ca744c 100644
--- a/src/bin/eolian_mono/eolian/mono/function_pointer.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_pointer.hh
@@ -56,7 +56,7 @@ struct function_pointer {
56 return false; 56 return false;
57 57
58 // Wrapper type, with callback matching the Unamanaged one 58 // Wrapper type, with callback matching the Unamanaged one
59 if (!as_generator("internal class " << f_name << "Wrapper\n" 59 if (!as_generator("internal class " << f_name << "Wrapper : IDisposable\n"
60 << "{\n\n" 60 << "{\n\n"
61 << scope_tab << "private " << f_name << "Internal _cb;\n" 61 << scope_tab << "private " << f_name << "Internal _cb;\n"
62 << scope_tab << "private IntPtr _cb_data;\n" 62 << scope_tab << "private IntPtr _cb_data;\n"
@@ -71,8 +71,31 @@ struct function_pointer {
71 71
72 << scope_tab << "~" << f_name << "Wrapper()\n" 72 << scope_tab << "~" << f_name << "Wrapper()\n"
73 << scope_tab << "{\n" 73 << scope_tab << "{\n"
74 << scope_tab << scope_tab << "Dispose(false);\n"
75 << scope_tab << "}\n\n"
76
77 << scope_tab << "protected virtual void Dispose(bool disposing)\n"
78 << scope_tab << "{\n"
74 << scope_tab << scope_tab << "if (this._cb_free_cb != null)\n" 79 << scope_tab << scope_tab << "if (this._cb_free_cb != null)\n"
75 << scope_tab << scope_tab << scope_tab << "this._cb_free_cb(this._cb_data);\n" 80 << scope_tab << scope_tab << "{\n"
81 << scope_tab << scope_tab << scope_tab << "if (disposing)\n"
82 << scope_tab << scope_tab << scope_tab << "{\n"
83 << scope_tab << scope_tab << scope_tab << scope_tab << "this._cb_free_cb(this._cb_data);\n"
84 << scope_tab << scope_tab << scope_tab << "}\n"
85 << scope_tab << scope_tab << scope_tab << "else\n"
86 << scope_tab << scope_tab << scope_tab << "{\n"
87 << scope_tab << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(this._cb_free_cb, this._cb_data);\n"
88 << scope_tab << scope_tab << scope_tab << "}\n"
89 << scope_tab << scope_tab << scope_tab << "this._cb_free_cb = null;\n"
90 << scope_tab << scope_tab << scope_tab << "this._cb_data = IntPtr.Zero;\n"
91 << scope_tab << scope_tab << scope_tab << "this._cb = null;\n"
92 << scope_tab << scope_tab << "}\n"
93 << scope_tab << "}\n\n"
94
95 << scope_tab << "public void Dispose()\n"
96 << scope_tab << "{\n"
97 << scope_tab << scope_tab << "Dispose(true);\n"
98 << scope_tab << scope_tab << "GC.SuppressFinalize(this);\n"
76 << scope_tab << "}\n\n" 99 << scope_tab << "}\n\n"
77 100
78 << scope_tab << "internal " << type << " ManagedCb(" << (parameter % ",") << ")\n" 101 << scope_tab << "internal " << type << " ManagedCb(" << (parameter % ",") << ")\n"
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 2f0bc62d6c..7973c7d763 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -600,7 +600,14 @@ struct klass
600 << scope_tab << visibility << "void Dispose(bool disposing)\n" 600 << scope_tab << visibility << "void Dispose(bool disposing)\n"
601 << scope_tab << "{\n" 601 << scope_tab << "{\n"
602 << scope_tab << scope_tab << "if (handle != System.IntPtr.Zero) {\n" 602 << scope_tab << scope_tab << "if (handle != System.IntPtr.Zero) {\n"
603 << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.efl_unref(handle);\n" 603 << scope_tab << scope_tab << scope_tab << "if (disposing)\n"
604 << scope_tab << scope_tab << scope_tab << "{\n"
605 << scope_tab << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.efl_unref(handle);\n"
606 << scope_tab << scope_tab << scope_tab << "}\n"
607 << scope_tab << scope_tab << scope_tab << "else\n"
608 << scope_tab << scope_tab << scope_tab << "{\n"
609 << scope_tab << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.efl_mono_thread_safe_efl_unref(handle);\n"
610 << scope_tab << scope_tab << scope_tab << "}\n"
604 << scope_tab << scope_tab << scope_tab << "handle = System.IntPtr.Zero;\n" 611 << scope_tab << scope_tab << scope_tab << "handle = System.IntPtr.Zero;\n"
605 << scope_tab << scope_tab << "}\n" 612 << scope_tab << scope_tab << "}\n"
606 << scope_tab << "}\n" 613 << scope_tab << "}\n"