aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-05-16 22:14:41 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-05-16 22:17:16 -0300
commite11c95fa563dace778b87e534350e332764574ef (patch)
tree07e5b0123461eb6bfbd380e47c80896cbf3be774
parentcsharp: pin-unpin lifetime (NEEDS REVIEW) (diff)
downloadefl-devs/vitorsousa/pin-unpin.tar.gz
Listening to invalidate events in order to properly free on parent del (WIP)devs/vitorsousa/pin-unpin
-rw-r--r--src/bindings/mono/eo_mono/WrapperSupervisor.cs4
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs37
-rw-r--r--src/lib/efl_mono/efl_custom_exports_mono.c2
-rw-r--r--src/tests/efl_mono/Inheritance.cs72
4 files changed, 33 insertions, 82 deletions
diff --git a/src/bindings/mono/eo_mono/WrapperSupervisor.cs b/src/bindings/mono/eo_mono/WrapperSupervisor.cs
index 68269f0d24..f2e1c942cc 100644
--- a/src/bindings/mono/eo_mono/WrapperSupervisor.cs
+++ b/src/bindings/mono/eo_mono/WrapperSupervisor.cs
@@ -11,11 +11,13 @@ namespace Eo
public class WrapperSupervisor
{
private System.WeakReference weakRef;
+#pragma warning disable CS0414
private Efl.Eo.IWrapper sharedRef;
+#pragma warning restore CS0414
private EventDictionary eoEvents;
/// <summary>Create a new supervisor for the given.</summary>
- /// <param name="eo">Efl object to be supervised.</param>
+ /// <param name="obj">Efl object to be supervised.</param>
public WrapperSupervisor(Efl.Eo.IWrapper obj)
{
weakRef = new WeakReference(obj);
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 6276d375b7..8cd86f403c 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -578,6 +578,7 @@ public class Globals
/// <returns>The C# wrapper for this instance.</returns>
public static Efl.Eo.IWrapper CreateWrapperFor(System.IntPtr handle, bool shouldIncRef=true)
{
+
if (handle == IntPtr.Zero)
{
return null;
@@ -645,8 +646,6 @@ public class Globals
{
Efl.Eo.Globals.efl_unref(handle);
}
-
- return null;
}
private static Efl.FreeWrapperSupervisorCb FreeWrapperSupervisorCallbackDelegate = new Efl.FreeWrapperSupervisorCb(FreeWrapperSupervisorCallback);
@@ -673,7 +672,12 @@ public class Globals
}
}
+ // Free the native eo
Efl.Eo.Globals.efl_unref(eo);
+
+ // now the WrapperSupervisor can be collected, and so its member:
+ // - the event dictionary
+ // - and the EoWrapper if it is still pinned
gch.Free();
}
catch (Exception e)
@@ -775,6 +779,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback);
private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback);
+ private static Efl.EventCb invalidateDelegate = new Efl.EventCb(InvalidateCallback);
/// <summary>Initializes a new instance of the <see cref="Object"/> class.
/// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>
@@ -864,27 +869,6 @@ public abstract class EoWrapper : IWrapper, IDisposable
}
}
- /// <summary>Verifies if the given object is equal to this one.</summary>
- /// <param name="instance">The object to compare to.</param>
- /// <returns>True if both objects point to the same native object.</returns>
- public override bool Equals(object instance)
- {
- var other = instance as Efl.Eo.IWrapper;
- if (other == null)
- {
- return false;
- }
-
- return handle == other.NativeHandle;
- }
-
- /// <summary>Gets the hash code for this object based on the native pointer it points to.</summary>
- /// <returns>The value of the pointer, to be used as the hash code of this object.</returns>
- public override int GetHashCode()
- {
- return handle.ToInt32();
- }
-
/// <summary>Turns the native pointer into a string representation.</summary>
/// <returns>A string with the type and the native pointer for this object.</returns>
public override String ToString()
@@ -992,6 +976,12 @@ public abstract class EoWrapper : IWrapper, IDisposable
ws.MakeShared();
}
+ private static void InvalidateCallback(IntPtr data, ref Efl.Event.NativeStruct evt)
+ {
+ var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data);
+ ws.MakeUnique();
+ }
+
/// <sumary>Create and set to the internal native state a C# supervisor for this Eo wrapper. For internal use only.</sumary>
private void AddWrapperSupervisor()
{
@@ -1010,6 +1000,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
{
AddNativeEventHandler("eo", "_EFL_EVENT_OWNERSHIP_UNIQUE", ownershipUniqueDelegate, ownershipUniqueDelegate);
AddNativeEventHandler("eo", "_EFL_EVENT_OWNERSHIP_SHARED", ownershipSharedDelegate, ownershipSharedDelegate);
+ AddNativeEventHandler("eo", "_EFL_EVENT_INVALIDATE", invalidateDelegate, invalidateDelegate);
Eina.Error.RaiseIfUnhandledException();
}
}
diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c
index 3e49726aea..55f0054da0 100644
--- a/src/lib/efl_mono/efl_custom_exports_mono.c
+++ b/src/lib/efl_mono/efl_custom_exports_mono.c
@@ -50,13 +50,11 @@ EAPI void efl_mono_wrapper_supervisor_callbacks_set(Efl_Mono_Free_Wrapper_Superv
EAPI void efl_mono_native_dispose(Eo *obj)
{
- printf("HHHHH %s:%i %s(%p)\n", __FILE__, __LINE__, __func__, obj); fflush(stderr); fflush(stdout);
_efl_mono_free_wrapper_supervisor_call(obj);
}
EAPI void efl_mono_thread_safe_native_dispose(Eo *obj)
{
- printf("HHHHH %s:%i %s(%p)\n", __FILE__, __LINE__, __func__, obj); fflush(stderr); fflush(stdout);
ecore_main_loop_thread_safe_call_async((Ecore_Cb)efl_mono_native_dispose, obj);
}
diff --git a/src/tests/efl_mono/Inheritance.cs b/src/tests/efl_mono/Inheritance.cs
index be702da864..4755ce2af5 100644
--- a/src/tests/efl_mono/Inheritance.cs
+++ b/src/tests/efl_mono/Inheritance.cs
@@ -10,11 +10,6 @@ using static EinaTestData.BaseData;
namespace TestSuite
{
-internal class Rubbish
-{
- public int Content { get; set; } = 0;
-}
-
class TestInheritance
{
internal class Inherit1 : Dummy.TestObject
@@ -39,7 +34,7 @@ class TestInheritance
return "Hello World";
}
}
-
+
internal class Inherit3Parent : Dummy.TestObject
{
public bool disposed = false;
@@ -50,7 +45,7 @@ class TestInheritance
Console.WriteLine("finalizer called for parent");
}
- protected override void Dispose (bool disposing)
+ protected override void Dispose(bool disposing)
{
Console.WriteLine("Dispose parent");
base.Dispose(disposing);
@@ -60,7 +55,7 @@ class TestInheritance
internal class Inherit3Child : Dummy.TestObject
{
Inherit3Parent parent;
- public Inherit3Child (Inherit3Parent parent) : base (parent)
+ public Inherit3Child(Inherit3Parent parent) : base(parent)
{
this.parent = parent;
}
@@ -70,7 +65,7 @@ class TestInheritance
Console.WriteLine("finalizer called for child");
}
- protected override void Dispose (bool disposing)
+ protected override void Dispose(bool disposing)
{
parent.childDisposed = true;
Console.WriteLine("Dispose parent");
@@ -94,46 +89,16 @@ class TestInheritance
Test.AssertEquals ("Hello World", s);
}
- private static void MakeRubbish(out WeakReference objWRef)
- {
- var obj = new Inherit3Parent();
-
- objWRef = new WeakReference(obj);
-
-
- int n = 2111000;
- var arr1 = new Rubbish[n];
- var arr2 = new Rubbish[n];
- var rand = new Random();
- for (int i = 0; i != n; ++i)
- {
- arr1[i] = new Rubbish();
- arr1[i].Content = rand.Next();
- }
-
- for (int i = n-1; i != -1; --i)
- {
- arr2[i] = new Rubbish();
- arr2[i].Content = arr1[(i+n/2)%n].Content + (arr1[i].Content%2 == 0 ? 1 : -1);
- }
-
- var x = rand.Next(n);
- Console.WriteLine($"arr1[x] = {arr1[x].Content}; arr2[x] = {arr2[x].Content}");
- }
-
- private static void hsasdgsdahd(out WeakReference parentWRef, out WeakReference childWRef)
+ private static void CreateAndCheckInheritedObjects(out WeakReference parentWRef, out WeakReference childWRef)
{
- //var parent = new Inherit3Parent();
- //var child = new Inherit3Child(parent);
-
- var parent = new Dummy.TestObject();
- var child = new Dummy.TestObject(parent);
+ var parent = new Inherit3Parent();
+ var child = new Inherit3Child(parent);
parentWRef = new WeakReference(parent);
childWRef = new WeakReference(child);
- Console.WriteLine($"MMMMM Parent [{parent.ToString()}] has {Efl.Eo.Globals.efl_ref_count(parent.NativeHandle)} refs");
- Console.WriteLine($"MMMMM Child [{child.ToString()}] has {Efl.Eo.Globals.efl_ref_count(child.NativeHandle)} refs");
+ Console.WriteLine($"Parent [{parent.ToString()}] has {Efl.Eo.Globals.efl_ref_count(parent.NativeHandle)} refs");
+ Console.WriteLine($"Child [{child.ToString()}] has {Efl.Eo.Globals.efl_ref_count(child.NativeHandle)} refs");
child = null;
@@ -141,15 +106,15 @@ class TestInheritance
System.GC.WaitForPendingFinalizers();
Efl.App.AppMain.Iterate();
- child = (Dummy.TestObject) childWRef.Target;
+ child = (Inherit3Child) childWRef.Target;
Test.AssertNotNull(parent);
Test.AssertNotNull(child);
- //Test.AssertEquals(false, parent.disposed);
- //Test.AssertEquals(false, parent.childDisposed);
+ Test.AssertEquals(false, parent.disposed);
+ Test.AssertEquals(false, parent.childDisposed);
- Console.WriteLine($"MMMMM Parent [{parent.ToString()}] has {Efl.Eo.Globals.efl_ref_count(parent.NativeHandle)} refs");
- Console.WriteLine($"MMMMM Child [{child.ToString()}] has {Efl.Eo.Globals.efl_ref_count(child.NativeHandle)} refs");
+ Console.WriteLine($"Parent [{parent.ToString()}] has {Efl.Eo.Globals.efl_ref_count(parent.NativeHandle)} refs");
+ Console.WriteLine($"Child [{child.ToString()}] has {Efl.Eo.Globals.efl_ref_count(child.NativeHandle)} refs");
parent = null;
child = null;
@@ -164,14 +129,11 @@ class TestInheritance
System.GC.WaitForPendingFinalizers();
Efl.App.AppMain.Iterate();
- hsasdgsdahd(out parentWRef, out childWRef);
-
- WeakReference objWRef;
- MakeRubbish(out objWRef);
+ CreateAndCheckInheritedObjects(out parentWRef, out childWRef);
for (int i = 0; i < 10; ++i)
{
- for (int j = 0; j < 1000; ++j)
+ for (int j = 0; j < 100; ++j)
{
System.GC.Collect();
}
@@ -180,11 +142,9 @@ class TestInheritance
Efl.App.AppMain.Iterate();
}
- var obj = (Rubbish) objWRef.Target;
var parent = (Dummy.TestObject) parentWRef.Target;
var child = (Dummy.TestObject) childWRef.Target;
- Test.AssertNull(obj);
Test.AssertNull(parent);
Test.AssertNull(child);
}