@@ -23,6 +23,32 @@ namespace Python.Runtime
2323 /// </summary>
2424 internal class NativeCall
2525 {
26+ #if NETCOREAPP
27+ [ UnmanagedFunctionPointer ( CallingConvention . Cdecl ) ]
28+ private delegate void Void_1_Delegate ( IntPtr a1 ) ;
29+
30+ [ UnmanagedFunctionPointer ( CallingConvention . Cdecl ) ]
31+ private delegate IntPtr IntPtr_3_Delegate ( IntPtr a1 , IntPtr a2 , IntPtr a3 ) ;
32+
33+ [ UnmanagedFunctionPointer ( CallingConvention . Cdecl ) ]
34+ private delegate int Int_3_Delegate ( IntPtr a1 , IntPtr a2 , IntPtr a3 ) ;
35+
36+ public static void Void_Call_1 ( IntPtr fp , IntPtr a1 )
37+ {
38+ ( ( Void_1_Delegate ) Marshal . GetDelegateForFunctionPointer ( fp , typeof ( Void_1_Delegate ) ) ) ( a1 ) ;
39+ }
40+
41+ public static IntPtr Call_3 ( IntPtr fp , IntPtr a1 , IntPtr a2 , IntPtr a3 )
42+ {
43+ return ( ( IntPtr_3_Delegate ) Marshal . GetDelegateForFunctionPointer ( fp , typeof ( IntPtr_3_Delegate ) ) ) ( a1 , a2 , a3 ) ;
44+ }
45+
46+
47+ public static int Int_Call_3 ( IntPtr fp , IntPtr a1 , IntPtr a2 , IntPtr a3 )
48+ {
49+ return ( ( Int_3_Delegate ) Marshal . GetDelegateForFunctionPointer ( fp , typeof ( Int_3_Delegate ) ) ) ( a1 , a2 , a3 ) ;
50+ }
51+ #else
2652 private static AssemblyBuilder aBuilder ;
2753 private static ModuleBuilder mBuilder ;
2854
@@ -106,19 +132,12 @@ private static void GenerateThunk(TypeBuilder tb, MethodInfo method)
106132
107133 il . Emit ( OpCodes . Ldarg_1 ) ;
108134
109- #if NETCOREAPP
110- il . EmitCalli ( OpCodes . Calli ,
111- CallingConventions . ExplicitThis ,
112- method . ReturnType ,
113- nargs , null
114- ) ;
115- #else
116135 il . EmitCalli ( OpCodes . Calli ,
117136 CallingConvention . Cdecl ,
118137 method . ReturnType ,
119138 nargs
120139 ) ;
121- #endif
140+
122141 il . Emit ( OpCodes . Ret ) ;
123142
124143 tb . DefineMethodOverride ( mb , method ) ;
@@ -139,9 +158,10 @@ public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
139158 {
140159 return Impl . Int_Call_3 ( fp , a1 , a2 , a3 ) ;
141160 }
161+ #endif
142162 }
143163
144-
164+ #if ! NETCORAPP
145165 /// <summary>
146166 /// Defines native call signatures to be generated by NativeCall.
147167 /// </summary>
@@ -155,4 +175,5 @@ public interface INativeCall
155175
156176 IntPtr Call_3 ( IntPtr funcPtr , IntPtr a1 , IntPtr a2 , IntPtr a3 ) ;
157177 }
178+ #endif
158179}
0 commit comments