Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify all size_t arguments to use UIntPtr #238

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions src/SFML.Audio/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Security;
using SFML.System;

using SIZE_T = System.UIntPtr;

namespace SFML.Audio
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -59,7 +61,7 @@ public Music(byte[] bytes) :
GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
CPointer = sfMusic_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length));
CPointer = sfMusic_createFromMemory(pin.AddrOfPinnedObject(), (SIZE_T)bytes.Length);
}
finally
{
Expand Down Expand Up @@ -390,7 +392,7 @@ public TimeSpan(Time offset, Time length)
private unsafe static extern IntPtr sfMusic_createFromStream(IntPtr stream);

[DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfMusic_createFromMemory(IntPtr data, ulong size);
private static extern IntPtr sfMusic_createFromMemory(IntPtr data, SIZE_T size);

[DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfMusic_destroy(IntPtr MusicStream);
Expand Down
6 changes: 4 additions & 2 deletions src/SFML.Audio/SoundBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Security;
using SFML.System;

using SIZE_T = System.UIntPtr;

namespace SFML.Audio
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -75,7 +77,7 @@ public SoundBuffer(byte[] bytes) :
GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
CPointer = sfSoundBuffer_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length));
CPointer = sfSoundBuffer_createFromMemory(pin.AddrOfPinnedObject(), (SIZE_T)bytes.Length);
}
finally
{
Expand Down Expand Up @@ -224,7 +226,7 @@ protected override void Destroy(bool disposing)
private unsafe static extern IntPtr sfSoundBuffer_createFromStream(IntPtr stream);

[DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private unsafe static extern IntPtr sfSoundBuffer_createFromMemory(IntPtr data, ulong size);
private unsafe static extern IntPtr sfSoundBuffer_createFromMemory(IntPtr data, SIZE_T size);

[DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private unsafe static extern IntPtr sfSoundBuffer_createFromSamples(short* Samples, ulong SampleCount, uint ChannelsCount, uint SampleRate);
Expand Down
8 changes: 5 additions & 3 deletions src/SFML.Audio/SoundRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Security;
using SFML.System;

using SIZE_T = System.UIntPtr;

namespace SFML.Audio
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -271,9 +273,9 @@ protected override void Destroy(bool disposing)
/// <param name="userData">User data -- unused</param>
/// <returns>False to stop recording audio data, true to continue</returns>
////////////////////////////////////////////////////////////
private bool ProcessSamples(IntPtr samples, uint nbSamples, IntPtr userData)
private bool ProcessSamples(IntPtr samples, SIZE_T nbSamples, IntPtr userData)
{
short[] samplesArray = new short[nbSamples];
short[] samplesArray = new short[(int)nbSamples];
Marshal.Copy(samples, samplesArray, 0, samplesArray.Length);

return OnProcessSamples(samplesArray);
Expand All @@ -283,7 +285,7 @@ private bool ProcessSamples(IntPtr samples, uint nbSamples, IntPtr userData)
private delegate bool StartCallback();

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool ProcessCallback(IntPtr samples, uint nbSamples, IntPtr userData);
private delegate bool ProcessCallback(IntPtr samples, SIZE_T nbSamples, IntPtr userData);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void StopCallback();
Expand Down
28 changes: 24 additions & 4 deletions src/SFML.Graphics/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using SFML.System;
using SFML.Window;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -41,8 +43,10 @@ public Font(string filename) : base(sfFont_createFromFile(filename))
////////////////////////////////////////////////////////////
public Font(Stream stream) : base(IntPtr.Zero)
{
myStream = new StreamAdaptor(stream);
CPointer = sfFont_createFromStream(myStream.InputStreamPtr);
using (var adaptor = new StreamAdaptor(stream))
{
CPointer = sfFont_createFromStream(adaptor.InputStreamPtr);
}

if (CPointer == IntPtr.Zero)
{
Expand All @@ -57,7 +61,23 @@ public Font(Stream stream) : base(IntPtr.Zero)
/// <param name="bytes">Byte array containing the file contents</param>
/// <exception cref="LoadingFailedException" />
////////////////////////////////////////////////////////////
public Font(byte[] bytes) : this(new MemoryStream(bytes)) { }
public Font(byte[] bytes) :
base(IntPtr.Zero)
{
GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
CPointer = sfFont_createFromMemory(pin.AddrOfPinnedObject(), (SIZE_T)bytes.Length);
}
finally
{
pin.Free();
}
if (CPointer == IntPtr.Zero)
{
throw new LoadingFailedException("font");
}
}

////////////////////////////////////////////////////////////
/// <summary>
Expand Down Expand Up @@ -230,7 +250,7 @@ internal struct InfoMarshalData
private static extern IntPtr sfFont_createFromStream(IntPtr stream);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfFont_createFromMemory(IntPtr data, ulong size);
private static extern IntPtr sfFont_createFromMemory(IntPtr data, SIZE_T size);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfFont_copy(IntPtr Font);
Expand Down
6 changes: 4 additions & 2 deletions src/SFML.Graphics/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Security;
using SFML.System;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -90,7 +92,7 @@ public Image(byte[] bytes) :
GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
CPointer = sfImage_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length));
CPointer = sfImage_createFromMemory(pin.AddrOfPinnedObject(), (SIZE_T)bytes.Length);
}
finally
{
Expand Down Expand Up @@ -365,7 +367,7 @@ protected override void Destroy(bool disposing)
private unsafe static extern IntPtr sfImage_createFromStream(IntPtr stream);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private unsafe static extern IntPtr sfImage_createFromMemory(IntPtr data, ulong size);
private unsafe static extern IntPtr sfImage_createFromMemory(IntPtr data, SIZE_T size);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfImage_copy(IntPtr Image);
Expand Down
6 changes: 4 additions & 2 deletions src/SFML.Graphics/RenderTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using SFML.System;
using SFML.Window;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -400,7 +402,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type,
{
fixed (Vertex* vertexPtr = vertices)
{
sfRenderTexture_drawPrimitives(CPointer, vertexPtr + start, count, type, ref marshaledStates);
sfRenderTexture_drawPrimitives(CPointer, vertexPtr + start, (SIZE_T)count, type, ref marshaledStates);
}
}
}
Expand Down Expand Up @@ -593,7 +595,7 @@ protected override void Destroy(bool disposing)
private static extern bool sfRenderTexture_generateMipmap(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private unsafe static extern void sfRenderTexture_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, uint vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates);
private unsafe static extern void sfRenderTexture_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, SIZE_T vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfRenderTexture_pushGLStates(IntPtr CPointer);
Expand Down
6 changes: 4 additions & 2 deletions src/SFML.Graphics/RenderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using SFML.System;
using SFML.Window;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -578,7 +580,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type,
{
fixed (Vertex* vertexPtr = vertices)
{
sfRenderWindow_drawPrimitives(CPointer, vertexPtr + start, count, type, ref marshaledStates);
sfRenderWindow_drawPrimitives(CPointer, vertexPtr + start, (SIZE_T)count, type, ref marshaledStates);
}
}
}
Expand Down Expand Up @@ -903,7 +905,7 @@ private void Initialize()
private static extern Vector2i sfRenderWindow_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private unsafe static extern void sfRenderWindow_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, uint vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates);
private unsafe static extern void sfRenderWindow_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, SIZE_T vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfRenderWindow_pushGLStates(IntPtr CPointer);
Expand Down
26 changes: 14 additions & 12 deletions src/SFML.Graphics/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using SFML.System;
using SFML.Window;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -406,7 +408,7 @@ public unsafe void SetUniformArray(string name, float[] array)
{
fixed (float* data = array)
{
sfShader_setFloatUniformArray(CPointer, name, data, (uint)array.Length);
sfShader_setFloatUniformArray(CPointer, name, data, (SIZE_T)array.Length);
}
}

Expand All @@ -421,7 +423,7 @@ public unsafe void SetUniformArray(string name, Glsl.Vec2[] array)
{
fixed (Glsl.Vec2* data = array)
{
sfShader_setVec2UniformArray(CPointer, name, data, (uint)array.Length);
sfShader_setVec2UniformArray(CPointer, name, data, (SIZE_T)array.Length);
}
}

Expand All @@ -436,7 +438,7 @@ public unsafe void SetUniformArray(string name, Glsl.Vec3[] array)
{
fixed (Glsl.Vec3* data = array)
{
sfShader_setVec3UniformArray(CPointer, name, data, (uint)array.Length);
sfShader_setVec3UniformArray(CPointer, name, data, (SIZE_T)array.Length);
}
}

Expand All @@ -451,7 +453,7 @@ public unsafe void SetUniformArray(string name, Glsl.Vec4[] array)
{
fixed (Glsl.Vec4* data = array)
{
sfShader_setVec4UniformArray(CPointer, name, data, (uint)array.Length);
sfShader_setVec4UniformArray(CPointer, name, data, (SIZE_T)array.Length);
}
}

Expand All @@ -466,7 +468,7 @@ public unsafe void SetUniformArray(string name, Glsl.Mat3[] array)
{
fixed (Glsl.Mat3* data = array)
{
sfShader_setMat3UniformArray(CPointer, name, data, (uint)array.Length);
sfShader_setMat3UniformArray(CPointer, name, data, (SIZE_T)array.Length);
}
}

