aboutsummaryrefslogtreecommitdiffstats
path: root/src/bindings
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/bindings
parentcsharp: Make classes abstract and rework casting (diff)
downloadefl-1c22a3d8190fd85570418a076356547f3eda606f.tar.gz
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 https://phab.enlightenment.org/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/bindings')
-rw-r--r--src/bindings/mono/efl_mono/meson.build7
-rw-r--r--src/bindings/mono/eina_mono/eina_accessor.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_array.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_binbuf.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_container_common.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_inarray.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_iterator.cs9
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs11
-rw-r--r--src/bindings/mono/eina_mono/eina_promises.cs12
-rw-r--r--src/bindings/mono/eina_mono/eina_strbuf.cs11
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs9
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_connection.cs9
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_message.cs9
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_object.cs9
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_proxy.cs9
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs12
-rw-r--r--src/bindings/mono/meson.build3
18 files changed, 132 insertions, 25 deletions
diff --git a/src/bindings/mono/efl_mono/meson.build b/src/bindings/mono/efl_mono/meson.build
index acfeb4bc3f..3edefb3c0c 100644
--- a/src/bindings/mono/efl_mono/meson.build
+++ b/src/bindings/mono/efl_mono/meson.build
@@ -8,13 +8,6 @@ bash = find_program('bash')
map = run_command('map_generate.sh').stdout()
-efl_mono_lib = library('eflcustomexportsmono',
- join_paths('..', '..', '..', 'lib', 'efl_mono', 'efl_custom_exports_mono.c'),
- install : true,
- install_dir : join_paths(dir_lib, 'efl-mono-'+version_major),
- dependencies : [eo, eina]
-)
-
efl_libs = configuration_data()
efl_libs.set('EFL_MONO_LIBRARY_MAP', map)
efl_libs.set('CUSTOM_EXPORTS_MONO_DL_MONO', 'eflcustomexportsmono')
diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs
index 31574d552f..d14a2039d5 100644
--- a/src/bindings/mono/eina_mono/eina_accessor.cs
+++ b/src/bindings/mono/eina_mono/eina_accessor.cs
@@ -72,7 +72,14 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
{
if (Ownership == Ownership.Managed && Handle != IntPtr.Zero)
{
- eina_accessor_free(Handle);
+ if (disposing)
+ {
+ eina_accessor_free(Handle);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_accessor_free, Handle);
+ }
Handle = IntPtr.Zero;
}
}
diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs
index 106af08226..afa73e9775 100644
--- a/src/bindings/mono/eina_mono/eina_array.cs
+++ b/src/bindings/mono/eina_mono/eina_array.cs
@@ -149,7 +149,14 @@ public class Array<T> : IEnumerable<T>, IDisposable
if (Own)
{
- eina_array_free(h);
+ if (disposing)
+ {
+ eina_array_free(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_array_free, h);
+ }
}
}
diff --git a/src/bindings/mono/eina_mono/eina_binbuf.cs b/src/bindings/mono/eina_mono/eina_binbuf.cs
index 24fdaee5b1..2ae04ec1bd 100644
--- a/src/bindings/mono/eina_mono/eina_binbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_binbuf.cs
@@ -103,7 +103,14 @@ public class Binbuf : IDisposable
Handle = IntPtr.Zero;
if (Own && h != IntPtr.Zero)
{
- eina_binbuf_free(Handle);
+ if (disposing)
+ {
+ eina_binbuf_free(Handle);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_binbuf_free, Handle);
+ }
}
}
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs
index 9695c098da..630b084207 100644
--- a/src/bindings/mono/eina_mono/eina_container_common.cs
+++ b/src/bindings/mono/eina_mono/eina_container_common.cs
@@ -229,7 +229,7 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
{
if (nat != IntPtr.Zero)
{
- Efl.Eo.Globals.efl_unref(nat);
+ Efl.Eo.Globals.efl_mono_thread_safe_efl_unref(nat);
}
}
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index 9659a809fd..d74c96970b 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -187,7 +187,14 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
if (Own)
{
- eina_hash_free(h);
+ if (disposing)
+ {
+ eina_hash_free(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_hash_free, h);
+ }
}
}
diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs
index 987b46600f..8fbd89191c 100644
--- a/src/bindings/mono/eina_mono/eina_inarray.cs
+++ b/src/bindings/mono/eina_mono/eina_inarray.cs
@@ -141,7 +141,14 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
if (Own)
{
- eina_inarray_free(h);
+ if (disposing)
+ {
+ eina_inarray_free(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_inarray_free, h);
+ }
}
}
diff --git a/src/bindings/mono/eina_mono/eina_iterator.cs b/src/bindings/mono/eina_mono/eina_iterator.cs
index c8f61410ce..75ca1b2785 100644
--- a/src/bindings/mono/eina_mono/eina_iterator.cs
+++ b/src/bindings/mono/eina_mono/eina_iterator.cs
@@ -73,7 +73,14 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
if (Own)
{
- eina_iterator_free(h);
+ if (disposing)
+ {
+ eina_iterator_free(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_iterator_free, h);
+ }
}
}
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index fe956508b8..4b9e5f5856 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -45,6 +45,8 @@ public static class ListNativeFunctions
eina_list_move_list(ref IntPtr to, ref IntPtr from, IntPtr data);
[DllImport(efl.Libs.Eina)] public static extern IntPtr
eina_list_free(IntPtr list);
+ [DllImport(efl.Libs.CustomExports)] public static extern void
+ efl_mono_thread_safe_eina_list_free(IntPtr list);
[DllImport(efl.Libs.Eina)] public static extern IntPtr
eina_list_nth(IntPtr list, uint n);
[DllImport(efl.Libs.Eina)] public static extern IntPtr
@@ -190,7 +192,14 @@ public class List<T> : IEnumerable<T>, IDisposable
if (Own)
{
- eina_list_free(h);
+ if (disposing)
+ {
+ eina_list_free(h);
+ }
+ else
+ {
+ efl_mono_thread_safe_eina_list_free(h);
+ }
}
}
diff --git a/src/bindings/mono/eina_mono/eina_promises.cs b/src/bindings/mono/eina_mono/eina_promises.cs
index c7b68fe7a9..25077a3c97 100644
--- a/src/bindings/mono/eina_mono/eina_promises.cs
+++ b/src/bindings/mono/eina_mono/eina_promises.cs
@@ -28,6 +28,9 @@ static internal class PromiseNativeMethods
[DllImport(efl.Libs.Eina)]
internal static extern void eina_promise_reject(IntPtr scheduler, Eina.Error reason);
+ [DllImport(efl.Libs.CustomExports)]
+ internal static extern void efl_mono_thread_safe_promise_reject(IntPtr scheduler, Eina.Error reason);
+
[DllImport(efl.Libs.Eina)]
internal static extern IntPtr eina_future_new(IntPtr promise);
@@ -148,7 +151,14 @@ public class Promise : IDisposable
{
if (Handle != IntPtr.Zero)
{
- eina_promise_reject(Handle, Eina.Error.ECANCELED);
+ if (disposing)
+ {
+ eina_promise_reject(Handle, Eina.Error.ECANCELED);
+ }
+ else
+ {
+ efl_mono_thread_safe_promise_reject(Handle, Eina.Error.ECANCELED);
+ }
Handle = IntPtr.Zero;
}
}
diff --git a/src/bindings/mono/eina_mono/eina_strbuf.cs b/src/bindings/mono/eina_mono/eina_strbuf.cs
index 5b25ff15de..927a21da08 100644
--- a/src/bindings/mono/eina_mono/eina_strbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_strbuf.cs
@@ -93,7 +93,16 @@ public class Strbuf : IDisposable
if (!Disposed && (Handle != IntPtr.Zero))
{
- eina_strbuf_free(Handle);
+ if (disposing)
+ {
+ eina_strbuf_free(Handle);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_strbuf_free, Handle);
+ }
+
+ Handle = IntPtr.Zero;
}
Disposed = true;
diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs
index 742dc4d366..3c9cb53ced 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -1405,7 +1405,14 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
if (!Disposed && (Handle != IntPtr.Zero))
{
// No need to call flush as eina_value_free already calls it for us.
- Free(this.Handle);
+ if (disposing)
+ {
+ Free(this.Handle);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_value_free, this.Handle);
+ }
}
Disposed = true;
diff --git a/src/bindings/mono/eldbus_mono/eldbus_connection.cs b/src/bindings/mono/eldbus_mono/eldbus_connection.cs
index 24a1ad9aff..ea8a45f7a1 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_connection.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_connection.cs
@@ -161,7 +161,14 @@ public class Connection : IDisposable
if (Own)
{
- eldbus_connection_unref(h);
+ if (disposing)
+ {
+ eldbus_connection_unref(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_connection_unref, h);
+ }
}
}
diff --git a/src/bindings/mono/eldbus_mono/eldbus_message.cs b/src/bindings/mono/eldbus_mono/eldbus_message.cs
index 4e2c154e6a..eec9167d18 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_message.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_message.cs
@@ -230,7 +230,14 @@ public class Message : IDisposable
if (Own)
{
- eldbus_message_unref(h);
+ if (disposing)
+ {
+ eldbus_message_unref(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_message_unref, h);
+ }
}
}
diff --git a/src/bindings/mono/eldbus_mono/eldbus_object.cs b/src/bindings/mono/eldbus_mono/eldbus_object.cs
index 1e9af69709..136e8407ac 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_object.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_object.cs
@@ -152,7 +152,14 @@ public class Object : System.IDisposable
if (Own)
{
- eldbus_object_unref(h);
+ if (disposing)
+ {
+ eldbus_object_unref(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_object_unref, h);
+ }
}
}
diff --git a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
index 0fab5ebcab..c8ac4d265a 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
@@ -111,7 +111,14 @@ public class Proxy : IDisposable
if (Own)
{
- eldbus_proxy_unref(h);
+ if (disposing)
+ {
+ eldbus_proxy_unref(h);
+ }
+ else
+ {
+ Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_proxy_unref, h);
+ }
}
}
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 3600cdec50..69adf045ce 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -2,6 +2,7 @@
using System;
using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
@@ -66,6 +67,11 @@ public class Globals
efl_ref_count_delegate(IntPtr eo);
[DllImport(efl.Libs.Eo)] public static extern int
efl_ref_count(IntPtr eo);
+ [DllImport(efl.Libs.CustomExports)] public static extern void
+ efl_mono_thread_safe_efl_unref(IntPtr eo);
+
+ [DllImport(efl.Libs.CustomExports)] public static extern void
+ efl_mono_thread_safe_free_cb_exec(EinaFreeCb free_cb, IntPtr cb_data);
[DllImport(efl.Libs.Eo)] public static extern IntPtr
efl_class_name_get(IntPtr eo);
@@ -415,7 +421,9 @@ public class Globals
}
}
- public static IntPtr instantiate_start(IntPtr klass, Efl.Object parent)
+ public static IntPtr instantiate_start(IntPtr klass, Efl.Object parent,
+ [CallerFilePath] string file = null,
+ [CallerLineNumber] int line = 0)
{
Eina.Log.Debug($"Instantiating from klass 0x{klass.ToInt64():x}");
System.IntPtr parent_ptr = System.IntPtr.Zero;
@@ -424,7 +432,7 @@ public class Globals
parent_ptr = parent.NativeHandle;
}
- System.IntPtr eo = Efl.Eo.Globals._efl_add_internal_start("file", 0, klass, parent_ptr, 1, 0);
+ System.IntPtr eo = Efl.Eo.Globals._efl_add_internal_start(file, line, klass, parent_ptr, 1, 0);
if (eo == System.IntPtr.Zero)
{
throw new Exception("Instantiation failed");
diff --git a/src/bindings/mono/meson.build b/src/bindings/mono/meson.build
index 67c77a647d..dc2c856404 100644
--- a/src/bindings/mono/meson.build
+++ b/src/bindings/mono/meson.build
@@ -94,7 +94,8 @@ blacklisted_files = [
efl_mono_lib = library('eflcustomexportsmono',
join_paths('..', '..', 'lib', 'efl_mono', 'efl_custom_exports_mono.c'),
install : true,
- dependencies : [eo, eina]
+ install_dir : join_paths(dir_lib, 'efl-mono-'+version_major),
+ dependencies : [eo, eina, ecore]
)
beta_option = []