Remove unsafe keyword where unused or extraneous

This commit is contained in:
YoshiRulz 2021-04-08 14:05:36 +10:00
parent 4d47861296
commit 3db06c4aa9
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
26 changed files with 53 additions and 53 deletions

View File

@ -37,7 +37,7 @@ namespace BizHawk.BizInvoke
/// Didn't I have code somewhere else to do this already? /// Didn't I have code somewhere else to do this already?
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static unsafe int ComputeClassFieldOffset() public static int ComputeClassFieldOffset()
{ {
var c = new CF(); var c = new CF();
int ret; int ret;
@ -48,7 +48,7 @@ namespace BizHawk.BizInvoke
} }
return ret; return ret;
} }
public static unsafe int ComputeStringOffset() public static int ComputeStringOffset()
{ {
var s = new string(new char[0]); var s = new string(new char[0]);
int ret; int ret;

View File

@ -5,7 +5,7 @@ using static BizHawk.BizInvoke.POSIXLibC;
namespace BizHawk.BizInvoke namespace BizHawk.BizInvoke
{ {
internal sealed unsafe class MemoryBlockLinuxPal : IMemoryBlockPal internal sealed class MemoryBlockLinuxPal : IMemoryBlockPal
{ {
public ulong Start { get; } public ulong Start { get; }
private readonly ulong _size; private readonly ulong _size;

View File

@ -64,7 +64,7 @@ namespace BizHawk.Bizware.BizwareGL
/// If the close operation is forever, then internal backup copies of resources will be freed, but it can never be reopened. /// If the close operation is forever, then internal backup copies of resources will be freed, but it can never be reopened.
/// This function may take some time to run, as it is /// This function may take some time to run, as it is
/// </summary> /// </summary>
public unsafe void Close(bool forever = true) public void Close(bool forever = true)
{ {
AssertIsOpen(true); AssertIsOpen(true);
IsOpened = false; IsOpened = false;

View File

@ -80,7 +80,7 @@ namespace BizHawk.Bizware.BizwareGL
UnlockBits(CurrLock); UnlockBits(CurrLock);
} }
public unsafe void YFlip() public void YFlip()
{ {
//TODO - could be faster //TODO - could be faster
var bmpdata = LockBits(); var bmpdata = LockBits();
@ -107,7 +107,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary> /// <summary>
/// Makes sure the alpha channel is clean and optionally y-flips /// Makes sure the alpha channel is clean and optionally y-flips
/// </summary> /// </summary>
public unsafe void Normalize(bool yflip) public void Normalize(bool yflip)
{ {
var bmpdata = LockBits(); var bmpdata = LockBits();
int[] newPixels = new int[Width * Height]; int[] newPixels = new int[Width * Height];
@ -380,7 +380,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary> /// <summary>
/// Loads the BitmapBuffer from a source buffer, which is expected to be the right pixel format /// Loads the BitmapBuffer from a source buffer, which is expected to be the right pixel format
/// </summary> /// </summary>
public unsafe void LoadFrom(int width, int stride, int height, byte* data, BitmapLoadOptions options) public void LoadFrom(int width, int stride, int height, byte* data, BitmapLoadOptions options)
{ {
bool cleanup = options.CleanupAlpha0; bool cleanup = options.CleanupAlpha0;
Width = width; Width = width;
@ -447,7 +447,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary> /// <summary>
/// clears this instance to (0,0,0,0) -- without allocating a new array (to avoid GC churn) /// clears this instance to (0,0,0,0) -- without allocating a new array (to avoid GC churn)
/// </summary> /// </summary>
public unsafe void ClearWithoutAlloc() public void ClearWithoutAlloc()
{ {
//http://techmikael.blogspot.com/2009/12/filling-array-with-default-value.html //http://techmikael.blogspot.com/2009/12/filling-array-with-default-value.html
//this guy says its faster //this guy says its faster
@ -498,7 +498,7 @@ namespace BizHawk.Bizware.BizwareGL
/// <summary> /// <summary>
/// Dumps this BitmapBuffer to a new System.Drawing.Bitmap /// Dumps this BitmapBuffer to a new System.Drawing.Bitmap
/// </summary> /// </summary>
public unsafe Bitmap ToSysdrawingBitmap() public Bitmap ToSysdrawingBitmap()
{ {
if (WrappedBitmap != null) if (WrappedBitmap != null)
return (Bitmap)WrappedBitmap.Clone(); return (Bitmap)WrappedBitmap.Clone();
@ -514,7 +514,7 @@ namespace BizHawk.Bizware.BizwareGL
/// Dumps this BitmapBuffer to an existing System.Drawing.Bitmap. /// Dumps this BitmapBuffer to an existing System.Drawing.Bitmap.
/// Some features of this may not be super fast (in particular, 32bpp to 24bpp conversion; we might fix that later with a customized loop) /// Some features of this may not be super fast (in particular, 32bpp to 24bpp conversion; we might fix that later with a customized loop)
/// </summary> /// </summary>
public unsafe void ToSysdrawingBitmap(Bitmap bmp) public void ToSysdrawingBitmap(Bitmap bmp)
{ {
if (WrappedBitmap != null) if (WrappedBitmap != null)
{ {

View File

@ -228,17 +228,17 @@ namespace BizHawk.Bizware.BizwareGL
g.Transform = new sd.Drawing2D.Matrix(mat.Row0.X, mat.Row0.Y, mat.Row1.X, mat.Row1.Y, mat.Row3.X, mat.Row3.Y); g.Transform = new sd.Drawing2D.Matrix(mat.Row0.X, mat.Row0.Y, mat.Row1.X, mat.Row1.Y, mat.Row3.X, mat.Row3.Y);
} }
private unsafe void DrawInternal(Art art, float x, float y, float w, float h) private void DrawInternal(Art art, float x, float y, float w, float h)
{ {
DrawInternal(art.BaseTexture, x, y, w, h, art.u0, art.v0, art.u1, art.v1); DrawInternal(art.BaseTexture, x, y, w, h, art.u0, art.v0, art.u1, art.v1);
} }
private unsafe void DrawInternal(Texture2d tex, float x, float y, float w, float h) private void DrawInternal(Texture2d tex, float x, float y, float w, float h)
{ {
DrawInternal(tex, x, y, w, h, 0, 0, 1, 1); DrawInternal(tex, x, y, w, h, 0, 0, 1, 1);
} }
private unsafe void DrawInternal(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1) private void DrawInternal(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1)
{ {
var g = ((dynamic) Gdi).GetCurrentGraphics() as sd.Graphics; var g = ((dynamic) Gdi).GetCurrentGraphics() as sd.Graphics;
PrepDraw(g, tex); PrepDraw(g, tex);
@ -264,7 +264,7 @@ namespace BizHawk.Bizware.BizwareGL
g.Transform = new sd.Drawing2D.Matrix(); //.Reset() doesn't work ? ? g.Transform = new sd.Drawing2D.Matrix(); //.Reset() doesn't work ? ?
} }
private unsafe void DrawInternal(Art art, float x, float y, float w, float h, bool fx, bool fy) private void DrawInternal(Art art, float x, float y, float w, float h, bool fx, bool fy)
{ {
} }

View File

@ -554,7 +554,7 @@ namespace BizHawk.Bizware.DirectX
} }
} }
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose) public void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose)
{ {
if (uniform.Owner == null) if (uniform.Owner == null)
{ {
@ -568,7 +568,7 @@ namespace BizHawk.Bizware.DirectX
} }
} }
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose) public void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose)
{ {
if (uniform.Owner == null) if (uniform.Owner == null)
{ {
@ -617,7 +617,7 @@ namespace BizHawk.Bizware.DirectX
} }
} }
public unsafe void SetPipelineUniform(PipelineUniform uniform, Vector4[] values) public void SetPipelineUniform(PipelineUniform uniform, Vector4[] values)
{ {
if (uniform.Owner == null) return; // uniform was optimized out if (uniform.Owner == null) return; // uniform was optimized out
var v = new SlimDX.Vector4[values.Length]; var v = new SlimDX.Vector4[values.Length];
@ -688,7 +688,7 @@ namespace BizHawk.Bizware.DirectX
} }
/// <exception cref="InvalidOperationException">GDI+ call returned unexpected data</exception> /// <exception cref="InvalidOperationException">GDI+ call returned unexpected data</exception>
public unsafe void LoadTextureData(Texture2d tex, BitmapBuffer bmp) public void LoadTextureData(Texture2d tex, BitmapBuffer bmp)
{ {
sdi.BitmapData bmpData = bmp.LockBits(); sdi.BitmapData bmpData = bmp.LockBits();
var tw = tex.Opaque as TextureWrapper; var tw = tex.Opaque as TextureWrapper;
@ -717,7 +717,7 @@ namespace BizHawk.Bizware.DirectX
} }
/// <exception cref="InvalidOperationException">SlimDX call returned unexpected data</exception> /// <exception cref="InvalidOperationException">SlimDX call returned unexpected data</exception>
public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex) public BitmapBuffer ResolveTexture2d(Texture2d tex)
{ {
//TODO - lazy create and cache resolving target in RT //TODO - lazy create and cache resolving target in RT
var target = new Texture(Dev, tex.IntWidth, tex.IntHeight, 1, Usage.None, Format.A8R8G8B8, Pool.SystemMemory); var target = new Texture(Dev, tex.IntWidth, tex.IntHeight, 1, Usage.None, Format.A8R8G8B8, Pool.SystemMemory);

View File

@ -218,7 +218,7 @@ namespace BizHawk.Bizware.OpenTK3
DrawInternal(art, x, y, width, height); DrawInternal(art, x, y, width, height);
} }
private unsafe void DrawInternal(Texture2d tex, float x, float y, float w, float h) private void DrawInternal(Texture2d tex, float x, float y, float w, float h)
{ {
Art art = new Art((ArtManager)null); Art art = new Art((ArtManager)null);
art.Width = w; art.Width = w;
@ -258,7 +258,7 @@ namespace BizHawk.Bizware.OpenTK3
} }
} }
private unsafe void PrepDrawSubrectInternal(Texture2d tex) private void PrepDrawSubrectInternal(Texture2d tex)
{ {
if (sTexture != tex) if (sTexture != tex)
{ {
@ -330,7 +330,7 @@ namespace BizHawk.Bizware.OpenTK3
#endif #endif
} }
private unsafe void DrawSubrectInternal(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1) private void DrawSubrectInternal(Texture2d tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1)
{ {
PrepDrawSubrectInternal(tex); PrepDrawSubrectInternal(tex);
EmitRectangleInternal(x, y, w, h, u0, v0, u1, v1); EmitRectangleInternal(x, y, w, h, u0, v0, u1, v1);

View File

@ -577,7 +577,7 @@ namespace BizHawk.Bizware.OpenTK3
return ret; return ret;
} }
public unsafe BitmapBuffer ResolveTexture2d(Texture2d tex) public BitmapBuffer ResolveTexture2d(Texture2d tex)
{ {
//note - this is dangerous since it changes the bound texture. could we save it? //note - this is dangerous since it changes the bound texture. could we save it?
BindTexture2d(tex); BindTexture2d(tex);

View File

@ -16,7 +16,7 @@ namespace BizHawk.Client.Common
private BitmapData _bmpData; private BitmapData _bmpData;
private readonly int[] _pixels; private readonly int[] _pixels;
public unsafe void Clear() public void Clear()
{ {
FromBitmap(false); FromBitmap(false);
Util.Memset(PixelPtr, 0, Stride * Height); Util.Memset(PixelPtr, 0, Stride * Height);
@ -37,7 +37,7 @@ namespace BizHawk.Client.Common
return Graphics.FromImage(_bmp); return Graphics.FromImage(_bmp);
} }
public unsafe void ToBitmap(bool copy=true) public void ToBitmap(bool copy = true)
{ {
if (_isBitmap) return; if (_isBitmap) return;
_isBitmap = true; _isBitmap = true;
@ -70,7 +70,7 @@ namespace BizHawk.Client.Common
private bool _isBitmap; private bool _isBitmap;
public unsafe void FromBitmap(bool copy = true) public void FromBitmap(bool copy = true)
{ {
if (!_isBitmap) if (!_isBitmap)
{ {

View File

@ -351,7 +351,7 @@ namespace BizHawk.Client.Common
return ret; return ret;
} }
private unsafe class SaveStateStream : Stream, ISpanStream private sealed class SaveStateStream : Stream, ISpanStream
{ {
/// <summary> /// <summary>
/// ///
@ -445,7 +445,7 @@ namespace BizHawk.Client.Common
} }
} }
private unsafe class LoadStateStream : Stream, ISpanStream private sealed class LoadStateStream : Stream, ISpanStream
{ {
public LoadStateStream(Stream backingStore, long offset, long size, long mask) public LoadStateStream(Stream backingStore, long offset, long size, long mask)
{ {
@ -481,7 +481,7 @@ namespace BizHawk.Client.Common
return Read(new Span<byte>(buffer, offset, count)); return Read(new Span<byte>(buffer, offset, count));
} }
public unsafe int Read(Span<byte> buffer) public int Read(Span<byte> buffer)
{ {
long n = Math.Min(_size - _position, buffer.Length); long n = Math.Min(_size - _position, buffer.Length);
int ret = (int)n; int ret = (int)n;

View File

@ -636,7 +636,7 @@ namespace BizHawk.Client.EmuHawk
private static bool FAILED(int hr) => hr < 0; private static bool FAILED(int hr) => hr < 0;
private static unsafe int AVISaveOptions(IntPtr stream, ref AVIWriterImports.AVICOMPRESSOPTIONS opts, IntPtr owner) private static int AVISaveOptions(IntPtr stream, ref AVIWriterImports.AVICOMPRESSOPTIONS opts, IntPtr owner)
{ {
fixed (AVIWriterImports.AVICOMPRESSOPTIONS* _popts = &opts) fixed (AVIWriterImports.AVICOMPRESSOPTIONS* _popts = &opts)
{ {
@ -847,7 +847,7 @@ namespace BizHawk.Client.EmuHawk
} }
// todo - why couldnt this take an ISoundProvider? it could do the timekeeping as well.. hmm // todo - why couldnt this take an ISoundProvider? it could do the timekeeping as well.. hmm
public unsafe void AddSamples(short[] samples) public void AddSamples(short[] samples)
{ {
int todo = samples.Length; int todo = samples.Length;
int idx = 0; int idx = 0;
@ -868,7 +868,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private unsafe void FlushBufferedAudio() private void FlushBufferedAudio()
{ {
int todo = _outStatus.audio_buffered_shorts; int todo = _outStatus.audio_buffered_shorts;
int todo_realsamples = todo / 2; int todo_realsamples = todo / 2;
@ -888,7 +888,7 @@ namespace BizHawk.Client.EmuHawk
} }
/// <exception cref="InvalidOperationException">attempted frame resize during encoding</exception> /// <exception cref="InvalidOperationException">attempted frame resize during encoding</exception>
public unsafe void AddFrame(IVideoProvider source) public void AddFrame(IVideoProvider source)
{ {
const int AVIIF_KEYFRAME = 0x00000010; const int AVIIF_KEYFRAME = 0x00000010;

View File

@ -104,11 +104,11 @@ namespace BizHawk.Client.EmuHawk
} }
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose) public void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose)
{ {
} }
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose) public void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose)
{ {
} }
@ -124,7 +124,7 @@ namespace BizHawk.Client.EmuHawk
{ {
} }
public unsafe void SetPipelineUniform(PipelineUniform uniform, Vector4[] values) public void SetPipelineUniform(PipelineUniform uniform, Vector4[] values)
{ {
} }
@ -334,7 +334,7 @@ namespace BizHawk.Client.EmuHawk
rtw.Dispose(); rtw.Dispose();
} }
public unsafe RenderTarget CreateRenderTarget(int w, int h) public RenderTarget CreateRenderTarget(int w, int h)
{ {
var tw = new GDIPTextureWrapper var tw = new GDIPTextureWrapper
{ {

View File

@ -8,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
{ {
public partial class QuickNES public partial class QuickNES
{ {
private unsafe void InitMemoryDomains() private void InitMemoryDomains()
{ {
List<MemoryDomain> mm = new List<MemoryDomain>(); List<MemoryDomain> mm = new List<MemoryDomain>();
for (int i = 0; ; i++) for (int i = 0; ; i++)

View File

@ -358,10 +358,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
//utilities //utilities
//TODO: make internal, wrap on the API instead of the comm //TODO: make internal, wrap on the API instead of the comm
public unsafe string GetAscii() { return _getAscii(str); } public string GetAscii() => _getAscii(str);
public bool GetBool() { return value != 0; } public bool GetBool() { return value != 0; }
private unsafe string _getAscii(sbyte* ptr) private string _getAscii(sbyte* ptr)
{ {
int len = 0; int len = 0;
sbyte* junko = (sbyte*)ptr; sbyte* junko = (sbyte*)ptr;

View File

@ -1,6 +1,6 @@
namespace BizHawk.Emulation.Cores.Nintendo.SNES namespace BizHawk.Emulation.Cores.Nintendo.SNES
{ {
unsafe partial class LibsnesApi public partial class LibsnesApi
{ {
public enum eMessage : int public enum eMessage : int
{ {

View File

@ -142,7 +142,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
} }
} }
public unsafe void QUERY_peek_cpu_regs(out CPURegs ret) public void QUERY_peek_cpu_regs(out CPURegs ret)
{ {
using (_exe.EnterExit()) using (_exe.EnterExit())
{ {

View File

@ -3,7 +3,7 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.SNES namespace BizHawk.Emulation.Cores.Nintendo.SNES
{ {
public unsafe partial class LibsnesCore : IStatable public partial class LibsnesCore : IStatable
{ {
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)
{ {

View File

@ -124,7 +124,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
OctoshockDll.shock_SetMemCb(psx, mem_cb, mask); OctoshockDll.shock_SetMemCb(psx, mem_cb, mask);
} }
private unsafe void SetMemoryDomains() private void SetMemoryDomains()
{ {
var mmd = new List<MemoryDomain>(); var mmd = new List<MemoryDomain>();

View File

@ -139,7 +139,7 @@ namespace BizHawk.Emulation.Cores.Libretro
} }
} }
public unsafe struct CommStructEnv public struct CommStructEnv
{ {
public retro_system_info retro_system_info; public retro_system_info retro_system_info;
public retro_system_av_info retro_system_av_info; public retro_system_av_info retro_system_av_info;

View File

@ -1,6 +1,6 @@
namespace BizHawk.Emulation.Cores.Libretro namespace BizHawk.Emulation.Cores.Libretro
{ {
unsafe partial class LibretroApi public partial class LibretroApi
{ {
private bool Handle_BRK(eMessage msg) private bool Handle_BRK(eMessage msg)
{ {
@ -18,4 +18,4 @@
#endif #endif
} }
} }
} }

View File

@ -2,7 +2,7 @@
namespace BizHawk.Emulation.Cores.Libretro namespace BizHawk.Emulation.Cores.Libretro
{ {
unsafe partial class LibretroApi public partial class LibretroApi
{ {
public enum eMessage : int public enum eMessage : int
{ {

View File

@ -11,7 +11,7 @@ using static BizHawk.Emulation.Cores.Waterbox.LibNymaCore;
namespace BizHawk.Emulation.Cores.Waterbox namespace BizHawk.Emulation.Cores.Waterbox
{ {
unsafe partial class NymaCore public partial class NymaCore
{ {
private const int MAX_INPUT_DATA = 256; private const int MAX_INPUT_DATA = 256;

View File

@ -9,7 +9,7 @@ using NymaTypes;
namespace BizHawk.Emulation.Cores.Waterbox namespace BizHawk.Emulation.Cores.Waterbox
{ {
unsafe partial class NymaCore : ISettable<NymaCore.NymaSettings, NymaCore.NymaSyncSettings> public partial class NymaCore : ISettable<NymaCore.NymaSettings, NymaCore.NymaSyncSettings>
{ {
public NymaSettingsInfo SettingsInfo { get; private set; } public NymaSettingsInfo SettingsInfo { get; private set; }
private NymaSettings _settings; private NymaSettings _settings;

View File

@ -64,7 +64,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
public bool SkipMemoryConsistencyCheck { get; set; } = false; public bool SkipMemoryConsistencyCheck { get; set; } = false;
} }
public unsafe class WaterboxHost : IMonitor, IImportResolver, IStatable, IDisposable, ICallbackAdjuster public sealed class WaterboxHost : IMonitor, IImportResolver, IStatable, IDisposable, ICallbackAdjuster
{ {
private IntPtr _nativeHost; private IntPtr _nativeHost;
private int _enterCount; private int _enterCount;

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
[FieldOffset(1024)] [FieldOffset(1024)]
public IntPtr Data; public IntPtr Data;
public unsafe IntPtr GetDataOrThrow() public IntPtr GetDataOrThrow()
{ {
if (ErrorMessageStart != 0) if (ErrorMessageStart != 0)
{ {

View File

@ -9,7 +9,7 @@ using static BizHawk.Emulation.Cores.Waterbox.LibWaterboxCore;
namespace BizHawk.Emulation.Cores.Waterbox namespace BizHawk.Emulation.Cores.Waterbox
{ {
public abstract unsafe class WaterboxMemoryDomain : MemoryDomain public abstract class WaterboxMemoryDomain : MemoryDomain
{ {
protected readonly IntPtr _data; protected readonly IntPtr _data;
protected readonly IMonitor _monitor; protected readonly IMonitor _monitor;