• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rffi.llexternal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: external

def external(name, args, result):
    unsafe = rffi.llexternal(name, args, result,
                             compilation_info=CConfig._compilation_info_)
    safe = rffi.llexternal(name, args, result,
                           compilation_info=CConfig._compilation_info_,
                           sandboxsafe=True, threadsafe=False)
    return unsafe, safe
开发者ID:ieure,项目名称:pypy,代码行数:7,代码来源:rmmap.py


示例2: test_cancollect_external

def test_cancollect_external():
    fext1 = rffi.llexternal('fext1', [], lltype.Void, threadsafe=False)
    def g():
        fext1()
    t = rtype(g, [])
    gg = graphof(t, g)
    assert not CollectAnalyzer(t).analyze_direct_call(gg)

    fext2 = rffi.llexternal('fext2', [], lltype.Void, threadsafe=True)
    def g():
        fext2()
    t = rtype(g, [])
    gg = graphof(t, g)
    assert CollectAnalyzer(t).analyze_direct_call(gg)

    S = lltype.GcStruct('S', ('x', lltype.Signed))
    FUNC = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Void))
    fext3 = rffi.llexternal('fext3', [FUNC], lltype.Void, threadsafe=False)
    def h(x):
        lltype.malloc(S, zero=True)
    def g():
        fext3(h)
    t = rtype(g, [])
    gg = graphof(t, g)
    assert CollectAnalyzer(t).analyze_direct_call(gg)
开发者ID:alkorzt,项目名称:pypy,代码行数:25,代码来源:test_framework.py


示例3: test_different_signatures

 def test_different_signatures(self):
     fcntl_int = rffi.llexternal('fcntl', [rffi.INT, rffi.INT, rffi.INT],
                                 rffi.INT)
     fcntl_str = rffi.llexternal('fcntl', [rffi.INT, rffi.INT, rffi.CCHARP],
                                 rffi.INT)
     fcntl_int(12345, 1, 0)
     fcntl_str(12345, 3, "xxx")
     fcntl_int(12345, 1, 0)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:test_ll2ctypes.py


示例4: test_different_signatures

 def test_different_signatures(self):
     if sys.platform=='win32':
         py.test.skip("No fcntl on win32")
     fcntl_int = rffi.llexternal('fcntl', [rffi.INT, rffi.INT, rffi.INT],
                                 rffi.INT)
     fcntl_str = rffi.llexternal('fcntl', [rffi.INT, rffi.INT, rffi.CCHARP],
                                 rffi.INT)
     fcntl_int(12345, 1, 0)
     fcntl_str(12345, 3, "xxx")
     fcntl_int(12345, 1, 0)
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_ll2ctypes.py


示例5: test_llexternal_macro

 def test_llexternal_macro(self):
     eci = ExternalCompilationInfo(
         post_include_bits = ["#define fn(x) (42 + x)"],
     )
     fn1 = rffi.llexternal('fn', [rffi.INT], rffi.INT, 
                           compilation_info=eci, macro=True)
     fn2 = rffi.llexternal('fn2', [rffi.DOUBLE], rffi.DOUBLE, 
                           compilation_info=eci, macro='fn')
     res = fn1(10)
     assert res == 52
     res = fn2(10.5)
     assert res == 52.5
开发者ID:ieure,项目名称:pypy,代码行数:12,代码来源:test_ll2ctypes.py


示例6: test_opaque_obj_2

    def test_opaque_obj_2(self):
        FILEP = rffi.COpaquePtr('FILE')
        fopen = rffi.llexternal('fopen', [rffi.CCHARP, rffi.CCHARP], FILEP)
        fclose = rffi.llexternal('fclose', [FILEP], rffi.INT)
        tmppath = udir.join('test_ll2ctypes.test_opaque_obj_2')
        ll_file = fopen(str(tmppath), "w")
        assert ll_file
        fclose(ll_file)
        assert tmppath.check(file=1)
        assert not ALLOCATED     # detects memory leaks in the test

        assert rffi.cast(FILEP, -1) == rffi.cast(FILEP, -1)
开发者ID:ieure,项目名称:pypy,代码行数:12,代码来源:test_ll2ctypes.py


示例7: setup_init_functions

def setup_init_functions(eci):
    init_buffer = rffi.llexternal('init_bufferobject', [], lltype.Void, compilation_info=eci)
    init_pycobject = rffi.llexternal('init_pycobject', [], lltype.Void, compilation_info=eci)
    init_capsule = rffi.llexternal('init_capsule', [], lltype.Void, compilation_info=eci)
    INIT_FUNCTIONS.extend([
        lambda space: init_buffer(),
        lambda space: init_pycobject(),
        lambda space: init_capsule(),
    ])
    from pypy.module.posix.interp_posix import add_fork_hook
    reinit_tls = rffi.llexternal('PyThread_ReInitTLS', [], lltype.Void,
                                 compilation_info=eci)    
    add_fork_hook('child', reinit_tls)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:api.py


示例8: test_func_not_in_clib

def test_func_not_in_clib():
    foobar = rffi.llexternal('I_really_dont_exist', [], lltype.Signed)
    py.test.raises(NotImplementedError, foobar)

    foobar = rffi.llexternal('I_really_dont_exist', [], lltype.Signed,
                             libraries=['m'])    # math library
    py.test.raises(NotImplementedError, foobar)

    foobar = rffi.llexternal('I_really_dont_exist', [], lltype.Signed,
                             libraries=['m', 'z'])  # math and zlib libraries
    py.test.raises(NotImplementedError, foobar)

    foobar = rffi.llexternal('I_really_dont_exist', [], lltype.Signed,
                             libraries=['I_really_dont_exist_either'])
    py.test.raises(NotImplementedError, foobar)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:15,代码来源:test_ll2ctypes.py


示例9: install_dll

 def install_dll(self, eci):
     """NOT_RPYTHON
     Called when the dll has been compiled"""
     if sys.platform == 'win32':
         self.get_pythonapi_handle = rffi.llexternal(
             'pypy_get_pythonapi_handle', [], DLLHANDLE,
             compilation_info=eci)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:state.py


示例10: define_callback_simple

    def define_callback_simple(cls):
        import gc
        from pypy.rpython.lltypesystem import lltype, rffi
        from pypy.rpython.annlowlevel import llhelper
        from pypy.translator.tool.cbuild import ExternalCompilationInfo

        c_source = py.code.Source("""
        int mystuff(int(*cb)(int, int))
        {
            return cb(40, 2) + cb(3, 4);
        }
        """)
        eci = ExternalCompilationInfo(separate_module_sources=[c_source])
        S = lltype.GcStruct('S', ('x', lltype.Signed))
        CALLBACK = lltype.FuncType([lltype.Signed, lltype.Signed],
                                   lltype.Signed)
        z = rffi.llexternal('mystuff', [lltype.Ptr(CALLBACK)], lltype.Signed,
                            compilation_info=eci)

        def mycallback(a, b):
            gc.collect()
            return a + b

        def f():
            p = lltype.malloc(S)
            p.x = 100
            result = z(mycallback)
            return result * p.x

        return f
开发者ID:enyst,项目名称:plexnet,代码行数:30,代码来源:test_asmgcroot.py


示例11: test_llexternal

    def test_llexternal(self):
        from pypy.rpython.lltypesystem.rffi import llexternal
        from pypy.rpython.lltypesystem import lltype
        z = llexternal('z', [lltype.Signed], lltype.Signed)
        def f(x):
            return z(x)
        t, ra = self.translate(f, [int])
        fgraph = graphof(t, f)
        backend_optimizations(t)
        assert fgraph.startblock.operations[0].opname == 'direct_call'

        result = ra.can_raise(fgraph.startblock.operations[0])
        assert not result

        z = lltype.functionptr(lltype.FuncType([lltype.Signed], lltype.Signed),
                               'foobar')
        def g(x):
            return z(x)
        t, ra = self.translate(g, [int])
        ggraph = graphof(t, g)

        assert ggraph.startblock.operations[0].opname == 'direct_call'

        result = ra.can_raise(ggraph.startblock.operations[0])
        assert result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_canraise.py


示例12: test_llexternal_source

 def test_llexternal_source(self):
     eci = ExternalCompilationInfo(
         separate_module_sources = ["int fn() { return 42; }"]
     )
     fn = rffi.llexternal('fn', [], rffi.INT, compilation_info=eci)
     res = fn()
     assert res == 42
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:test_ll2ctypes.py


示例13: configure_boehm_once

    def configure_boehm_once(cls):
        """ Configure boehm only once, since we don't cache failures
        """
        if hasattr(cls, 'malloc_fn_ptr'):
            return cls.malloc_fn_ptr
        from pypy.rpython.tool import rffi_platform
        compilation_info = rffi_platform.configure_boehm()

        # Versions 6.x of libgc needs to use GC_local_malloc().
        # Versions 7.x of libgc removed this function; GC_malloc() has
        # the same behavior if libgc was compiled with
        # THREAD_LOCAL_ALLOC.
        class CConfig:
            _compilation_info_ = compilation_info
            HAS_LOCAL_MALLOC = rffi_platform.Has("GC_local_malloc")
        config = rffi_platform.configure(CConfig)
        if config['HAS_LOCAL_MALLOC']:
            GC_MALLOC = "GC_local_malloc"
        else:
            GC_MALLOC = "GC_malloc"
        malloc_fn_ptr = rffi.llexternal(GC_MALLOC,
                                        [lltype.Signed], # size_t, but good enough
                                        llmemory.GCREF,
                                        compilation_info=compilation_info,
                                        sandboxsafe=True,
                                        _nowrapper=True)
        cls.malloc_fn_ptr = malloc_fn_ptr
        cls.compilation_info = compilation_info
        return malloc_fn_ptr
