[Pkg-mono-svn-commits] [SCM] mono branch, master-experimental, updated. debian/2.10.1-4-37-g03befb1

Mirco Bauer meebey at meebey.net
Sun Aug 7 16:04:04 UTC 2011


The following commit has been merged in the master-experimental branch:
commit 629d53a3a056477345e10df22c19ffb350968df8
Merge: 17daca8f2e514efd7ba6ff378d94d30064f2169f f165789868007ccb2d56b70e6e3cac72f3b6cf22
Author: Mirco Bauer <meebey at meebey.net>
Date:   Sun Aug 7 17:43:59 2011 +0200

    Merge commit 'upstream/2.10.3' into master-experimental-patches/console_no_utf8_bom

diff --combined mcs/class/corlib/System/Console.cs
index e340513,8b68f4f..c4b2402
--- a/mcs/class/corlib/System/Console.cs
+++ b/mcs/class/corlib/System/Console.cs
@@@ -28,9 -28,6 +28,6 @@@
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  //
- #if NET_2_0 || BOOTSTRAP_NET_2_0
- #define NET2_API
- #endif
  
  using System.Diagnostics;
  using System.IO;
@@@ -42,22 -39,31 +39,31 @@@ using System.Text
  
  namespace System
  {
- 	public
- #if NET2_API
- 	static
- #else
- 	sealed
- #endif
- 	class Console
+ 	public static class Console
  	{
  #if !NET_2_1
  		private class WindowsConsole
  		{
+ 			public static bool ctrlHandlerAdded = false;
+ 			private delegate bool WindowsCancelHandler (int keyCode);
+ 			private static WindowsCancelHandler cancelHandler = new WindowsCancelHandler (DoWindowsConsoleCancelEvent);
+ 
  			[DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  			private static extern int GetConsoleCP ();
  			[DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  			private static extern int GetConsoleOutputCP ();
  
+ 			[DllImport ("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
+ 			private static extern bool SetConsoleCtrlHandler (WindowsCancelHandler handler, bool addHandler);
+ 
+ 			// Only call the event handler if Control-C was pressed (code == 0), nothing else
+ 			private static bool DoWindowsConsoleCancelEvent (int keyCode)
+ 			{
+ 				if (keyCode == 0)
+ 					DoConsoleCancelEvent ();
+ 				return keyCode == 0;
+ 			}
+ 
  			[MethodImpl (MethodImplOptions.NoInlining)]
  			public static int GetInputCodePage ()
  			{
@@@ -69,6 -75,18 +75,18 @@@
  			{
  				return GetConsoleOutputCP ();
  			}
+ 
+ 			public static void AddCtrlHandler ()
+ 			{
+ 				SetConsoleCtrlHandler (cancelHandler, true);
+ 				ctrlHandlerAdded = true;
+ 			}
+ 			
+ 			public static void RemoveCtrlHandler ()
+ 			{
+ 				SetConsoleCtrlHandler (cancelHandler, false);
+ 				ctrlHandlerAdded = false;
+ 			}
  		}
  #endif
  		internal static TextWriter stdout;
@@@ -77,7 -95,7 +95,7 @@@
  
  		static Console ()
  		{
- #if !NET2_API || NET_2_1
+ #if NET_2_1
  			Encoding inputEncoding;
  			Encoding outputEncoding;
  #endif
@@@ -108,7 -126,8 +126,7 @@@
  				int code_page = 0;
  				Encoding.InternalCodePage (ref code_page);
  
 -				if (code_page != -1 && ((code_page & 0x0fffffff) == 3 // UTF8Encoding.UTF8_CODE_PAGE
 -					|| ((code_page & 0x10000000) != 0)))
 +				if (code_page == UTF8Encoding.UTF8_CODE_PAGE || ((code_page & 0x10000000) != 0))
  					inputEncoding = outputEncoding = Encoding.UTF8Unmarked;
  				else
  					inputEncoding = outputEncoding = Encoding.Default;
@@@ -118,7 -137,7 +136,7 @@@
  			((StreamWriter)stderr).AutoFlush = true;
  			stderr = TextWriter.Synchronized (stderr, true);
  
- #if NET2_API && !NET_2_1
+ #if !NET_2_1
  			if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole) {
  				StreamWriter w = new CStreamWriter (OpenStandardOutput (0), outputEncoding);
  				w.AutoFlush = true;
@@@ -131,7 -150,7 +149,7 @@@
  				stdout = TextWriter.Synchronized (stdout, true);
  				stdin = new UnexceptionalStreamReader (OpenStandardInput (0), inputEncoding);
  				stdin = TextReader.Synchronized (stdin);
- #if NET2_API && !NET_2_1
+ #if !NET_2_1
  			}
  #endif
  
@@@ -140,12 -159,6 +158,6 @@@
  			GC.SuppressFinalize (stdin);
  		}
  
- #if !NET2_API
- 		private Console ()
- 		{
- 		}
- #endif
- 
  		public static TextWriter Error {
  			get {
  				return stderr;
@@@ -164,14 -177,9 +176,9 @@@
  			}
  		}
  
- 		public static Stream OpenStandardError ()
- 		{
- 			return OpenStandardError (0);
- 		}
- 
  		private static Stream Open (IntPtr handle, FileAccess access, int bufferSize)
  		{
- #if NET_2_1 && !MONOTOUCH
+ #if MOONLIGHT
  			if (SecurityManager.SecurityEnabled && !Debugger.IsAttached && Environment.GetEnvironmentVariable ("MOONLIGHT_ENABLE_CONSOLE") == null)
  				return new NullStream ();
  #endif
@@@ -182,6 -190,11 +189,11 @@@
  			}
  		}
  
+ 		public static Stream OpenStandardError ()
+ 		{
+ 			return OpenStandardError (0);
+ 		}
+ 
  		// calling any FileStream constructor with a handle normally
  		// requires permissions UnmanagedCode permissions. In this 
  		// case we assert this permission so the console can be used
@@@ -318,7 -331,10 +330,10 @@@
  
  		public static void Write (string format, params object[] arg)
  		{
- 			stdout.Write (format, arg);
+ 			if (arg == null)
+ 				stdout.Write (format);
+ 			else
+ 				stdout.Write (format, arg);
  		}
  
  		public static void Write (char[] buffer, int index, int count)
@@@ -336,7 -352,6 +351,6 @@@
  			stdout.Write (format, arg0, arg1, arg2);
  		}
  
- #if ! BOOTSTRAP_WITH_OLDLIB
  		[CLSCompliant (false)]
  		public static void Write (string format, object arg0, object arg1, object arg2, object arg3, __arglist)
  		{
@@@ -355,7 -370,6 +369,6 @@@
  
  			stdout.Write (String.Format (format, args));
  		}
- #endif
  
  		public static void WriteLine ()
  		{
@@@ -431,7 -445,10 +444,10 @@@
  
  		public static void WriteLine (string format, params object[] arg)
  		{
- 			stdout.WriteLine (format, arg);
+ 			if (arg == null)
+ 				stdout.WriteLine (format);
+ 			else
+ 				stdout.WriteLine (format, arg);
  		}
  
  		public static void WriteLine (char[] buffer, int index, int count)
@@@ -449,7 -466,6 +465,6 @@@
  			stdout.WriteLine (format, arg0, arg1, arg2);
  		}
  
- #if ! BOOTSTRAP_WITH_OLDLIB
  		[CLSCompliant (false)]
  		public static void WriteLine (string format, object arg0, object arg1, object arg2, object arg3, __arglist)
  		{
@@@ -468,9 -484,8 +483,8 @@@
  
  			stdout.WriteLine (String.Format (format, args));
  		}
- #endif
  
- #if NET2_API && !NET_2_1
+ #if !NET_2_1
  		public static int Read ()
  		{
  			if ((stdin is CStreamReader) && ConsoleDriver.IsConsole) {
@@@ -501,7 -516,7 +515,7 @@@
  
  #endif
  
- #if NET2_API && !NET_2_1
+ #if !NET_2_1
  		// FIXME: Console should use these encodings when changed
  		static Encoding inputEncoding;
  		static Encoding outputEncoding;
@@@ -694,12 -709,22 +708,22 @@@
  					ConsoleDriver.Init ();
  
  				cancel_event += value;
+ 
+ 				if (Environment.IsRunningOnWindows && !WindowsConsole.ctrlHandlerAdded)
+ 					WindowsConsole.AddCtrlHandler();
  			}
  			remove {
  				if (ConsoleDriver.Initialized == false)
  					ConsoleDriver.Init ();
  
  				cancel_event -= value;
+ 
+ 				if (cancel_event == null && Environment.IsRunningOnWindows)
+ 				{
+ 					// Need to remove our hook if there's nothing left in the event
+ 					if (WindowsConsole.ctrlHandlerAdded)
+ 						WindowsConsole.RemoveCtrlHandler();
+ 				}
  			}
  		}
  

-- 
mono



More information about the Pkg-mono-svn-commits mailing list