当前位置: 首页>>代码示例>>Python>>正文


Python ll2ctypes.lltype2ctypes函数代码示例

本文整理汇总了Python中pypy.rpython.lltypesystem.ll2ctypes.lltype2ctypes函数的典型用法代码示例。如果您正苦于以下问题:Python lltype2ctypes函数的具体用法?Python lltype2ctypes怎么用?Python lltype2ctypes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了lltype2ctypes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_array_type_bug

 def test_array_type_bug(self):
     A = lltype.Array(lltype.Signed)
     a1 = lltype.malloc(A, 0, flavor='raw')
     a2 = lltype.malloc(A, 0, flavor='raw')
     c1 = lltype2ctypes(a1)
     c2 = lltype2ctypes(a2)
     assert type(c1) is type(c2)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:test_ll2ctypes.py

示例2: test_primitive

def test_primitive():
    assert lltype2ctypes(5) == 5
    assert lltype2ctypes('?') == ord('?')
    assert lltype2ctypes('\xE0') == 0xE0
    assert ctypes2lltype(lltype.Signed, 5) == 5
    assert ctypes2lltype(lltype.Char, ord('a')) == 'a'
    assert ctypes2lltype(lltype.Char, 0xFF) == '\xFF'
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_ll2ctypes.py

示例3: test_recursive_struct

 def test_recursive_struct(self):
     SX = lltype.ForwardReference()
     S1 = lltype.Struct('S1', ('p', lltype.Ptr(SX)), ('x', lltype.Signed))
     SX.become(S1)
     # a chained list
     s1 = lltype.malloc(S1, flavor='raw')
     s2 = lltype.malloc(S1, flavor='raw')
     s3 = lltype.malloc(S1, flavor='raw')
     s1.x = 111
     s2.x = 222
     s3.x = 333
     s1.p = s2
     s2.p = s3
     s3.p = lltype.nullptr(S1)
     sc1 = lltype2ctypes(s1)
     sc2 = sc1.contents.p
     sc3 = sc2.contents.p
     assert not sc3.contents.p
     assert sc1.contents.x == 111
     assert sc2.contents.x == 222
     assert sc3.contents.x == 333
     sc3.contents.x += 1
     assert s3.x == 334
     s3.x += 2
     assert sc3.contents.x == 336
     lltype.free(s1, flavor='raw')
     lltype.free(s2, flavor='raw')
     lltype.free(s3, flavor='raw')
     # a self-cycle
     s1 = lltype.malloc(S1, flavor='raw')
     s1.x = 12
     s1.p = s1
     sc1 = lltype2ctypes(s1)
     assert sc1.contents.x == 12
     assert (ctypes.addressof(sc1.contents.p.contents) ==
             ctypes.addressof(sc1.contents))
     s1.x *= 5
     assert sc1.contents.p.contents.p.contents.p.contents.x == 60
     lltype.free(s1, flavor='raw')
     # a longer cycle
     s1 = lltype.malloc(S1, flavor='raw')
     s2 = lltype.malloc(S1, flavor='raw')
     s1.x = 111
     s1.p = s2
     s2.x = 222
     s2.p = s1
     sc1 = lltype2ctypes(s1)
     assert sc1.contents.x == 111
     assert sc1.contents.p.contents.x == 222
     assert (ctypes.addressof(sc1.contents.p.contents) !=
             ctypes.addressof(sc1.contents))
     assert (ctypes.addressof(sc1.contents.p.contents.p.contents) ==
             ctypes.addressof(sc1.contents))
     lltype.free(s1, flavor='raw')
     lltype.free(s2, flavor='raw')
     assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:56,代码来源:test_ll2ctypes.py

示例4: test_array_type_bug

 def test_array_type_bug(self):
     A = lltype.Array(lltype.Signed)
     a1 = lltype.malloc(A, 0, flavor='raw')
     a2 = lltype.malloc(A, 0, flavor='raw')
     c1 = lltype2ctypes(a1)
     c2 = lltype2ctypes(a2)
     assert type(c1) is type(c2)
     lltype.free(a1, flavor='raw')
     lltype.free(a2, flavor='raw')
     assert not ALLOCATED     # detects memory leaks in the test
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_ll2ctypes.py

示例5: test_convert_subarray

    def test_convert_subarray(self):
        A = lltype.GcArray(lltype.Signed)
        a = lltype.malloc(A, 20)
        inside = lltype.direct_ptradd(lltype.direct_arrayitems(a), 3)
 
        lltype2ctypes(inside)

        start = rffi.cast(lltype.Signed, lltype.direct_arrayitems(a))
        inside_int = rffi.cast(lltype.Signed, inside)

        assert inside_int == start+rffi.sizeof(lltype.Signed)*3
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_ll2ctypes.py

示例6: test_funcptr2

 def test_funcptr2(self):
     FUNCTYPE = lltype.FuncType([rffi.CCHARP], lltype.Signed)
     cstrlen = standard_c_lib.strlen
     llstrlen = ctypes2lltype(lltype.Ptr(FUNCTYPE), cstrlen)
     assert lltype.typeOf(llstrlen) == lltype.Ptr(FUNCTYPE)
     p = rffi.str2charp("hi there")
     res = llstrlen(p)
     assert res == 8
     cstrlen2 = lltype2ctypes(llstrlen)
     cp = lltype2ctypes(p)
     assert cstrlen2.restype == ctypes.c_long
     res = cstrlen2(cp)
     assert res == 8
     rffi.free_charp(p)
     assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:15,代码来源:test_ll2ctypes.py

示例7: test_substructures

    def test_substructures(self):
        S1  = lltype.Struct('S1', ('x', lltype.Signed))
        BIG = lltype.Struct('BIG', ('s1a', S1), ('s1b', S1))
        s = lltype.malloc(BIG, flavor='raw')
        s.s1a.x = 123
        s.s1b.x = 456
        sc = lltype2ctypes(s)
        assert sc.contents.s1a.x == 123
        assert sc.contents.s1b.x == 456
        sc.contents.s1a.x += 1
        sc.contents.s1b.x += 10
        assert s.s1a.x == 124
        assert s.s1b.x == 466
        s.s1a.x += 3
        s.s1b.x += 30
        assert sc.contents.s1a.x == 127
        assert sc.contents.s1b.x == 496
        lltype.free(s, flavor='raw')

        s = lltype.malloc(BIG, flavor='raw')
        s1ac = lltype2ctypes(s.s1a)
        s1ac.contents.x = 53
        sc = lltype2ctypes(s)
        assert sc.contents.s1a.x == 53
        sc.contents.s1a.x += 1
        assert s1ac.contents.x == 54
        assert s.s1a.x == 54
        s.s1a.x += 2
        assert s1ac.contents.x == 56
        assert sc.contents.s1a.x == 56
        sc.contents.s1a.x += 3
        assert s1ac.contents.x == 59
        assert s.s1a.x == 59

        t = ctypes2lltype(lltype.Ptr(BIG), sc)
        assert t == s
        assert t.s1a == s.s1a
        assert t.s1a.x == 59
        s.s1b.x = 8888
        assert t.s1b == s.s1b
        assert t.s1b.x == 8888
        t1 = ctypes2lltype(lltype.Ptr(S1), s1ac)
        assert t.s1a == t1
        assert t1.x == 59
        t1.x += 1
        assert sc.contents.s1a.x == 60
        lltype.free(s, flavor='raw')
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:48,代码来源:test_ll2ctypes.py

