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


Python ll2ctypes.ctypes2lltype函数代码示例

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


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

示例1: 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

示例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_gcref_truth

    def test_gcref_truth(self):
        p0 = ctypes.c_void_p(0)
        ref0 = ctypes2lltype(llmemory.GCREF, p0)
        assert not ref0

        p1234 = ctypes.c_void_p(1234)
        ref1234 = ctypes2lltype(llmemory.GCREF, p1234)        
        assert p1234
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_ll2ctypes.py

示例4: 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

示例5: test_primitive

    def test_primitive(self):
        assert lltype2ctypes(5) == 5
        assert lltype2ctypes('?') == ord('?')
        assert lltype2ctypes('\xE0') == 0xE0
        assert lltype2ctypes(unichr(1234)) == 1234
        assert ctypes2lltype(lltype.Signed, 5) == 5
        assert ctypes2lltype(lltype.Char, ord('a')) == 'a'
        assert ctypes2lltype(lltype.UniChar, ord(u'x')) == u'x'
        assert ctypes2lltype(lltype.Char, 0xFF) == '\xFF'
        assert lltype2ctypes(5.25) == 5.25
        assert ctypes2lltype(lltype.Float, 5.25) == 5.25
        assert lltype2ctypes(u'x') == ord(u'x')
        res = lltype2ctypes(rffi.r_singlefloat(-3.5))
        assert isinstance(res, ctypes.c_float)
        assert res.value == -3.5
        res = ctypes2lltype(lltype.SingleFloat, ctypes.c_float(-3.5))
        assert isinstance(res, rffi.r_singlefloat)
        assert float(res) == -3.5
        assert lltype2ctypes(rffi.r_ulong(-1)) == sys.maxint * 2 + 1
        res = ctypes2lltype(lltype.Unsigned, sys.maxint * 2 + 1)
        assert (res, type(res)) == (rffi.r_ulong(-1), rffi.r_ulong)

        res = lltype2ctypes(llmemory.sizeof(lltype.Signed))
        assert res == struct.calcsize("l")
        S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
        res = lltype2ctypes(llmemory.sizeof(S))
        assert res == struct.calcsize("ll")

        p = lltype.nullptr(S)
        cptr = lltype2ctypes(p)
        assert not cptr
        py.test.raises(ValueError, 'cptr.contents')   # NULL pointer access
        res = ctypes2lltype(lltype.Ptr(S), cptr)
        assert res == p
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:35,代码来源:test_ll2ctypes.py

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: test_gcref_casts

    def test_gcref_casts(self):
        p0 = ctypes.c_void_p(0)
        ref0 = ctypes2lltype(llmemory.GCREF, p0)

        assert lltype.cast_ptr_to_int(ref0) == 0
        assert llmemory.cast_ptr_to_adr(ref0) == llmemory.NULL

        NODE = lltype.GcStruct('NODE')
        assert lltype.cast_opaque_ptr(lltype.Ptr(NODE), ref0) == lltype.nullptr(NODE)

        node = lltype.malloc(NODE)
        ref1 = lltype.cast_opaque_ptr(llmemory.GCREF, node)

        intval  = rffi.cast(lltype.Signed, node)
        intval1 = rffi.cast(lltype.Signed, ref1)

        assert intval == intval1

        ref2 = ctypes2lltype(llmemory.GCREF, intval1)

        assert lltype.cast_opaque_ptr(lltype.Ptr(NODE), ref2) == node
开发者ID:alkorzt,项目名称:pypy,代码行数:21,代码来源:test_ll2ctypes.py

示例11: test_indirect_recursive_struct_more

    def test_indirect_recursive_struct_more(self):
        NODE = lltype.ForwardReference()
        NODE2 = lltype.Struct('NODE2', ('ping', lltype.Ptr(NODE)))
        NODE.become(lltype.Struct('NODE', ('pong', NODE2)))

        # Building NODE2 first used to fail.
        get_ctypes_type(NODE2)

        CNODEPTR = get_ctypes_type(NODE)
        pc = CNODEPTR()
        pc.pong.ping = ctypes.pointer(pc)
        p = ctypes2lltype(lltype.Ptr(NODE), ctypes.pointer(pc))
        assert p.pong.ping == p
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_ll2ctypes.py

示例12: test_c_callback_with_void_arg_2

 def test_c_callback_with_void_arg_2(self):
     ftest = []
     def f(x):
         ftest.append(x)
     F = lltype.FuncType([lltype.Void], lltype.Void)
     fn = lltype.functionptr(F, 'askjh', _callable=f, _void0=-5)
     fn(-5)
     assert ftest == [-5]
     fn2 = lltype2ctypes(fn)
     fn2()
     assert ftest == [-5, -5]
     fn3 = ctypes2lltype(lltype.Ptr(F), fn2)
     fn3(-5)
     assert ftest == [-5, -5, -5]
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:test_ll2ctypes.py

示例13: test_recursive_struct_more

 def test_recursive_struct_more(self):
     NODE = lltype.ForwardReference()
     NODE.become(lltype.Struct('NODE', ('value', lltype.Signed),
                                       ('next', lltype.Ptr(NODE))))
     CNODEPTR = get_ctypes_type(NODE)
     pc = CNODEPTR()
     pc.value = 42
     pc.next = ctypes.pointer(pc)
     p = ctypes2lltype(lltype.Ptr(NODE), ctypes.pointer(pc))
     assert p.value == 42
     assert p.next == p
     pc2 = lltype2ctypes(p)
     assert pc2.contents.value == 42
     assert pc2.contents.next.contents.value == 42
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:test_ll2ctypes.py

示例14: 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

示例15: test_funcptr1

    def test_funcptr1(self):
        def dummy(n):
            return n+1

        FUNCTYPE = lltype.FuncType([lltype.Signed], lltype.Signed)
        cdummy = lltype2ctypes(llhelper(lltype.Ptr(FUNCTYPE), dummy))
        assert isinstance(cdummy,
                          ctypes.CFUNCTYPE(ctypes.c_long, ctypes.c_long))
        res = cdummy(41)
        assert res == 42
        lldummy = ctypes2lltype(lltype.Ptr(FUNCTYPE), cdummy)
        assert lltype.typeOf(lldummy) == lltype.Ptr(FUNCTYPE)
        res = lldummy(41)
        assert res == 42
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:15,代码来源:test_ll2ctypes.py


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