Skip to content

Commit

Permalink
Merge branch 'main' into Nullable-WebKit
Browse files Browse the repository at this point in the history
  • Loading branch information
tj-devel709 authored Jun 15, 2022
2 parents 9440e6c + 3e6fdd8 commit b0a178e
Show file tree
Hide file tree
Showing 25 changed files with 490 additions and 377 deletions.
8 changes: 7 additions & 1 deletion msbuild/Xamarin.MacDev.Tasks.Core/Tasks/DSymUtilTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ void ExecuteDSymUtil (ITaskItem item, List<ITaskItem> contentFiles)
args.Add ("dsymutil");
args.Add ("-num-threads");
args.Add ("4");
args.Add ("-z");
if (AppleSdkSettings.XcodeVersion < new Version (13, 3)) {
// Apple removed the -z / --minimize option in Xocde 13.3, so now if you use it you get a warning: "ignoring unknown option: -z"
// So just don't pass -z when Xcode >= 13.3
// Ref: https://github.com/llvm/llvm-project/commit/5d07dc897707f877c45cab6c7e4b65dad7d3ff6d
// Ref: https://github.com/dotnet/runtime/issues/66770
args.Add ("-z");
}
args.Add ("-o");
args.Add (dSymDir);

Expand Down
92 changes: 64 additions & 28 deletions src/CoreText/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -62,72 +64,88 @@ public static void AssertWritable (NSDictionary dictionary)
: b;
}

public static int? GetInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static int? GetInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).Int32Value;
}

public static nuint? GetUnsignedIntegerValue (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static nuint? GetUnsignedIntegerValue (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).NUIntValue;
}

public static T[] GetNativeArray<T> (NSDictionary dictionary, NSObject key, Converter<NativeHandle, T> converter)
public static T[]? GetNativeArray<T> (NSDictionary dictionary, NSObject? key, Converter<NativeHandle, T> converter)
{
if (key is null)
return null;
var cfArrayRef = CFDictionary.GetValue (dictionary.Handle, key.Handle);
if (cfArrayRef == NativeHandle.Zero || CFArray.GetCount (cfArrayRef) == 0)
return new T [0];
return NSArray.ArrayFromHandle (cfArrayRef, converter);
}

public static float? GetSingleValue (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static float? GetSingleValue (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).FloatValue;
}

public static string[] GetStringArray (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static string[]? GetStringArray (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return Array.Empty<string> ();
return CFArray.StringArrayFromHandle (value.Handle);
return CFArray.StringArrayFromHandle (value.Handle)!;
}

public static string GetStringValue (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static string? GetStringValue (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSString) value).ToString ();
}

public static uint? GetUInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static uint? GetUInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).UInt32Value;
}

public static bool? GetBoolValue (NSDictionary dictionary, NSObject key)
{
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).BoolValue;
}

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, int? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
Expand All @@ -136,6 +154,8 @@ public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObjec

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, float? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
Expand All @@ -144,6 +164,8 @@ public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObjec

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, uint? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
Expand All @@ -152,6 +174,8 @@ public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObjec

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, bool? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
Expand All @@ -160,45 +184,55 @@ public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObjec

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, nuint? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
dictionary.Remove (key);
}

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, IEnumerable<string> value)
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, IEnumerable<string>? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
List<string> v;
if (value == null || (v = new List<string>(value)).Count == 0)
SetValue (dictionary, key, (NSObject) null);
if (value is null || (v = new List<string>(value)).Count == 0)
SetValue (dictionary, key, (NSObject?) null);
else
using (var array = NSArray.FromStrings (v.ToArray ()))
SetValue (dictionary, key, array);
}

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, NSObject value)
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, NSObject? value)
{
if (value != null)
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value is not null)
dictionary [key] = value;
else
dictionary.Remove (key);
}

public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, string value)
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, string? value)
{
if (value == null)
SetValue (dictionary, key, (NSObject) null);
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value is null)
SetValue (dictionary, key, (NSObject?) null);
else
using (var s = new NSString (value))
SetValue (dictionary, key, (NSObject) s);
}

