def MakeGetSetDef(name, get, set, doc, closure=IntPtr.Zero): deallocs = [] _get = IntPtr.Zero if get: getdgt = Ironclad.dgt_ptr_ptrptr(get) _get = Marshal.GetFunctionPointerForDelegate(getdgt) deallocs.append(GC_NotYet(getdgt)) _set = IntPtr.Zero if set: setdgt = Ironclad.dgt_int_ptrptrptr(set) _set = Marshal.GetFunctionPointerForDelegate(setdgt) deallocs.append(GC_NotYet(setdgt)) return new_PyGetSetDef(name, _get, _set, doc, closure), lambda: map(apply, deallocs)
def testFinalDecRefOfObjectWithTypeCalls_tp_dealloc(self, mapper, _): calls = [] def TypeDealloc(ptr): calls.append(ptr) deallocDgt = dgt_void_ptr(TypeDealloc) deallocFP = Marshal.GetFunctionPointerForDelegate(deallocDgt) typePtr = Marshal.AllocHGlobal(Marshal.SizeOf(PyTypeObject())) deallocPtr = CPyMarshal.Offset(typePtr, Marshal.OffsetOf(PyTypeObject, "tp_dealloc")) CPyMarshal.WritePtr(deallocPtr, deallocFP) obj = object() objPtr = mapper.Store(obj) CPyMarshal.WritePtrField(objPtr, PyObject, "ob_type", typePtr) mapper.IncRef(objPtr) mapper.DecRef(objPtr) self.assertEquals(calls, [], "called prematurely") mapper.DecRef(objPtr) self.assertEquals(calls, [objPtr], "not called when refcount hit 0")
def MangleCall(arg): return Marshal.GetFunctionPointerForDelegate( dgt_void_void(lambda: calls.append(arg)))
def MakeMethodDef(name, implementation, flags, doc="doc"): dgt = DELEGATE_TYPES[flags](implementation) return new_PyMethodDef(name, Marshal.GetFunctionPointerForDelegate(dgt), int(flags), doc), GC_NotYet(dgt)