예제 #1
0
    def testReadDouble(self):
        data = Marshal.AllocHGlobal(CPyMarshal.DoubleSize)

        doubleStruct = DoubleStruct(2.2e22)
        Marshal.StructureToPtr(doubleStruct, data, False)
        self.assertEquals(CPyMarshal.ReadDouble(data), 2.2e22)

        Marshal.FreeHGlobal(data)
예제 #2
0
파일: cpython.py 프로젝트: slozier/ironclad
def MakeItemsTablePtr(items):
    if not items:
        return IntPtr.Zero, lambda: None
    itemtype = items[0].__class__
    typesize = Marshal.SizeOf(itemtype())
    size = typesize * (len(items) + 1)
    
    tablePtr = Marshal.AllocHGlobal(size)
    CPyMarshal.Zero(tablePtr, size)
    for i, item in enumerate(items):
        Marshal.StructureToPtr(item, OffsetPtr(tablePtr, typesize * i), False)

    def dealloc():
        Marshal.DestroyStructure(tablePtr, itemtype)
        Marshal.FreeHGlobal(tablePtr)
    return tablePtr, dealloc