internal static void RestoreRuntimeData(RuntimeDataStorage storage) { InitImport(); storage.GetValue("py_clr_module", out py_clr_module); var rootHandle = storage.GetValue <IntPtr>("root"); root = (CLRModule)ManagedType.GetManagedObject(rootHandle); }
internal static void SaveRuntimeData(RuntimeDataStorage storage) { // Increment the reference counts here so that the objects don't // get freed in Shutdown. Runtime.XIncref(py_clr_module); Runtime.XIncref(root.pyHandle); storage.AddValue("py_clr_module", py_clr_module); storage.AddValue("root", root.pyHandle); }
internal static void SaveRuntimeData(RuntimeDataStorage storage) { foreach (var tpHandle in cache.Values) { Runtime.XIncref(tpHandle); } storage.AddValue("cache", cache); storage.AddValue("slots", _slotsImpls); }
internal static void RestoreRuntimeData(RuntimeDataStorage storage) { storage.GetValue("py_clr_module", out py_clr_module); var rootHandle = storage.GetValue <IntPtr>("root"); root = (CLRModule)ManagedType.GetManagedObject(rootHandle); BorrowedReference dict = Runtime.PyImport_GetModuleDict(); Runtime.PyDict_SetItemString(dict, "clr", ClrModuleReference); SetupNamespaceTracking(); }
internal static void RestoreRuntimeData(RuntimeDataStorage storage) { Debug.Assert(cache == null || cache.Count == 0); storage.GetValue("slots", out _slotsImpls); storage.GetValue("cache", out cache); foreach (var entry in cache) { Type type = entry.Key; IntPtr handle = entry.Value; SlotsHolder holder = CreateSolotsHolder(handle); InitializeSlots(handle, _slotsImpls[type], holder); // FIXME: mp_length_slot.CanAssgin(clrType) } }
internal static void SaveRuntimeData(RuntimeDataStorage storage) { var contexts = storage.AddValue("contexts", new Dictionary <IntPtr, InterDomainContext>()); storage.AddValue("cache", cache); foreach (var cls in cache.Values) { // This incref is for cache to hold the cls, // thus no need for decreasing it at RestoreRuntimeData. Runtime.XIncref(cls.pyHandle); var context = contexts[cls.pyHandle] = new InterDomainContext(); cls.Save(context); } }
internal static void SaveRuntimeData(RuntimeDataStorage storage) { var contexts = storage.AddValue("contexts", new Dictionary <IntPtr, InterDomainContext>()); storage.AddValue("cache", cache); foreach (var cls in cache) { if (!cls.Key.Valid) { // Don't serialize an invalid class continue; } // This incref is for cache to hold the cls, // thus no need for decreasing it at RestoreRuntimeData. Runtime.XIncref(cls.Value.pyHandle); var context = contexts[cls.Value.pyHandle] = new InterDomainContext(); cls.Value.Save(context); // Remove all members added in InitBaseClass. // this is done so that if domain reloads and a member of a // reflected dotnet class is removed, it is removed from the // Python object's dictionary tool; thus raising an AttributeError // instead of a TypeError. // Classes are re-initialized on in RestoreRuntimeData. var dict = new BorrowedReference(Marshal.ReadIntPtr(cls.Value.tpHandle, TypeOffset.tp_dict)); foreach (var member in cls.Value.dotNetMembers) { // No need to decref the member, the ClassBase instance does // not own the reference. if ((Runtime.PyDict_DelItemString(dict, member) == -1) && (Exceptions.ExceptionMatches(Exceptions.KeyError))) { // Trying to remove a key that's not in the dictionary // raises an error. We don't care about it. Runtime.PyErr_Clear(); } else if (Exceptions.ErrorOccurred()) { throw new PythonException(); } } // We modified the Type object, notify it we did. Runtime.PyType_Modified(cls.Value.tpHandle); } }
internal static IntPtr RestoreRuntimeData(RuntimeDataStorage storage) { PyCLRMetaType = storage.PopValue <IntPtr>(); _metaSlotsHodler = new SlotsHolder(PyCLRMetaType); TypeManager.InitializeSlots(PyCLRMetaType, typeof(MetaType), _metaSlotsHodler); IntPtr mdef = Marshal.ReadIntPtr(PyCLRMetaType, TypeOffset.tp_methods); foreach (var methodName in CustomMethods) { var mi = typeof(MetaType).GetMethod(methodName); ThunkInfo thunkInfo = Interop.GetThunk(mi, "BinaryFunc"); _metaSlotsHodler.KeeapAlive(thunkInfo); mdef = TypeManager.WriteMethodDef(mdef, methodName, thunkInfo.Address); } return(PyCLRMetaType); }
internal static void RestoreRuntimeData(RuntimeDataStorage storage) { Debug.Assert(cache == null || cache.Count == 0); storage.GetValue("slots", out _slotsImpls); storage.GetValue <Dictionary <MaybeType, IntPtr> >("cache", out var _cache); foreach (var entry in _cache) { if (!entry.Key.Valid) { Runtime.XDecref(entry.Value); continue; } Type type = entry.Key.Value;; IntPtr handle = entry.Value; cache[type] = handle; SlotsHolder holder = CreateSolotsHolder(handle); InitializeSlots(handle, _slotsImpls[type], holder); // FIXME: mp_length_slot.CanAssgin(clrType) } }
internal static Dictionary <ManagedType, InterDomainContext> RestoreRuntimeData(RuntimeDataStorage storage) { cache = storage.GetValue <Dictionary <MaybeType, ClassBase> >("cache"); var invalidClasses = new List <KeyValuePair <MaybeType, ClassBase> >(); var contexts = storage.GetValue <Dictionary <IntPtr, InterDomainContext> >("contexts"); var loadedObjs = new Dictionary <ManagedType, InterDomainContext>(); foreach (var pair in cache) { if (!pair.Key.Valid) { invalidClasses.Add(pair); continue; } // re-init the class InitClassBase(pair.Key.Value, pair.Value); // We modified the Type object, notify it we did. Runtime.PyType_Modified(pair.Value.tpHandle); var context = contexts[pair.Value.pyHandle]; pair.Value.Load(context); loadedObjs.Add(pair.Value, context); } foreach (var pair in invalidClasses) { cache.Remove(pair.Key); Runtime.XDecref(pair.Value.pyHandle); } return(loadedObjs); }
internal static Dictionary <ManagedType, InterDomainContext> RestoreRuntimeData(RuntimeDataStorage storage) { cache = storage.GetValue <Dictionary <Type, ClassBase> >("cache"); var contexts = storage.GetValue <Dictionary <IntPtr, InterDomainContext> >("contexts"); var loadedObjs = new Dictionary <ManagedType, InterDomainContext>(); foreach (var cls in cache.Values) { var context = contexts[cls.pyHandle]; cls.Load(context); loadedObjs.Add(cls, context); } return(loadedObjs); }
internal static void SaveRuntimeData(RuntimeDataStorage storage) { Runtime.XIncref(PyCLRMetaType); storage.PushValue(PyCLRMetaType); }
internal static Dictionary <ManagedType, InterDomainContext> RestoreRuntimeData(RuntimeDataStorage storage) { cache = storage.GetValue <Dictionary <MaybeType, ClassBase> >("cache"); var invalidClasses = new List <KeyValuePair <MaybeType, ClassBase> >(); var contexts = storage.GetValue <Dictionary <IntPtr, InterDomainContext> >("contexts"); var loadedObjs = new Dictionary <ManagedType, InterDomainContext>(); foreach (var pair in cache) { if (!pair.Key.Valid) { invalidClasses.Add(pair); continue; } // Ensure, that matching Python type exists first. // It is required for self-referential classes // (e.g. with members, that refer to the same class) var pyType = InitPyType(pair.Key.Value, pair.Value); // re-init the class InitClassBase(pair.Key.Value, pair.Value, pyType); // We modified the Type object, notify it we did. Runtime.PyType_Modified(pair.Value.TypeReference); var context = contexts[pair.Value.pyHandle]; pair.Value.Load(context); var slotsHolder = TypeManager.GetSlotsHolder(pyType); pair.Value.InitializeSlots(slotsHolder); Runtime.PyType_Modified(pair.Value.TypeReference); loadedObjs.Add(pair.Value, context); } foreach (var pair in invalidClasses) { cache.Remove(pair.Key); Runtime.XDecref(pair.Value.pyHandle); } return(loadedObjs); }