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

[metal] Add nullability to (generated and manual) bindings #15162

Merged
merged 2 commits into from
Jun 2, 2022
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
4 changes: 2 additions & 2 deletions src/Metal/MTLCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IMTLCounterSet[] GetIMTLCounterSets (this IMTLDevice This)
[BindingImpl (BindingImplOptions.Optimizable)]
public static IMTLCounterSampleBuffer? CreateIMTLCounterSampleBuffer (this IMTLDevice This, MTLCounterSampleBufferDescriptor descriptor, out NSError? error)
{
if (descriptor == null)
if (descriptor is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptor));
var errorValue = NativeHandle.Zero;

Expand All @@ -46,7 +46,7 @@ public static partial class MTLComputeCommandEncoder_Extensions {
[BindingImpl (BindingImplOptions.Optimizable)]
public static void SampleCounters (this IMTLComputeCommandEncoder This, IMTLCounterSampleBuffer sampleBuffer, nuint sampleIndex, bool barrier)
{
if (sampleBuffer == null)
if (sampleBuffer is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (sampleBuffer));
global::ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_UIntPtr_bool (This.Handle, Selector.GetHandle ("sampleCountersInBuffer:atSampleIndex:withBarrier:"), sampleBuffer.Handle, (UIntPtr) sampleIndex, barrier);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Metal/MTLDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static IMTLDevice? SystemDefault {
get {
// Metal could be unavailable on the hardware (and we don't want to return an invalid instance)
// also the instance could be disposed (by mistake) which would make the app unusable
if ((system_default == null) || (system_default.Handle == IntPtr.Zero)) {
if ((system_default is null) || (system_default.Handle == IntPtr.Zero)) {
try {
var h = MTLCreateSystemDefaultDevice ();
if (h != IntPtr.Zero)
Expand Down Expand Up @@ -149,7 +149,7 @@ public static unsafe void TrampolineNotificationHandler (IntPtr block, IntPtr de
{
var descriptor = (BlockLiteral*) block;
var del = (MTLDeviceNotificationHandler) (descriptor->Target);
if (del != null)
if (del is not null)
del ((IMTLDevice) Runtime.GetNSObject (device)!, (Foundation.NSString) Runtime.GetNSObject (notifyName)!);
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public static unsafe void TrampolineNotificationHandler (IntPtr block, IntPtr de
#endif
public static void RemoveObserver (NSObject observer)
{
if (observer == null)
if (observer is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (observer));

MTLRemoveDeviceObserver (observer.Handle);
Expand All @@ -194,7 +194,7 @@ public static void RemoveObserver (NSObject observer)
public static partial class MTLDevice_Extensions {
public static IMTLBuffer? CreateBuffer<T> (this IMTLDevice This, T [] data, MTLResourceOptions options) where T : struct
{
if (data == null)
if (data is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));

var handle = GCHandle.Alloc (data, GCHandleType.Pinned); // This requires a pinned GCHandle, since it's not possible to use unsafe code to get the address of a generic object.
Expand All @@ -210,7 +210,7 @@ public static partial class MTLDevice_Extensions {
[Obsolete ("Use the overload that takes an IntPtr instead. The 'data' parameter must be page-aligned and allocated using vm_allocate or mmap, which won't be the case for managed arrays, so this method will always fail.")]
public static IMTLBuffer? CreateBufferNoCopy<T> (this IMTLDevice This, T [] data, MTLResourceOptions options, MTLDeallocator deallocator) where T : struct
{
if (data == null)
if (data is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));

var handle = GCHandle.Alloc (data, GCHandleType.Pinned); // This requires a pinned GCHandle, since it's not possible to use unsafe code to get the address of a generic object.
Expand All @@ -224,7 +224,7 @@ public static partial class MTLDevice_Extensions {

public unsafe static void GetDefaultSamplePositions (this IMTLDevice This, MTLSamplePosition [] positions, nuint count)
{
if (positions == null)
if (positions is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (positions));

if (positions.Length < (nint)count)
Expand All @@ -250,9 +250,9 @@ public unsafe static void GetDefaultSamplePositions (this IMTLDevice This, MTLSa
#endif
public static void ConvertSparseTileRegions (this IMTLDevice This, MTLRegion [] tileRegions, MTLRegion [] pixelRegions, MTLSize tileSize, nuint numRegions)
{
if (tileRegions == null)
if (tileRegions is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (tileRegions));
if (pixelRegions == null)
if (pixelRegions is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (pixelRegions));

var tileRegionsHandle = GCHandle.Alloc (tileRegions, GCHandleType.Pinned);
Expand All @@ -279,9 +279,9 @@ public static void ConvertSparseTileRegions (this IMTLDevice This, MTLRegion []
#endif
public static void ConvertSparsePixelRegions (this IMTLDevice This, MTLRegion [] pixelRegions, MTLRegion [] tileRegions, MTLSize tileSize, MTLSparseTextureRegionAlignmentMode mode, nuint numRegions)
{
if (tileRegions == null)
if (tileRegions is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (tileRegions));
if (pixelRegions == null)
if (pixelRegions is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (pixelRegions));

var tileRegionsHandle = GCHandle.Alloc (tileRegions, GCHandleType.Pinned);
Expand Down
4 changes: 2 additions & 2 deletions src/Metal/MTLIntersectionFunctionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public static class MTLIntersectionFunctionTableExtensions {
#endif
public static void SetBuffers (this IMTLIntersectionFunctionTable table, IMTLBuffer[] buffers, nuint[] offsets, NSRange range)
{
if (buffers == null)
if (buffers is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffers));
if (offsets == null)
if (offsets is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (offsets));

var bufferPtrArray = buffers.Length <= 1024 ? stackalloc IntPtr[buffers.Length] : new IntPtr [buffers.Length];
Expand Down
4 changes: 2 additions & 2 deletions src/Metal/MTLRasterizationRateLayerDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public double[] VerticalSampleStorage {
#endif
static public MTLRasterizationRateLayerDescriptor Create (MTLSize sampleCount, float[] horizontal, float[] vertical)
{
if (horizontal == null)
if (horizontal is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (horizontal));
if (vertical == null)
if (vertical is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (vertical));
if (sampleCount.Width != horizontal.Length)
throw new ArgumentOutOfRangeException ("Horizontal length should be equal to the sampleCount.Width.");
Expand Down
8 changes: 4 additions & 4 deletions src/Metal/MTLResourceStateCommandEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public static partial class MTLResourceStateCommandEncoder_Extensions {
#endif
public static void Update (this IMTLResourceStateCommandEncoder This, IMTLTexture texture, MTLSparseTextureMappingMode mode, MTLRegion[] regions, nuint[] mipLevels, nuint[] slices)
{
if (texture == null)
if (texture is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (texture));
if (regions == null)
if (regions is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (regions));
if (mipLevels == null)
if (mipLevels is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (mipLevels));
if (slices == null)
if (slices is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (slices));

var regionsHandle = GCHandle.Alloc (regions, GCHandleType.Pinned);
Expand Down
4 changes: 2 additions & 2 deletions src/Metal/MTLVertexDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial class MTLVertexDescriptor {
#endif
public static MTLVertexDescriptor? FromModelIO (MDLVertexDescriptor descriptor)
{
if (descriptor == null)
if (descriptor is null)
throw new ArgumentException ("descriptor");
return Runtime.GetNSObject<MTLVertexDescriptor> (MTKMetalVertexDescriptorFromModelIO (descriptor.Handle));
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public partial class MTLVertexDescriptor {
#endif
public static MTLVertexDescriptor? FromModelIO (MDLVertexDescriptor descriptor, out NSError? error)
{
if (descriptor == null)
if (descriptor is null)
throw new ArgumentException ("descriptor");
IntPtr err;
var vd = Runtime.GetNSObject<MTLVertexDescriptor> (MTKMetalVertexDescriptorFromModelIOWithError (descriptor.Handle, out err));
Expand Down