示例8: test_uninitialized2ctypes

    def test_uninitialized2ctypes(self):
        # for now, uninitialized fields are filled with 0xDD in the ctypes data
        def checkobj(o, size):
            p = ctypes.cast(ctypes.c_void_p(ctypes.addressof(o)),
                            ctypes.POINTER(ctypes.c_ubyte*size))
            for i in range(size):
                assert p.contents[i] == 0xDD

        def checkval(v, fmt):
            res = struct.pack(fmt, v)
            assert res == "\xDD" * len(res)

        checkval(uninitialized2ctypes(rffi.CHAR), 'B')
        checkval(uninitialized2ctypes(rffi.SHORT), 'h')
        checkval(uninitialized2ctypes(rffi.INT), 'i')
        checkval(uninitialized2ctypes(rffi.UINT), 'I')
        checkval(uninitialized2ctypes(rffi.LONGLONG), 'q')
        checkval(uninitialized2ctypes(rffi.DOUBLE), 'd')
        checkobj(uninitialized2ctypes(rffi.INTP),
                 ctypes.sizeof(ctypes.c_void_p))
        checkobj(uninitialized2ctypes(rffi.CCHARP),
                 ctypes.sizeof(ctypes.c_void_p))

        S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
        s = lltype.malloc(S, flavor='raw')
        sc = lltype2ctypes(s)
        checkval(sc.contents.x, 'l')
        checkval(sc.contents.y, 'l')
        lltype.free(s, flavor='raw')
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:30,代码来源:test_ll2ctypes.py

示例9: test_arrayofstruct

 def test_arrayofstruct(self):
     S1 = lltype.Struct('S1', ('x', lltype.Signed))
     A = lltype.Array(S1, hints={'nolength': True})
     a = lltype.malloc(A, 5, flavor='raw')
     a[0].x = 100
     a[1].x = 101
     a[2].x = 102
     a[3].x = 103
     a[4].x = 104
     ac = lltype2ctypes(a, normalize=False)
     assert ac.contents.items[0].x == 100
     assert ac.contents.items[2].x == 102
     ac.contents.items[3].x += 500
     assert a[3].x == 603
     a[4].x += 600
     assert ac.contents.items[4].x == 704
     a1 = ctypes2lltype(lltype.Ptr(A), ac)
     assert a1 == a
     assert a1[2].x == 102
     aitem1 = ctypes2lltype(lltype.Ptr(S1),
                            ctypes.pointer(ac.contents.items[1]))
     assert aitem1.x == 101
     assert aitem1 == a1[1]
     lltype.free(a, flavor='raw')
     assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:25,代码来源:test_ll2ctypes.py

示例10: test_forced_ptr_cast

    def test_forced_ptr_cast(self):
        import array
        A = lltype.Array(lltype.Signed, hints={'nolength': True})
        B = lltype.Array(lltype.Char, hints={'nolength': True})
        a = lltype.malloc(A, 10, flavor='raw')
        for i in range(10):
            a[i] = i*i

        b = rffi.cast(lltype.Ptr(B), a)

        checker = array.array('l')
        for i in range(10):
            checker.append(i*i)
        expected = checker.tostring()

        for i in range(len(expected)):
            assert b[i] == expected[i]

        c = rffi.cast(rffi.VOIDP, a)
        addr = lltype2ctypes(c)
        #assert addr == ctypes.addressof(a._obj._ctypes_storage)
        d = ctypes2lltype(rffi.VOIDP, addr)
        assert lltype.typeOf(d) == rffi.VOIDP
        assert c == d
        e = rffi.cast(lltype.Ptr(A), d)
        for i in range(10):
            assert e[i] == i*i

        c = lltype.nullptr(rffi.VOIDP.TO)
        addr = rffi.cast(lltype.Signed, c)
        assert addr == 0

        lltype.free(a, flavor='raw')
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:34,代码来源:test_ll2ctypes.py

