|
1 | 1 | using System; |
2 | 2 | using System.Reflection; |
3 | | -using System.Reflection.Emit; |
4 | 3 | using System.Runtime.InteropServices; |
5 | 4 | using System.Threading; |
6 | 5 |
|
7 | 6 | namespace Python.Runtime |
8 | 7 | { |
| 8 | +#if AOT |
| 9 | + internal class NativeCall |
| 10 | + { |
| 11 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 12 | + private delegate void Void_1_Delegate(IntPtr a1); |
| 13 | + |
| 14 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 15 | + private delegate int Int_3_Delegate(IntPtr a1, IntPtr a2, IntPtr a3); |
| 16 | + |
| 17 | + public static void Void_Call_1(IntPtr fp, IntPtr a1) |
| 18 | + { |
| 19 | + ((Void_1_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Void_1_Delegate)))(a1); |
| 20 | + } |
| 21 | + |
| 22 | + public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) |
| 23 | + { |
| 24 | + var d = (Interop.TernaryFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(Interop.TernaryFunc)); |
| 25 | + return d(a1, a2, a3); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) |
| 30 | + { |
| 31 | + return ((Int_3_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Int_3_Delegate)))(a1, a2, a3); |
| 32 | + } |
| 33 | + } |
| 34 | +#endif |
| 35 | + |
| 36 | +#if !AOT |
| 37 | + using System.Reflection.Emit; |
9 | 38 | /// <summary> |
10 | 39 | /// Provides support for calling native code indirectly through |
11 | 40 | /// function pointers. Most of the important parts of the Python |
@@ -174,4 +203,5 @@ public interface INativeCall |
174 | 203 | IntPtr Call_3(IntPtr funcPtr, IntPtr a1, IntPtr a2, IntPtr a3); |
175 | 204 | } |
176 | 205 | #endif |
| 206 | +#endif |
177 | 207 | } |
0 commit comments