예제 #1
0
 def do1():
     # see NOTE in interestingptrmaptest
     obj = object()
     ref = WeakReference(obj)
     CPyMarshal.WriteIntField(ptr, PyObject, "ob_refcnt", 1)
     CPyMarshal.WritePtrField(ptr, PyObject, "ob_type", mapper.PyBaseObject_Type)
     mapper.StoreBridge(ptr, obj)
     del obj
     return ref
예제 #2
0
        def do1():
            obj = object()
            ref = WeakReference(obj)
            # need to use same allocator as mapper, otherwise it gets upset on shutdown
            ptr = allocator.Alloc(Marshal.SizeOf(PyObject()))
            CPyMarshal.WriteIntField(ptr, PyObject, "ob_refcnt", 2)
            CPyMarshal.WritePtrField(ptr, PyObject, "ob_type", mapper.PyBaseObject_Type)
            mapper.StoreBridge(ptr, obj)

            # refcount > 1 means ref should have been strengthened
            del obj
            return ref, ptr
예제 #3
0
            def do():
                # see NOTE in interestingptrmaptest
                obj = object()
                ref = WeakReference(obj)
                CPyMarshal.WriteIntField(ptr, PyObject, "ob_refcnt", 1)
                CPyMarshal.WritePtrField(ptr, PyObject, "ob_type", mapper.PyBaseObject_Type)
                mapper.StoreBridge(ptr, obj)

                self.assertEquals(mapper.Retrieve(ptr), obj, "object not stored")
                self.assertEquals(mapper.Store(obj), ptr, "object not reverse-mapped")

                mapper.Weaken(obj)
                CPyMarshal.WriteIntField(ptr, PyObject, "ob_refcnt", 1)

                mapper.IncRef(ptr)
                del obj
                return ref
예제 #4
0
 def assertMaps(self, mapper, func, ptr, refcnt):
     func(ptr)
     obj = mapper.Retrieve(ptr)
     ref = WeakReference(obj)
     self.assertEquals(mapper.Store(obj), ptr)
     self.assertEquals(mapper.RefCount(ptr), refcnt)
     
     while mapper.RefCount(ptr) > 2:
         mapper.DecRef(ptr)
     del obj
     gcwait()
     self.assertEquals(ref.IsAlive, True)
     
     obj = ref.Target
     mapper.DecRef(ptr)
     del obj
     gcwait()
     self.assertEquals(ref.IsAlive, False)
예제 #5
0
 def getVars(self):
     obj = object()
     ptr = Marshal.AllocHGlobal(Marshal.SizeOf(PyObject()))
     CPyMarshal.WriteIntField(ptr, PyObject, 'ob_refcnt', 1)
     self.ptrs.append(ptr)
     return InterestingPtrMap(), ptr, obj, WeakReference(obj)