From: Michal Strehovský Date: Sun, 11 Oct 2020 16:01:54 +0000 (+0200) Subject: Move Internal.Console to shared CoreLib & port to Unix (#42983) X-Git-Tag: submit/tizen/20210909.063632~5130 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58f28f6f1ff4ae319d5c1eeb25160f90aa04857a;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Move Internal.Console to shared CoreLib & port to Unix (#42983) --- diff --git a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj index 4d4c53f0..2075234 100644 --- a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -104,7 +104,6 @@ - @@ -244,12 +243,6 @@ - - Common\Interop\Windows\Kernel32\Interop.GetStdHandle.cs - - - Common\Interop\Windows\Kernel32\Interop.HandleTypes.cs - - + diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Console.Unix.cs b/src/libraries/System.Private.CoreLib/src/Internal/Console.Unix.cs new file mode 100644 index 0000000..3dcf49a --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Internal/Console.Unix.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; + +namespace Internal +{ + public static partial class Console + { + public static unsafe void Write(string s) + { + byte[] bytes = Encoding.UTF8.GetBytes(s); + fixed (byte* pBytes = bytes) + { + Interop.Sys.Log(pBytes, bytes.Length); + } + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs b/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs new file mode 100644 index 0000000..e9027c8 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; + +namespace Internal +{ + public static partial class Console + { + private static readonly IntPtr s_outputHandle = + Interop.Kernel32.GetStdHandle(Interop.Kernel32.HandleTypes.STD_OUTPUT_HANDLE); + + public static unsafe void Write(string s) + { + byte[] bytes = Encoding.UTF8.GetBytes(s); + fixed (byte* pBytes = bytes) + { + Interop.Kernel32.WriteFile(s_outputHandle, pBytes, bytes.Length, out _, IntPtr.Zero); + } + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Console.cs b/src/libraries/System.Private.CoreLib/src/Internal/Console.cs new file mode 100644 index 0000000..5034a2b --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Internal/Console.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Internal +{ + // + // Simple limited console class for internal printf-style debugging in System.Private.CoreLib + // and low-level tests that want to call System.Private.CoreLib directly + // + + public static partial class Console + { + public static void WriteLine(string? s) => + Write(s + Environment.NewLineConst); + + public static void WriteLine() => + Write(Environment.NewLineConst); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 93c774f..ad02631 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -37,6 +37,7 @@ + @@ -1389,6 +1390,9 @@ Common\Interop\Windows\Kernel32\Interop.GetProcessTimes_IntPtr.cs + + Common\Interop\Windows\Kernel32\Interop.GetStdHandle.cs + Common\Interop\Windows\Kernel32\Interop.GetSystemDirectoryW.cs @@ -1416,6 +1420,9 @@ Common\Interop\Windows\Kernel32\Interop.GlobalMemoryStatusEx.cs + + Common\Interop\Windows\Kernel32\Interop.HandleTypes.cs + Common\Interop\Windows\Kernel32\Interop.IsWow64Process_IntPtr.cs @@ -1584,6 +1591,7 @@ Common\Interop\Windows\User32\Interop.USEROBJECTFLAGS.cs + @@ -1667,6 +1675,9 @@ Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs + + Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs + Common\System\IO\Win32Marshal.cs @@ -1733,6 +1744,9 @@ Common\Interop\Unix\System.Native\Interop.LockFileRegion.cs + + Common\Interop\Unix\System.Native\Interop.Log.cs + Common\Interop\Unix\System.Native\Interop.LowLevelMonitor.cs @@ -1787,6 +1801,7 @@ Common\Interop\Unix\System.Native\Interop.Write.cs + diff --git a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj index 954e3f9..bb55203 100644 --- a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -139,7 +139,6 @@ - diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs deleted file mode 100644 index 6206ed6..0000000 --- a/src/mono/netcore/System.Private.CoreLib/src/Mono/Console.Mono.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Diagnostics; - -namespace Internal -{ - // Some CoreCLR tests use it for internal printf-style debugging in System.Private.CoreLib - public static class Console - { - public static void Write(string? s) => DebugProvider.WriteCore(s ?? string.Empty); - - public static void WriteLine(string? s) => Write(s + Environment.NewLineConst); - - public static void WriteLine() => Write(Environment.NewLineConst); - } -}