diff --git a/src/bindings/mono/efl_mono/meson.build b/src/bindings/mono/efl_mono/meson.build index 8bfba319c1..e93d323747 100644 --- a/src/bindings/mono/efl_mono/meson.build +++ b/src/bindings/mono/efl_mono/meson.build @@ -41,6 +41,7 @@ if get_option('build-tests') mono_friend_assemblies += 'efl_sharp_test_suite' else mono_friend_assemblies += 'efl_mono_test' + mono_friend_assemblies += 'efl-mono-suite' endif endif diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs index 9465891998..a4f2ff4c5f 100644 --- a/src/bindings/mono/eina_mono/eina_common.cs +++ b/src/bindings/mono/eina_mono/eina_common.cs @@ -31,7 +31,7 @@ internal delegate void EinaFreeCb(IntPtr data); } -internal static class NativeCustomExportFunctions +internal static partial class NativeCustomExportFunctions { [DllImport(efl.Libs.CustomExports)] public static extern void efl_mono_native_free(IntPtr ptr); diff --git a/src/bindings/mono/eina_mono/eina_environment.cs b/src/bindings/mono/eina_mono/eina_environment.cs new file mode 100644 index 0000000000..7cef31cbf1 --- /dev/null +++ b/src/bindings/mono/eina_mono/eina_environment.cs @@ -0,0 +1,53 @@ +using System; +using System.Runtime.InteropServices; + +namespace Eina +{ + +/// +/// Class to deal with native Environment variables. +/// +/// To be used in place of methods when +/// accessing the native environment directly. +/// Since EFL 1.24. +/// +internal static class Environment +{ + /// + /// Returns the value of the environment variable named name. + /// + /// Since EFL 1.24 + /// + /// The name of the variable to be retrieved + /// The value of the variable. null if not set. + public static string GetEnv(string name) + { + return Eina.NativeCustomExportFunctions.efl_mono_native_getenv(name); + } + + /// + /// Sets a native environment variable. + /// + /// Since EFL 1.24 + /// + /// The name of the variable + /// The value to be set. + /// true if an existing variable must be overwritten. + public static void SetEnv(string name, string value, bool overwrite=true) + { + Eina.Error error = Eina.NativeCustomExportFunctions.efl_mono_native_setenv(name, value, overwrite ? 1 : 0); + Eina.Error.Raise(error); + } +} + +internal static partial class NativeCustomExportFunctions +{ + [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)] + [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] + public static extern string efl_mono_native_getenv(string name); + + [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)] + public static extern Eina.Error efl_mono_native_setenv(string name, string value, int overwrite); +} + +} \ No newline at end of file diff --git a/src/bindings/mono/eina_mono/meson.build b/src/bindings/mono/eina_mono/meson.build index 1d9e4e6a43..82c418f399 100644 --- a/src/bindings/mono/eina_mono/meson.build +++ b/src/bindings/mono/eina_mono/meson.build @@ -16,5 +16,6 @@ mono_files += files( 'eina_value.cs', 'eina_promises.cs', 'eina_accessor.cs', - 'eina_strbuf.cs' + 'eina_strbuf.cs', + 'eina_environment.cs', ) diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c index c3e8191e22..ede573f875 100644 --- a/src/lib/efl_mono/efl_custom_exports_mono.c +++ b/src/lib/efl_mono/efl_custom_exports_mono.c @@ -202,6 +202,17 @@ EAPI Efl_Substitute_Ctor_Cb efl_mono_avoid_top_level_constructor_callback_addr_g return &_efl_mono_avoid_top_level_constructor_cb; } +// Environment wrappers // +EAPI const char *efl_mono_native_getenv(const char *name) +{ + return getenv(name); +} + +EAPI Eina_Error efl_mono_native_setenv(const char *name, const char *value, int overwrite) +{ + return setenv(name, value, overwrite); +} + // Iterator Wrapper // typedef struct _Eina_Iterator_Wrapper_Mono diff --git a/src/tests/efl_mono/Main.cs b/src/tests/efl_mono/Main.cs index 059ad4cf0d..7829cf359f 100644 --- a/src/tests/efl_mono/Main.cs +++ b/src/tests/efl_mono/Main.cs @@ -30,8 +30,13 @@ class TestMain static int Main(string[] args) { - if (Environment.GetEnvironmentVariable("ELM_ENGINE") == null) - Environment.SetEnvironmentVariable("ELM_ENGINE", "buffer"); + /// We do not use System.Environment due to CoreCLR open issues regarding + /// setenv modifying the actual C environment. See issue #1592 in CoreCLR repo. + Eina.Config.Init(); + if (Eina.Environment.GetEnv("ELM_ENGINE") == null) + { + Eina.Environment.SetEnv("ELM_ENGINE", "buffer", true); + } Efl.All.Init(Efl.Csharp.Components.Ui); @@ -114,6 +119,7 @@ class TestMain Console.WriteLine("[ END SUITE ] " + ckRunSuite); Efl.All.Shutdown(); + Eina.Config.Shutdown(); // For the extra init in getenv/setenv above if (!pass) return -1;