lauromoura pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=50a1572c093d8c2620cd4d1e9d48950fe7eeae95

commit 50a1572c093d8c2620cd4d1e9d48950fe7eeae95
Author: Bruno da Silva Belo <brunodasilvab...@gmail.com>
Date:   Tue Sep 10 17:42:19 2019 -0300

    csharp: Adding ToString methods to Strbuf and custommarshaler.
    
    Summary:
    WIN32 should use a allocator and deallocator different from EFL, sometimes, 
when
    freeing a pointer, it should use win32_free. To stardardize, A 
custommarshaler
    is used to fix this problem.
    
    Fixes T8201
    
    Reviewers: lauromoura, felipealmeida
    
    Reviewed By: lauromoura
    
    Subscribers: cedric, brunobelo, felipealmeida, #reviewers, lauromoura, 
#committers
    
    Tags: #efl
    
    Maniphest Tasks: T8201
    
    Differential Revision: https://phab.enlightenment.org/D9842
---
 src/bindings/mono/eina_mono/eina_strbuf.cs | 25 ++++++++++++++++++++++---
 src/bindings/mono/eina_mono/eina_value.cs  | 11 ++++++-----
 src/tests/efl_mono/Strbuf.cs               | 10 ++++++++++
 3 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/src/bindings/mono/eina_mono/eina_strbuf.cs 
b/src/bindings/mono/eina_mono/eina_strbuf.cs
index a538de0fd2..6fd35a4638 100644
--- a/src/bindings/mono/eina_mono/eina_strbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_strbuf.cs
@@ -32,9 +32,18 @@ static internal class StrbufNativeMethods
     [return: MarshalAsAttribute(UnmanagedType.U1)]
     internal static extern bool eina_strbuf_append_char(IntPtr buf, char c);
 
-    [DllImport(efl.Libs.Eina)]
+    [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)]
+    [return:
+     MarshalAs(UnmanagedType.CustomMarshaler,
+              MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]
     internal static extern string eina_strbuf_string_steal(IntPtr buf);
 
+    [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)]
+    [return:
+     MarshalAs(UnmanagedType.CustomMarshaler,
+              MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]
+    internal static extern string eina_strbuf_string_get(IntPtr buf);
+
     [DllImport(efl.Libs.Eina)]
     internal static extern IntPtr eina_strbuf_length_get(IntPtr buf); // Uses 
IntPtr as wrapper for size_t
 }
@@ -176,8 +185,18 @@ public class Strbuf : IDisposable
             throw new ObjectDisposedException(base.GetType().Name);
         }
 
-        return eina_strbuf_string_steal(Handle);
+        return eina_strbuf_string_steal(this.Handle);
     }
-}
 
+    /// <summary>Copy the content of a buffer.</summary>
+    public override string ToString()
+    {
+        if (Disposed)
+        {
+            throw new ObjectDisposedException(base.GetType().Name);
+        }
+
+        return eina_strbuf_string_get(this.Handle);
+    }
+}
 } // namespace eina
diff --git a/src/bindings/mono/eina_mono/eina_value.cs 
b/src/bindings/mono/eina_mono/eina_value.cs
index 57a615772b..54c437d352 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -173,7 +173,10 @@ static internal class UnsafeNativeMethods
     internal static extern int eina_value_compare_wrapper(IntPtr handle, 
IntPtr other);
 
     [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)]
-    internal static extern IntPtr eina_value_to_string(IntPtr handle); // We 
take ownership of the returned string.
+    [return:
+     MarshalAs(UnmanagedType.CustomMarshaler,
+              MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]
+    internal static extern string eina_value_to_string(IntPtr handle); // We 
take ownership of the returned string.
 
     [DllImport(efl.Libs.CustomExports)]
     [return: MarshalAsAttribute(UnmanagedType.U1)]
@@ -2611,10 +2614,8 @@ public class Value : IDisposable, IComparable<Value>, 
IEquatable<Value>
     public override String ToString()
     {
         SanityChecks();
-        IntPtr ptr = eina_value_to_string(this.Handle);
-        String str = Marshal.PtrToStringAnsi(ptr);
-        MemoryNative.Free(ptr);
-        return str;
+        return eina_value_to_string(this.Handle);
+
     }
 
     /// <summary>Empties an optional Eina.Value, freeing what was previously 
contained.</summary>
diff --git a/src/tests/efl_mono/Strbuf.cs b/src/tests/efl_mono/Strbuf.cs
index ef2cc56f16..78e9c5cbc3 100644
--- a/src/tests/efl_mono/Strbuf.cs
+++ b/src/tests/efl_mono/Strbuf.cs
@@ -16,6 +16,16 @@ class TestStrBuf
         Test.AssertEquals("Here's Johnny!", buf.Steal());
     }
 
+    public static void test_tostring()
+    {
+        Eina.Strbuf buf = new Eina.Strbuf();
+        buf.Append("Hello");
+        buf.Append(' ');
+        buf.Append("World!");
+
+        Test.AssertEquals("Hello World!", buf.ToString());
+    }
+
     public static void test_eolian()
     {
         var obj = new Dummy.TestObject();

-- 


Reply via email to