Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -20,12 +20,10 @@ namespace System.Runtime.InteropServices
_value = value;
}
#if NET_4_0
public BStrWrapper (object value)
{
_value = (string)value;
}
#endif
public string WrappedObject { get { return _value; } }
}

View File

@@ -38,8 +38,6 @@ namespace System.Runtime.InteropServices
InterfaceIsDual = 0,
InterfaceIsIUnknown = 1,
InterfaceIsIDispatch = 2,
#if NET_4_5
InterfaceIsIInspectable = 3
#endif
}
}

View File

@@ -0,0 +1,38 @@
// IErrorInfo interface
//
// Eberhard Beilharz (eb1@sil.org)
//
// Copyright (C) 2011 SIL International
using System;
using System.Runtime.CompilerServices;
using System.Security;
namespace System.Runtime.InteropServices
{
[ComImport]
[SuppressUnmanagedCodeSecurity]
[Guid ("1CF2B120-547D-101B-8E65-08002B2BD119")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
internal interface IErrorInfo
{
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
[PreserveSig]
int GetGUID (out Guid pGuid);
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
[PreserveSig]
int GetSource ([MarshalAs (UnmanagedType.BStr)] out string pBstrSource);
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
[PreserveSig]
int GetDescription ([MarshalAs (UnmanagedType.BStr)] out string pbstrDescription);
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
[PreserveSig]
int GetHelpFile ([MarshalAs (UnmanagedType.BStr)] out string pBstrHelpFile);
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
[PreserveSig]
int GetHelpContext (out uint pdwHelpContext);
}
}

View File

@@ -0,0 +1,63 @@
// ManagedErrorInfo class
//
// Eberhard Beilharz (eb1@sil.org)
//
// Copyright (C) 2012 SIL International
using System;
using System.Runtime.CompilerServices;
using System.Security;
namespace System.Runtime.InteropServices
{
/// <summary>
/// Helper class that allows to pass an exception as an IErrorInfo object. This is useful
/// when we get an exception in managed code that is called from unmanaged code that is called
/// from managed code and we want to get to the exception in the outer managed code.
/// </summary>
internal class ManagedErrorInfo: IErrorInfo
{
private Exception m_Exception;
public ManagedErrorInfo (Exception e)
{
m_Exception = e;
}
public Exception Exception {
get { return m_Exception; }
}
#region IErrorInfo
public int GetGUID (out Guid guid)
{
// not supported
guid = Guid.Empty;
return 0;
}
public int GetSource (out string source)
{
source = m_Exception.Source;
return 0;
}
public int GetDescription (out string description)
{
description = m_Exception.Message;
return 0;
}
public int GetHelpFile (out string helpFile)
{
helpFile = m_Exception.HelpLink;
return 0;
}
public int GetHelpContext(out uint helpContext)
{
// not supported
helpContext = 0;
return 0;
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -65,11 +65,7 @@ namespace System.Runtime.InteropServices
return Path.GetDirectoryName (typeof (int).Assembly.Location);
}
#if NET_4_0
[SecuritySafeCritical]
#else
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
#endif
public static string GetSystemVersion ()
{
return "v" + Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build;

View File

@@ -26,7 +26,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_0
using System;
using System.IO;
@@ -163,4 +162,3 @@ namespace System.Runtime.InteropServices
}
}
#endif

View File

@@ -61,9 +61,9 @@ namespace System.Runtime.InteropServices
// MonoSafeHandle
//
protected IntPtr handle;
IntPtr invalid_handle_value;
int refcount = 0;
int refcount;
bool owns_handle;
bool closed, disposed;
#if NET_2_1
protected SafeHandle ()
@@ -74,39 +74,21 @@ namespace System.Runtime.InteropServices
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeHandle (IntPtr invalidHandleValue, bool ownsHandle)
{
invalid_handle_value = invalidHandleValue;
owns_handle = ownsHandle;
handle = invalidHandleValue;
if (!ownsHandle) {
GC.SuppressFinalize (this);
} else {
owns_handle = true;
}
refcount = 1;
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public void Close ()
{
if (refcount == 0)
throw new ObjectDisposedException (GetType ().FullName);
int newcount = 0, current = 0;
bool registered = false;
RuntimeHelpers.PrepareConstrainedRegions ();
try {
do {
current = refcount;
newcount = current-1;
// perform changes in finally to avoid async interruptions
try {}
finally {
if (Interlocked.CompareExchange (ref refcount, newcount, current) == current)
registered = true;
}
} while (!registered);
} finally {
if (registered && newcount == 0 && owns_handle && !IsInvalid){
ReleaseHandle ();
handle = invalid_handle_value;
refcount = -1;
}
}
Dispose ();
}
//
@@ -121,8 +103,8 @@ namespace System.Runtime.InteropServices
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
public void DangerousAddRef (ref bool success)
{
if (refcount <= 0)
throw new ObjectDisposedException (GetType ().FullName);
if (closed)
throw new ObjectDisposedException ("SafeHandle was closed");
bool registered = false;
int newcount, current;
@@ -153,29 +135,13 @@ namespace System.Runtime.InteropServices
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public IntPtr DangerousGetHandle ()
{
if (refcount <= 0){
throw new ObjectDisposedException (GetType ().FullName);
}
return handle;
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public void DangerousRelease ()
{
if (refcount <= 0)
throw new ObjectDisposedException (GetType ().FullName);
int newcount, current;
do {
current = refcount;
newcount = current-1;
} while (Interlocked.CompareExchange (ref refcount, newcount, current) != current);
if (newcount == 0 && owns_handle && !IsInvalid){
ReleaseHandle ();
handle = invalid_handle_value;
}
RunRelease ();
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
@@ -192,21 +158,52 @@ namespace System.Runtime.InteropServices
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public void SetHandleAsInvalid ()
{
handle = invalid_handle_value;
closed = true;
}
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
protected virtual void Dispose (bool disposing)
{
if (disposing)
Close ();
else {
//
// The docs say `never call this with disposing=false',
// the question is whether:
// * The runtime will ever call Dipose(false) for SafeHandles (special runtime case)
// * Whether we should just call ReleaseHandle regardless?
//
if (disposing) {
if (disposed)
return;
RunRelease ();
disposed = true;
} else {
if (owns_handle && !closed && !IsInvalid){
ReleaseHandle ();
}
}
}
void RunRelease ()
{
if (refcount == 0)
throw new ObjectDisposedException (GetType ().FullName);
int newcount = 0, current = 0;
bool registered = false;
RuntimeHelpers.PrepareConstrainedRegions ();
try {
do {
current = refcount;
newcount = current-1;
// perform changes in finally to avoid async interruptions
try {}
finally {
if (Interlocked.CompareExchange (ref refcount, newcount, current) == current)
registered = true;
}
} while (!registered);
} finally {
if (registered && newcount == 0) {
if (owns_handle && !closed && !IsInvalid)
ReleaseHandle ();
closed = true;
}
}
}
@@ -222,7 +219,7 @@ namespace System.Runtime.InteropServices
public bool IsClosed {
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
get {
return refcount <= 0;
return closed;
}
}
@@ -233,10 +230,7 @@ namespace System.Runtime.InteropServices
~SafeHandle ()
{
if (owns_handle && !IsInvalid){
ReleaseHandle ();
handle = invalid_handle_value;
}
Dispose (false);
}
}
}

View File

@@ -24,7 +24,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_4_0
using System;
@@ -56,4 +55,3 @@ namespace System.Runtime.InteropServices {
}
}
#endif

View File

@@ -49,9 +49,7 @@ namespace System.Runtime.InteropServices
ImportAsX86 = 256,
ReflectionOnlyLoading = 4096,
SerializableValueClasses = 32,
#if NET_4_0
NoDefineVersionResource = 8192
#endif
}
}
#endif