Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6335d97

Browse files
committed
improved GetThunk reliability
1 parent d6607b0 commit 6335d97

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/runtime/interop.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,9 @@ internal static Type GetPrototype(MethodInfo method)
157157

158158
internal static Dictionary<IntPtr, Delegate> allocatedThunks = new Dictionary<IntPtr, Delegate>();
159159

160-
internal static ThunkInfo GetThunk(MethodInfo method, string funcType = null)
160+
internal static ThunkInfo GetThunk(MethodInfo method)
161161
{
162-
Type dt;
163-
if (funcType != null)
164-
dt = typeof(Interop).GetNestedType(funcType) as Type;
165-
else
166-
dt = GetPrototype(method);
167-
168-
if (dt == null)
169-
{
170-
return ThunkInfo.Empty;
171-
}
162+
Type dt = GetPrototype(method);
172163
Delegate d = Delegate.CreateDelegate(dt, method);
173164
return GetThunk(d);
174165
}
@@ -192,6 +183,9 @@ internal static ThunkInfo GetThunk(Delegate @delegate)
192183
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
193184
public delegate int B_I32(BorrowedReference ob);
194185

186+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
187+
public delegate int BB_I32(BorrowedReference ob, BorrowedReference a);
188+
195189
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
196190
public delegate int BBB_I32(BorrowedReference ob, BorrowedReference a1, BorrowedReference a2);
197191

src/runtime/metatype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal static PyType RestoreRuntimeData(MetatypeState storage)
5656
foreach (var methodName in CustomMethods)
5757
{
5858
var mi = typeof(MetaType).GetMethod(methodName);
59-
ThunkInfo thunkInfo = Interop.GetThunk(mi, "BinaryFunc");
59+
ThunkInfo thunkInfo = Interop.GetThunk(mi);
6060
_metaSlotsHodler.KeeapAlive(thunkInfo);
6161
mdef = TypeManager.WriteMethodDef(mdef, methodName, thunkInfo.Address);
6262
}

src/runtime/typemanager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ internal static SlotsHolder SetupMetaSlots(Type impl, PyType type)
652652
private static IntPtr AddCustomMetaMethod(string name, PyType type, IntPtr mdef, SlotsHolder slotsHolder)
653653
{
654654
MethodInfo mi = typeof(MetaType).GetMethod(name);
655-
ThunkInfo thunkInfo = Interop.GetThunk(mi, "BinaryFunc");
655+
ThunkInfo thunkInfo = Interop.GetThunk(mi);
656656
slotsHolder.KeeapAlive(thunkInfo);
657657

658658
// XXX: Hard code with mode check.

0 commit comments

Comments
 (0)