Add [MustDisposeResource] annoations to array helpers

This commit is contained in:
Susko3 2024-04-06 15:37:29 +02:00
parent 99d90c0fb6
commit d919dacea8
13 changed files with 34 additions and 1 deletions

View File

@ -12,4 +12,8 @@
<ProjectReference Include="..\SDL3-CS.SourceGeneration\SDL3-CS.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/> <ProjectReference Include="..\SDL3-CS.SourceGeneration\SDL3-CS.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
</ItemGroup>
</Project> </Project>

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -59,6 +60,7 @@ namespace SDL
[Macro] [Macro]
public static int SDL_AUDIO_FRAMESIZE(SDL_AudioSpec x) => SDL_AUDIO_BYTESIZE((x).format) * (x).channels; public static int SDL_AUDIO_FRAMESIZE(SDL_AudioSpec x) => SDL_AUDIO_BYTESIZE((x).format) * (x).channels;
[MustDisposeResource]
public static unsafe SDLArray<SDL_AudioDeviceID>? SDL_GetAudioOutputDevices() public static unsafe SDLArray<SDL_AudioDeviceID>? SDL_GetAudioOutputDevices()
{ {
int count; int count;
@ -66,6 +68,7 @@ namespace SDL
return SDLArray.Create(array, count); return SDLArray.Create(array, count);
} }
[MustDisposeResource]
public static unsafe SDLArray<SDL_AudioDeviceID>? SDL_GetAudioCaptureDevices() public static unsafe SDLArray<SDL_AudioDeviceID>? SDL_GetAudioCaptureDevices()
{ {
int count; int count;

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -11,6 +12,7 @@ namespace SDL
/// <returns> /// <returns>
/// An array of <see cref="nint"/> that can be passed to <see cref="Marshal.PtrToStringUTF8(System.IntPtr)"/>. /// An array of <see cref="nint"/> that can be passed to <see cref="Marshal.PtrToStringUTF8(System.IntPtr)"/>.
/// </returns> /// </returns>
[MustDisposeResource]
public static unsafe SDLArray<IntPtr>? SDL_GetGamepadMappings() public static unsafe SDLArray<IntPtr>? SDL_GetGamepadMappings()
{ {
int count; int count;
@ -18,6 +20,7 @@ namespace SDL
return SDLArray.Create(array, count); return SDLArray.Create(array, count);
} }
[MustDisposeResource]
public static unsafe SDLArray<SDL_JoystickID>? SDL_GetGamepads() public static unsafe SDLArray<SDL_JoystickID>? SDL_GetGamepads()
{ {
int count; int count;
@ -25,6 +28,7 @@ namespace SDL
return SDLArray.Create(array, count); return SDLArray.Create(array, count);
} }
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_GamepadBinding>? SDL_GetGamepadBindings(SDL_Gamepad* gamepad) public static unsafe SDLPointerArray<SDL_GamepadBinding>? SDL_GetGamepadBindings(SDL_Gamepad* gamepad)
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -10,6 +11,7 @@ namespace SDL
public static partial class SDL3 public static partial class SDL3
{ {
[MustDisposeResource]
public static unsafe SDLArray<SDL_HapticID>? SDL_GetHaptics() public static unsafe SDLArray<SDL_HapticID>? SDL_GetHaptics()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -10,6 +11,7 @@ namespace SDL
public static partial class SDL3 public static partial class SDL3
{ {
[MustDisposeResource]
public static unsafe SDLArray<SDL_JoystickID>? SDL_GetJoysticks() public static unsafe SDLArray<SDL_JoystickID>? SDL_GetJoysticks()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -15,6 +16,7 @@ namespace SDL
public static partial class SDL3 public static partial class SDL3
{ {
[MustDisposeResource]
public static unsafe SDLArray<SDL_KeyboardID>? SDL_GetKeyboards() public static unsafe SDLArray<SDL_KeyboardID>? SDL_GetKeyboards()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -32,6 +33,7 @@ namespace SDL
[Macro] [Macro]
public static SDLButtonMask SDL_BUTTON(SDLButton button) => (SDLButtonMask)(1 << ((int)button - 1)); public static SDLButtonMask SDL_BUTTON(SDLButton button) => (SDLButtonMask)(1 << ((int)button - 1));
[MustDisposeResource]
public static unsafe SDLArray<SDL_MouseID>? SDL_GetMice() public static unsafe SDLArray<SDL_MouseID>? SDL_GetMice()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -34,6 +35,7 @@ namespace SDL
[Macro] [Macro]
public static SDL_PEN_CAPABILITIES SDL_PEN_AXIS_CAPABILITY(SDL_PenAxis axis) => SDL_PEN_CAPABILITY((int)axis + SDL_PEN_FLAG_AXIS_BIT_OFFSET); public static SDL_PEN_CAPABILITIES SDL_PEN_AXIS_CAPABILITY(SDL_PenAxis axis) => SDL_PEN_CAPABILITY((int)axis + SDL_PEN_FLAG_AXIS_BIT_OFFSET);
[MustDisposeResource]
public static unsafe SDLArray<SDL_PenID>? SDL_GetPens() public static unsafe SDLArray<SDL_PenID>? SDL_GetPens()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -10,6 +11,7 @@ namespace SDL
public static partial class SDL3 public static partial class SDL3
{ {
[MustDisposeResource]
public static unsafe SDLArray<SDL_SensorID>? SDL_GetSensors() public static unsafe SDLArray<SDL_SensorID>? SDL_GetSensors()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -19,6 +20,7 @@ namespace SDL
[Constant] [Constant]
public const SDL_TouchID SDL_MOUSE_TOUCHID = unchecked((SDL_TouchID)(-1)); public const SDL_TouchID SDL_MOUSE_TOUCHID = unchecked((SDL_TouchID)(-1));
[MustDisposeResource]
public static unsafe SDLArray<SDL_TouchID>? SDL_GetTouchDevices() public static unsafe SDLArray<SDL_TouchID>? SDL_GetTouchDevices()
{ {
int count; int count;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
@ -54,6 +55,7 @@ namespace SDL
[Macro] [Macro]
public static bool SDL_WINDOWPOS_ISCENTERED(int X) => (((X) & 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK); public static bool SDL_WINDOWPOS_ISCENTERED(int X) => (((X) & 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK);
[MustDisposeResource]
public static unsafe SDLArray<SDL_DisplayID>? SDL_GetDisplays() public static unsafe SDLArray<SDL_DisplayID>? SDL_GetDisplays()
{ {
int count; int count;
@ -61,6 +63,7 @@ namespace SDL
return SDLArray.Create(array, count); return SDLArray.Create(array, count);
} }
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_DisplayMode>? SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID) public static unsafe SDLPointerArray<SDL_DisplayMode>? SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID)
{ {
int count; int count;

View File

@ -2,9 +2,11 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
[MustDisposeResource]
public sealed unsafe class SDLArray<T> : IDisposable public sealed unsafe class SDLArray<T> : IDisposable
where T : unmanaged where T : unmanaged
{ {
@ -41,6 +43,7 @@ namespace SDL
internal static unsafe class SDLArray internal static unsafe class SDLArray
{ {
[MustDisposeResource]
internal static SDLArray<T>? Create<T>(T* array, int count) internal static SDLArray<T>? Create<T>(T* array, int count)
where T : unmanaged where T : unmanaged
{ {
@ -50,6 +53,7 @@ namespace SDL
return new SDLArray<T>(array, count); return new SDLArray<T>(array, count);
} }
[MustDisposeResource]
internal static SDLPointerArray<T>? Create<T>(T** array, int count) internal static SDLPointerArray<T>? Create<T>(T** array, int count)
where T : unmanaged where T : unmanaged
{ {
@ -58,6 +62,5 @@ namespace SDL
return new SDLPointerArray<T>(array, count); return new SDLPointerArray<T>(array, count);
} }
} }
} }

View File

@ -3,10 +3,12 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations;
namespace SDL namespace SDL
{ {
// T* can't be used as a type parameter, so this has to be a separate class // T* can't be used as a type parameter, so this has to be a separate class
[MustDisposeResource]
public sealed unsafe class SDLPointerArray<T> : IDisposable public sealed unsafe class SDLPointerArray<T> : IDisposable
where T : unmanaged where T : unmanaged
{ {