Files
osu-framework/osu.Framework/Platform/Apple/Native/NSMutableData.cs
Salman Alshamrani e54bb466b1 Remove incorrect exposure of manual release methods
`NSData`/`NSMutableData` provide constructors which internally mark them for auto-release pool.

New obj-c rule of thumb: If an object is created and auto-released, releasing them manually still keeps them in the pool, and the pool will still try to release the object despite being released already, and end up causing a segmentation fault error. Any object created with a convenient constructor is marked as auto-released (see https://stackoverflow.com/a/24807570), and therefore methods to manually release them should NOT be exposed.
2025-01-17 02:17:53 -05:00

30 lines
996 B
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
namespace osu.Framework.Platform.Apple.Native
{
internal readonly struct NSMutableData
{
internal IntPtr Handle { get; }
private static readonly IntPtr class_pointer = Class.Get("NSMutableData");
private static readonly IntPtr sel_data_with_length = Selector.Get("dataWithLength:");
private static readonly IntPtr sel_mutable_bytes = Selector.Get("mutableBytes");
internal NSMutableData(IntPtr handle)
{
Handle = handle;
}
internal unsafe byte* MutableBytes => (byte*)Interop.SendIntPtr(Handle, sel_mutable_bytes);
internal static NSMutableData FromLength(int length)
{
IntPtr handle = Interop.SendIntPtr(class_pointer, sel_data_with_length, length);
return new NSMutableData(handle);
}
}
}