开发者ID:craigkerstiens,项目名称:pypy,代码行数:29,代码来源:gc.py


示例14: test_qsort

    def test_qsort(self):
        CMPFUNC = lltype.FuncType([rffi.VOIDP, rffi.VOIDP], rffi.INT)
        qsort = rffi.llexternal('qsort', [rffi.VOIDP,
                                          rffi.SIZE_T,
                                          rffi.SIZE_T,
                                          lltype.Ptr(CMPFUNC)],
                                lltype.Void)

        lst = [23, 43, 24, 324, 242, 34, 78, 5, 3, 10]
        A = lltype.Array(lltype.Signed, hints={'nolength': True})
        a = lltype.malloc(A, 10, flavor='raw')
        for i in range(10):
            a[i] = lst[i]

        SIGNEDPTR = lltype.Ptr(lltype.FixedSizeArray(lltype.Signed, 1))

        def my_compar(p1, p2):
            p1 = rffi.cast(SIGNEDPTR, p1)
            p2 = rffi.cast(SIGNEDPTR, p2)
            print 'my_compar:', p1[0], p2[0]
            return rffi.cast(rffi.INT, cmp(p1[0], p2[0]))

        qsort(rffi.cast(rffi.VOIDP, a),
              rffi.cast(rffi.SIZE_T, 10),
              rffi.cast(rffi.SIZE_T, llmemory.sizeof(lltype.Signed)),
              llhelper(lltype.Ptr(CMPFUNC), my_compar))

        for i in range(10):
            print a[i],
        print
        lst.sort()
        for i in range(10):
            assert a[i] == lst[i]
        lltype.free(a, flavor='raw')
        assert not ALLOCATED     # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:35,代码来源:test_ll2ctypes.py


示例15: test_pass_around_t_object

    def test_pass_around_t_object(self):
        from pypy.rpython.annlowlevel import base_ptr_lltype
        T = base_ptr_lltype()
        
        class X(object):
            _TYPE = T
            x = 10

        def callback(x):
            return x.x

        c_source = py.code.Source("""
        int eating_callback(void *arg, int(*call)(int))
        {
            return call(arg);
        }
        """)

        eci = ExternalCompilationInfo(separate_module_sources=[c_source],
                                      export_symbols=['eating_callback'])

        args = [T, rffi.CCallback([T], rffi.INT)]
        eating_callback = rffi.llexternal('eating_callback', args, rffi.INT,
                                          compilation_info=eci)

        res = eating_callback(X(), callback)
        assert res == 10
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:27,代码来源:test_ll2ctypes.py


示例16: test_llexternal_with_callback

    def test_llexternal_with_callback(self):
        from pypy.rpython.lltypesystem.rffi import llexternal
        from pypy.rpython.lltypesystem import lltype

        class Abc:
            pass
        abc = Abc()

        FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
        z = llexternal('z', [lltype.Ptr(FUNC)], lltype.Signed)
        def g(n):
            abc.foobar = n
            return n + 1
        def f(x):
            return z(g)
        t, wa = self.translate(f, [int])
        fgraph = graphof(t, f)
        backend_optimizations(t)
        assert fgraph.startblock.operations[0].opname == 'direct_call'

        result = wa.analyze(fgraph.startblock.operations[0])
        assert len(result) == 1
        (struct, T, name), = result
        assert struct == "struct"
        assert name.endswith("foobar")
开发者ID:alkorzt,项目名称:pypy,代码行数:25,代码来源:test_writeanalyze.py


示例17: test_gcc_options

    def test_gcc_options(self):
        # check that the env var CC is correctly interpreted, even if
        # it contains the compiler name followed by some options.
        if sys.platform == 'win32':
            py.test.skip("only for gcc")

        from pypy.rpython.lltypesystem import lltype, rffi
        dir = udir.ensure('test_gcc_options', dir=1)
        dir.join('someextraheader.h').write('#define someextrafunc() 42\n')
        eci = ExternalCompilationInfo(includes=['someextraheader.h'])
        someextrafunc = rffi.llexternal('someextrafunc', [], lltype.Signed,
                                        compilation_info=eci)

        def entry_point(argv):
            return someextrafunc()

        old_cc = os.environ.get('CC')
        try:
            os.environ['CC'] = 'gcc -I%s' % dir
            t, cbuilder = self.compile(entry_point)
        finally:
            if old_cc is None:
                del os.environ['CC']
            else:
                os.environ['CC'] = old_cc
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_standalone.py


