forked from enlightenment/efl
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
This commit is contained in:
parent
6ce53b9c0f
commit
50a1572c09
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue