PyObject_GC_UnTrack() private method

private PyObject_GC_UnTrack ( IntPtr tp ) : void
tp IntPtr
return void
示例#1
0
        public ExtensionType() : base()
        {
            // Create a new PyObject whose type is a generated type that is
            // implemented by the particuar concrete ExtensionType subclass.
            // The Python instance object is related to an instance of a
            // particular concrete subclass with a hidden CLR gchandle.

            IntPtr tp = TypeManager.GetTypeHandle(this.GetType());

//          int rc = (int)Marshal.ReadIntPtr(tp, TypeOffset.ob_refcnt);
//          if (rc > 1050) {
//          DebugUtil.Print("tp is: ", tp);
//          DebugUtil.DumpType(tp);
//          }

            IntPtr py = Runtime.PyType_GenericAlloc(tp, 0);

            GCHandle gc = GCHandle.Alloc(this);

            Marshal.WriteIntPtr(py, ObjectOffset.magic(), (IntPtr)gc);

            // We have to support gc because the type machinery makes it very
            // hard not to - but we really don't have a need for it in most
            // concrete extension types, so untrack the object to save calls
            // from Python into the managed runtime that are pure overhead.

            Runtime.PyObject_GC_UnTrack(py);

            this.tpHandle = tp;
            this.pyHandle = py;
            this.gcHandle = gc;
        }
示例#2
0
        /// <summary>
        /// Standard dealloc implementation for instances of reflected types.
        /// </summary>
        public static void tp_dealloc(IntPtr ob)
        {
            ManagedType self = GetManagedObject(ob);

            tp_clear(ob);
            Runtime.PyObject_GC_UnTrack(self.pyHandle);
            Runtime.PyObject_GC_Del(self.pyHandle);
            self.FreeGCHandle();
        }
示例#3
0
        public static void tp_dealloc(IntPtr ob)
        {
            ManagedType self = GetManagedObject(ob);
            IntPtr      dict = Marshal.ReadIntPtr(ob, ObjectOffset.ob_dict);

            Runtime.Decref(dict);
            Runtime.PyObject_GC_UnTrack(self.pyHandle);
            Runtime.PyObject_GC_Del(self.pyHandle);
            Runtime.Decref(self.tpHandle);
            self.gcHandle.Free();
        }
示例#4
0
        void SetupGc()
        {
            GCHandle gc = AllocGCHandle(TrackTypes.Extension);

            Marshal.WriteIntPtr(pyHandle, ObjectOffset.magic(tpHandle), (IntPtr)gc);

            // We have to support gc because the type machinery makes it very
            // hard not to - but we really don't have a need for it in most
            // concrete extension types, so untrack the object to save calls
            // from Python into the managed runtime that are pure overhead.

            Runtime.PyObject_GC_UnTrack(pyHandle);
        }
示例#5
0
        void SetupGc()
        {
            GCHandle gc = AllocGCHandle(TrackTypes.Extension);

            InitGCHandle(ObjectReference, TypeReference, gc);

            // We have to support gc because the type machinery makes it very
            // hard not to - but we really don't have a need for it in most
            // concrete extension types, so untrack the object to save calls
            // from Python into the managed runtime that are pure overhead.

            Runtime.PyObject_GC_UnTrack(pyHandle);
        }
示例#6
0
        new public static void tp_dealloc(IntPtr ob)
        {
            CLRObject self = (CLRObject)GetManagedObject(ob);

            // don't let the python GC destroy this object
            Runtime.PyObject_GC_UnTrack(self.pyHandle);

            // The python should now have a ref count of 0, but we don't actually want to
            // deallocate the object until the C# object that references it is destroyed.
            // So we don't call PyObject_GC_Del here and instead we set the python
            // reference to a weak reference so that the C# object can be collected.
            GCHandle gc = GCHandle.Alloc(self, GCHandleType.Weak);

            Marshal.WriteIntPtr(self.pyHandle, ObjectOffset.magic(self.tpHandle), (IntPtr)gc);
            self.gcHandle.Free();
            self.gcHandle = gc;
        }
示例#7
0
        public new static void tp_dealloc(IntPtr ob)
        {
            var self = (CLRObject)GetManagedObject(ob);

            // don't let the python GC destroy this object
            Runtime.PyObject_GC_UnTrack(self.pyHandle);

            // The python should now have a ref count of 0, but we don't actually want to
            // deallocate the object until the C# object that references it is destroyed.
            // So we don't call PyObject_GC_Del here and instead we set the python
            // reference to a weak reference so that the C# object can be collected.
            GCHandle gc = GCHandle.Alloc(self, GCHandleType.Weak);

            Debug.Assert(self.TypeReference == Runtime.PyObject_TYPE(self.ObjectReference));
            SetGCHandle(self.ObjectReference, self.TypeReference, gc);
            self.gcHandle.Free();
            self.gcHandle = gc;
        }
示例#8
0
        public new static void tp_dealloc(NewReference ob)
        {
            var self = (CLRObject?)GetManagedObject(ob.Borrow());

            // don't let the python GC destroy this object
            Runtime.PyObject_GC_UnTrack(ob.Borrow());

            // self may be null after Shutdown begun
            if (self is not null)
            {
                // The python should now have a ref count of 0, but we don't actually want to
                // deallocate the object until the C# object that references it is destroyed.
                // So we don't call PyObject_GC_Del here and instead we set the python
                // reference to a weak reference so that the C# object can be collected.
                GCHandle oldHandle = GetGCHandle(ob.Borrow());
                GCHandle gc        = GCHandle.Alloc(self, GCHandleType.Weak);
                SetGCHandle(ob.Borrow(), gc);
                oldHandle.Free();
            }
        }