19 Sep 2011 20:35
[mono/mono] [3 commits] ad78b706: Report error about missing async support types
Marek Safar (marek.safar <at> gmail.com <mono-patches <at> lists.ximian.com>
2011-09-19 18:35:21 GMT
2011-09-19 18:35:21 GMT
Branch: refs/heads/master
Home: https://github.com/mono/mono
Commit: ad78b706d9a71ab95a76ad8f1d6c0db5ff99869b
Author: Marek Safar <marek.safar <at> gmail.com>
Date: 09/19/2011 14:34:26
URL: https://github.com/mono/mono/commit/ad78b706d9a71ab95a76ad8f1d6c0db5ff99869b
Report error about missing async support types
Changed paths:
M mcs/mcs/async.cs
Added paths:
A mcs/errors/cs1993.cs
Modified: mcs/mcs/async.cs
===================================================================
--- a/mcs/mcs/async.cs
+++ b/mcs/mcs/async.cs
<at> <at> -645,22 +645,26 <at> <at> namespace Mono.CSharp
bf = pred_members.AsyncTaskMethodBuilderCreate;
sr = pred_members.AsyncTaskMethodBuilderSetResult;
se = pred_members.AsyncTaskMethodBuilderSetException;
- task = pred_members.AsyncTaskMethodBuilderTask.Resolve (Location);
+ task = pred_members.AsyncTaskMethodBuilderTask.Get ();
} else {
builder_type = Module.PredefinedTypes.AsyncTaskMethodBuilderGeneric;
bf = pred_members.AsyncTaskMethodBuilderGenericCreate;
sr = pred_members.AsyncTaskMethodBuilderGenericSetResult;
se = pred_members.AsyncTaskMethodBuilderGenericSetException;
- task = pred_members.AsyncTaskMethodBuilderGenericTask.Resolve (Location);
+ task = pred_members.AsyncTaskMethodBuilderGenericTask.Get ();
has_task_return_type = true;
}
- set_result = sr.Resolve (Location);
- set_exception = se.Resolve (Location);
- var builder_factory = bf.Resolve (Location);
- var bt = builder_type.Resolve ();
- if (bt == null || set_result == null || builder_factory == null || set_exception == null)
- return false;
+ set_result = sr.Get ();
+ set_exception = se.Get ();
+ var builder_factory = bf.Get ();
+ if (!builder_type.Define () || set_result == null || builder_factory == null || set_exception ==
null) {
+ Report.Error (1993, Location,
+ "Cannot find compiler required types for asynchronous functions support. Are you targeting the
wrong framework version?");
+ return base.DoDefineMembers ();
+ }
+
+ var bt = builder_type.TypeSpec;
//
// Inflate generic Task types
Added: mcs/errors/cs1993.cs
===================================================================
--- /dev/null
+++ b/mcs/errors/cs1993.cs
<at> <at> -0,0 +1,44 <at> <at>
+// CS1993: Cannot find compiler required types for asynchronous functions support. Are you targeting
the wrong framework version?
+// Line: 38
+// Compiler options: -langversion:future -sdk:2
+
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks
+{
+ class Task<T>
+ {
+ }
+}
+
+static class S
+{
+ public static A GetAwaiter (this int i)
+ {
+ return new A ();
+ }
+}
+
+class A
+{
+ bool IsCompleted {
+ get {
+ return true;
+ }
+ }
+
+ void OnCompleted (System.Action a)
+ {
+ }
+
+ int GetResult ()
+ {
+ return 3;
+ }
+
+ static async Task<int> Test ()
+ {
+ return await 2;
+ }
+}
+
Commit: e1c66efea89da6ea5b9c148bd52e6c464fbea0b7
Author: Marek Safar <marek.safar <at> gmail.com>
Date: 09/19/2011 14:34:27
URL: https://github.com/mono/mono/commit/e1c66efea89da6ea5b9c148bd52e6c464fbea0b7
Add 4.5 readonly collection interfaces
Changed paths:
M mcs/class/corlib/System.Collections.Generic/Dictionary.cs
M mcs/class/corlib/System.Collections.Generic/List.cs
M mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
M mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
M mcs/class/corlib/corlib.dll.sources
Added paths:
A mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs
A mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs
Modified: mcs/class/corlib/System.Collections.Generic/Dictionary.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
+++ b/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
<at> <at> -12,6 +12,7 <at> <at>
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite
// Copyright (C) 2007 HotFeet GmbH (http://www.hotfeet.ch)
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -57,13 +58,10 <at> <at> namespace System.Collections.Generic {
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<,>))]
- public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>,
- IDictionary,
- ICollection,
- ICollection<KeyValuePair<TKey, TValue>>,
- IEnumerable<KeyValuePair<TKey, TValue>>,
- ISerializable,
- IDeserializationCallback
+ public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, ISerializable, IDeserializationCallback
+#if NET_4_5
+ , IReadOnlyDictionary<TKey, TValue>
+#endif
{
// The implementation of this class uses a hash table and linked lists
// (see: http://msdn2.microsoft.com/en-us/library/ms379571(VS.80).aspx).
<at> <at> -642,6 +640,16 <at> <at> namespace System.Collections.Generic {
ICollection<TValue> IDictionary<TKey, TValue>.Values {
get { return Values; }
}
+
+#if NET_4_5
+ IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys {
+ get { return Keys; }
+ }
+
+ IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values {
+ get { return Values; }
+ }
+#endif
public KeyCollection Keys {
get { return new KeyCollection (this); }
Modified: mcs/class/corlib/System.Collections.Generic/List.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.Generic/List.cs
+++ b/mcs/class/corlib/System.Collections.Generic/List.cs
<at> <at> -6,9 +6,11 <at> <at>
// Martin Baulig (martin <at> ximian.com)
// Carlos Alberto Cortez (calberto.cortez <at> gmail.com)
// David Waite (mass <at> akuma.org)
+// Marek Safar (marek.safar <at> gmail.com)
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -38,7 +40,11 <at> <at> namespace System.Collections.Generic {
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
- public class List <T> : IList <T>, IList, ICollection {
+ public class List<T> : IList<T>, IList
+#if NET_4_5
+ , IReadOnlyList<T>
+#endif
+ {
T [] _items;
int _size;
int _version;
Modified: mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
+++ b/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
<at> <at> -2,9 +2,10 <at> <at>
//
// System.Collections.ObjectModel.Collection
//
-// Author:
+// Authors:
// Zoltan Varga (vargaz <at> gmail.com)
// David Waite (mass <at> akuma.org)
+// Marek Safar (marek.safar <at> gmail.com)
//
// (C) 2005 Novell, Inc.
// (C) 2005 David Waite
<at> <at> -13,6 +14,7 <at> <at>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -45,8 +47,11 <at> <at> namespace System.Collections.ObjectModel
[ComVisible (false)]
[Serializable]
[DebuggerDisplay ("Count={Count}")]
- [DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
- public class Collection <T> : IList <T>, ICollection <T>, IEnumerable <T>, IList, ICollection, IEnumerable
+ [DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+ public class Collection<T> : IList<T>, IList
+#if NET_4_5
+ , IReadOnlyList<T>
+#endif
{
IList <T> list;
object syncRoot;
Modified: mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
+++ b/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
<at> <at> -2,9 +2,10 <at> <at>
//
// System.Collections.ObjectModel.ReadOnlyCollection
//
-// Author:
+// Authors:
// Zoltan Varga (vargaz <at> gmail.com)
// David Waite (mass <at> akuma.org)
+// Marek Safar (marek.safar <at> gmail.com)
//
// (C) 2005 Novell, Inc.
// (C) 2005 David Waite
<at> <at> -13,6 +14,7 <at> <at>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -44,8 +46,11 <at> <at> namespace System.Collections.ObjectModel
[ComVisible (false)]
[Serializable]
[DebuggerDisplay ("Count={Count}")]
- [DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
- public class ReadOnlyCollection <T> : IList <T>, ICollection <T>, IEnumerable <T>, IList,
ICollection, IEnumerable
+ [DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+ public class ReadOnlyCollection<T> : IList<T>, IList
+#if NET_4_5
+ , IReadOnlyList<T>
+#endif
{
IList <T> list;
Modified: mcs/class/corlib/corlib.dll.sources
===================================================================
--- a/mcs/class/corlib/corlib.dll.sources
+++ b/mcs/class/corlib/corlib.dll.sources
<at> <at> -1521,6 +1521,8 <at> <at> System.Collections.Generic/IList.cs
System.Collections.Generic/IComparer.cs
System.Collections.Generic/IEqualityComparer.cs
System.Collections.Generic/IDictionary.cs
+System.Collections.Generic/IReadOnlyList.cs
+System.Collections.Generic/IReadOnlyDictionary.cs
System.Collections.Generic/KeyValuePair.cs
System.Collections.Generic/EqualityComparer.cs
System.Collections.Generic/KeyNotFoundException.cs
Added: mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs
<at> <at> -0,0 +1,45 <at> <at>
+//
+// IReadOnlyDictionary.cs
+//
+// Authors:
+// Marek Safar <marek.safar <at> gmail.com>
+//
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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_4_5
+
+namespace System.Collections.Generic
+{
+ public interface IReadOnlyDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
+ {
+ int Count { get; }
+ TValue this [TKey key] { get; }
+ IEnumerable<TKey> Keys { get; }
+ IEnumerable<TValue> Values { get; }
+
+ bool ContainsKey (TKey key);
+ bool TryGetValue (TKey key, out TValue value);
+ }
+}
+
+#endif
Added: mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs
<at> <at> -0,0 +1,40 <at> <at>
+//
+// IReadOnlyList.cs
+//
+// Authors:
+// Marek Safar <marek.safar <at> gmail.com>
+//
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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_4_5
+
+namespace System.Collections.Generic
+{
+ public interface IReadOnlyList<out T> : IEnumerable<T>
+ {
+ int Count { get; }
+ T this [int index] { get; }
+ }
+}
+
+#endif
Commit: 11db01b5a136988b91a979e6dce4b686c1386418
Author: Marek Safar <marek.safar <at> gmail.com>
Date: 09/19/2011 14:34:27
URL: https://github.com/mono/mono/commit/11db01b5a136988b91a979e6dce4b686c1386418
Add few new 4.5 overloads
Changed paths:
M mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
M mcs/class/corlib/System.IO/BinaryReader.cs
M mcs/class/corlib/System.IO/BinaryWriter.cs
M mcs/class/corlib/System.IO/MemoryStream.cs
M mcs/class/corlib/System.IO/Stream.cs
M mcs/class/corlib/System.IO/StreamReader.cs
M mcs/class/corlib/System.IO/StreamWriter.cs
M mcs/class/corlib/corlib.dll.sources
Added paths:
A mcs/class/corlib/System.Runtime.CompilerServices/ContractHelper.cs
A mcs/class/corlib/System/IProgress.cs
Modified: mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
===================================================================
--- a/mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
+++ b/mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
<at> <at> -35,6 +35,7 <at> <at> using System.Runtime.ConstrainedExecution;
namespace System.Diagnostics.Contracts.Internal
{
+ [Obsolete ("Type has been moved to System.Runtime.CompilerServices")]
public static class ContractHelper
{
#if MOONLIGHT
Modified: mcs/class/corlib/System.IO/BinaryReader.cs
===================================================================
--- a/mcs/class/corlib/System.IO/BinaryReader.cs
+++ b/mcs/class/corlib/System.IO/BinaryReader.cs
<at> <at> -9,6 +9,7 <at> <at>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -55,11 +56,27 <at> <at> namespace System.IO {
private bool m_disposed;
-
- public BinaryReader(Stream input) : this(input, Encoding.UTF8UnmarkedUnsafe) {
+
+ public BinaryReader(Stream input)
+ : this(input, Encoding.UTF8UnmarkedUnsafe)
+ {
}
-
- public BinaryReader(Stream input, Encoding encoding) {
+
+#if NET_4_5
+ readonly bool leave_open;
+
+ public BinaryReader(Stream input, Encoding encoding)
+ : this (input, encoding, false)
+ {
+ }
+
+ public BinaryReader(Stream input, Encoding encoding, bool leaveOpen)
+#else
+ const bool leave_open = false;
+
+ public BinaryReader(Stream input, Encoding encoding)
+#endif
+ {
if (input == null || encoding == null)
throw new ArgumentNullException(Locale.GetText ("Input or Encoding is a null reference."));
if (!input.CanRead)
<at> <at> -67,6 +84,9 <at> <at> namespace System.IO {
m_stream = input;
m_encoding = encoding;
+#if NET_4_5
+ leave_open = leaveOpen;
+#endif
decoder = encoding.GetDecoder ();
// internal buffer size is documented to be between 16 and the value
<at> <at> -87,7 +107,7 <at> <at> namespace System.IO {
protected virtual void Dispose (bool disposing)
{
- if (disposing && m_stream != null)
+ if (disposing && m_stream != null && !leave_open)
m_stream.Close ();
m_disposed = true;
Modified: mcs/class/corlib/System.IO/BinaryWriter.cs
===================================================================
--- a/mcs/class/corlib/System.IO/BinaryWriter.cs
+++ b/mcs/class/corlib/System.IO/BinaryWriter.cs
<at> <at> -1,12 +1,14 <at> <at>
//
// System.IO.BinaryWriter
//
-// Author:
+// Authors:
// Matt Kimball (matt <at> kimball.net)
+// Marek Safar (marek.safar <at> gmail.com)
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -47,15 +49,31 <at> <at> namespace System.IO {
private byte [] buffer;
byte [] stringBuffer;
int maxCharsPerRound;
- private bool disposed = false;
+ bool disposed;
- protected BinaryWriter() : this (Stream.Null, Encoding.UTF8UnmarkedUnsafe) {
+ protected BinaryWriter() : this (Stream.Null, Encoding.UTF8UnmarkedUnsafe)
+ {
}
- public BinaryWriter(Stream output) : this(output, Encoding.UTF8UnmarkedUnsafe) {
+ public BinaryWriter(Stream output) : this(output, Encoding.UTF8UnmarkedUnsafe)
+ {
}
-
- public BinaryWriter(Stream output, Encoding encoding) {
+
+#if NET_4_5
+ readonly bool leave_open;
+
+ public BinaryWriter(Stream output, Encoding encoding)
+ : this (output, encoding, false)
+ {
+ }
+
+ public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
+#else
+ const bool leave_open = false;
+
+ public BinaryWriter(Stream output, Encoding encoding)
+#endif
+ {
if (output == null)
throw new ArgumentNullException("output");
if (encoding == null)
<at> <at> -63,6 +81,9 <at> <at> namespace System.IO {
if (!output.CanWrite)
throw new ArgumentException(Locale.GetText ("Stream does not support writing or already closed."));
+#if NET_4_5
+ leave_open = leaveOpen;
+#endif
OutStream = output;
m_encoding = encoding;
buffer = new byte [16];
<at> <at> -90,7 +111,7 <at> <at> namespace System.IO {
protected virtual void Dispose (bool disposing)
{
- if (disposing && OutStream != null)
+ if (disposing && OutStream != null && !leave_open)
OutStream.Close();
buffer = null;
Modified: mcs/class/corlib/System.IO/MemoryStream.cs
===================================================================
--- a/mcs/class/corlib/System.IO/MemoryStream.cs
+++ b/mcs/class/corlib/System.IO/MemoryStream.cs
<at> <at> -418,11 +418,5 <at> <at> namespace System.IO
stream.Write (internalBuffer, initialIndex, length - initialIndex);
}
-
-#if NET_4_0
- protected override void ObjectInvariant ()
- {
- }
-#endif
}
}
Modified: mcs/class/corlib/System.IO/Stream.cs
===================================================================
--- a/mcs/class/corlib/System.IO/Stream.cs
+++ b/mcs/class/corlib/System.IO/Stream.cs
<at> <at> -260,6 +260,9 <at> <at> namespace System.IO
destination.Write (buffer, 0, nread);
}
+#if NET_4_5
+ [ObsoleteAttribute("Do not call or override this method")]
+#endif
protected virtual void ObjectInvariant ()
{
}
Modified: mcs/class/corlib/System.IO/StreamReader.cs
===================================================================
--- a/mcs/class/corlib/System.IO/StreamReader.cs
+++ b/mcs/class/corlib/System.IO/StreamReader.cs
<at> <at> -8,10 +8,7 <at> <at>
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -137,9 +134,25 <at> <at> namespace System.IO {
public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks)
: this (stream, encoding, detectEncodingFromByteOrderMarks, DefaultBufferSize) { }
-
+
+#if NET_4_5
+ readonly bool leave_open;
+
+ public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks,
int bufferSize)
+ : this (stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, false)
+ {
+ }
+
+ public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks,
int bufferSize, bool leaveOpen)
+#else
+ const bool leave_open = false;
+
public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks,
int bufferSize)
+#endif
{
+#if NET_4_5
+ leave_open = leaveOpen;
+#endif
Initialize (stream, encoding, detectEncodingFromByteOrderMarks, bufferSize);
}
<at> <at> -259,7 +272,7 <at> <at> namespace System.IO {
protected override void Dispose (bool disposing)
{
- if (disposing && base_stream != null)
+ if (disposing && base_stream != null && !leave_open)
base_stream.Close ();
if (input_buffer != null && input_buffer.Length == DefaultBufferSize && input_buffer_recycle ==
null) {
Modified: mcs/class/corlib/System.IO/StreamWriter.cs
===================================================================
--- a/mcs/class/corlib/System.IO/StreamWriter.cs
+++ b/mcs/class/corlib/System.IO/StreamWriter.cs
<at> <at> -4,12 +4,11 <at> <at>
// Authors:
// Dietmar Maurer (dietmar <at> ximian.com)
// Paolo Molaro (lupus <at> ximian.com)
+// Marek Safar (marek.safar <at> gmail.com)
//
// (C) Ximian, Inc. http://www.ximian.com
-//
-
-//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
<at> <at> -79,7 +78,21 <at> <at> namespace System.IO {
preamble_done = true;
}
- public StreamWriter (Stream stream, Encoding encoding, int bufferSize) {
+#if NET_4_5
+ readonly bool leave_open;
+
+ public StreamWriter (Stream stream, Encoding encoding, int bufferSize)
+ : this (stream, encoding, bufferSize, false)
+ {
+ }
+
+ public StreamWriter (Stream stream, Encoding encoding, int bufferSize, bool leaveOpen)
+#else
+ const bool leave_open = false;
+
+ public StreamWriter (Stream stream, Encoding encoding, int bufferSize)
+#endif
+ {
if (null == stream)
throw new ArgumentNullException("stream");
if (null == encoding)
<at> <at> -89,6 +102,9 <at> <at> namespace System.IO {
if (!stream.CanWrite)
throw new ArgumentException ("Can not write to stream");
+#if NET_4_5
+ leave_open = leaveOpen;
+#endif
internalStream = stream;
Initialize(encoding, bufferSize);
<at> <at> -102,8 +118,9 <at> <at> namespace System.IO {
public StreamWriter (string path, bool append, Encoding encoding)
: this (path, append, encoding, DefaultFileBufferSize) {}
-
- public StreamWriter (string path, bool append, Encoding encoding, int bufferSize) {
+
+ public StreamWriter (string path, bool append, Encoding encoding, int bufferSize)
+ {
if (null == encoding)
throw new ArgumentNullException("encoding");
if (bufferSize <= 0)
<at> <at> -152,7 +169,7 <at> <at> namespace System.IO {
protected override void Dispose (bool disposing)
{
Exception exc = null;
- if (!DisposedAlready && disposing && internalStream != null) {
+ if (!DisposedAlready && disposing && internalStream != null && !leave_open) {
try {
Flush();
} catch (Exception e) {
Modified: mcs/class/corlib/corlib.dll.sources
===================================================================
--- a/mcs/class/corlib/corlib.dll.sources
+++ b/mcs/class/corlib/corlib.dll.sources
<at> <at> -182,6 +182,7 <at> <at> System/InvalidCastException.cs
System/InvalidOperationException.cs
System/InvalidProgramException.cs
System/InvalidTimeZoneException.cs
+System/IProgress.cs
System/IServiceProvider.cs
System/KnownTerminals.cs
System/Lazy.cs
<at> <at> -618,6 +619,7 <at> <at> System.Runtime.CompilerServices/CompilerGeneratedAttribute.cs
System.Runtime.CompilerServices/CompilerGlobalScopeAttribute.cs
System.Runtime.CompilerServices/CompilerMarshalOverride.cs
System.Runtime.CompilerServices/ConditionalWeakTable.cs
+System.Runtime.CompilerServices/ContractHelper.cs
System.Runtime.CompilerServices/CustomConstantAttribute.cs
System.Runtime.CompilerServices/DateTimeConstantAttribute.cs
System.Runtime.CompilerServices/DecimalConstantAttribute.cs
Added: mcs/class/corlib/System.Runtime.CompilerServices/ContractHelper.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System.Runtime.CompilerServices/ContractHelper.cs
<at> <at> -0,0 +1,166 <at> <at>
+//
+// ContractHelper.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76 <at> gmail.com)
+//
+// Copyright 2010 Novell (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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_4_5
+
+using System;
+using System.Text;
+using System.Reflection;
+using System.Runtime.ConstrainedExecution;
+using System.Diagnostics.Contracts;
+using System.Diagnostics;
+
+namespace System.Runtime.CompilerServices
+{
+ public static class ContractHelper
+ {
+#if MOONLIGHT
+ const string SystemWindowsBrowser = ", System.Windows.Browser, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
+ const string HtmlPage = "System.Windows.Browser.HtmlPage" + SystemWindowsBrowser;
+ const string HtmlWindow = "System.Windows.Browser.HtmlWindow" + SystemWindowsBrowser;
+ static MethodInfo alert;
+ static object window;
+
+ static ContractHelper ()
+ {
+ Type htmlpage = Type.GetType (HtmlPage);
+ MethodInfo get_window = htmlpage.GetMethod ("get_Window", BindingFlags.Static | BindingFlags.Public);
+ window = get_window.Invoke (null, null);
+ Type htmlwindow = Type.GetType (HtmlWindow);
+ alert = htmlwindow.GetMethod ("Alert", BindingFlags.Instance | BindingFlags.Public);
+ }
+#endif
+
+ [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
+ [DebuggerNonUserCode]
+ public static string RaiseContractFailedEvent (ContractFailureKind failureKind, string
userMessage, string conditionText, Exception innerException)
+ {
+
+ StringBuilder msg = new StringBuilder (60);
+ switch (failureKind) {
+ case ContractFailureKind.Assert:
+ msg.Append ("Assertion failed");
+ break;
+ case ContractFailureKind.Assume:
+ msg.Append ("Assumption failed");
+ break;
+ case ContractFailureKind.Invariant:
+ msg.Append ("Invariant failed");
+ break;
+ case ContractFailureKind.Postcondition:
+ msg.Append ("Postcondition failed");
+ break;
+ case ContractFailureKind.PostconditionOnException:
+ msg.Append ("Postcondition failed after throwing an exception");
+ break;
+ case ContractFailureKind.Precondition:
+ msg.Append ("Precondition failed");
+ break;
+ default:
+ throw new NotSupportedException ("Not supported: " + failureKind);
+ }
+ if (conditionText != null) {
+ msg.Append (": ");
+ msg.Append (conditionText);
+ } else {
+ msg.Append ('.');
+ }
+ if (userMessage != null) {
+ msg.Append (" ");
+ msg.Append (userMessage);
+ }
+ string msgString = msg.ToString ();
+
+ Exception handlerException = null;
+ bool unwind = false, handled = false;
+
+ var contractFailed = Contract.InternalContractFailedEvent;
+ if (contractFailed != null) {
+ // Execute all event handlers
+ var handlers = contractFailed.GetInvocationList ();
+ var e = new ContractFailedEventArgs (failureKind, msgString, conditionText, innerException);
+ foreach (var handler in handlers) {
+ try {
+ handler.DynamicInvoke (null, e);
+ } catch (Exception ex) {
+ e.SetUnwind ();
+ // If multiple handlers throw an exception then the specification states that it
+ // is undetermined which one becomes the InnerException.
+ handlerException = ex.InnerException;
+ }
+ }
+ unwind = e.Unwind;
+ handled = e.Handled;
+ }
+
+ if (unwind) {
+ Exception ex = innerException ?? handlerException;
+ throw new ContractException (msgString, failureKind, conditionText, userMessage, ex);
+ }
+
+ return handled ? null : msgString;
+ }
+
+ [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
+ [DebuggerNonUserCode]
+ public static void TriggerFailure (ContractFailureKind kind, string displayMessage, string
userMessage, string conditionText, Exception innerException)
+ {
+ StringBuilder msg = new StringBuilder (50);
+
+ if (conditionText != null) {
+ msg.Append ("Expression: ");
+ msg.AppendLine (conditionText);
+ }
+ msg.Append ("Description: ");
+ if (displayMessage != null) {
+ msg.Append (displayMessage);
+ }
+#if MOONLIGHT
+ // Silverlight shows a dialog that let you Abort (kill process/browser), Retry or Ignore
+ // Moonlight will simply warn and ignore (at least until FailFast is implemented)
+ // using reflection into System.Windows.Browser to popup an browser alert
+ alert.Invoke (window, new object [] { msg.ToString () });
+#else
+ if (Environment.UserInteractive) {
+ // FIXME: This should trigger an assertion.
+ // But code will never get here at the moment, as Environment.UserInteractive currently
+ // always returns false.
+ throw new ContractShouldAssertException (msg.ToString ());
+ } else {
+ // Note that FailFast() currently throws a NotImplementedException()
+ Environment.FailFast(msg.ToString()/*, new ExecutionEngineException()*/);
+ }
+#endif
+ }
+
+ }
+
+}
+
+#endif
+
Added: mcs/class/corlib/System/IProgress.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System/IProgress.cs
<at> <at> -0,0 +1,39 <at> <at>
+//
+// IProgress.cs
+//
+// Authors:
+// Marek Safar <marek.safar <at> gmail.com>
+//
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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_4_5
+
+namespace System
+{
+ public interface IProgress<in T>
+ {
+ void Report (T value);
+ }
+}
+
+#endif
_______________________________________________
Mono-patches maillist - Mono-patches <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches
RSS Feed