Beispiel #1
0
 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);
 }
Beispiel #2
0
 internal static void SaveRuntimeData(RuntimeDataStorage storage)
 {
     foreach (var tpHandle in cache.Values)
     {
         Runtime.XIncref(tpHandle);
     }
     storage.AddValue("cache", cache);
     storage.AddValue("slots", _slotsImpls);
 }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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);
            }
        }