Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ICSharpCode.Decompiler/CSharp/Syntax/IAnnotatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;

Expand Down Expand Up @@ -115,6 +116,8 @@ public AnnotationList(int initialCapacity) : base(initialCapacity)
{
}

[SuppressMessage("Reliability", "CA2002:Do not lock on objects with weak identity",
Justification = "AnnotationList is a private nested type — the surrounding Annotatable class deliberately locks on the AnnotationList instance to serialize annotation reads/writes; external code cannot obtain a reference to it.")]
public object Clone()
{
lock (this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ExtensionDeclaration : EntityDeclaration
{
public readonly static TokenRole ExtensionKeywordRole = new TokenRole("extension");

public override SymbolKind SymbolKind => throw new System.NotImplementedException();
public override SymbolKind SymbolKind => SymbolKind.TypeDefinition;

public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole(Roles.TypeParameter); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal static bool IsBinaryCompatibleWithType(BinaryNumericInstruction binary,
return false; // operator not supported on pointer types
}
}
else if ((type.IsKnownType(KnownTypeCode.IntPtr) || type.IsKnownType(KnownTypeCode.UIntPtr)) && type.Kind is not TypeKind.NInt or TypeKind.NUInt)
else if ((type.IsKnownType(KnownTypeCode.IntPtr) || type.IsKnownType(KnownTypeCode.UIntPtr)) && type.Kind is not (TypeKind.NInt or TypeKind.NUInt))
{
// If the LHS is C# 9 IntPtr (but not nint or C# 11 IntPtr):
// "target.intptr *= 2;" is compiler error, but
Expand Down
15 changes: 9 additions & 6 deletions ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static unsafe string GetRealPath(string path, Encoding encoding)
fixed (byte* input = bytes)
{

byte* output = GetRealPath(input, null);
byte* output = NativeMethods.GetRealPath(input, null);
if (output == null)
{
return null;
Expand All @@ -330,15 +330,18 @@ static unsafe string GetRealPath(string path, Encoding encoding)
}
byte[] result = new byte[len];
Marshal.Copy((IntPtr)output, result, 0, result.Length);
Free(output);
NativeMethods.Free(output);
return encoding.GetString(result);
}
}

[DllImport("libc", EntryPoint = "realpath")]
static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);
static class NativeMethods
{
[DllImport("libc", EntryPoint = "realpath")]
internal static extern unsafe byte* GetRealPath(byte* path, byte* resolvedPath);

[DllImport("libc", EntryPoint = "free")]
static extern unsafe void Free(void* ptr);
[DllImport("libc", EntryPoint = "free")]
internal static extern unsafe void Free(void* ptr);
}
}
}
15 changes: 14 additions & 1 deletion ICSharpCode.Decompiler/Metadata/MetadataFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
Expand All @@ -45,7 +46,7 @@ namespace ICSharpCode.Decompiler.Metadata
/// decompiled type systems.
/// </remarks>
[DebuggerDisplay("{Kind}: {FileName}")]
public class MetadataFile
public class MetadataFile : IDisposable
{
public enum MetadataFileKind
{
Expand Down Expand Up @@ -285,6 +286,8 @@ public virtual int GetContainingSectionIndex(int rva)
throw new BadImageFormatException("This metadata file does not support sections.");
}

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations",
Justification = "Throw signals that this MetadataFileKind has no PE sections; derived PE-like kinds override.")]
public virtual ImmutableArray<SectionHeader> SectionHeaders => throw new BadImageFormatException("This metadata file does not support sections.");

/// <summary>
Expand All @@ -297,6 +300,16 @@ public IModuleReference WithOptions(TypeSystemOptions options)
return new MetadataFileWithOptions(this, options);
}

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
}

private class MetadataFileWithOptions : IModuleReference
{
readonly MetadataFile peFile;
Expand Down
8 changes: 5 additions & 3 deletions ICSharpCode.Decompiler/Metadata/PEFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace ICSharpCode.Decompiler.Metadata
{
[DebuggerDisplay("{FileName}")]
public class PEFile : MetadataFile, IDisposable, IModuleReference
public sealed class PEFile : MetadataFile, IModuleReference
{
public PEReader Reader { get; }

Expand All @@ -55,9 +55,11 @@ public PEFile(string fileName, PEReader reader, MetadataReaderOptions metadataOp
public override int MetadataOffset => Reader.PEHeaders.MetadataStartOffset;
public override bool IsMetadataOnly => false;

public void Dispose()
protected override void Dispose(bool disposing)
{
Reader.Dispose();
if (disposing)
Reader.Dispose();
base.Dispose(disposing);
}

IModule TypeSystem.IModuleReference.Resolve(ITypeResolveContext context)
Expand Down
8 changes: 5 additions & 3 deletions ICSharpCode.Decompiler/Metadata/WebCilFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace ICSharpCode.Decompiler.Metadata
{
public class WebCilFile : MetadataFile, IDisposable, IModuleReference
public sealed class WebCilFile : MetadataFile, IModuleReference
{
readonly MemoryMappedViewAccessor view;
readonly long webcilOffset;
Expand Down Expand Up @@ -245,9 +245,11 @@ public override unsafe SectionData GetSectionData(int rva)
return new MetadataModule(context.Compilation, this, TypeSystemOptions.Default);
}

public void Dispose()
protected override void Dispose(bool disposing)
{
view.Dispose();
if (disposing)
view.Dispose();
base.Dispose(disposing);
}

public struct WebcilHeader
Expand Down
11 changes: 10 additions & 1 deletion ICSharpCode.Decompiler/Output/PlainTextOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@

namespace ICSharpCode.Decompiler
{
public sealed class PlainTextOutput : ITextOutput
public sealed class PlainTextOutput : ITextOutput, IDisposable
{
readonly TextWriter writer;
readonly bool ownsWriter;
int indent;
bool needsIndent;

Expand All @@ -44,11 +45,19 @@ public PlainTextOutput(TextWriter writer)
if (writer == null)
throw new ArgumentNullException(nameof(writer));
this.writer = writer;
this.ownsWriter = false;
}

public PlainTextOutput()
{
this.writer = new StringWriter();
this.ownsWriter = true;
}

public void Dispose()
{
if (ownsWriter)
writer.Dispose();
}

public TextLocation Location {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sealed class CustomAttribute : IAttribute
CustomAttributeValue<IType> value;
bool valueDecoded;
bool hasDecodeErrors;
readonly object syncRoot = new object();

internal CustomAttribute(MetadataModule module, IMethod attrCtor, CustomAttributeHandle handle)
{
Expand Down Expand Up @@ -76,7 +77,7 @@ public bool HasDecodeErrors {

void DecodeValue()
{
lock (this)
lock (syncRoot)
{
try
{
Expand Down
3 changes: 3 additions & 0 deletions ICSharpCode.Decompiler/Util/EmptyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace ICSharpCode.Decompiler.Util
{
Expand Down Expand Up @@ -99,6 +100,8 @@ object IEnumerator.Current {
get { throw new NotSupportedException(); }
}

[SuppressMessage("Usage", "CA1063:Implement IDisposable Correctly",
Justification = "Explicit IDisposable implementation for IEnumerator<T>; intentional no-op for the singleton.")]
void IDisposable.Dispose()
{
}
Expand Down
5 changes: 5 additions & 0 deletions ICSharpCode.Decompiler/Util/LongSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace ICSharpCode.Decompiler.Util
{
/// <summary>
/// An immutable set of longs, that is implemented as a list of intervals.
/// </summary>
[SuppressMessage("Usage", "CA2231:Overload operator equals on overriding value type Equals",
Justification = "Equality on LongSet is intentionally only available via SetEquals — the IEquatable<LongSet>.Equals overload is itself [Obsolete] in favor of SetEquals.")]
public struct LongSet : IEquatable<LongSet>
{
/// <summary>
Expand Down Expand Up @@ -362,6 +365,8 @@ public override bool Equals(object? obj)
return obj is LongSet && SetEquals((LongSet)obj);
}

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations",
Justification = "Throw is an explicit guard against using LongSet in hash-based containers; use SetEquals for comparison.")]
public override int GetHashCode()
{
throw new NotImplementedException();
Expand Down
5 changes: 5 additions & 0 deletions ICSharpCode.Decompiler/Util/ResXResourceWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// includes code by Mike Krüger and Lluis Sanchez

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
Expand All @@ -40,6 +41,10 @@

namespace ICSharpCode.Decompiler.Util
{
[SuppressMessage("Usage", "CA1063:Implement IDisposable Correctly",
Justification = "Ported from the Mono ResXResourceWriter implementation; preserved verbatim for fidelity with the upstream.")]
[SuppressMessage("Usage", "CA2213:Disposable fields should be disposed",
Justification = "By design: the writer doesn't own the underlying stream/textwriter passed in by the caller. Mono behavior preserved.")]
#if INSIDE_SYSTEM_WEB
internal
#else
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/Util/ResourcesFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.Util
/// <summary>
/// .resources file.
/// </summary>
public class ResourcesFile : IEnumerable<KeyValuePair<string, object?>>, IDisposable
public sealed class ResourcesFile : IEnumerable<KeyValuePair<string, object?>>, IDisposable
{
sealed class MyBinaryReader : BinaryReader
{
Expand Down
14 changes: 12 additions & 2 deletions ICSharpCode.ILSpyX/AssemblyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ LoadedAssembly OpenAssembly(string file, Func<LoadedAssembly> load)
{
VerifyAccess();
file = Path.GetFullPath(file);
LoadedAssembly evicted;
LoadedAssembly newAsm;
lock (lockObj)
{
if (!byFilename.TryGetValue(file, out LoadedAssembly? target))
Expand All @@ -348,16 +350,18 @@ LoadedAssembly OpenAssembly(string file, Func<LoadedAssembly> load)
if (index < 0)
return null;

var newAsm = new LoadedAssembly(this, file, stream: Task.FromResult<Stream?>(stream),
newAsm = new LoadedAssembly(this, file, stream: Task.FromResult<Stream?>(stream),
fileLoaders: manager?.LoaderRegistry,
applyWinRTProjections: ApplyWinRTProjections, useDebugSymbols: UseDebugSymbols);
newAsm.IsAutoLoaded = target.IsAutoLoaded;

Debug.Assert(newAsm.FileName == file);
byFilename[file] = newAsm;
this.assemblies[index] = newAsm;
return newAsm;
evicted = target;
}
evicted.Dispose();
return newAsm;
}

public LoadedAssembly? ReloadAssembly(string file)
Expand Down Expand Up @@ -387,6 +391,7 @@ LoadedAssembly OpenAssembly(string file, Func<LoadedAssembly> load)
this.assemblies.Remove(target);
this.assemblies.Insert(index, newAsm);
}
target.Dispose();
return newAsm;
}

Expand All @@ -398,16 +403,21 @@ public void Unload(LoadedAssembly assembly)
assemblies.Remove(assembly);
byFilename.Remove(assembly.FileName);
}
assembly.Dispose();
}

public void Clear()
{
VerifyAccess();
LoadedAssembly[] removed;
lock (lockObj)
{
removed = assemblies.ToArray();
assemblies.Clear();
byFilename.Clear();
}
foreach (var asm in removed)
asm.Dispose();
}
public void Sort(IComparer<LoadedAssembly> comparer)
{
Expand Down
11 changes: 10 additions & 1 deletion ICSharpCode.ILSpyX/LoadedAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpyX
/// * a file that is still being loaded in the background
/// </summary>
[DebuggerDisplay("[LoadedAssembly {shortName}]")]
public sealed class LoadedAssembly
public sealed class LoadedAssembly : IDisposable
{
/// <summary>
/// Maps from MetadataFile (successfully loaded .NET module) back to the LoadedAssembly instance
Expand Down Expand Up @@ -652,5 +652,14 @@ public AssemblyReferenceClassifier GetAssemblyReferenceClassifier(bool applyWinR
}

UniversalAssemblyResolver? universalResolver;

public void Dispose()
{
if (loadingTask.Status == TaskStatus.RanToCompletion)
{
loadingTask.Result.MetadataFile?.Dispose();
}
(debugInfoProvider as IDisposable)?.Dispose();
}
}
}
7 changes: 6 additions & 1 deletion ICSharpCode.ILSpyX/PdbProvider/PortableDebugInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace ICSharpCode.ILSpyX.PdbProvider
{
public class PortableDebugInfoProvider : IDebugInfoProvider
public sealed class PortableDebugInfoProvider : IDebugInfoProvider, IDisposable
{
string? pdbFileName;
string moduleFileName;
Expand Down Expand Up @@ -252,5 +252,10 @@ public MetadataFile ToMetadataFile()
var kind = IsEmbedded || Path.GetExtension(SourceFileName).Equals(".pdb", StringComparison.OrdinalIgnoreCase) ? MetadataFileKind.ProgramDebugDatabase : MetadataFileKind.Metadata;
return new MetadataFile(kind, SourceFileName, provider, options, 0, IsEmbedded);
}

public void Dispose()
{
provider.Dispose();
}
}
}
3 changes: 2 additions & 1 deletion ILSpy.ReadyToRun/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[assembly: TargetPlatform("Windows10.0")]
[assembly: SupportedOSPlatform("Windows7.0")]

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyVersion("1.0.0.0")]
Loading
Loading