Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/CoreFoundation/CFAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static CFAllocator MallocZone {
}
}

// Internal only: to get the null handle, use 'CFAllocator.null_ptr' instead.
/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
Expand Down
4 changes: 2 additions & 2 deletions src/CoreMedia/CMBlockBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public bool IsEmpty {

public static CMBlockBuffer? FromMemoryBlock (IntPtr memoryBlock, nuint blockLength, CMCustomBlockAllocator? customBlockSource, nuint offsetToData, nuint dataLength, CMBlockBufferFlags flags, out CMBlockBufferError error)
{
var blockAllocator = memoryBlock == IntPtr.Zero ? NativeHandle.Zero : CFAllocator.Null.Handle;
var blockAllocator = memoryBlock == IntPtr.Zero ? NativeHandle.Zero : (NativeHandle) CFAllocator.null_ptr;
IntPtr buffer;
unsafe {
if (customBlockSource is null) {
Expand Down Expand Up @@ -339,7 +339,7 @@ public bool IsEmpty {

public CMBlockBufferError AppendMemoryBlock (IntPtr memoryBlock, nuint blockLength, CMCustomBlockAllocator customBlockSource, nuint offsetToData, nuint dataLength, CMBlockBufferFlags flags)
{
var blockAllocator = memoryBlock == IntPtr.Zero ? NativeHandle.Zero : CFAllocator.Null.Handle;
var blockAllocator = memoryBlock == IntPtr.Zero ? NativeHandle.Zero : (NativeHandle) CFAllocator.null_ptr;
unsafe {
if (customBlockSource is null) {
return CMBlockBufferAppendMemoryBlock (GetCheckedHandle (), memoryBlock, blockLength, blockAllocator, null, offsetToData, dataLength, flags);
Expand Down
6 changes: 3 additions & 3 deletions src/Foundation/NSArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static NSArray FromNativeObjectsImpl<T> (T? []? items, nint count, bool allowNul
throw new ArgumentNullException ($"{nameof (items)}[{i}]");
// The analyzer cannot deal with arrays, we manually keep alive the whole array below
#pragma warning disable RBI0014
IntPtr h = item is null ? NSNull.Null.Handle : item.Handle;
IntPtr h = item is null ? NSNull.NullHandle : item.Handle;
handles [i] = h;
#pragma warning restore RBI0014
}
Expand Down Expand Up @@ -672,7 +672,7 @@ static T UnsafeGetItem<T> (NativeHandle handle, nuint index) where T : class, IN
// A native code could return NSArray with NSNull.Null elements
// and they should be valid for things like T : NSDate so we handle
// them as just null values inside the array
if (val == NSNull.Null.Handle)
if (val == NSNull.NullHandle)
return null;

return Runtime.GetINativeObject<T> (val, false);
Expand All @@ -684,7 +684,7 @@ static object UnsafeGetItem (NativeHandle handle, nuint index, Type type)
// A native code could return NSArray with NSNull.Null elements
// and they should be valid for things like T : NSDate so we handle
// them as just null values inside the array
if (val == NSNull.Null.Handle)
if (val == NSNull.NullHandle)
return null;

return Runtime.GetINativeObject (val, false, type);
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/NSArray_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static public NSArray<TKey> FromNSObjects (int count, params TKey [] items)
var item = items [i];
// The analyzer cannot deal with arrays, we manually keep alive the whole array below
#pragma warning disable RBI0014
IntPtr h = item is null ? NSNull.Null.Handle : item.Handle;
IntPtr h = item is null ? NSNull.NullHandle : item.Handle;
Marshal.WriteIntPtr (buf, (int) (i * IntPtr.Size), h);
#pragma warning restore RBI0014
}
Expand Down
9 changes: 9 additions & 0 deletions src/Foundation/NSNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,14 @@ static public NSNull Null {
return _null;
}
}

static IntPtr nullHandle;
internal static IntPtr NullHandle {
get {
if (nullHandle == IntPtr.Zero)
nullHandle = _NullHandle;
return nullHandle;
}
}
}
}
2 changes: 1 addition & 1 deletion src/ObjCRuntime/BindAs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ unsafe static IntPtr ConvertManagedArrayToNSArray2<T, U> (T []? array, delegate*
for (nint i = 0; i < count; i++) {
var item = convert2 (convert1 (array [i]));
if (item == IntPtr.Zero)
item = NSNull.Null.Handle;
item = NSNull.NullHandle;
ptrs [i] = item;
}
fixed (void* ptr = ptrs) {
Expand Down
2 changes: 1 addition & 1 deletion src/SceneKit/SCNSkinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static NSArray ToNSArray (SCNMatrix4 []? items)

for (nint i = 0; i < count; i++) {
var item = NSValue.FromSCNMatrix4 (items [i]);
var h = item?.Handle ?? NSNull.Null.Handle;
var h = item?.Handle ?? NSNull.NullHandle;
Marshal.WriteIntPtr (buf, (int) (i * IntPtr.Size), h);
}

Expand Down
4 changes: 4 additions & 0 deletions src/foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6682,6 +6682,10 @@ interface NSNull : NSSecureCoding, NSCopying
[Export ("null"), Static]
[Internal]
NSNull _Null { get; }

[Export ("null"), Static]
[Internal]
IntPtr _NullHandle { get; }
}

[MacCatalyst (13, 1)]
Expand Down
4 changes: 0 additions & 4 deletions tests/cecil-tests/HandleSafety.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public partial class HandleSafetyTest {
"CoreImage.CIAutoAdjustmentFilterOptions.ToDictionary ()",
"CoreImage.CIImage.FromCGImage (CoreGraphics.CGImage, CoreGraphics.CGColorSpace)",
"CoreImage.CISamplerOptions.ToDictionary ()",
"CoreMedia.CMBlockBuffer.AppendMemoryBlock (System.IntPtr, System.UIntPtr, CoreMedia.CMCustomBlockAllocator, System.UIntPtr, System.UIntPtr, CoreMedia.CMBlockBufferFlags)",
"CoreMedia.CMBlockBuffer.FromMemoryBlock (System.IntPtr, System.UIntPtr, CoreMedia.CMCustomBlockAllocator, System.UIntPtr, System.UIntPtr, CoreMedia.CMBlockBufferFlags, CoreMedia.CMBlockBufferError&)",
"CoreMidi.MidiCIDeviceInfo..ctor (CoreMidi.MidiEndpoint, Foundation.NSData, Foundation.NSData, Foundation.NSData, Foundation.NSData)",
"CoreMidi.MidiDevice.Add (System.String, System.Boolean, System.UIntPtr, System.UIntPtr, CoreMidi.MidiEntity)",
"CoreMidi.MidiDeviceList.Add (CoreMidi.MidiDevice)",
Expand Down Expand Up @@ -107,8 +105,6 @@ public partial class HandleSafetyTest {
"Foundation.DictionaryContainerHelper.GetHandle (Foundation.DictionaryContainer)",
"Foundation.NSArray.FromNativeObjectsImpl`1 (T[], System.IntPtr, System.Boolean)",
"Foundation.NSArray.FromNSObjects (System.Collections.Generic.IList`1<Foundation.NSObject>)",
"Foundation.NSArray.UnsafeGetItem (ObjCRuntime.NativeHandle, System.UIntPtr, System.Type)",
"Foundation.NSArray.UnsafeGetItem`1 (ObjCRuntime.NativeHandle, System.UIntPtr)",
"Foundation.NSArray`1.FromNSObjects`0 (System.Int32, TKey[])",
"Foundation.NSDecimal.ToString ()",
"Foundation.NSFastEnumerator`1.Fetch ()",
Expand Down
Loading