Merge xcode14.1 into net7.0-xcode14.1.

This commit is contained in:
Rolf Bjarne Kvinge 2022-11-02 19:03:30 +01:00
Родитель 988bf9b4ba 0304f2bca1
Коммит 940e1d09e9
5 изменённых файлов: 55 добавлений и 31 удалений

Просмотреть файл

@ -211,8 +211,8 @@ MACCATALYST_NUGET_VERSION_FULL=$(MACCATALYST_NUGET_VERSION_NO_METADATA)+$(NUGET_
# Xcode version should have both a major and a minor version (even if the minor version is 0)
XCODE_VERSION=14.1
XCODE_URL=https://dl.internalx.com/internal-files/xcodes/Xcode_14.1_Release_candidate_2.xip
XCODE_DEVELOPER_ROOT=/Applications/Xcode_14.1.0-rc.2.app/Contents/Developer
XCODE_URL=https://dl.internalx.com/internal-files/xcodes/Xcode_14.1.xip
XCODE_DEVELOPER_ROOT=/Applications/Xcode_14.1.0.app/Contents/Developer
XCODE_PRODUCT_BUILD_VERSION:=$(shell /usr/libexec/PlistBuddy -c 'Print :ProductBuildVersion' $(XCODE_DEVELOPER_ROOT)/../version.plist 2>/dev/null || echo " $(shell tput setaf 1 2>/dev/null)The required Xcode ($(XCODE_VERSION)) is not installed in $(basename $(basename $(XCODE_DEVELOPER_ROOT)))$(shell tput sgr0 2>/dev/null)" >&2)
# Tell both Xcode and our build logic which Xcode we're using.

Просмотреть файл

@ -71,9 +71,16 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved.
<Target Name="_CompileToNative" DependsOnTargets="$(_CompileToNativeDependsOn)"
Inputs="$(_NativeWatchApp)"
Outputs="$(_NativeExecutable);$(_AppBundlePath)_WatchKitStub\WK">
<PropertyGroup Condition="'$(_SdkIsSimulator)' != 'true'">
<!-- Remove any arm64e slices when building for device -->
<WKDittoArchitectures Condition="'$(WKDittoArchitectures)' == ''">--arch arm64_32 --arch arm64 --arch armv7k</WKDittoArchitectures>
</PropertyGroup>
<Ditto
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)'"
AdditionalArguments="$(WKDittoArchitectures)"
ToolExe="$(DittoExe)"
ToolPath="$(DittoPath)"
Source="$(_NativeWatchApp)"
@ -85,6 +92,7 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved.
<Ditto
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)'"
AdditionalArguments="$(WKDittoArchitectures)"
ToolExe="$(DittoExe)"
ToolPath="$(DittoPath)"
Source="$(_NativeWatchApp)"

Просмотреть файл

