From 4496022a3ca5223baceb11609d7659e1f34d6549 Mon Sep 17 00:00:00 2001 From: Vitor Sousa Date: Fri, 28 Jun 2019 10:40:52 -0300 Subject: csharp: fix Eina_Stringshare support in containers for manual and generated API Summary: Both C strings and eina stringshares are bound as regular strings in EFL#, as working directly with these types would demand unnecessary hassle from the user viewpoint. But for eina containers this distinction is important, and since C# generics do not provide a convenient way of dealing with the same type requiring a different management based on some other condition (at least not without compromising the usability for other types), we added a simple `System.String` wrapper named `Eina.Stringshare` that works as a placeholder for signaling this distinction. Working with this class should be transparent in most use cases because it converts to and from `System.String` implicitly. It also implements equality/inequality methods for easier comparison with strings and other stringshare objects. Add new methods and a new container element trait for dealing specifically with `Eina_Stringshare` elements. Adapt eolian_mono to identify and generate the proper placeholder in methods that require stringshare containers. Remove some direct uses of DllImport-ed functions in favor of more flexible manual binding methods. Move `Eina.Stringshare` DllImport directives to a static class named `NativeMethods`, in accordance with the code design warning CA1060. Also add a TODO comment to move all other DllImport directives to this class. Change parameter of the method `Efl.Csharp.Application.OnInitialize` from `Eina.Array` to `string[]`. This will make this API more similar with the default C# way of receiving command line arguments. Add tests for containers storing stringshare elements. Reviewers: felipealmeida, lauromoura, segfaultxavi, bu5hm4n Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9178 --- src/lib/efl_mono/efl_custom_exports_mono.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/lib/efl_mono') diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c index 8d57ad730f..aa2572f49d 100644 --- a/src/lib/efl_mono/efl_custom_exports_mono.c +++ b/src/lib/efl_mono/efl_custom_exports_mono.c @@ -125,6 +125,12 @@ EAPI void efl_mono_native_free_ref(void **ptr) free(*ptr); } +EAPI void efl_mono_native_stringshare_del_ref(void **str) +{ + if (!str) return; + eina_stringshare_del(*str); +} + EAPI void *efl_mono_native_alloc_copy(const void *val, unsigned int size) { if (!val) return NULL; @@ -161,6 +167,11 @@ EAPI Eina_Free_Cb efl_mono_native_free_addr_get() return (Eina_Free_Cb)free; } +EAPI Eina_Free_Cb efl_mono_native_stringshare_del_addr_get() +{ + return (Eina_Free_Cb)eina_stringshare_del; +} + EAPI Eina_Free_Cb efl_mono_native_efl_unref_addr_get() { return (Eina_Free_Cb)efl_mono_thread_safe_efl_unref; -- cgit v1.2.1