diff --git a/src/spritekit.cs b/src/spritekit.cs index f25a70eaba98..b6ae1313febd 100644 --- a/src/spritekit.cs +++ b/src/spritekit.cs @@ -2529,7 +2529,11 @@ partial interface SKAction : NSSecureCoding, NSCopying { SKAction FollowPath (CGPath path, double sec); [Static, Export ("followPath:asOffset:orientToPath:duration:")] +#if XAMCORE_5_0 SKAction FollowPath (CGPath path, bool offset, bool orientToPath, double sec); +#else + SKAction FollowPath (CGPath path, bool offset, bool orient, double sec); +#endif [iOS (8, 0), Mac (10, 10)] // this method is missing the NS_AVAILABLE macro, but it shows up in the 10.10 sdk, but not the 10.9 sdk. [MacCatalyst (13, 1)] @@ -2539,7 +2543,11 @@ partial interface SKAction : NSSecureCoding, NSCopying { [iOS (8, 0), Mac (10, 10)] // this method is missing the NS_AVAILABLE macro, but it shows up in the 10.10 sdk, but not the 10.9 sdk. [MacCatalyst (13, 1)] [Static, Export ("followPath:asOffset:orientToPath:speed:")] +#if XAMCORE_5_0 SKAction FollowPath (CGPath path, bool offset, bool orientToPath, nfloat speed); +#else + SKAction FollowPath (CGPath path, bool offset, bool orient, nfloat speed); +#endif [Static, Export ("speedBy:duration:")] SKAction SpeedBy (nfloat speed, double sec); diff --git a/tests/common/DotNet.cs b/tests/common/DotNet.cs index 5f1a7698ad5c..2db45a36696b 100644 --- a/tests/common/DotNet.cs +++ b/tests/common/DotNet.cs @@ -181,6 +181,21 @@ public static ExecutionResult Execute (string verb, string project, Dictionary csTypeToFieldDef = new Dictionary (); IEnumerable assemblies; AssemblyDefinition xamarinAssembly; @@ -328,11 +327,6 @@ IEnumerable AllTypes (TypeDefinition type) } } - string ToOutputFileName (string pathToInputFileName) - { - return Path.Combine (outputDirectory, Path.GetFileName (pathToInputFileName)); - } - void MarkForSave (AssemblyDefinition assembly) { var annotations = linkContext.Annotations; diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index 6ce1973a8d9c..b937abd8df6f 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -3309,6 +3309,12 @@ void Specialize (AutoIndentStringBuilder sb, out string initialization_method) bool HasIntPtrBoolCtor (TypeDefinition type, List exceptions) { + return HasIntPtrBoolCtor (type, exceptions, out var _); + } + + bool HasIntPtrBoolCtor (TypeDefinition type, List exceptions, [NotNullWhen (true)] out MethodDefinition? ctor) + { + ctor = null; if (!type.HasMethods) return false; foreach (var method in type.Methods) { @@ -3330,6 +3336,7 @@ bool HasIntPtrBoolCtor (TypeDefinition type, List exceptions) if (!method.Parameters [0].ParameterType.Is ("System", "IntPtr")) continue; } + ctor = method; return true; } return false; @@ -4528,6 +4535,11 @@ void GenerateCallToSuperForConstructor (AutoIndentStringBuilder sb, ObjCMethod m } public TypeDefinition GetInstantiableType (TypeDefinition td, List exceptions, string descriptiveMethodName) + { + return GetInstantiableType (td, exceptions, descriptiveMethodName, out var _); + } + + public TypeDefinition GetInstantiableType (TypeDefinition td, List exceptions, string descriptiveMethodName, out MethodDefinition ctor) { TypeDefinition nativeObjType = td; @@ -4540,7 +4552,7 @@ public TypeDefinition GetInstantiableType (TypeDefinition td, List ex } // verify that the type has a ctor with two parameters - if (!HasIntPtrBoolCtor (nativeObjType, exceptions)) + if (!HasIntPtrBoolCtor (nativeObjType, exceptions, out ctor)) throw ErrorHelper.CreateError (4103, Errors.MT4103, nativeObjType.FullName, descriptiveMethodName); return nativeObjType; diff --git a/tools/create-dotnet-linker-launch-json/create-dotnet-linker-launch-json.csproj b/tools/create-dotnet-linker-launch-json/create-dotnet-linker-launch-json.csproj index 7a25f66db1fa..fdbbca182f1b 100644 --- a/tools/create-dotnet-linker-launch-json/create-dotnet-linker-launch-json.csproj +++ b/tools/create-dotnet-linker-launch-json/create-dotnet-linker-launch-json.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net$(BundledNETCoreAppTargetFrameworkVersion) create_dotnet_linker_launch_json enable enable diff --git a/tools/dotnet-linker/AppBundleRewriter.cs b/tools/dotnet-linker/AppBundleRewriter.cs index 92f6384e547b..ae5ad1e0ad1a 100644 --- a/tools/dotnet-linker/AppBundleRewriter.cs +++ b/tools/dotnet-linker/AppBundleRewriter.cs @@ -231,6 +231,12 @@ public TypeReference System_IntPtr { } } + public FieldReference System_IntPtr_Zero { + get { + return GetFieldReference (CorlibAssembly, System_IntPtr, "Zero", "System.IntPtr::Zero", out var _); + } + } + public TypeReference System_Nullable_1 { get { return GetTypeReference (CorlibAssembly, "System.Nullable`1", out var _); @@ -779,6 +785,16 @@ public MethodReference Runtime_HasNSObject { } } + public MethodReference Runtime_TryGetNSObject { + get { + return GetMethodReference (PlatformAssembly, + ObjCRuntime_Runtime, "TryGetNSObject", + nameof (Runtime_TryGetNSObject), + isStatic: true, + System_IntPtr, + System_Boolean); + } + } public MethodReference Runtime_GetNSObject__System_IntPtr { get { return GetMethodReference (PlatformAssembly, @@ -814,19 +830,6 @@ public MethodReference Runtime_GetNSObject_T___System_IntPtr { } } - public MethodReference Runtime_GetINativeObject__IntPtr_Boolean_Type_Type { - get { - return GetMethodReference (PlatformAssembly, - ObjCRuntime_Runtime, "GetINativeObject", - nameof (Runtime_GetINativeObject__IntPtr_Boolean_Type_Type), - isStatic: true, - System_IntPtr, - System_Boolean, - System_Type, - System_Type); - } - } - public MethodReference Runtime_CreateRuntimeException { get { return GetMethodReference (PlatformAssembly, @@ -1142,6 +1145,7 @@ public void ClearCurrentAssembly () current_assembly = null; type_map.Clear (); method_map.Clear (); + field_map.Clear (); } } } diff --git a/tools/dotnet-linker/Steps/ManagedRegistrarStep.cs b/tools/dotnet-linker/Steps/ManagedRegistrarStep.cs index 0e89314fa655..88947f73bd46 100644 --- a/tools/dotnet-linker/Steps/ManagedRegistrarStep.cs +++ b/tools/dotnet-linker/Steps/ManagedRegistrarStep.cs @@ -921,14 +921,42 @@ bool EmitConversion (MethodDefinition method, ILProcessor il, TypeReference type // cast to the generic type to verify that the item is actually of the correct type il.Emit (OpCodes.Unbox_Any, type); } else { - var nativeObjType = StaticRegistrar.GetInstantiableType (type.Resolve (), exceptions, GetMethodSignature (method)); + StaticRegistrar.GetInstantiableType (type.Resolve (), exceptions, GetMethodSignature (method), out var ctor); + EnsureVisible (method, ctor); + var targetType = method.Module.ImportReference (type); + var handleVariable = il.Body.AddVariable (abr.System_IntPtr); + var objectVariable = il.Body.AddVariable (targetType); + var loadHandle = il.Create (OpCodes.Ldloc, handleVariable); + var loadObjectVariable = il.Create (OpCodes.Ldloc, objectVariable); + il.Emit (OpCodes.Stloc, handleVariable); + // objectVariable = null + il.Emit (OpCodes.Ldnull); + il.Emit (OpCodes.Stloc, objectVariable); + // if (handle == IntPtr.Zero) + // goto done; + il.Emit (OpCodes.Ldloc, handleVariable); // handle + il.Emit (OpCodes.Ldsfld, abr.System_IntPtr_Zero); + il.Emit (OpCodes.Beq, loadObjectVariable); + // objectVariable = TryGetNSObject (handle, false) as TargetType + il.Emit (OpCodes.Ldloc, handleVariable); // handle + il.Emit (OpCodes.Ldc_I4_0); // false + il.Emit (OpCodes.Call, abr.Runtime_TryGetNSObject); + il.Emit (OpCodes.Castclass, targetType); + il.Emit (OpCodes.Stloc, objectVariable); + // if (objectVariable is null) + // objectVariable = new TargetType (handle, false) + il.Emit (OpCodes.Ldloc, objectVariable); + il.Emit (OpCodes.Brfalse, loadHandle); + il.Emit (OpCodes.Br, loadObjectVariable); + il.Append (loadHandle); + if (ctor.Parameters [0].ParameterType.Is ("ObjCRuntime", "NativeHandle")) + il.Emit (OpCodes.Call, abr.NativeObject_op_Implicit_NativeHandle); il.Emit (OpCodes.Ldc_I4_0); // false - il.Emit (OpCodes.Ldtoken, method.Module.ImportReference (type)); // target type - il.Emit (OpCodes.Call, abr.Type_GetTypeFromHandle); - il.Emit (OpCodes.Ldtoken, method.Module.ImportReference (nativeObjType)); // implementation type - il.Emit (OpCodes.Call, abr.Type_GetTypeFromHandle); - il.Emit (OpCodes.Call, abr.Runtime_GetINativeObject__IntPtr_Boolean_Type_Type); - il.Emit (OpCodes.Castclass, type); + il.Emit (OpCodes.Newobj, method.Module.ImportReference (ctor)); + il.Emit (OpCodes.Stloc, objectVariable); + // done: + // (load objectVariable on the stack) + il.Append (loadObjectVariable); } nativeType = abr.System_IntPtr; } else { diff --git a/tools/dotnet-linker/dotnet-linker.csproj b/tools/dotnet-linker/dotnet-linker.csproj index 66ff6ea83c1a..e4c7270fff37 100644 --- a/tools/dotnet-linker/dotnet-linker.csproj +++ b/tools/dotnet-linker/dotnet-linker.csproj @@ -1,9 +1,10 @@ - net7.0 + net$(BundledNETCoreAppTargetFrameworkVersion) dotnet_linker $(DefineConstants);BUNDLER true + nullable diff --git a/tools/nnyeah/tests/nnyeah-tests.csproj b/tools/nnyeah/tests/nnyeah-tests.csproj index 0595d6104ffa..d36e78ef04e8 100644 --- a/tools/nnyeah/tests/nnyeah-tests.csproj +++ b/tools/nnyeah/tests/nnyeah-tests.csproj @@ -12,6 +12,7 @@ + @@ -21,6 +22,7 @@ +