Skip to content

Commit 51fdede

Browse files
authored
Fix .NET 6.0 issues (#803)
1 parent 689535c commit 51fdede

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

Src/IronPython.Modules/_ctypes/CFuncPtr.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44

55
#if FEATURE_CTYPES
66

7-
using System.Linq.Expressions;
8-
using System.Numerics;
9-
107
using System;
118
using System.Collections.Generic;
12-
using System.Dynamic;
139
using System.Diagnostics;
10+
using System.Dynamic;
11+
using System.Linq;
12+
using System.Linq.Expressions;
13+
using System.Numerics;
1414
using System.Reflection;
1515
using System.Reflection.Emit;
1616
using System.Runtime.CompilerServices;
1717
using System.Runtime.InteropServices;
1818
using System.Threading;
1919

20-
using Microsoft.Scripting;
2120
using Microsoft.Scripting.Ast;
2221
using Microsoft.Scripting.Generation;
2322
using Microsoft.Scripting.Runtime;
24-
using Microsoft.Scripting.Utils;
2523

2624
using IronPython.Runtime;
2725
using IronPython.Runtime.Binding;
@@ -388,7 +386,7 @@ private Expression AddReturnChecks(CodeContext context, DynamicMetaObject[] args
388386
typeof(PythonOps).GetMethod(nameof(PythonOps.MakeTuple)),
389387
Expression.NewArrayInit(
390388
typeof(object),
391-
ArrayUtils.ConvertAll(args, x => Utils.Convert(x.Expression, typeof(object)))
389+
Microsoft.Scripting.Utils.ArrayUtils.ConvertAll(args, x => Utils.Convert(x.Expression, typeof(object)))
392390
)
393391
)
394392
);
@@ -609,7 +607,7 @@ private INativeType GetNativeReturnType() {
609607
#endif
610608

611609
method.Emit(OpCodes.Ldarg_0);
612-
method.Emit(OpCodes.Calli, GetCalliSignature(convention, sig, calliRetType));
610+
method.EmitCalli(OpCodes.Calli, convention, calliRetType, sig.Select(x => x.NativeType).ToArray());
613611

614612
// if we have a return value we need to store it and marshal to Python
615613
// before we run any cleanup code.
@@ -960,5 +958,19 @@ public string __repr__(CodeContext context) {
960958
}
961959
}
962960
}
961+
962+
#if NETSTANDARD2_0
963+
#nullable enable
964+
internal static class ILGeneratorExtensions {
965+
private static MethodInfo? EmitCalliMethodInfo = typeof(ILGenerator).GetMethod("EmitCalli", new Type[] { typeof(OpCode), typeof(CallingConvention), typeof(Type), typeof(Type[]) });
966+
967+
public static void EmitCalli(this ILGenerator ilgen, OpCode opcode, CallingConvention unmanagedCallConv, Type? returnType, Type[]? parameterTypes) {
968+
// should exist in runtimes of interest, but just in case, let it throw if the method doesn't exist...
969+
EmitCalliMethodInfo!.Invoke(ilgen, new object[] { opcode, unmanagedCallConv, returnType!, parameterTypes! });
970+
}
971+
}
972+
#nullable restore
973+
#endif
963974
}
975+
964976
#endif

Src/IronPython/Lib/iptest/test_env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
is_netcoreapp21 = clr.FrameworkDescription.startswith(".NET Core 2.x")
2929
is_netcoreapp31 = clr.FrameworkDescription.startswith(".NET Core 3.1")
3030
is_net50 = clr.FrameworkDescription.startswith(".NET 5.0")
31+
is_net60 = clr.FrameworkDescription.startswith(".NET 6.0")
3132
if is_netcoreapp: clr.AddReference("System.Runtime.Extensions")
3233
is_posix = sys.platform == 'posix' or System.Environment.OSVersion.Platform == System.PlatformID.Unix
3334
is_osx = os.path.exists('/System/Library/CoreServices/SystemVersion.plist')

Src/IronPython/Runtime/Binding/PythonBinder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ internal IList<Type> GetExtensionTypesInternal(Type t) {
378378
}
379379

380380
public override bool IncludeExtensionMember(MemberInfo member) {
381+
// exclude static virtual members on interfaces
382+
if (member.DeclaringType.IsInterface && member.IsStaticVirtual()) return false;
381383
return !member.DeclaringType.IsDefined(typeof(PythonHiddenBaseClassAttribute), false);
382384
}
383385

Src/IronPython/Runtime/Types/PythonTypeInfo.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,11 @@ public ScriptDomainManager/*!*/ DomainManager {
13711371

13721372
IEnumerable<MemberInfo> foundMembers = type.GetMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | flags);
13731373

1374+
if (type.IsInterface) {
1375+
// exclude static virtual members on interfaces
1376+
foundMembers = foundMembers.Where(mi => !mi.IsStaticVirtual());
1377+
}
1378+
13741379
if (!Binder.DomainManager.Configuration.PrivateBinding) {
13751380
foundMembers = CompilerHelpers.FilterNonVisibleMembers(type, foundMembers);
13761381
}
@@ -2071,6 +2076,22 @@ private static MethodInfo[] GetMethodSet(string name, int expected) {
20712076
return filtered;
20722077
}
20732078

2079+
private static bool IsStaticVirtual(this MethodInfo member)
2080+
=> member.IsStatic && member.IsVirtual;
2081+
2082+
internal static bool IsStaticVirtual(this MemberInfo member) {
2083+
switch (member) {
2084+
case MethodInfo mi:
2085+
return mi.IsStaticVirtual();
2086+
case PropertyInfo pi:
2087+
if (pi.GetMethod?.IsStaticVirtual() == true) return true;
2088+
if (pi.SetMethod?.IsStaticVirtual() == true) return true;
2089+
break;
2090+
}
2091+
return false;
2092+
}
2093+
2094+
20742095
#endregion
20752096
}
20762097
}

0 commit comments

Comments
 (0)