@@ -112,47 +112,47 @@ internal static void Stash()
112112 PostStashHook ? . Invoke ( ) ;
113113 }
114114
115- internal static void RestoreRuntimeData ( )
115+ internal static bool RestoreRuntimeData ( )
116116 {
117117 try
118118 {
119- RestoreRuntimeDataImpl ( ) ;
119+ return RestoreRuntimeDataImpl ( ) ;
120120 }
121121 finally
122122 {
123123 ClearStash ( ) ;
124124 }
125125 }
126126
127- private static void RestoreRuntimeDataImpl ( )
127+ private static bool RestoreRuntimeDataImpl ( )
128128 {
129129 PreRestoreHook ? . Invoke ( ) ;
130130 BorrowedReference capsule = PySys_GetObject ( "clr_data" ) ;
131131 if ( capsule . IsNull )
132132 {
133- return ;
133+ return false ;
134134 }
135135 IntPtr mem = PyCapsule_GetPointer ( capsule , IntPtr . Zero ) ;
136136 int length = ( int ) Marshal . ReadIntPtr ( mem ) ;
137137 byte [ ] data = new byte [ length ] ;
138138 Marshal . Copy ( mem + IntPtr . Size , data , 0 , length ) ;
139139 var ms = new MemoryStream ( data ) ;
140140 var formatter = CreateFormatter ( ) ;
141- var storage = ( PythonNetState ) formatter . Deserialize ( ms ) ;
142141
143- PyCLRMetaType = MetaType . RestoreRuntimeData ( storage . Metatype ) ;
142+ if ( formatter . Deserialize ( ms ) is PythonNetState storage )
143+ {
144+ PyCLRMetaType = MetaType . RestoreRuntimeData ( storage . Metatype ) ;
144145
145- TypeManager . RestoreRuntimeData ( storage . Types ) ;
146- ClassManager . RestoreRuntimeData ( storage . Classes ) ;
146+ TypeManager . RestoreRuntimeData ( storage . Types ) ;
147+ ClassManager . RestoreRuntimeData ( storage . Classes ) ;
147148
148- RestoreRuntimeDataObjects ( storage . SharedObjects ) ;
149+ RestoreRuntimeDataObjects ( storage . SharedObjects ) ;
149150
150- ImportHook . RestoreRuntimeData ( storage . ImportHookState ) ;
151- }
151+ ImportHook . RestoreRuntimeData ( storage . ImportHookState ) ;
152+ return true ;
153+ }
152154
153- public static bool HasStashData ( )
154- {
155- return ! PySys_GetObject ( "clr_data" ) . IsNull ;
155+ return false ;
156156 }
157157
158158 public static void ClearStash ( )
0 commit comments