| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d7d44e8 commit 6aa75c5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,20 @@ public static Type FormatterType | |||
| 31 | 31 | ||
| 32 | 32 | public static ICLRObjectStorer WrappersStorer { get; set; } | |
| 33 | 33 | ||
| 34 | + /// <summary> | ||
| 35 | + /// Clears the old "clr_data" entry if a previous one is present. | ||
| 36 | + /// </summary> | ||
| 37 | + static void ClearCLRData () | ||
| 38 | + { | ||
| 39 | + IntPtr capsule = PySys_GetObject("clr_data").DangerousGetAddressUnchecked(); | ||
| 40 | + if (capsule != IntPtr.Zero) | ||
| 41 | + { | ||
| 42 | + IntPtr oldData = PyCapsule_GetPointer(capsule, null); | ||
| 43 | + PyMem_Free(oldData); | ||
| 44 | + PyCapsule_SetPointer(capsule, IntPtr.Zero); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 34 | 48 | internal static void Stash() | |
| 35 | 49 | { | |
| 36 | 50 | var metaStorage = new RuntimeDataStorage(); | |
@@ -70,15 +84,10 @@ internal static void Stash() | |||
| 70 | 84 | Marshal.WriteIntPtr(mem, (IntPtr)ms.Length); | |
| 71 | 85 | Marshal.Copy(data, 0, mem + IntPtr.Size, (int)ms.Length); | |
| 72 | 86 | ||
| 73 | - IntPtr capsule = PySys_GetObject("clr_data").DangerousGetAddressUnchecked(); | ||
| 74 | - if (capsule != IntPtr.Zero) | ||
| 75 | - { | ||
| 76 | - IntPtr oldData = PyCapsule_GetPointer(capsule, null); | ||
| 77 | - PyMem_Free(oldData); | ||
| 78 | - PyCapsule_SetPointer(capsule, IntPtr.Zero); | ||
| 79 | - } | ||
| 80 | - capsule = PyCapsule_New(mem, null, IntPtr.Zero); | ||
| 87 | + ClearCLRData(); | ||
| 88 | + IntPtr capsule = PyCapsule_New(mem, null, IntPtr.Zero); | ||
| 81 | 89 | PySys_SetObject("clr_data", capsule); | |
| 90 | + // Let the dictionary own the reference | ||
| 82 | 91 | XDecref(capsule); | |
| 83 | 92 | } | |
| 84 | 93 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments