| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 139dc87 commit 9307bb3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -491,6 +491,9 @@ internal static Type GetPrototype(string name) | |||
| 491 | 491 | return pmap[name] as Type; | |
| 492 | 492 | } | |
| 493 | 493 | ||
| 494 | + | ||
| 495 | + internal static Dictionary<IntPtr, Delegate> allocatedThunks = new Dictionary<IntPtr, Delegate>(); | ||
| 496 | + | ||
| 494 | 497 | internal static ThunkInfo GetThunk(MethodInfo method, string funcType = null) | |
| 495 | 498 | { | |
| 496 | 499 | Type dt; | |
@@ -505,6 +508,7 @@ internal static ThunkInfo GetThunk(MethodInfo method, string funcType = null) | |||
| 505 | 508 | } | |
| 506 | 509 | Delegate d = Delegate.CreateDelegate(dt, method); | |
| 507 | 510 | var info = new ThunkInfo(d); | |
| 511 | + allocatedThunks[info.Address] = d; | ||
| 508 | 512 | return info; | |
| 509 | 513 | } | |
| 510 | 514 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ internal static int PyVisit(IntPtr ob, IntPtr visit, IntPtr arg) | |||
| 178 | 178 | { | |
| 179 | 179 | return 0; | |
| 180 | 180 | } | |
| 181 | - var visitFunc = (Interop.ObjObjFunc)Marshal.GetDelegateForFunctionPointer(visit, typeof(Interop.ObjObjFunc)); | ||
| 181 | + var visitFunc = NativeCall.GetDelegate<Interop.ObjObjFunc>(visit); | ||
| 182 | 182 | return visitFunc(ob, arg); | |
| 183 | 183 | } | |
| 184 | 184 | ||
@@ -196,7 +196,7 @@ internal void CallTypeClear() | |||
| 196 | 196 | { | |
| 197 | 197 | return; | |
| 198 | 198 | } | |
| 199 | - var clearFunc = (Interop.InquiryFunc)Marshal.GetDelegateForFunctionPointer(clearPtr, typeof(Interop.InquiryFunc)); | ||
| 199 | + var clearFunc = NativeCall.GetDelegate<Interop.InquiryFunc>(clearPtr); | ||
| 200 | 200 | clearFunc(pyHandle); | |
| 201 | 201 | } | |
| 202 | 202 | ||
@@ -214,7 +214,8 @@ internal void CallTypeTraverse(Interop.ObjObjFunc visitproc, IntPtr arg) | |||
| 214 | 214 | { | |
| 215 | 215 | return; | |
| 216 | 216 | } | |
| 217 | - var traverseFunc = (Interop.ObjObjArgFunc)Marshal.GetDelegateForFunctionPointer(traversePtr, typeof(Interop.ObjObjArgFunc)); | ||
| 217 | + var traverseFunc = NativeCall.GetDelegate<Interop.ObjObjArgFunc>(traversePtr); | ||
| 218 | + | ||
| 218 | 219 | var visiPtr = Marshal.GetFunctionPointerForDelegate(visitproc); | |
| 219 | 220 | traverseFunc(pyHandle, visiPtr, arg); | |
| 220 | 221 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,10 +40,15 @@ public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) | |||
| 40 | 40 | return d(a1, a2, a3); | |
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | - private static T GetDelegate<T>(IntPtr fp) where T: Delegate | ||
| 43 | + internal static T GetDelegate<T>(IntPtr fp) where T: Delegate | ||
| 44 | 44 | { | |
| 45 | - // Use Marshal.GetDelegateForFunctionPointer<> directly after upgrade the framework | ||
| 46 | - return (T)Marshal.GetDelegateForFunctionPointer(fp, typeof(T)); | ||
| 45 | + Delegate d = null; | ||
| 46 | + if (!Interop.allocatedThunks.TryGetValue(fp, out d)) | ||
| 47 | + { | ||
| 48 | + // We don't cache this delegate because this is a pure delegate ot unmanaged. | ||
| 49 | + d = Marshal.GetDelegateForFunctionPointer<T>(fp); | ||
| 50 | + } | ||
| 51 | + return (T)d; | ||
| 47 | 52 | } | |
| 48 | 53 | } | |
| 49 | 54 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments