Compare commits

...
3 Commits
Author SHA1 Message Date
Egor Bogatov 360dca39d3 use gunichar2 for appctx_keys and appctx_values 2019-08-27 19:54:32 +03:00
Alexander Köplinger ae171d5ee6 Remove AppContext.cs that was moved to shared 2019-08-27 01:50:15 +02:00
Egor Bogatov 2efd81d9ed Move AppContext.CoreCLR.cs to shared, remove static ctor (#26045)
* Remove AppContext.CoreCLR.cs (move to shared)

Signed-off-by: dotnet-bot <[email protected]>
2019-08-26 23:25:16 +00:00
4 changed files with 38 additions and 37 deletions

No files matched your search

+6 -6
View File
@@ -97,8 +97,8 @@ static gboolean no_exec = FALSE;
#ifdef ENABLE_NETCORE
static int n_appctx_props;
static char **appctx_keys;
static char **appctx_values;
static gunichar2 **appctx_keys;
static gunichar2 **appctx_values;
#endif
static const char *
@@ -3336,12 +3336,12 @@ void
mono_runtime_register_appctx_properties (int nprops, const char **keys, const char **values)
{
n_appctx_props = nprops;
appctx_keys = g_new0 (char*, nprops);
appctx_values = g_new0 (char*, nprops);
appctx_keys = g_new0 (gunichar2*, nprops);
appctx_values = g_new0 (gunichar2*, nprops);
for (int i = 0; i < nprops; ++i) {
appctx_keys [i] = g_strdup (keys [i]);
appctx_values [i] = g_strdup (values [i]);
appctx_keys [i] = g_utf8_to_utf16 (keys [i], strlen (keys [i]), NULL, NULL, NULL);
appctx_values [i] = g_utf8_to_utf16 (values [i], strlen (values [i]), NULL, NULL, NULL);
}
}
@@ -146,7 +146,6 @@
<Compile Include="src\Mono\MonoDomain.cs" />
<Compile Include="src\Mono\MonoDomainSetup.cs" />
<Compile Include="src\Mono\RuntimeHandles.cs" />
<Compile Include="src\System\AppContext.cs" />
<Compile Include="src\System\ArgIterator.cs" />
<Compile Include="src\System\Array.cs" />
<Compile Include="src\System\Attribute.cs" />
@@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.Loader;
@@ -13,7 +15,7 @@ namespace System
{
public static partial class AppContext
{
private static readonly Dictionary<string, object?> s_dataStore = new Dictionary<string, object?>();
private static Dictionary<string, object?>? s_dataStore;
private static Dictionary<string, bool>? s_switches;
private static string? s_defaultBaseDirectory;
@@ -33,6 +35,9 @@ namespace System
if (name == null)
throw new ArgumentNullException(nameof(name));
if (s_dataStore == null)
return null;
object? data;
lock (s_dataStore)
{
@@ -46,6 +51,11 @@ namespace System
if (name == null)
throw new ArgumentNullException(nameof(name));
if (s_dataStore == null)
{
Interlocked.CompareExchange(ref s_dataStore, new Dictionary<string, object?>(), null);
}
lock (s_dataStore)
{
s_dataStore[name] = data;
@@ -121,5 +131,26 @@ namespace System
s_switches[switchName] = isEnabled;
}
}
#if !CORERT
internal static unsafe void Setup(char** pNames, char** pValues, int count)
{
Debug.Assert(s_dataStore == null, "s_dataStore is not expected to be inited before Setup is called");
s_dataStore = new Dictionary<string, object?>(count);
for (int i = 0; i < count; i++)
{
s_dataStore.Add(new string(pNames[i]), new string(pValues[i]));
}
}
private static string GetBaseDirectoryCore()
{
// Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly
string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
if (directory != null && !Path.EndsInDirectorySeparator(directory))
directory += PathInternal.DirectorySeparatorCharAsString;
return directory ?? string.Empty;
}
#endif
}
}
@@ -1,29 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
using System.Reflection;
namespace System
{
partial class AppContext
{
// Called by the runtime
internal static unsafe void Setup (char** pNames, char** pValues, int count)
{
for (int i = 0; i < count; i++)
s_dataStore.Add (new string ((sbyte*)pNames[i]), new string ((sbyte*)pValues[i]));
}
static string GetBaseDirectoryCore ()
{
// Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly
var directory = Path.GetDirectoryName (Assembly.GetEntryAssembly()?.Location);
if (directory != null && !Path.EndsInDirectorySeparator (directory))
directory += Path.DirectorySeparatorChar;
return directory ?? string.Empty;
}
}
}