8000 Address PR feedback · dotnet/corefx@ca9e711 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ca9e711

Browse files
committed
Address PR feedback
PR feedback: - Remove AppX checks and split Environment.Windows into Environment.Windows, Environment.CoreCLR, and Environment.NETNative - Change marshaling of service pack version field in OSVERSIONINFOEX - Forward TickCount to EnvironmentAugments rather than implementing it via a P/Invoke - Move environment variables support from coreclr to corefx Plus: - Use GetLogicalProcessorInformationEx to get the processor count, and cache it - Use GetUserNameExW instead of GetUserNameW, as it's available on more platforms - Fix compilation for .NET Native - Fixed a test
1 parent fe5f4fb commit ca9e711

20 files changed

+994
-309
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
using Microsoft.Win32.SafeHandles;
8+
9+
internal static partial class Interop
10+
{
11+
internal static partial class Sys
12+
{
13+
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEnviron", SetLastError = true)]
14+
internal static unsafe extern byte** GetEnviron();
15+
}
16+
}

src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@ internal static partial class Sys
1616
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAllMountPoints", SetLastError = true)]
1717
private static extern int GetAllMountPoints(MountPointFound mpf);
1818

19-
internal static List<string> GetAllMountPoints()
19+
internal static string[] GetAllMountPoints()
2020
{
21-
List<string> lst = new List<string>();
21+
int count = 0;
22+
var found = new string[4];
23+
2224
unsafe
2325
{
2426
int result = GetAllMountPoints((byte* name) =>
2527
{
26-
lst.Add(Marshal.PtrToStringAnsi((IntPtr)name));
28+
if (count == found.Length)
29+
{
30+
Array.Resize(ref found, count * 2);
31+
}
32+
found[count++] = Marshal.PtrToStringAnsi((IntPtr)name);
2733
});
2834
}
2935

30-
return lst;
8000 36+
Array.Resize(ref found, count);
37+
return found;
3138
}
3239
}
3340
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.InteropServices;
6+
using System.Text;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class mincore
11+
{
12+
[DllImport(Libraries.ProcessEnvironment, CharSet = CharSet.Unicode, SetLastError = true)]
13+
internal static extern int ExpandEnvironmentStringsW(string lpSrc, [Out] StringBuilder lpDst, int nSize);
14+
15+
[DllImport(Libraries.ProcessEnvironment, CharSet = CharSet.Unicode, SetLastError = true)]
16+
internal static extern int GetEnvironmentVariableW(string lpName, [Out] StringBuilder lpValue, int size);
17+
18+
[DllImport(Libraries.ProcessEnvironment, CharSet = CharSet.Unicode, SetLastError = true)]
19+
internal static extern bool SetEnvironmentVariableW(string lpName, string lpValue);
20+
21+
[DllImport(Libraries.ProcessEnvironment, CharSet = CharSet.Unicode)]
22+
internal static extern unsafe char* GetEnvironmentStringsW();
23+
24+
[DllImport(Libraries.ProcessEnvironment, CharSet = CharSet.Unicode, SetLastError = true)]
25+
internal static extern unsafe bool FreeEnvironmentStringsW(char* pStrings);
26+
}
27+
}

src/Common/src/Interop/Windows/mincore/Interop.ExpandEnvironmentStringsW.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
#pragma warning disable 0649 // fields never explicitly assigned to
9+
#pragma warning disable 0169 // fields never used
10+
11+
internal partial class Interop
12+
{
13+
internal partial class mincore
14+
{
15+
[DllImport(Libraries.SystemInfo_L1_1, SetLastError = true)]
16+
internal static extern bool GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, IntPtr Buffer, ref uint ReturnedLength);
17+
18+
internal enum LOGICAL_PROCESSOR_RELATIONSHIP
19+
{
20+
RelationGroup = 4
21+
}
22+
23+
internal struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
24+
{
25+
public LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
26+
public uint Size;
27+
public GROUP_RELATIONSHIP Group; // part of a union, but we only need the Group
28+
}
29+
30+
internal unsafe struct GROUP_RELATIONSHIP
31+
{
32+
private byte MaximumGroupCount;
33+
public ushort ActiveGroupCount;
34+
private fixed byte Reserved[20];
35+
public PROCESSOR_GROUP_INFO GroupInfo; // actually a GroupInfo[ANYSIZE_ARRAY], so used for its address
36+
}
37+
38+
internal unsafe struct PROCESSOR_GROUP_INFO
39+
{
40+
public byte MaximumProcessorCount;
41+
public byte ActiveProcessorCount;
42+
public fixed byte Reserved[38];
43+
public IntPtr ActiveProcessorMask;
44+
}
45+
}
46+
}

src/Common/src/Interop/Windows/mincore/Interop.GetVersionExW.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ internal partial class mincore
1212
internal static extern bool GetVersionExW(ref OSVERSIONINFOEX osvi);
1313