示例11: test_storage_stays_around

 def test_storage_stays_around(self):
     data = "hello, world!" * 100
     A = lltype.Array(rffi.CHAR, hints={'nolength': True})
     S = lltype.Struct('S', ('a', lltype.Ptr(A)))
     s = lltype.malloc(S, flavor='raw')
     lltype2ctypes(s)     # force it to escape
     s.a = lltype.malloc(A, len(data), flavor='raw')
     # the storage for the array should not be freed by lltype even
     # though the _ptr object appears to go away here
     for i in xrange(len(data)):
         s.a[i] = data[i]
     for i in xrange(len(data)):
         assert s.a[i] == data[i]
     lltype.free(s.a, flavor='raw')
     lltype.free(s, flavor='raw')
     assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:16,代码来源:test_ll2ctypes.py

示例12: test_cstruct_to_ll

def test_cstruct_to_ll():
    S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
    s = lltype.malloc(S, flavor='raw')
    s2 = lltype.malloc(S, flavor='raw')
    s.x = 123
    sc = lltype2ctypes(s)
    t = ctypes2lltype(lltype.Ptr(S), sc)
    assert lltype.typeOf(t) == lltype.Ptr(S)
    assert s == t
    assert not (s != t)
    assert t == s
    assert not (t != s)
    assert t != lltype.nullptr(S)
    assert not (t == lltype.nullptr(S))
    assert lltype.nullptr(S) != t
    assert not (lltype.nullptr(S) == t)
    assert t != s2
    assert not (t == s2)
    assert s2 != t
    assert not (s2 == t)
    assert t.x == 123
    t.x += 1
    assert s.x == 124
    s.x += 1
    assert t.x == 125
    lltype.free(s, flavor='raw')
    lltype.free(s2, flavor='raw')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:27,代码来源:test_ll2ctypes.py

示例13: test_carray_to_ll

def test_carray_to_ll():
    A = lltype.Array(lltype.Signed, hints={'nolength': True})
    a = lltype.malloc(A, 10, flavor='raw')
    a2 = lltype.malloc(A, 10, flavor='raw')
    a[0] = 100
    a[1] = 101
    a[2] = 110
    ac = lltype2ctypes(a)
    b = ctypes2lltype(lltype.Ptr(A), ac)
    assert lltype.typeOf(b) == lltype.Ptr(A)
    assert b == a
    assert not (b != a)
    assert a == b
    assert not (a != b)
    assert b != lltype.nullptr(A)
    assert not (b == lltype.nullptr(A))
    assert lltype.nullptr(A) != b
    assert not (lltype.nullptr(A) == b)
    assert b != a2
    assert not (b == a2)
    assert a2 != b
    assert not (a2 == b)
    assert b[2] == 110
    b[2] *= 2
    assert a[2] == 220
    a[2] *= 3
    assert b[2] == 660
    lltype.free(a, flavor='raw')
    lltype.free(a2, flavor='raw')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:test_ll2ctypes.py

示例14: test_gcref_forth_and_back

 def test_gcref_forth_and_back(self):
     cp = ctypes.c_void_p(1234)
     v = ctypes2lltype(llmemory.GCREF, cp)
     assert lltype2ctypes(v).value == cp.value
     v1 = ctypes2lltype(llmemory.GCREF, cp)
     assert v == v1
     assert v
     v2 = ctypes2lltype(llmemory.GCREF, ctypes.c_void_p(1235))
     assert v2 != v
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ll2ctypes.py

示例15: test_prebuilt_ll2ctypes_array

    def test_prebuilt_ll2ctypes_array(self):
        from pypy.rpython.lltypesystem import rffi, ll2ctypes
        A = rffi.CArray(Char)
        a = malloc(A, 6, flavor='raw')
        a[0] = 'a'
        a[1] = 'b'
        a[2] = 'c'
        a[3] = 'd'
        a[4] = '\x00'
        a[5] = '\x00'
        # side effects when converting to c structure
        ll2ctypes.lltype2ctypes(a)
        def llf():
            s = ''
            for i in range(4):
                s += a[i]
            return 'abcd' == s

        fn = self.getcompiled(llf)
        assert fn()
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:20,代码来源:test_lltyped.py


注:本文中的pypy.rpython.lltypesystem.ll2ctypes.lltype2ctypes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。