示例18: define_callback_simple

    def define_callback_simple(cls):
        c_source = py.code.Source("""
        int mystuff(int(*cb)(int, int))
        {
            return cb(40, 2) + cb(3, 4);
        }
        """)
        eci = ExternalCompilationInfo(separate_module_sources=[c_source])
        S = lltype.GcStruct('S', ('x', lltype.Signed))
        CALLBACK = lltype.FuncType([lltype.Signed, lltype.Signed],
                                   lltype.Signed)
        z = rffi.llexternal('mystuff', [lltype.Ptr(CALLBACK)], lltype.Signed,
                            compilation_info=eci)

        def mycallback(a, b):
            gc.collect()
            return a + b

        def f():
            p = lltype.malloc(S)
            p.x = 100
            result = z(mycallback)
            return result * p.x

        return f
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_asmgcroot.py


示例19: __init__

 def __init__(self, rtyper, stats=None, translate_support_code=False,
              annmixlevel=None, gcdescr=None):
     self.rtyper = rtyper
     self.translate_support_code = translate_support_code
     self.compiled_functions = []
     self.fail_ops = []
     self.in_out_args = []
     if translate_support_code:
         get_size = llmemory.sizeof
     else:
         get_size = rffi.sizeof
     self._arraydescrs = [
         ArrayDescr(get_size(llmemory.GCREF), self.SIZE_GCPTR),    # 0
         ArrayDescr(get_size(lltype.Signed),  self.SIZE_INT),      # 1
         ArrayDescr(get_size(lltype.Char),    self.SIZE_CHAR),     # 2
         ArrayDescr(get_size(lltype.UniChar), self.SIZE_UNICHAR),  # 3
         ]
     self._descr_caches = {}
     self.fielddescr_vtable = self.fielddescrof(rclass.OBJECT, 'typeptr')
     if sys.maxint == 2147483647:
         self.size_of_int = 4
     else:
         self.size_of_int = 8
     if runicode.MAXUNICODE > 0xffff:
         self.size_of_unicode = 4
     else:
         self.size_of_unicode = 2
     self.gcarray_gcref   = lltype.GcArray(llmemory.GCREF)
     self.gcarray_signed  = lltype.GcArray(lltype.Signed)
     self.gcarray_char    = lltype.GcArray(lltype.Char)
     self.gcarray_unichar = lltype.GcArray(lltype.UniChar)
     basesize, _, ofs_length = symbolic.get_array_token(
         self.gcarray_signed, self.translate_support_code)
     self.array_index_array = basesize
     self.array_index_length = ofs_length
     basesize, _, ofs_length = symbolic.get_array_token(
         rstr.STR, self.translate_support_code)
     self.string_index_array = basesize
     self.string_index_length = ofs_length
     basesize, _, ofs_length = symbolic.get_array_token(
         rstr.UNICODE, self.translate_support_code)
     self.unicode_index_array = basesize
     self.unicode_index_length = ofs_length
     self.vtable_descr = self.fielddescrof(rclass.OBJECT, 'typeptr')
     self._ovf_error_instance = self._get_prebuilt_error(OverflowError)
     self._zer_error_instance = self._get_prebuilt_error(ZeroDivisionError)
     #
     # temporary (Boehm only)
     from pypy.translator.tool.cbuild import ExternalCompilationInfo
     compilation_info = ExternalCompilationInfo(libraries=['gc'])
     self.malloc_fn_ptr = rffi.llexternal("GC_malloc",
                                          [rffi.SIZE_T],
                                          llmemory.GCREF,
                                          compilation_info=compilation_info,
                                          sandboxsafe=True,
                                          _nowrapper=True)
     assert rffi.sizeof(rffi.SIZE_T) == self.size_of_int
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:57,代码来源:runner.py


示例20: proc_func

 def proc_func(self, func):
     name = func.__name__
     arg_tps = [self.proc_tp(arg) for arg in func.argtypes]
     ll_item = rffi.llexternal(
         name, arg_tps,
         self.proc_tp(func.restype), 
         compilation_info=self.CConfig._compilation_info_)
     self.ns[name] = ll_item
     return ll_item
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:genrffi.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rffi.ptradd函数代码示例发布时间:2022-05-27
下一篇:
Python rffi.getintfield函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap