Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Oct 28, 2024
2 parents 2596e1d + 7978416 commit 7095410
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
19 changes: 8 additions & 11 deletions src/IKVM.ByteCode/Buffers/MappedFileMemoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sealed unsafe class MappedFileMemoryManager : MemoryManager<byte>

readonly MemoryMappedFile _file;
readonly MemoryMappedViewAccessor _view;
readonly byte* _addr;

/// <summary>
/// Initializes a new instance.
Expand All @@ -31,15 +32,15 @@ public MappedFileMemoryManager(MemoryMappedFile file, MemoryMappedViewAccessor v
throw new InvalidOperationException();
if (_view.SafeMemoryMappedViewHandle.IsClosed || _view.SafeMemoryMappedViewHandle.IsInvalid)
throw new InvalidOperationException();

_view.SafeMemoryMappedViewHandle.AcquirePointer(ref _addr);
}

/// <inheritdoc />
public override Span<byte> GetSpan()
{
byte* ptr = null;
_view.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
var len = _view.SafeMemoryMappedViewHandle.ByteLength;
return new Span<byte>(ptr, checked((int)len));
return new Span<byte>(_addr, checked((int)len));
}

/// <inheritdoc />
Expand All @@ -48,9 +49,7 @@ public override MemoryHandle Pin(int elementIndex = 0)
if (elementIndex < 0 || elementIndex >= checked((int)_view.SafeMemoryMappedViewHandle.ByteLength))
throw new ArgumentOutOfRangeException(nameof(elementIndex));

byte* ptr = null;
_view.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
return new MemoryHandle(Unsafe.Add<byte>(ptr, elementIndex));
return new MemoryHandle(Unsafe.Add<byte>(_addr, elementIndex));
}

/// <inheritdoc />
Expand All @@ -62,11 +61,9 @@ public override void Unpin()
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (true)
{
_view.Dispose();
_file.Dispose();
}
_view.SafeMemoryMappedViewHandle.ReleasePointer();
_view.Dispose();
_file.Dispose();
}

}
Expand Down
12 changes: 5 additions & 7 deletions src/IKVM.ByteCode/Decoding/ClassFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public sealed class ClassFile : IDisposable
public const uint MAGIC = 0xCAFEBABE;
public const uint MIN_CLASS_SIZE = 30;


/// <summary>
/// Attempts to measure a class starting at the current position.
/// </summary>
Expand Down Expand Up @@ -178,20 +177,19 @@ public static bool TryRead(in ReadOnlySequence<byte> buffer, out ClassFile? claz
/// <exception cref="ByteCodeException"></exception>
public static bool TryMeasure(in ReadOnlySequence<byte> buffer, ref int size, out SequencePosition consumed, out SequencePosition examined)
{
consumed = buffer.Start;

var reader = new ClassFormatReader(buffer);
if (TryMeasure(ref reader, ref size) == false)
{
// examined up to the position of the reader, but consumed nothing
examined = reader.Position;
// examined up to the end of the buffer, but consumed nothing
examined = buffer.End;
consumed = buffer.Start;
return false;
}
else
{
// examined up to the point of the reader, consumed the same
// examined up to the end of thebuffer, but consumed up until the position of the reader
examined = buffer.End;
consumed = reader.Position;
examined = reader.Position;
return true;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/IKVM.ByteCode/Text/EncodingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Text;

namespace IKVM.ByteCode.Text
{
Expand Down

0 comments on commit 7095410

Please sign in to comment.