Expand All @@ -481,7 +483,7 @@ public unsafe void SetUniformArray(string name, Glsl.Mat4[] array)
{
fixed (Glsl.Mat4* data = array)
{
sfShader_setMat4UniformArray(CPointer, name, data, (uint)array.Length);
sfShader_setMat4UniformArray(CPointer, name, data, (SIZE_T)array.Length);
}
}

Expand Down Expand Up @@ -816,22 +818,22 @@ public Shader(IntPtr ptr) :
private static extern void sfShader_setCurrentTextureUniform(IntPtr shader, string name);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe void sfShader_setFloatUniformArray(IntPtr shader, string name, float* data, uint length);
private static extern unsafe void sfShader_setFloatUniformArray(IntPtr shader, string name, float* data, SIZE_T length);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe void sfShader_setVec2UniformArray(IntPtr shader, string name, Glsl.Vec2* data, uint length);
private static extern unsafe void sfShader_setVec2UniformArray(IntPtr shader, string name, Glsl.Vec2* data, SIZE_T length);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe void sfShader_setVec3UniformArray(IntPtr shader, string name, Glsl.Vec3* data, uint length);
private static extern unsafe void sfShader_setVec3UniformArray(IntPtr shader, string name, Glsl.Vec3* data, SIZE_T length);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe void sfShader_setVec4UniformArray(IntPtr shader, string name, Glsl.Vec4* data, uint length);
private static extern unsafe void sfShader_setVec4UniformArray(IntPtr shader, string name, Glsl.Vec4* data, SIZE_T length);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe void sfShader_setMat3UniformArray(IntPtr shader, string name, Glsl.Mat3* data, uint length);
private static extern unsafe void sfShader_setMat3UniformArray(IntPtr shader, string name, Glsl.Mat3* data, SIZE_T length);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe void sfShader_setMat4UniformArray(IntPtr shader, string name, Glsl.Mat4* data, uint length);
private static extern unsafe void sfShader_setMat4UniformArray(IntPtr shader, string name, Glsl.Mat4* data, SIZE_T length);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete]
private static extern void sfShader_setFloatParameter(IntPtr shader, string name, float x);
Expand Down
8 changes: 5 additions & 3 deletions src/SFML.Graphics/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using SFML.System;
using SFML.System;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
Expand Down Expand Up @@ -276,7 +278,7 @@ public Styles Style
////////////////////////////////////////////////////////////
public Vector2f FindCharacterPos(uint index)
{
return sfText_findCharacterPos(CPointer, index);
return sfText_findCharacterPos(CPointer, (SIZE_T)index);
}

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -448,7 +450,7 @@ protected override void Destroy(bool disposing)
private static extern FloatRect sfText_getRect(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern Vector2f sfText_findCharacterPos(IntPtr CPointer, uint Index);
private static extern Vector2f sfText_findCharacterPos(IntPtr CPointer, SIZE_T Index);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern FloatRect sfText_getLocalBounds(IntPtr CPointer);
Expand Down
6 changes: 4 additions & 2 deletions src/SFML.Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using SFML.System;
using SFML.Window;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -137,7 +139,7 @@ public Texture(byte[] bytes) :
try
{
IntRect rect = new IntRect(0, 0, 0, 0);
CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref rect);
CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), (SIZE_T)bytes.Length, ref rect);
}
finally
{
Expand Down Expand Up @@ -493,7 +495,7 @@ protected override void Destroy(bool disposing)
private static extern IntPtr sfTexture_createFromImage(IntPtr image, ref IntRect area);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfTexture_createFromMemory(IntPtr data, ulong size, ref IntRect area);
private static extern IntPtr sfTexture_createFromMemory(IntPtr data, SIZE_T size, ref IntRect area);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfTexture_copy(IntPtr texture);
Expand Down
6 changes: 4 additions & 2 deletions src/SFML.Graphics/VertexArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Security;
using SFML.System;

using SIZE_T = System.UIntPtr;

namespace SFML.Graphics
{
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -66,7 +68,7 @@ public VertexArray(VertexArray copy) :
////////////////////////////////////////////////////////////
public uint VertexCount
{
get { return sfVertexArray_getVertexCount(CPointer); }
get { return (uint)sfVertexArray_getVertexCount(CPointer); }
}

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -203,7 +205,7 @@ protected override void Destroy(bool disposing)
private static extern void sfVertexArray_destroy(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern uint sfVertexArray_getVertexCount(IntPtr CPointer);
private static extern SIZE_T sfVertexArray_getVertexCount(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe Vertex* sfVertexArray_getVertex(IntPtr CPointer, uint index);
Expand Down
Loading