public static void SetNativeValue<T> (NSDictionary dictionary, NSObject key, IEnumerable<T> value)
public static void SetNativeValue<T> (NSDictionary dictionary, NSObject key, IEnumerable<T>? value)
where T : INativeObject
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
List<NativeHandle> v;
if (value == null || (v = GetHandles (value)).Count == 0)
SetNativeValue (dictionary, key, (INativeObject) null);
if (value is null || (v = GetHandles (value)).Count == 0)
SetNativeValue (dictionary, key, (INativeObject?) null);
else
using (var array = CFArray.FromIntPtrs (v.ToArray ()))
SetNativeValue (dictionary, key, array);
Expand All @@ -213,9 +247,11 @@ static List<NativeHandle> GetHandles<T> (IEnumerable<T> value)
return v;
}

public static void SetNativeValue (NSDictionary dictionary, NSObject key, INativeObject value)
public static void SetNativeValue (NSDictionary dictionary, NSObject key, INativeObject? value)
{
if (value != null) {
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value is not null) {
AssertWritable (dictionary);
CFMutableDictionary.SetValue (dictionary.Handle, key.Handle, value.Handle);
}
Expand Down
35 changes: 19 additions & 16 deletions src/CoreText/CTBaselineClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

using System;

using ObjCRuntime;
Expand All @@ -44,12 +47,12 @@ public enum CTBaselineClass {

static partial class CTBaselineClassID {
#if !NET
public static readonly NSString Roman;
public static readonly NSString IdeographicCentered;
public static readonly NSString IdeographicLow;
public static readonly NSString IdeographicHigh;
public static readonly NSString Hanging;
public static readonly NSString Math;
public static readonly NSString? Roman;
public static readonly NSString? IdeographicCentered;
public static readonly NSString? IdeographicLow;
public static readonly NSString? IdeographicHigh;
public static readonly NSString? Hanging;
public static readonly NSString? Math;

static CTBaselineClassID ()
{
Expand All @@ -63,7 +66,7 @@ static CTBaselineClassID ()
}
#endif

public static NSString ToNSString (CTBaselineClass key)
public static NSString? ToNSString (CTBaselineClass key)
{
switch (key) {
case CTBaselineClass.Roman: return Roman;
Expand All @@ -79,12 +82,12 @@ public static NSString ToNSString (CTBaselineClass key)

public static CTBaselineClass FromHandle (IntPtr handle)
{
if (handle == Roman.Handle) return CTBaselineClass.Roman;
if (handle == IdeographicCentered.Handle) return CTBaselineClass.IdeographicCentered;
if (handle == IdeographicLow.Handle) return CTBaselineClass.IdeographicLow;
if (handle == IdeographicHigh.Handle) return CTBaselineClass.IdeographicHigh;
if (handle == Hanging.Handle) return CTBaselineClass.Hanging;
if (handle == Math.Handle) return CTBaselineClass.Math;
if (handle == Roman?.Handle) return CTBaselineClass.Roman;
if (handle == IdeographicCentered?.Handle) return CTBaselineClass.IdeographicCentered;
if (handle == IdeographicLow?.Handle) return CTBaselineClass.IdeographicLow;
if (handle == IdeographicHigh?.Handle) return CTBaselineClass.IdeographicHigh;
if (handle == Hanging?.Handle) return CTBaselineClass.Hanging;
if (handle == Math?.Handle) return CTBaselineClass.Math;

throw new ArgumentOutOfRangeException ("handle");
}
Expand All @@ -98,8 +101,8 @@ public enum CTBaselineFont {

static partial class CTBaselineFontID {
#if !NET
public static readonly NSString Reference;
public static readonly NSString Original;
public static readonly NSString? Reference;
public static readonly NSString? Original;

static CTBaselineFontID ()
{
Expand All @@ -109,7 +112,7 @@ static CTBaselineFontID ()
}
#endif // !NET

public static NSString ToNSString (CTBaselineFont key)
public static NSString? ToNSString (CTBaselineFont key)
{
switch (key) {
case CTBaselineFont.Reference: return Reference;
Expand Down
2 changes: 2 additions & 0 deletions src/CoreText/CTFont.Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

using CoreFoundation;

namespace CoreText {
Expand Down
Loading

0 comments on commit b0a178e

Please sign in to comment.