Skip to content

Commit

Permalink
Merge branch 'main' into dev/mag/mobileprops
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroa authored Aug 14, 2023
2 parents e68ccb9 + f24a016 commit 2aa9a5d
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 30 deletions.
8 changes: 8 additions & 0 deletions src/spritekit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions tests/common/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
var outputStr = output.ToString ();
Console.WriteLine ($"'{Executable} {StringUtils.FormatArguments (args)}' failed with exit code {rv.ExitCode}.");
Console.WriteLine (outputStr);
if (rv.ExitCode != 0) {
var msg = new StringBuilder ();
msg.AppendLine ($"'dotnet {verb}' failed with exit code {rv.ExitCode}");
msg.AppendLine ($"Full command: {Executable} {StringUtils.FormatArguments (args)}");
#if !MSBUILD_TASKS
var errors = BinLog.GetBuildLogErrors (binlogPath).ToArray ();
if (errors.Any ()) {
var errorsToList = errors.Take (10).ToArray ();
msg.AppendLine ($"Listing first {errorsToList.Length} error(s) (of {errors.Length} error(s)):");
foreach (var error in errorsToList)
msg.AppendLine ($" {string.Join ($"{Environment.NewLine} ", error.ToString ().Split ('\n', '\r'))}");
}
#endif
Assert.Fail (msg.ToString ());
}
Assert.AreEqual (0, rv.ExitCode, $"Exit code: {Executable} {StringUtils.FormatArguments (args)}");
}
return new ExecutionResult (output, output, rv.ExitCode) {
Expand Down
2 changes: 1 addition & 1 deletion tests/monotouch-test/ObjCRuntime/BlocksTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static TestClass ()
}
}

#if !DEVICE && !MONOMAC && !AOT // some of these tests cause the AOT compiler to assert
#if !DEVICE && !MONOMAC && !AOT && !__MACCATALYST__ // some of these tests cause the AOT compiler to assert
// No MonoPInvokeCallback
static void InvalidTrampoline1 () { }

Expand Down
6 changes: 0 additions & 6 deletions tools/common/Rewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class Rewriter {
const string classPtrName = "class_ptr";
CSToObjCMap map;
string pathToXamarinAssembly;
string? outputDirectory = null;
Dictionary<string, FieldDefinition> csTypeToFieldDef = new Dictionary<string, FieldDefinition> ();
IEnumerable<AssemblyDefinition> assemblies;
AssemblyDefinition xamarinAssembly;
Expand Down Expand Up @@ -328,11 +327,6 @@ IEnumerable<TypeDefinition> AllTypes (TypeDefinition type)
}
}

string ToOutputFileName (string pathToInputFileName)
{
return Path.Combine (outputDirectory, Path.GetFileName (pathToInputFileName));
}

void MarkForSave (AssemblyDefinition assembly)
{
var annotations = linkContext.Annotations;
Expand Down
14 changes: 13 additions & 1 deletion tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,12 @@ void Specialize (AutoIndentStringBuilder sb, out string initialization_method)

bool HasIntPtrBoolCtor (TypeDefinition type, List<Exception> exceptions)
{
return HasIntPtrBoolCtor (type, exceptions, out var _);
}

bool HasIntPtrBoolCtor (TypeDefinition type, List<Exception> exceptions, [NotNullWhen (true)] out MethodDefinition? ctor)
{
ctor = null;
if (!type.HasMethods)
return false;
foreach (var method in type.Methods) {
Expand All @@ -3330,6 +3336,7 @@ bool HasIntPtrBoolCtor (TypeDefinition type, List<Exception> exceptions)
if (!method.Parameters [0].ParameterType.Is ("System", "IntPtr"))
continue;
}
ctor = method;
return true;
}
return false;
Expand Down Expand Up @@ -4528,6 +4535,11 @@ void GenerateCallToSuperForConstructor (AutoIndentStringBuilder sb, ObjCMethod m
}

public TypeDefinition GetInstantiableType (TypeDefinition td, List<Exception> exceptions, string descriptiveMethodName)
{
return GetInstantiableType (td, exceptions, descriptiveMethodName, out var _);
}

public TypeDefinition GetInstantiableType (TypeDefinition td, List<Exception> exceptions, string descriptiveMethodName, out MethodDefinition ctor)
{
TypeDefinition nativeObjType = td;

Expand All @@ -4540,7 +4552,7 @@ public TypeDefinition GetInstantiableType (TypeDefinition td, List<Exception> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework>
<RootNamespace>create_dotnet_linker_launch_json</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
30 changes: 17 additions & 13 deletions tools/dotnet-linker/AppBundleRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1142,6 +1145,7 @@ public void ClearCurrentAssembly ()
current_assembly = null;
type_map.Clear ();
method_map.Clear ();
field_map.Clear ();
}
}
}
42 changes: 35 additions & 7 deletions tools/dotnet-linker/Steps/ManagedRegistrarStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tools/dotnet-linker/dotnet-linker.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework>
<RootNamespace>dotnet_linker</RootNamespace>
<DefineConstants>$(DefineConstants);BUNDLER</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<Import Project="..\..\eng\Versions.props" />
Expand Down
2 changes: 2 additions & 0 deletions tools/nnyeah/tests/nnyeah-tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.1.758" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,6 +22,7 @@
<Compile Include="../../common/ApplePlatform.cs" Link="ApplePlatform.cs" />

<Compile Include="../../../tests/mtouch/Cache.cs" Link="Cache.cs" />
<Compile Include="../../../tests/common/BinLog.cs" Link="BinLog.cs" />
<Compile Include="../../../tests/common/Configuration.cs" Link="Configuration.cs" />
<Compile Include="../../../tests/common/Profile.cs" Link="Profile.cs" />
<Compile Include="../../../tests/common/ExecutionHelper.cs" Link="ExecutionHelper.cs" />
Expand Down

0 comments on commit 2aa9a5d

Please sign in to comment.