1414
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
15-
internal struct OSVERSIONINFOEX
15+
internal unsafe struct OSVERSIONINFOEX
1616
{
1717
public int dwOSVersionInfoSize;
1818
public int dwMajorVersion;
1919
public int dwMinorVersion;
2020
public int dwBuildNumber;
2121
public int dwPlatformId;
22-
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
23-
public string szCSDVersion;
22+
public fixed char szCSDVersion[128];
2423
public ushort wServicePackMajor;
2524
public ushort wServicePackMinor;
2625
public ushort wSuiteMask;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Collections.Generic
6+
{
7+
internal partial class LowLevelDictionary<TKey, TValue> : IDictionary
8+
{
9+
bool IDictionary.IsFixedSize => false;
10+
bool IDictionary.IsReadOnly => false;
11+
12+
object IDictionary.this[object key]
13+
{
14+
get { return this[(TKey)key]; }
15+
set { this[(TKey)key] = (TValue)value; }
16+
}
17+
18+
ICollection IDictionary.Keys
19+
{
20+
get
21+
{
22+
if (_numEntries == 0)
23+
{
24+
return Array.Empty<TKey>();
25+
}
26+
27+
var keys = new TKey[_numEntries];
28+
int dst = 0;
29+
for (int bucket = 0; bucket < _buckets.Length; bucket++)
30+
{
31+
for (Entry entry = _buckets[bucket]; entry != null; entry = entry._next)
32+
{
33+
keys[dst++] = entry._key;
34+
}
35+
}
36+
return keys;
37+
}
38+
}
39+
40+
ICollection IDictionary.Values
41+
{
42+
get
43+
{
44+
if (_numEntries == 0)
45+
{
46+
return Array.Empty<TValue>();
47+
}
48+
49+
var values = new TValue[_numEntries];
50+
int dst = 0;
51+
for (int bucket = 0; bucket < _buckets.Length; bucket++)
52+
{
53+
for (Entry entry = _buckets[bucket]; entry != null; entry = entry._next)
54+
{
55+
values[dst++] = entry._value;
56+
}
57+
}
58+
return values;
59+
}
60+
}
61+
62+
public LowLevelDictionary<TKey, TValue> Clone()
63+
{
64+
var result = new LowLevelDictionary<TKey, TValue>(_numEntries);
65+
for (int bucket = 0; bucket < _buckets.Length; bucket++)
66+
{
67+
for (Entry entry = _buckets[bucket]; entry != null; entry = entry._next)
68+
{
69+
result.Add(entry._key, entry._value);
70+
}
71+
}
72+
return result;
73+
}
74+
75+
bool ICollection.IsSynchronized => false;
76+
77+
object ICollection.SyncRoot => this;
78+
79+
void IDictionary.Add(object key, object value) => Add((TKey)key, (TValue)value);
80+
81+
bool IDictionary.Contains(object key) => Find((TKey)key) != null;
82+
83+
IDictionaryEnumerator IDictionary.GetEnumerator() => new DictionaryEnumerator(this);
84+
IEnumerator IEnumerable.GetEnumerator() => new DictionaryEnumerator(this);
85+
86+
void IDictionary.Remove(object key) { Remove((TKey)key); }
87+
88+
void IDictionary.Clear() => Clear();
89+
90+
void ICollection.CopyTo(Array array, int index)
91+
{
92+
int dst = 0;
93+
for (int bucket = 0; bucket < _buckets.Length; bucket++)
94+
{
95+
for (Entry entry = _buckets[bucket]; entry != null; entry = entry._next)
96+
{
97+
array.SetValue(new DictionaryEntry(entry._key, entry._value), dst++);
98+
}
99+
}
100+
}
101+
102+
private sealed class DictionaryEnumerator : IDictionaryEnumerator
103+
{
104+
private readonly DictionaryEntry[] _entries;
105+
private int _pos = -1;
106+
107+
internal DictionaryEnumerator(LowLevelDictionary<TKey, TValue> dict)
108+
{
109+
var entries = new DictionaryEntry[dict._numEntries];
110+
int dst = 0;
111+
for (int bucket = 0; bucket < dict._buckets.Length; bucket++)
112+
{
113+
for (Entry entry = dict._buckets[bucket]; entry != null; entry = entry._next)
114+
{
115+
entries[dst++] = new DictionaryEntry(entry._key, entry._value);
116+
}
117+
}
118+
_entries = entries;
119+
}
120+
121+
public object Current => Entry;
122+
public object Key => Entry.Key;
123+
public object Value => Entry.Value;
124+
125+
public DictionaryEntry Entry
126+
{
127+
get
128+
{
129+
if (_pos < 0 || _pos >= _entries.Length)
130+
{
131+
throw new InvalidOperationException();
132+
}
133+
return _entries[_pos];
134+
}
135+
}
136+
137+
public bool MoveNext()
138+
{
139+
if (_pos < _entries.Length)
140+
{
141+
_pos++;
142+
}
143+
return _pos < _entries.Length;
144+
}
145+
146+
public void Reset() { throw new NotSupportedException(); }
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)
0