// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-//
+//
using System;
using System.Diagnostics.SymbolStore;
this.Emit(OpCodes.Endfinally);
}
- //Check if we've alredy set this label.
+ //Check if we've already set this label.
//The only reason why we might have set this is if we have a finally block.
if (m_labelList[endLabel.GetLabelValue()] == -1)
{
Label finallyEndLabel = this.DefineLabel();
current.SetFinallyEndLabel(finallyEndLabel);
- // generate leave for try clause
+ // generate leave for try clause
this.Emit(OpCodes.Leave, finallyEndLabel);
if (catchEndAddr == 0)
catchEndAddr = m_length;
// WARNING: This is not a generic function to determine the innerness
// of an exception. This is somewhat of a mis-nomer. This gives a
// random result for cases where the two exceptions being compared do
- // not having a nesting relation.
+ // not having a nesting relation.
internal bool IsInner(__ExceptionInfo exc)
{
Debug.Assert(exc != null);
}
}
- // cannot find an existing document so add one to the array
+ // cannot find an existing document so add one to the array
EnsureCapacity();
m_iLastFound = m_DocumentCount;
m_Documents[m_iLastFound] = new REDocument(document);
// See the LICENSE file in the project root for more information.
-//
+//
namespace System.Reflection.Emit
{
if (!(type is TypeBuilder) && !(type is TypeBuilderInstantiation))
throw new ArgumentException(SR.Argument_MustBeTypeBuilder);
- // The following checks establishes invariants that more simply put require type to be generic and
+ // The following checks establishes invariants that more simply put require type to be generic and
// method to be a generic method definition declared on the generic type definition of type.
- // To create generic method G<Foo>.M<Bar> these invariants require that G<Foo>.M<S> be created by calling
+ // To create generic method G<Foo>.M<Bar> these invariants require that G<Foo>.M<S> be created by calling
// this function followed by MakeGenericMethod on the resulting MethodInfo to finally get G<Foo>.M<Bar>.
- // We could also allow G<T>.M<Bar> to be created before G<Foo>.M<Bar> (BindGenParm followed by this method)
+ // We could also allow G<T>.M<Bar> to be created before G<Foo>.M<Bar> (BindGenParm followed by this method)
// if we wanted to but that just complicates things so these checks are designed to prevent that scenario.
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
throw new ArgumentException(SR.Argument_InvalidMethodDeclaringType, nameof(type));
// The following converts from Type or TypeBuilder of G<T> to TypeBuilderInstantiation G<T>. These types
- // both logically represent the same thing. The runtime displays a similar convention by having
+ // both logically represent the same thing. The runtime displays a similar convention by having
// G<M>.M() be encoded by a typeSpec whose parent is the typeDef for G<M> and whose instantiation is also G<M>.
if (type.IsGenericTypeDefinition)
type = type.MakeGenericType(type.GetGenericArguments());
runtimeType2 = t2;
}
- // If the type builder view is eqaul then it is equal
+ // If the type builder view is eqaul then it is equal
if (tb1 != null && tb2 != null && Object.ReferenceEquals(tb1, tb2))
return true;
- // if the runtimetype view is eqaul than it is equal
+ // if the runtimetype view is eqaul than it is equal
if (runtimeType1 != null && runtimeType2 != null && runtimeType1 == runtimeType2)
return true;
return m_bakedRuntimeType.IsAssignableFrom(fromRuntimeType);
}
- // So if c is not a runtimeType nor TypeBuilder. We don't know how to deal with it.
+ // So if c is not a runtimeType nor TypeBuilder. We don't know how to deal with it.
// return false then.
if (fromTypeBuilder == null)
return false;
if (meth.IsGenericMethodDefinition)
- meth.GetToken(); // Doubles as "CreateMethod" for MethodBuilder -- analagous to CreateType()
+ meth.GetToken(); // Doubles as "CreateMethod" for MethodBuilder -- analogous to CreateType()
methodAttrs = meth.Attributes;
internal unsafe sealed class RtFieldInfo : RuntimeFieldInfo, IRuntimeFieldInfo
{
#region Private Data Members
- // agressive caching
+ // aggressive caching
private IntPtr m_fieldHandle;
private FieldAttributes m_fieldAttributes;
// lazy caching
}
// If the invocationFlags are still 0, then
- // this should be an usable field, determine the other flags
+ // this should be an usable field, determine the other flags
if (invocationFlags == 0)
{
if ((m_fieldAttributes & FieldAttributes.InitOnly) != (FieldAttributes)0)
// UnsafeSetValue doesn't perform any consistency or visibility check.
// It is the caller's responsibility to ensure the operation is safe.
// When the caller needs to perform visibility checks they should call
- // InternalSetValue() instead. When the caller needs to perform
- // consistency checks they should call CheckConsistency() before
+ // InternalSetValue() instead. When the caller needs to perform
+ // consistency checks they should call CheckConsistency() before
// calling this method.
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
// UnsafeGetValue doesn't perform any consistency or visibility check.
// It is the caller's responsibility to ensure the operation is safe.
// When the caller needs to perform visibility checks they should call
- // InternalGetValue() instead. When the caller needs to perform
- // consistency checks they should call CheckConsistency() before
+ // InternalGetValue() instead. When the caller needs to perform
+ // consistency checks they should call CheckConsistency() before
// calling this method.
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
#endregion
- #region FieldInfo Overrides
+ #region FieldInfo Overrides
public override Object GetValue(Object obj)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
}
//
- // IList & ICollection methods.
+ // IList & ICollection methods.
// This enables two-way data binding and index access in Jupiter
//
Object IList.this[int index]
}
else
{
- // All WinRT reference type (including arbitary managed type) will be PropertyType.ObjectArray
+ // All WinRT reference type (including arbitrary managed type) will be PropertyType.ObjectArray
return new CLRIReferenceArrayImpl<Object>(PropertyType.InspectableArray, (Object[])obj);
}
}
}
// Push a new token into this list
- // Returns true if you need to copy back this list into the dictionary (so that you
+ // Returns true if you need to copy back this list into the dictionary (so that you
// don't lose change outside the dictionary). false otherwise.
public bool Push(EventRegistrationToken token)
{
//
// The full structure of this table is:
// object the event is being registered on ->
- // Table [RemoveMethod] ->
+ // Table [RemoveMethod] ->
// Table [Handler] -> Token
//
// Note: There are a couple of optimizations I didn't do here because they don't make sense for managed events:
// 1. Flatten the event cache (see EventCacheKey in native WinRT event implementation below)
//
- // This is because managed events use ConditionalWeakTable to hold Objects->(Event->(Handler->Tokens)),
- // and when object goes away everything else will be nicely cleaned up. If I flatten it like native WinRT events,
- // I'll have to use Dictionary (as ConditionalWeakTable won't work - nobody will hold the new key alive anymore)
- // instead, and that means I'll have to add more code from native WinRT events into managed WinRT event to support
- // self-cleanup in the finalization, as well as reader/writer lock to protect against race conditions in the finalization,
+ // This is because managed events use ConditionalWeakTable to hold Objects->(Event->(Handler->Tokens)),
+ // and when object goes away everything else will be nicely cleaned up. If I flatten it like native WinRT events,
+ // I'll have to use Dictionary (as ConditionalWeakTable won't work - nobody will hold the new key alive anymore)
+ // instead, and that means I'll have to add more code from native WinRT events into managed WinRT event to support
+ // self-cleanup in the finalization, as well as reader/writer lock to protect against race conditions in the finalization,
// which adds a lot more complexity and doesn't really worth it.
- //
- // 2. Use conditionalWeakTable to hold Handler->Tokens.
- //
- // The reason is very simple - managed object use dictionary (see EventRegistrationTokenTable) to hold delegates alive.
- // If the delegates aren't alive, it means either they have been unsubscribed, or the object itself is gone,
+ //
+ // 2. Use conditionalWeakTable to hold Handler->Tokens.
+ //
+ // The reason is very simple - managed object use dictionary (see EventRegistrationTokenTable) to hold delegates alive.
+ // If the delegates aren't alive, it means either they have been unsubscribed, or the object itself is gone,
// and in either case, they've been already taken care of.
- //
+ //
internal volatile static
ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>> s_eventRegistrations =
new ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>>();
// Select a registration token to unregister
// We don't care which one but I'm returning the last registered token to be consistent
- // with native event registration implementation
+ // with native event registration implementation
bool moreItems = tokens.Pop(out token);
if (!moreItems)
{
// Remove it from cache if this list become empty
- // This must be done because EventRegistrationTokenList now becomes invalid
+ // This must be done because EventRegistrationTokenList now becomes invalid
// (mostly because there is no safe default value for EventRegistrationToken to express 'no token')
// NOTE: We should try to remove registrationTokens itself from cache if it is empty, otherwise
// we could run into a race condition where one thread removes it from cache and another thread adds
//
// EventRegistrationTokenListWithCount
- //
+ //
// A list of EventRegistrationTokens that maintains a count
//
// The reason this needs to be a separate class is that we need a finalizer for this class
- // If the delegate is collected, it will take this list away with it (due to dependent handles),
+ // If the delegate is collected, it will take this list away with it (due to dependent handles),
// and we need to remove the PerInstancEntry from cache
// See ~EventRegistrationTokenListWithCount for more details
//
//
// The full structure of this table is:
// EventCacheKey (instanceKey, eventMethod) -> EventCacheEntry (Handler->tokens)
- //
+ //
// A InstanceKey is the IUnknown * or static type instance
//
// Couple of things to note:
// based on the same COM object. For example:
// m_canvas.GetAt(0).Event += Func;
// m_canvas.GetAt(0).Event -= Func; // GetAt(0) might create a new RCW
- //
+ //
// 2. Handler->Token is a ConditionalWeakTable because we don't want to keep the delegate alive
- // and we want EventRegistrationTokenListWithCount to be finalized after the delegate is no longer alive
+ // and we want EventRegistrationTokenListWithCount to be finalized after the delegate is no longer alive
// 3. It is possible another COM object is created at the same address
- // before the entry in cache is destroyed. More specifically,
- // a. The same delegate is being unsubscribed. In this case we'll give them a
+ // before the entry in cache is destroyed. More specifically,
+ // a. The same delegate is being unsubscribed. In this case we'll give them a
// stale token - unlikely to be a problem
// b. The same delegate is subscribed then unsubscribed. We need to make sure give
// them the latest token in this case. This is guaranteed by always giving the last token and always use equality to
object instanceKey = GetInstanceKey(removeMethod);
// Call addMethod outside of RW lock
- // At this point we don't need to worry about race conditions and we can avoid deadlocks
+ // At this point we don't need to worry about race conditions and we can avoid deadlocks
// if addMethod waits on finalizer thread
// If we later throw we need to remove the method
EventRegistrationToken token = addMethod(handler);
//
// We need to find the key that equals to this handler
// Suppose we have 3 handlers A, B, C that are equal (refer to the same object and method),
- // the first handler (let's say A) will be used as the key and holds all the tokens.
+ // the first handler (let's say A) will be used as the key and holds all the tokens.
// We don't need to hold onto B and C, because the COM object itself will keep them alive,
// and they won't die anyway unless the COM object dies or they get unsubscribed.
// It may appear that it is fine to hold A, B, C, and add them and their corresponding tokens
// (but with the same object/method), so we need to find the first delegate that matches
// and unsubscribe it
// It actually doesn't matter which delegate - as long as it matches
- // Note that inside TryGetValueWithValueEquality we assumes that any delegate
+ // Note that inside TryGetValueWithValueEquality we assumes that any delegate
// with the same value equality would have the same hash code
object key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
Debug.Assert((key != null && tokens != null) || (key == null && tokens == null),
{
// Remove it from (handler)->(tokens)
// NOTE: We should not check whether registrationTokens has 0 entries and remove it from the cache
- // (just like managed event implementation), because this might have raced with the finalizer of
+ // (just like managed event implementation), because this might have raced with the finalizer of
// EventRegistrationTokenList
registrationTokens.Remove(key);
}
}
// Call removeMethod outside of RW lock
- // At this point we don't need to worry about race conditions and we can avoid deadlocks
+ // At this point we don't need to worry about race conditions and we can avoid deadlocks
// if removeMethod waits on finalizer thread
removeMethod(token);
}
///
/// <summary>
/// A reader-writer lock implementation that is intended to be simple, yet very
- /// efficient. In particular only 1 interlocked operation is taken for any lock
+ /// efficient. In particular only 1 interlocked operation is taken for any lock
/// operation (we use spin locks to achieve this). The spin lock is never held
/// for more than a few instructions (in particular, we never call event APIs
- /// or in fact any non-trivial API while holding the spin lock).
- ///
- /// Currently this ReaderWriterLock does not support recursion, however it is
- /// not hard to add
+ /// or in fact any non-trivial API while holding the spin lock).
+ ///
+ /// Currently this ReaderWriterLock does not support recursion, however it is
+ /// not hard to add
/// </summary>
internal class MyReaderWriterLock
{
private int myLock;
// Who owns the lock owners > 0 => readers
- // owners = -1 means there is one writer. Owners must be >= -1.
+ // owners = -1 means there is one writer. Owners must be >= -1.
private int owners;
- // These variables allow use to avoid Setting events (which is expensive) if we don't have to.
- private uint numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent
+ // These variables allow use to avoid Setting events (which is expensive) if we don't have to.
+ private uint numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent
private uint numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent
- // conditions we wait on.
- private EventWaitHandle writeEvent; // threads waiting to aquire a write lock go here.
- private EventWaitHandle readEvent; // threads waiting to aquire a read lock go here (will be released in bulk)
+ // conditions we wait on.
+ private EventWaitHandle writeEvent; // threads waiting to acquire a write lock go here.
+ private EventWaitHandle readEvent; // threads waiting to acquire a read lock go here (will be released in bulk)
internal MyReaderWriterLock()
{
- // All state can start out zeroed.
+ // All state can start out zeroed.
}
internal void AcquireReaderLock(int millisecondsTimeout)
for (;;)
{
// We can enter a read lock if there are only read-locks have been given out
- // and a writer is not trying to get in.
+ // and a writer is not trying to get in.
if (owners >= 0 && numWriteWaiters == 0)
{
// Good case, there is no contention, we are basically done
break;
}
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (readEvent == null) // Create the needed event
+ // Drat, we need to wait. Mark that we have waiters and wait.
+ if (readEvent == null) // Create the needed event
{
LazyCreateEvent(ref readEvent, false);
- continue; // since we left the lock, start over.
+ continue; // since we left the lock, start over.
}
WaitOnEvent(readEvent, ref numReadWaiters, millisecondsTimeout);
if (writeEvent == null) // create the needed event.
{
LazyCreateEvent(ref writeEvent, true);
- continue; // since we left the lock, start over.
+ continue; // since we left the lock, start over.
}
WaitOnEvent(writeEvent, ref numWriteWaiters, millisecondsTimeout);
/// A routine for lazily creating a event outside the lock (so if errors
/// happen they are outside the lock and that we don't do much work
/// while holding a spin lock). If all goes well, reenter the lock and
- /// set 'waitEvent'
+ /// set 'waitEvent'
/// </summary>
private void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent)
{
else
newEvent = new ManualResetEvent(false);
EnterMyLock();
- if (waitEvent == null) // maybe someone snuck in.
+ if (waitEvent == null) // maybe someone snuck in.
waitEvent = newEvent;
}
/// <summary>
- /// Waits on 'waitEvent' with a timeout of 'millisceondsTimeout.
+ /// Waits on 'waitEvent' with a timeout of 'millisceondsTimeout.
/// Before the wait 'numWaiters' is incremented and is restored before leaving this routine.
/// </summary>
private void WaitOnEvent(EventWaitHandle waitEvent, ref uint numWaiters, int millisecondsTimeout)
numWaiters++;
bool waitSuccessful = false;
- ExitMyLock(); // Do the wait outside of any lock
+ ExitMyLock(); // Do the wait outside of any lock
try
{
if (!waitEvent.WaitOne(millisecondsTimeout, false))
{
EnterMyLock();
--numWaiters;
- if (!waitSuccessful) // We are going to throw for some reason. Exit myLock.
+ if (!waitSuccessful) // We are going to throw for some reason. Exit myLock.
ExitMyLock();
}
}
/// <summary>
- /// Determines the appropriate events to set, leaves the locks, and sets the events.
+ /// Determines the appropriate events to set, leaves the locks, and sets the events.
/// </summary>
private void ExitAndWakeUpAppropriateWaiters()
{
if (owners == 0 && numWriteWaiters > 0)
{
ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- writeEvent.Set(); // release one writer.
+ writeEvent.Set(); // release one writer.
}
else if (owners >= 0 && numReadWaiters != 0)
{
ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- readEvent.Set(); // release all readers.
+ readEvent.Set(); // release all readers.
}
else
ExitMyLock();
for (int i = 0; ; i++)
{
if (i < 3 && Environment.ProcessorCount > 1)
- Thread.SpinWait(20); // Wait a few dozen instructions to let another processor release lock.
+ Thread.SpinWait(20); // Wait a few dozen instructions to let another processor release lock.
else
- Thread.Sleep(0); // Give up my quantum.
+ Thread.Sleep(0); // Give up my quantum.
if (Interlocked.CompareExchange(ref myLock, 1, 0) == 0)
return;
//
// Get activation factory object for a specified WinRT type
// If the WinRT type is a native type, we'll always create a unique RCW for it,
- // This is necessary because WinRT factories are often implemented as a singleton,
- // and getting back a RCW for such WinRT factory would usually get back a RCW from
+ // This is necessary because WinRT factories are often implemented as a singleton,
+ // and getting back a RCW for such WinRT factory would usually get back a RCW from
// another apartment, even if the interface pointe returned from GetActivationFactory
// is a raw pointer. As a result, user would randomly get back RCWs for activation
// factories from other apartments and make transiton to those apartments and cause
{
#if FEATURE_COMINTEROP_WINRT_MANAGED_ACTIVATION
return GetManagedActivationFactory(type);
-#else
+#else
// Managed factories are not supported so as to minimize public surface (and test effort)
throw new NotSupportedException();
#endif
// We need this dummy class to satisfy a QI when the TracingStatusChangedHandler
// after being stored in a GIT cookie and then called by the WinRT API. This usually
- // happens when calling a MAnaged WinMD which access this feature.
+ // happens when calling a Managed WinMD which access this feature.
[ComImport]
[Guid("410B7711-FF3B-477F-9C9A-D2EFDA302DC3")]
[WindowsRuntimeImport]
// 7 bytes of padding
}
-internal struct FieldAlignementTest
+internal struct FieldAlignmentTest
{
public byte m_byte1; // 1 byte
// 1 byte of padding
// 7 bytes of padding
}
-struct FieldAlignementTest_Decimal
+struct FieldAlignmentTest_Decimal
{
public byte b; // 1 byte
// 7 bytes of padding
// This is because unlike fields of other types well known to mcg (like long, char etc.)
// which need to be aligned according to their byte size, decimal is really a struct
// with 8 byte alignment requirement.
- public FieldAlignementTest p; // 80 bytes (72 bytes on x86/Unix)
+ public FieldAlignmentTest p; // 80 bytes (72 bytes on x86/Unix)
public short s; // 2 bytes
// 6 bytes of padding
}
-struct FieldAlignementTest_Guid
+struct FieldAlignmentTest_Guid
{
public byte b; // 1 byte
// 3 bytes of padding
// 2 bytes of padding
}
-struct FieldAlignementTest_Variant
+struct FieldAlignmentTest_Variant
{
public byte b; // 1 byte
// 7 bytes of padding
public class OffsetTest
{
-
+
public static void NullParameter()
{
Assert.Throws<ArgumentNullException>(() => Marshal.OffsetOf(null, null));
Assert.Throws<ArgumentNullException>(() => Marshal.OffsetOf(null, "abcd"));
}
-
+
public static void NonExistField()
{
Assert.Throws<ArgumentException>(() => Marshal.OffsetOf(typeof(NonExistField), "NonExistField"));
}
-
+
public static void NoLayoutClass()
{
Assert.Throws<ArgumentException>(() => Marshal.OffsetOf(typeof(NoLayoutPoint), "x"));
}
-
+
public static void StructField()
{
Assert.AreEqual(new IntPtr(4), Marshal.OffsetOf(typeof(someStruct), "var"));
}
-
+
public static void ClassExplicitField()
{
Assert.AreEqual(new IntPtr(0), Marshal.OffsetOf(typeof(MySystemTime), "wYear"));
Assert.AreEqual(new IntPtr(14), Marshal.OffsetOf(typeof(MySystemTime), "wMilliseconds"));
}
-
+
public static void ClassSequentialField()
{
Assert.AreEqual(new IntPtr(0), Marshal.OffsetOf(typeof(MyPoint), "x"));
Assert.AreEqual(new IntPtr(4), Marshal.OffsetOf(typeof(MyPoint), "y"));
}
-
+
public static void ProjectedType()
{
-#if BUG_1212387
+#if BUG_1212387
Assert.AreEqual(new IntPtr(0), Marshal.OffsetOf(typeof(Windows.Foundation.Point), "_x"));
Assert.AreEqual(new IntPtr(1), Marshal.OffsetOf(typeof(Windows.UI.Color), "_R"));
-#endif
+#endif
}
-
+
public static void TestExplicitLayout()
{
var t = typeof(ExplicitLayoutTest);
Assert.AreEqual(new IntPtr(48), Marshal.OffsetOf(t, "m_char1"));
}
-
+
public static void TestFieldAlignment()
{
- var t = typeof(FieldAlignementTest);
+ var t = typeof(FieldAlignmentTest);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
{
Assert.AreEqual(80, Marshal.SizeOf(t));
}
}
-
+
public static void TestFieldAlignment_Decimal()
{
- var t = typeof(FieldAlignementTest_Decimal);
+ var t = typeof(FieldAlignmentTest_Decimal);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
{
}
}
-
+
public static void TestFieldAlignment_Guid()
{
- var t = typeof(FieldAlignementTest_Guid);
+ var t = typeof(FieldAlignmentTest_Guid);
Assert.AreEqual(24, Marshal.SizeOf(t));
Assert.AreEqual(new IntPtr(0), Marshal.OffsetOf(t, "b"));
Assert.AreEqual(new IntPtr(20), Marshal.OffsetOf(t, "s"));
}
-
+
public static void TestFieldAlignment_Variant()
{
- var t = typeof(FieldAlignementTest_Variant);
+ var t = typeof(FieldAlignmentTest_Variant);
Assert.AreEqual(new IntPtr(0), Marshal.OffsetOf(t, "b"));
Assert.AreEqual(new IntPtr(8), Marshal.OffsetOf(t, "v"));
public static int Main(String[] args)
{
- //https://github.com/dotnet/coreclr/issues/2075
+ //https://github.com/dotnet/coreclr/issues/2075
//TestFieldAlignment_Variant();
TestFieldAlignment_Guid();
TestFieldAlignment_Decimal();
/*
* Some comments about the test:
* Expected: The code runs and completes successfully.
- * Acutal: The application hangs when it is run.
+ * Actual: The application hangs when it is run.
* The csharp compiler seems to be generating the same IL in both the cases.
*
* Some comments about the bug:
//
/*
- On windows the address range from 0 - 64 kb is protected
+ On windows the address range from 0 - 64 kb is protected
by the os, if code tries to access it, an access violation is triggered, which is translated
into a NullReferenceException by the runtime. If the offset to the field of the class is above
- 32 KB, we add some addtional code that checks for null accesses. The address range on mac is
- much smaller, 0-4 KB, and if the field offset is above 2 KB we are adding this additional code again.
+ 32 KB, we add some additional code that checks for null accesses. The address range on mac is
+ much smaller, 0-4 KB, and if the field offset is above 2 KB we are adding this additional code again.
*/
using System;
namespace System.IO
{
// This abstract base class represents a writer that can write a sequential
- // stream of characters. A subclass must minimally implement the
+ // stream of characters. A subclass must minimally implement the
// Write(char) method.
//
- // This class is intended for character output, not bytes.
- // There are methods on the Stream class for writing bytes.
+ // This class is intended for character output, not bytes.
+ // There are methods on the Stream class for writing bytes.
public abstract partial class TextWriter : MarshalByRefObject, IDisposable
{
public static readonly TextWriter Null = new NullTextWriter();
- // We don't want to allocate on every TextWriter creation, so cache the char array.
+ // We don't want to allocate on every TextWriter creation, so cache the char array.
private static readonly char[] s_coreNewLine = Environment.NewLine.ToCharArray();
/// <summary>
- /// This is the 'NewLine' property expressed as a char[].
+ /// This is the 'NewLine' property expressed as a char[].
/// It is exposed to subclasses as a protected field for read-only
- /// purposes. You should only modify it by using the 'NewLine' property.
- /// In particular you should never modify the elements of the array
- /// as they are shared among many instances of TextWriter.
+ /// purposes. You should only modify it by using the 'NewLine' property.
+ /// In particular you should never modify the elements of the array
+ /// as they are shared among many instances of TextWriter.
/// </summary>
protected char[] CoreNewLine = s_coreNewLine;
private string CoreNewLineStr = Environment.NewLine;
/// <summary>
/// Returns the line terminator string used by this TextWriter. The default line
- /// terminator string is Environment.NewLine, which is platform specific.
+ /// terminator string is Environment.NewLine, which is platform specific.
/// On Windows this is a carriage return followed by a line feed ("\r\n").
/// On OSX and Linux this is a line feed ("\n").
/// </summary>
Write(value.ToString(FormatProvider));
}
- // Writes the text representation of an unsigned long to the text
- // stream. The text representation of the given value is produced
+ // Writes the text representation of an unsigned long to the text
+ // stream. The text representation of the given value is produced
// by calling the UInt64.ToString() method.
//
[CLSCompliant(false)]
/// <summary>
/// Equivalent to Write(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
+ /// StringBuilder.GetChunks() method to avoid creating the intermediate string
/// </summary>
/// <param name="value">The string (as a StringBuilder) to write to the stream</param>
public virtual void Write(StringBuilder value)
// Writes out a formatted string. Uses the same semantics as
// String.Format.
- //
+ //
public virtual void Write(string format, object arg0)
{
Write(string.Format(FormatProvider, format, arg0));
// Writes out a formatted string. Uses the same semantics as
// String.Format.
- //
+ //
public virtual void Write(string format, object arg0, object arg1)
{
Write(string.Format(FormatProvider, format, arg0, arg1));
// Writes out a formatted string. Uses the same semantics as
// String.Format.
- //
+ //
public virtual void Write(string format, object arg0, object arg1, object arg2)
{
Write(string.Format(FormatProvider, format, arg0, arg1, arg2));
// Writes out a formatted string. Uses the same semantics as
// String.Format.
- //
+ //
public virtual void Write(string format, params object[] arg)
{
Write(string.Format(FormatProvider, format, arg));
WriteLine();
}
- // Writes the text representation of an unsigned integer followed by
+ // Writes the text representation of an unsigned integer followed by
// a line terminator to the text stream.
//
[CLSCompliant(false)]
WriteLine();
}
- // Writes the text representation of an unsigned long followed by
+ // Writes the text representation of an unsigned long followed by
// a line terminator to the text stream.
//
[CLSCompliant(false)]
/// <summary>
/// Equivalent to WriteLine(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
+ /// StringBuilder.GetChunks() method to avoid creating the intermediate string
/// </summary>
public virtual void WriteLine(StringBuilder value)
{
}
}
- // Writes out a formatted string and a new line. Uses the same
+ // Writes out a formatted string and a new line. Uses the same
// semantics as String.Format.
- //
+ //
public virtual void WriteLine(string format, object arg0)
{
WriteLine(string.Format(FormatProvider, format, arg0));
}
- // Writes out a formatted string and a new line. Uses the same
+ // Writes out a formatted string and a new line. Uses the same
// semantics as String.Format.
- //
+ //
public virtual void WriteLine(string format, object arg0, object arg1)
{
WriteLine(string.Format(FormatProvider, format, arg0, arg1));
}
- // Writes out a formatted string and a new line. Uses the same
+ // Writes out a formatted string and a new line. Uses the same
// semantics as String.Format.
- //
+ //
public virtual void WriteLine(string format, object arg0, object arg1, object arg2)
{
WriteLine(string.Format(FormatProvider, format, arg0, arg1, arg2));
}
- // Writes out a formatted string and a new line. Uses the same
+ // Writes out a formatted string and a new line. Uses the same
// semantics as String.Format.
- //
+ //
public virtual void WriteLine(string format, params object[] arg)
{
WriteLine(string.Format(FormatProvider, format, arg));
/// <summary>
/// Equivalent to WriteAsync(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
+ /// StringBuilder.GetChunks() method to avoid creating the intermediate string
/// </summary>
/// <param name="value">The string (as a StringBuilder) to write to the stream</param>
public virtual Task WriteAsync(StringBuilder value, CancellationToken cancellationToken = default)
{
- // Do the agument checking before 'going async' so you get it early
+ // Do the argument checking before 'going async' so you get it early
if (value == null)
{
throw new ArgumentNullException(nameof(value));
/// <summary>
/// Equivalent to WriteLineAsync(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
+ /// StringBuilder.GetChunks() method to avoid creating the intermediate string
/// </summary>
/// <param name="value">The string (as a StringBuilder) to write to the stream</param>
public async virtual Task WriteLineAsync(StringBuilder value, CancellationToken cancellationToken = default)