|
4 | 4 |
|
5 | 5 | #if FEATURE_CTYPES |
6 | 6 |
|
7 | | -using System.Linq.Expressions; |
8 | | -using System.Numerics; |
9 | | - |
10 | 7 | using System; |
11 | 8 | using System.Collections.Generic; |
12 | | -using System.Dynamic; |
13 | 9 | using System.Diagnostics; |
| 10 | +using System.Dynamic; |
| 11 | +using System.Linq; |
| 12 | +using System.Linq.Expressions; |
| 13 | +using System.Numerics; |
14 | 14 | using System.Reflection; |
15 | 15 | using System.Reflection.Emit; |
16 | 16 | using System.Runtime.CompilerServices; |
17 | 17 | using System.Runtime.InteropServices; |
18 | 18 | using System.Threading; |
19 | 19 |
|
20 | | -using Microsoft.Scripting; |
21 | | -using Microsoft.Scripting.Ast; |
22 | | -using Microsoft.Scripting.Generation; |
23 | | -using Microsoft.Scripting.Runtime; |
24 | | -using Microsoft.Scripting.Utils; |
25 | | - |
26 | 20 | using IronPython.Runtime; |
27 | 21 | using IronPython.Runtime.Binding; |
28 | 22 | using IronPython.Runtime.Operations; |
29 | 23 | using IronPython.Runtime.Types; |
30 | 24 |
|
| 25 | +using Microsoft.Scripting.Ast; |
| 26 | +using Microsoft.Scripting.Generation; |
| 27 | +using Microsoft.Scripting.Runtime; |
| 28 | + |
31 | 29 | namespace IronPython.Modules { |
32 | 30 | /// <summary> |
33 | 31 | /// Provides support for interop with native code from Python code. |
@@ -388,7 +386,7 @@ private Expression AddReturnChecks(CodeContext context, DynamicMetaObject[] args |
388 | 386 | typeof(PythonOps).GetMethod(nameof(PythonOps.MakeTuple)), |
389 | 387 | Expression.NewArrayInit( |
390 | 388 | 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))) |
392 | 390 | ) |
393 | 391 | ) |
394 | 392 | ); |
@@ -609,7 +607,7 @@ private INativeType GetNativeReturnType() { |
609 | 607 | #endif |
610 | 608 |
|
611 | 609 | 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()); |
613 | 611 |
|
614 | 612 | // if we have a return value we need to store it and marshal to Python |
615 | 613 | // before we run any cleanup code. |
@@ -658,25 +656,6 @@ private INativeType GetNativeReturnType() { |
658 | 656 | #endif |
659 | 657 | } |
660 | 658 |
|
661 | | - private static SignatureHelper GetMethodSigHelper(CallingConvention convention, Type calliRetType) { |
662 | | -#if FEATURE_REFEMIT_FULL |
663 | | - return SignatureHelper.GetMethodSigHelper(convention, calliRetType); |
664 | | -#else |
665 | | - var helper = typeof(SignatureHelper).GetMethod("GetMethodSigHelper", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(CallingConvention), typeof(Type) }, null); |
666 | | - return (SignatureHelper)helper.Invoke(null, new object[] { convention, calliRetType }); |
667 | | -#endif |
668 | | - } |
669 | | - |
670 | | - private static SignatureHelper GetCalliSignature(CallingConvention convention, ArgumentMarshaller/*!*/[] sig, Type calliRetType) { |
671 | | - SignatureHelper signature = GetMethodSigHelper(convention, calliRetType); |
672 | | - |
673 | | - foreach (ArgumentMarshaller argMarshaller in sig) { |
674 | | - signature.AddArgument(argMarshaller.NativeType); |
675 | | - } |
676 | | - |
677 | | - return signature; |
678 | | - } |
679 | | - |
680 | 659 | #region Argument Marshalling |
681 | 660 |
|
682 | 661 | /// <summary> |
@@ -960,6 +939,19 @@ public string __repr__(CodeContext context) { |
960 | 939 | } |
961 | 940 | } |
962 | 941 | } |
| 942 | + |
| 943 | +#if NETSTANDARD2_0 |
| 944 | +#nullable enable |
| 945 | + internal static class ILGeneratorExtensions { |
| 946 | + private static MethodInfo? EmitCalliMethodInfo = typeof(ILGenerator).GetMethod("EmitCalli", new Type[] { typeof(OpCode), typeof(CallingConvention), typeof(Type), typeof(Type[]) }); |
| 947 | + |
| 948 | + public static void EmitCalli(this ILGenerator ilgen, OpCode opcode, CallingConvention unmanagedCallConv, Type? returnType, Type[]? parameterTypes) { |
| 949 | + // should exist in runtimes of interest, but just in case, let it throw if the method doesn't exist... |
| 950 | + EmitCalliMethodInfo!.Invoke(ilgen, new object[] { opcode, unmanagedCallConv, returnType!, parameterTypes! }); |
| 951 | + } |
| 952 | + } |
| 953 | +#nullable restore |
| 954 | +#endif |
963 | 955 | } |
964 | 956 |
|
965 | 957 | #endif |
0 commit comments