@ -1437,38 +1437,36 @@ namespace ObjCRuntime {
return null;
var obj = TryGetNSObject (ptr, evenInFinalizerQueue: false);
T? o;
if (obj is null) {
// Try to get the managed type that correspond to this exact native type
IntPtr p = Class.GetClassForObject (ptr);
// If unknown then we'll get the Class that Lookup to NSObject even if this is not NSObject.
// We can use this condition to fallback on the provided (generic argument) type
Type target_type;
if (p != NSObjectClass) {
target_type = Class.Lookup (p);
if (target_type == typeof(NSObject))
target_type = typeof(T);
else if (typeof (T).IsGenericType)
target_type = typeof(T);
else if (target_type.IsSubclassOf (typeof(T))) {
// do nothing, this is fine.
} else if (Messaging.bool_objc_msgSend_IntPtr (ptr, Selector.GetHandle ("isKindOfClass:"), Class.GetHandle (typeof (T)))) {
// If the instance itself claims it's an instance of the provided (generic argument) type,
// then we believe the instance. See bug #20692 for a test case.
target_type = typeof(T);
}
} else {
target_type = typeof(NSObject);
// First check if we got an object of the expected type
if (obj is T o)
return o;
// We either didn't find an object, or it was of the wrong type, so we need to create a new instance.
// Try to get the managed type that correspond to this exact native type
IntPtr p = Class.GetClassForObject (ptr);
// If unknown then we'll get the Class that Lookup to NSObject even if this is not NSObject.
// We can use this condition to fallback on the provided (generic argument) type
Type target_type;
if (p != NSObjectClass) {
target_type = Class.Lookup (p);
if (target_type == typeof(NSObject))
target_type = typeof(T);
else if (typeof (T).IsGenericType)
target_type = typeof(T);
else if (target_type.IsSubclassOf (typeof(T))) {
// do nothing, this is fine.
} else if (Messaging.bool_objc_msgSend_IntPtr (ptr, Selector.GetHandle ("isKindOfClass:"), Class.GetHandle (typeof (T)))) {
// If the instance itself claims it's an instance of the provided (generic argument) type,
// then we believe the instance. See bug #20692 for a test case.
target_type = typeof(T);
}
o = ConstructNSObject<T> (ptr, target_type, MissingCtorResolution.ThrowConstructor1NotFound);
} else {
o = obj as T;
if (o is null)
throw new InvalidCastException ($"Unable to cast object of type '{obj.GetType ().FullName}' to type '{typeof(T).FullName}'.");
target_type = typeof(NSObject);
}
return o;
return ConstructNSObject<T> (ptr, target_type, MissingCtorResolution.ThrowConstructor1NotFound);
}
static public T? GetNSObject<T> (IntPtr ptr, bool owns) where T : NSObject

Просмотреть файл

@ -2172,8 +2172,9 @@ namespace MonoTouchFixtures.ObjCRuntime {
// sure this is by design or by accident, but that's how we're behaving right now at least
ptr = Messaging.IntPtr_objc_msgSend (Class.GetHandle (typeof (D2)), Selector.GetHandle ("alloc"));
ptr = Messaging.IntPtr_objc_msgSend_long (ptr, Selector.GetHandle ("initWithBar:"), 2);
// Unable to cast object of type 'AppDelegate+D1' to type 'AppDelegate+D2'
Assert.Throws<InvalidCastException> (() => Runtime.GetNSObject<D2> (ptr), "b ex");
// Failed to marshal the Objective-C object 0x60000230a410 (type: MonoTouchFixtures_ObjCRuntime_RegistrarTest_D2). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'MonoTouchFixtures.ObjCRuntime.RegistrarTest+D2' does not have a constructor that takes one NativeHandle argument
var ex = Assert.Throws<RuntimeException> (() => Runtime.GetNSObject<D2> (ptr), "b ex");
Assert.That (ex.Message, Does.Contain ("Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'MonoTouchFixtures.ObjCRuntime.RegistrarTest+D2' does not have a constructor that takes one"), "Exception message");
var obj = Runtime.GetNSObject<D1> (ptr);
Assert.AreEqual ("bar", obj.ctor1, "b ctor1");
} finally {

Просмотреть файл

@ -141,6 +141,23 @@ namespace MonoTouchFixtures.ObjCRuntime {
}
}
[Test]
public void GetNSObject_T_SameHandleDifferentInstances ()
{
using var a = new NSDictionary<NSString, NSObject> ();
using var b = new NSDictionary<NSString, NSString> ();
using var c = new NSDictionary ();
if (a.Handle != b.Handle || a.Handle != c.Handle)
Assert.Ignore ("The dictionaries are actually different");
var handle = a.Handle;
Assert.DoesNotThrow (() => Runtime.GetNSObject<NSDictionary> (handle), "A");
Assert.DoesNotThrow (() => Runtime.GetNSObject<NSDictionary<NSString, NSObject>> (handle), "B");
Assert.DoesNotThrow (() => Runtime.GetNSObject<NSDictionary<NSString, NSString>> (handle), "C");
}
[Test]
public void UsableUntilDead ()
{