| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -164,11 +164,7 @@ internal static void Initialize(bool initSigs = false) | |||
| 164 | 164 | // Initialize modules that depend on the runtime class. | |
| 165 | 165 | AssemblyManager.Initialize(); | |
| 166 | 166 | OperatorMethod.Initialize(); | |
| 167 | - if (RuntimeData.HasStashData()) | ||
| 168 | - { | ||
| 169 | - RuntimeData.RestoreRuntimeData(); | ||
| 170 | - } | ||
| 171 | - else | ||
| 167 | + if (!RuntimeData.RestoreRuntimeData()) | ||
| 172 | 168 | { | |
| 173 | 169 | PyCLRMetaType = MetaType.Initialize(); | |
| 174 | 170 | ImportHook.Initialize(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | namespace Python.Runtime; | |
| 6 | 6 | ||
| 7 | 7 | public class NoopFormatter : IFormatter { | |
| 8 | - public object Deserialize(Stream s) => throw new NotImplementedException(); | ||
| 8 | + public object Deserialize(Stream s) => null; // throw new NotImplementedException(); | ||
| 9 | 9 | public void Serialize(Stream s, object o) {} | |
| 10 | 10 | ||
| 11 | 11 | public SerializationBinder? Binder { get; set; } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,47 +112,47 @@ internal static void Stash() | |||
| 112 | 112 | PostStashHook?.Invoke(); | |
| 113 | 113 | } | |
| 114 | 114 | ||
| 115 | - internal static void RestoreRuntimeData() | ||
| 115 | + internal static bool RestoreRuntimeData() | ||
| 116 | 116 | { | |
| 117 | 117 | try | |
| 118 | 118 | { | |
| 119 | - RestoreRuntimeDataImpl(); | ||
| 119 | + return RestoreRuntimeDataImpl(); | ||
| 120 | 120 | } | |
| 121 | 121 | finally | |
| 122 | 122 | { | |
| 123 | 123 | ClearStash(); | |
| 124 | 124 | } | |
| 125 | 125 | } | |
| 126 | 126 | ||
| 127 | - private static void RestoreRuntimeDataImpl() | ||
| 127 | + private static bool RestoreRuntimeDataImpl() | ||
| 128 | 128 | { | |
| 129 | 129 | PreRestoreHook?.Invoke(); | |
| 130 | 130 | BorrowedReference capsule = PySys_GetObject("clr_data"); | |
| 131 | 131 | if (capsule.IsNull) | |
| 132 | 132 | { | |
| 133 | - return; | ||
| 133 | + return false; | ||
| 134 | 134 | } | |
| 135 | 135 | IntPtr mem = PyCapsule_GetPointer(capsule, IntPtr.Zero); | |
| 136 | 136 | int length = (int)Marshal.ReadIntPtr(mem); | |
| 137 | 137 | byte[] data = new byte[length]; | |
| 138 | 138 | Marshal.Copy(mem + IntPtr.Size, data, 0, length); | |
| 139 | 139 | var ms = new MemoryStream(data); | |
| 140 | 140 | var formatter = CreateFormatter(); | |
| 141 | - var storage = (PythonNetState)formatter.Deserialize(ms); | ||
| 142 | 141 | ||
| 143 | - PyCLRMetaType = MetaType.RestoreRuntimeData(storage.Metatype); | ||
| 142 | + if (formatter.Deserialize(ms) is PythonNetState storage) | ||
| 143 | + { | ||
| 144 | + PyCLRMetaType = MetaType.RestoreRuntimeData(storage.Metatype); | ||
| 144 | 145 | ||
| 145 | - TypeManager.RestoreRuntimeData(storage.Types); | ||
| 146 | - ClassManager.RestoreRuntimeData(storage.Classes); | ||
| 146 | + TypeManager.RestoreRuntimeData(storage.Types); | ||
| 147 | + ClassManager.RestoreRuntimeData(storage.Classes); | ||
| 147 | 148 | ||
| 148 | - RestoreRuntimeDataObjects(storage.SharedObjects); | ||
| 149 | + RestoreRuntimeDataObjects(storage.SharedObjects); | ||
| 149 | 150 | ||
| 150 | - ImportHook.RestoreRuntimeData(storage.ImportHookState); | ||
| 151 | - } | ||
| 151 | + ImportHook.RestoreRuntimeData(storage.ImportHookState); | ||
| 152 | + return true; | ||
| 153 | + } | ||
| 152 | 154 | ||
| 153 | - public static bool HasStashData() | ||
| 154 | - { | ||
| 155 | - return !PySys_GetObject("clr_data").IsNull; | ||
| 155 | + return false; | ||
| 156 | 156 | } | |
| 157 | 157 | ||
| 158 | 158 | public static void ClearStash() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments