diff options
author | Bruno da Silva Belo <brunodasilvabelo@gmail.com> | 2019-09-10 17:42:19 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-09-10 17:42:19 -0300 |
commit | 50a1572c093d8c2620cd4d1e9d48950fe7eeae95 (patch) | |
tree | 99ba8c4cf90f8e6f3e676555be548be807f622cd | |
parent | 6ce53b9c0f85a8b94ad90bc9abebc0c21d08e84c (diff) |
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
-rw-r--r-- | src/bindings/mono/eina_mono/eina_strbuf.cs | 25 | ||||
-rw-r--r-- | src/bindings/mono/eina_mono/eina_value.cs | 11 | ||||
-rw-r--r-- | 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 | |||
32 | [return: MarshalAsAttribute(UnmanagedType.U1)] | 32 | [return: MarshalAsAttribute(UnmanagedType.U1)] |
33 | internal static extern bool eina_strbuf_append_char(IntPtr buf, char c); | 33 | internal static extern bool eina_strbuf_append_char(IntPtr buf, char c); |
34 | 34 | ||
35 | [DllImport(efl.Libs.Eina)] | 35 | [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)] |
36 | [return: | ||
37 | MarshalAs(UnmanagedType.CustomMarshaler, | ||
38 | MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))] | ||
36 | internal static extern string eina_strbuf_string_steal(IntPtr buf); | 39 | internal static extern string eina_strbuf_string_steal(IntPtr buf); |
37 | 40 | ||
41 | [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)] | ||
42 | [return: | ||
43 | MarshalAs(UnmanagedType.CustomMarshaler, | ||
44 | MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] | ||
45 | internal static extern string eina_strbuf_string_get(IntPtr buf); | ||
46 | |||
38 | [DllImport(efl.Libs.Eina)] | 47 | [DllImport(efl.Libs.Eina)] |
39 | internal static extern IntPtr eina_strbuf_length_get(IntPtr buf); // Uses IntPtr as wrapper for size_t | 48 | internal static extern IntPtr eina_strbuf_length_get(IntPtr buf); // Uses IntPtr as wrapper for size_t |
40 | } | 49 | } |
@@ -176,8 +185,18 @@ public class Strbuf : IDisposable | |||
176 | throw new ObjectDisposedException(base.GetType().Name); | 185 | throw new ObjectDisposedException(base.GetType().Name); |
177 | } | 186 | } |
178 | 187 | ||
179 | return eina_strbuf_string_steal(Handle); | 188 | return eina_strbuf_string_steal(this.Handle); |
180 | } | 189 | } |
181 | } | ||
182 | 190 | ||
191 | /// <summary>Copy the content of a buffer.</summary> | ||
192 | public override string ToString() | ||
193 | { | ||
194 | if (Disposed) | ||
195 | { | ||
196 | throw new ObjectDisposedException(base.GetType().Name); | ||
197 | } | ||
198 | |||
199 | return eina_strbuf_string_get(this.Handle); | ||
200 | } | ||
201 | } | ||
183 | } // namespace eina | 202 | } // 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 | |||
173 | internal static extern int eina_value_compare_wrapper(IntPtr handle, IntPtr other); | 173 | internal static extern int eina_value_compare_wrapper(IntPtr handle, IntPtr other); |
174 | 174 | ||
175 | [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)] | 175 | [DllImport(efl.Libs.Eina, CharSet=CharSet.Ansi)] |
176 | internal static extern IntPtr eina_value_to_string(IntPtr handle); // We take ownership of the returned string. | 176 | [return: |
177 | MarshalAs(UnmanagedType.CustomMarshaler, | ||
178 | MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))] | ||
179 | internal static extern string eina_value_to_string(IntPtr handle); // We take ownership of the returned string. | ||
177 | 180 | ||
178 | [DllImport(efl.Libs.CustomExports)] | 181 | [DllImport(efl.Libs.CustomExports)] |
179 | [return: MarshalAsAttribute(UnmanagedType.U1)] | 182 | [return: MarshalAsAttribute(UnmanagedType.U1)] |
@@ -2611,10 +2614,8 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value> | |||
2611 | public override String ToString() | 2614 | public override String ToString() |
2612 | { | 2615 | { |
2613 | SanityChecks(); | 2616 | SanityChecks(); |
2614 | IntPtr ptr = eina_value_to_string(this.Handle); | 2617 | return eina_value_to_string(this.Handle); |
2615 | String str = Marshal.PtrToStringAnsi(ptr); | 2618 | |
2616 | MemoryNative.Free(ptr); | ||
2617 | return str; | ||
2618 | } | 2619 | } |
2619 | 2620 | ||
2620 | /// <summary>Empties an optional Eina.Value, freeing what was previously contained.</summary> | 2621 | /// <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 | |||
16 | Test.AssertEquals("Here's Johnny!", buf.Steal()); | 16 | Test.AssertEquals("Here's Johnny!", buf.Steal()); |
17 | } | 17 | } |
18 | 18 | ||
19 | public static void test_tostring() | ||
20 | { | ||
21 | Eina.Strbuf buf = new Eina.Strbuf(); | ||
22 | buf.Append("Hello"); | ||
23 | buf.Append(' '); | ||
24 | buf.Append("World!"); | ||
25 | |||
26 | Test.AssertEquals("Hello World!", buf.ToString()); | ||
27 | } | ||
28 | |||
19 | public static void test_eolian() | 29 | public static void test_eolian() |
20 | { | 30 | { |
21 | var obj = new Dummy.TestObject(); | 31 | var obj = new Dummy.TestObject(); |