Page MenuHomePhabricator

csharp: fix Eina_Stringshare support in containers for manual and generated API

Authored by vitor.sousa on Jun 25 2019, 11:37 AM.



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
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<System.String> 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.

Diff Detail

rEFL core/efl
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
vitor.sousa created this revision.Jun 25 2019, 11:37 AM
vitor.sousa requested review of this revision.Jun 25 2019, 11:37 AM

Adding @segfaultxavi to know if he is OK with the change in the Efl.Csharp.Application.OnInitialize method.

Adding @segfaultxavi to know if he is OK with the change in the Efl.Csharp.Application.OnInitialize method.

Definitely! The purpose of the bindings is to make the API as close to the target language as possible!
Ideally, I would like all references to Eina.Array in the C# API replaced with C# arrays.

vitor.sousa planned changes to this revision.Jun 27 2019, 10:47 AM

I replicated the tests with iterators and ownership to stringshare too.
And now iterators with ownership are no longer allowed.
I am going to fix this test.

Fix tests that use iterators with element ownership.

lauromoura accepted this revision.Jun 27 2019, 3:24 PM
This revision is now accepted and ready to land.Jun 27 2019, 3:24 PM
This revision was automatically updated to reflect the committed changes.