/// <summary> /// Copy Method /// </summary> /// /// <remarks> /// Returns a copy of the dictionary. /// </remarks> public PyDict Copy() { IntPtr op = Runtime.PyDict_Copy(obj); if (op == IntPtr.Zero) { throw new PythonException(); } return(new PyDict(op)); }
internal static IntPtr CreateSubType(IntPtr args) { IntPtr py_name = Runtime.PyTuple_GetItem(args, 0); IntPtr bases = Runtime.PyTuple_GetItem(args, 1); IntPtr dict = Runtime.PyTuple_GetItem(args, 2); IntPtr base_ = Runtime.PyTuple_GetItem(bases, 0); string name = Runtime.GetManagedString(py_name); IntPtr type = AllocateTypeObject(name); Marshal.WriteIntPtr(type, TypeOffset.ob_type, Runtime.PyCLRMetaType); Runtime.Incref(Runtime.PyCLRMetaType); Marshal.WriteIntPtr(type, TypeOffset.tp_basicsize, (IntPtr)obSize); Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, IntPtr.Zero); IntPtr offset = (IntPtr)ObjectOffset.ob_dict; Marshal.WriteIntPtr(type, TypeOffset.tp_dictoffset, offset); IntPtr dc = Runtime.PyDict_Copy(dict); Marshal.WriteIntPtr(type, TypeOffset.tp_dict, dc); Marshal.WriteIntPtr(type, TypeOffset.tp_base, base_); Runtime.Incref(base_); int flags = TypeFlags.Default; flags |= TypeFlags.Managed; flags |= TypeFlags.HeapType; flags |= TypeFlags.BaseType; flags |= TypeFlags.Subclass; flags |= TypeFlags.HaveGC; Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags); CopySlot(base_, type, TypeOffset.tp_traverse); CopySlot(base_, type, TypeOffset.tp_clear); CopySlot(base_, type, TypeOffset.tp_is_gc); Runtime.PyType_Ready(type); IntPtr tp_dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict); IntPtr mod = Runtime.PyString_FromString("CLR"); Runtime.PyDict_SetItemString(tp_dict, "__module__", mod); // for now, move up hidden handle... IntPtr gc = Marshal.ReadIntPtr(base_, TypeOffset.magic()); Marshal.WriteIntPtr(type, TypeOffset.magic(), gc); return(type); }