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

Python gateway.interp2app函数代码示例

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

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



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

示例1: setup_class

    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit',))
        cls.space = space
        w_f = space.appexec([], """():
        def f():
            pass
        return f
        """)
        ll_code = cast_instance_to_base_ptr(w_f.code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2]
        i3 = int_add(i1, i2)
        guard_true(i3) []
        """, namespace={'ptr0': 3}).operations

        def interp_on_compile():
            pypyjitdriver.on_compile(logger, LoopToken(), oplist, 'loop',
                                     0, False, ll_code)

        def interp_on_compile_bridge():
            pypyjitdriver.on_compile_bridge(logger, LoopToken(), oplist, 0)
        
        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
开发者ID:pombredanne,项目名称:pypy,代码行数:28,代码来源:test_jit_hook.py


示例2: setup_class

 def setup_class(cls):
     cls.space = gettestobjspace(**{"objspace.std.withcelldict": True})
     cls.w_impl_used = cls.space.appexec([], """():
         import __pypy__
         def impl_used(obj):
             assert "ModuleDictImplementation" in __pypy__.internal_repr(obj)
         return impl_used
     """)
     def is_in_cache(space, w_code, w_globals, w_name):
         name = space.str_w(w_name)
         cache = get_global_cache(space, w_code, w_globals)
         index = [space.str_w(w_n) for w_n in w_code.co_names_w].index(name)
         return space.wrap(cache[index].w_value is not None)
     is_in_cache = gateway.interp2app(is_in_cache)
     cls.w_is_in_cache = cls.space.wrap(is_in_cache) 
     stored_builtins = []
     def rescue_builtins(space):
         w_dict = space.builtin.getdict()
         content = {}
         for key, cell in w_dict.implementation.content.iteritems():
             newcell = ModuleCell()
             newcell.w_value = cell.w_value
             content[key] = newcell
         stored_builtins.append(content)
     rescue_builtins = gateway.interp2app(rescue_builtins)
     cls.w_rescue_builtins = cls.space.wrap(rescue_builtins) 
     def restore_builtins(space):
         w_dict = space.builtin.getdict()
         if not isinstance(w_dict.implementation, ModuleDictImplementation):
             w_dict.implementation = ModuleDictImplementation(space)
         w_dict.implementation.content = stored_builtins.pop()
     restore_builtins = gateway.interp2app(restore_builtins)
     cls.w_restore_builtins = cls.space.wrap(restore_builtins) 
开发者ID:enyst,项目名称:plexnet,代码行数:33,代码来源:test_celldict.py


示例3: test_interp2app_unwrap_spec_c_int

    def test_interp2app_unwrap_spec_c_int(self):
        from rpython.rlib.rarithmetic import r_longlong

        space = self.space
        w = space.wrap

        def g(space, x):
            return space.wrap(x + 6)

        app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "c_int"])
        app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "c_uint"])
        app_ng = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "c_nonnegint"])
        assert app_ug is not app_g
        w_app_g = space.wrap(app_g)
        w_app_ug = space.wrap(app_ug)
        w_app_ng = space.wrap(app_ng)
        #
        assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)), space.wrap(13))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_g, space.wrap(r_longlong(0x80000000)))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_g, space.wrap(r_longlong(-0x80000001)))
        #
        assert self.space.eq_w(space.call_function(w_app_ug, space.wrap(7)), space.wrap(13))
        assert self.space.eq_w(
            space.call_function(w_app_ug, space.wrap(0x7FFFFFFF)), space.wrap(r_longlong(0x7FFFFFFF + 6))
        )
        space.raises_w(space.w_ValueError, space.call_function, w_app_ug, space.wrap(-1))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_ug, space.wrap(r_longlong(0x100000000)))
        #
        assert self.space.eq_w(space.call_function(w_app_ng, space.wrap(7)), space.wrap(13))
        space.raises_w(space.w_OverflowError, space.call_function, w_app_ng, space.wrap(r_longlong(0x80000000)))
        space.raises_w(space.w_ValueError, space.call_function, w_app_ng, space.wrap(-1))
开发者ID:Qointum,项目名称:pypy,代码行数:31,代码来源:test_gateway.py


示例4: _attach_helpers

def _attach_helpers(space):
    from pypy.interpreter import pytraceback

    def hide_top_frame(space, w_frame):
        w_last = None
        while w_frame.f_backref():
            w_last = w_frame
            w_frame = w_frame.f_backref()
        assert w_last
        w_saved = w_last.f_backref()
        w_last.f_backref = vref_None
        return w_saved

    def restore_top_frame(space, w_frame, w_saved):
        while w_frame.f_backref():
            w_frame = w_frame.f_backref()
        w_frame.f_backref = non_virtual_ref(w_saved)

    def read_exc_type(space, w_frame):
        if w_frame.last_exception is None:
            return space.w_None
        else:
            return w_frame.last_exception.w_type

    from pypy.interpreter import gateway

    hide_gw = gateway.interp2app(hide_top_frame)
    space.setitem(space.builtin.w_dict, space.wrap("hide_top_frame"), space.wrap(hide_gw))
    restore_gw = gateway.interp2app(restore_top_frame)
    space.setitem(space.builtin.w_dict, space.wrap("restore_top_frame"), space.wrap(restore_gw))

    read_exc_type_gw = gateway.interp2app(read_exc_type)
    space.setitem(space.builtin.w_dict, space.wrap("read_exc_type"), space.wrap(read_exc_type_gw))
开发者ID:GaussDing,项目名称:pypy,代码行数:33,代码来源:test_zzpickle_and_slow.py


示例5: setup_class

    def setup_class(cls):
        cls.w_TEXT = cls.space.wrapbytes(TEXT)
        cls.DATA = DATA
        cls.w_DATA = cls.space.wrapbytes(DATA)
        cls.DATA_CRLF = DATA_CRLF
        cls.w_DATA_CRLF = cls.space.wrapbytes(DATA_CRLF)
        cls.temppath = str(py.test.ensuretemp("bz2").join("foo"))
        cls.w_temppath = cls.space.wrap(cls.temppath)
        if cls.runappdirect:
            cls.w_create_temp_file = create_temp_file
            cls.w_create_broken_temp_file = create_broken_temp_file
            cls.w_decompress = decompress
        else:
            @gateway.unwrap_spec(crlf=bool)
            def create_temp_file_w(crlf=False):
                create_temp_file(cls, crlf)
            cls.w_create_temp_file = cls.space.wrap(
                gateway.interp2app(create_temp_file_w))

            @gateway.unwrap_spec(data=bytes)
            def decompress_w(space, data):
                return space.wrapbytes(decompress(cls, data))
            cls.w_decompress = cls.space.wrap(gateway.interp2app(decompress_w))

            def create_broken_temp_file_w():
                create_broken_temp_file(cls)
            cls.w_create_broken_temp_file = cls.space.wrap(
                gateway.interp2app(create_broken_temp_file_w))
        cls.w_random_data = cls.space.wrapbytes(RANDOM_DATA)
开发者ID:Qointum,项目名称:pypy,代码行数:29,代码来源:test_bz2_file.py


示例6: setup_class

    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Can't run this test with -A")
        space = gettestobjspace(usemodules=('pypyjit',))
        cls.space = space
        w_f = space.appexec([], """():
        def function():
            pass
        return function
        """)
        cls.w_f = w_f
        ll_code = cast_instance_to_base_ptr(w_f.code)
        code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2, p2]
        i3 = int_add(i1, i2)
        debug_merge_point(0, 0, 0, 0, 0, ConstPtr(ptr0))
        guard_nonnull(p2) []
        guard_true(i3) []
        """, namespace={'ptr0': code_gcref}).operations
        greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)]
        offset = {}
        for i, op in enumerate(oplist):
            if i != 1:
               offset[op] = i

        di_loop = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                               oplist, 'loop', greenkey)
        di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                        oplist, 'loop', greenkey)
        di_loop.asminfo = AsmInfo(offset, 0, 0)
        di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                 oplist, 'bridge', fail_descr_no=0)
        di_bridge.asminfo = AsmInfo(offset, 0, 0)

        def interp_on_compile():
            di_loop.oplist = cls.oplist
            pypy_hooks.after_compile(di_loop)

        def interp_on_compile_bridge():
            pypy_hooks.after_compile_bridge(di_bridge)

        def interp_on_optimize():
            di_loop_optimize.oplist = cls.oplist
            pypy_hooks.before_compile(di_loop_optimize)

        def interp_on_abort():
            pypy_hooks.on_abort(ABORT_TOO_LONG, pypyjitdriver, greenkey,
                                'blah')

        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
        cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
        cls.w_int_add_num = space.wrap(rop.INT_ADD)
        cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT)
        cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
        cls.orig_oplist = oplist
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:test_jit_hook.py


示例7: create_builder

def create_builder(name, strtype, builder_cls):
    class W_Builder(W_Root):
        def __init__(self, space, size):
            if size < 0:
                self.builder = builder_cls()
            else:
                self.builder = builder_cls(size)

        def _check_done(self, space):
            if self.builder is None:
                raise OperationError(space.w_ValueError, space.wrap(
                        "Can't operate on a built builder"))

        @unwrap_spec(size=int)
        def descr__new__(space, w_subtype, size=-1):
            return W_Builder(space, size)

        @unwrap_spec(s=strtype)
        def descr_append(self, space, s):
            self._check_done(space)
            self.builder.append(s)

        @unwrap_spec(s=strtype, start=int, end=int)
        def descr_append_slice(self, space, s, start, end):
            self._check_done(space)
            if not 0 <= start <= end <= len(s):
                raise OperationError(space.w_ValueError, space.wrap(
                        "bad start/stop"))
            self.builder.append_slice(s, start, end)

        def descr_build(self, space):
            self._check_done(space)
            s = self.builder.build()
            self.builder = None
            if strtype is str:
                return space.wrapbytes(s)
            else:
                return space.wrap(s)

        def descr_len(self, space):
            if self.builder is None:
                raise OperationError(space.w_ValueError, space.wrap(
                        "no length of built builder"))
            return space.wrap(self.builder.getlength())

    W_Builder.__name__ = "W_%s" % name
    W_Builder.typedef = TypeDef(name,
        __new__ = interp2app(func_with_new_name(
                                    W_Builder.descr__new__.im_func,
                                    '%s_new' % (name,))),
        append = interp2app(W_Builder.descr_append),
        append_slice = interp2app(W_Builder.descr_append_slice),
        build = interp2app(W_Builder.descr_build),
        __len__ = interp2app(W_Builder.descr_len),
    )
    W_Builder.typedef.acceptable_as_base_class = False
    return W_Builder
开发者ID:Qointum,项目名称:pypy,代码行数:57,代码来源:interp_builders.py


示例8: test_interp2app_unwrap_spec_bool

 def test_interp2app_unwrap_spec_bool(self):
     space = self.space
     w = space.wrap
     def g(space, b):
         return space.wrap(b)
     app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, bool])
     app_g2 = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, bool])
     assert app_g is app_g2
     w_app_g = space.wrap(app_g)
     assert self.space.eq_w(space.call_function(w_app_g, space.wrap(True)),
                            space.wrap(True))
开发者ID:enyst,项目名称:plexnet,代码行数:11,代码来源:test_gateway.py


示例9: test_caching_methods

    def test_caching_methods(self):
        class Base(gateway.Wrappable):
            def f(self):
                return 1

        class A(Base):
            pass
        class B(Base):
            pass
        app_A = gateway.interp2app(A.f)
        app_B = gateway.interp2app(B.f)
        assert app_A is not app_B
开发者ID:enyst,项目名称:plexnet,代码行数:12,代码来源:test_gateway.py


示例10: test_interp2app_unwrap_spec_nonnegint

    def test_interp2app_unwrap_spec_nonnegint(self):
        space = self.space
        w = space.wrap

        def g(space, x):
            return space.wrap(x * 6)

        app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "nonnegint"])
        app_g2 = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, "nonnegint"])
        assert app_g is app_g2
        w_app_g = space.wrap(app_g)
        assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)), space.wrap(42))
        assert self.space.eq_w(space.call_function(w_app_g, space.wrap(0)), space.wrap(0))
        space.raises_w(space.w_ValueError, space.call_function, w_app_g, space.wrap(-1))
开发者ID:Qointum,项目名称:pypy,代码行数:14,代码来源:test_gateway.py


示例11: setup_class

 def setup_class(cls):
     cls.w_TEXT = cls.space.wrap(TEXT)
     cls.w_DATA = cls.space.wrap(DATA)
     cls.w_DATA_CRLF = cls.space.wrap(DATA_CRLF)
     cls.w_temppath = cls.space.wrap(
         str(py.test.ensuretemp("bz2").join("foo")))
     if cls.runappdirect:
         cls.w_create_temp_file = create_temp_file
         cls.w_create_broken_temp_file = lambda self: create_broken_temp_file()
         cls.w_decompress = lambda self, *args: decompress(cls.space, *args)
     else:
         cls.w_create_temp_file = cls.space.wrap(interp2app(create_temp_file))
         cls.w_create_broken_temp_file = cls.space.wrap(interp2app(create_broken_temp_file))
         cls.w_decompress = cls.space.wrap(interp2app(decompress))
     cls.w_random_data = cls.space.wrap(RANDOM_DATA)
开发者ID:charred,项目名称:pypy,代码行数:15,代码来源:test_bz2_file.py


示例12: register_builtin_error_handlers

def register_builtin_error_handlers(space):
    "NOT_RPYTHON"
    state = space.fromcache(CodecState)
    for error in ("strict", "ignore", "replace", "xmlcharrefreplace",
                  "backslashreplace"):
        name = error + "_errors"
        state.codec_error_registry[error] = space.wrap(interp2app(globals()[name]))
开发者ID:Darriall,项目名称:pypy,代码行数:7,代码来源:interp_codecs.py


示例13: setup_method

    def setup_method(self, func):
        @unwrap_spec(name=str, init=str, body=str)
        def create_cdll(space, name, init, body):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            /* fix for cpython 2.7 Python.h if running tests with -A
               since pypy compiles with -fvisibility-hidden */
            #undef PyMODINIT_FUNC
            #define PyMODINIT_FUNC RPY_EXPORTED void

            %(body)s

            PyMODINIT_FUNC
            init%(name)s(void) {
            %(init)s
            }
            """ % dict(
                name=name, init=init, body=body
            )
            kwds = dict(separate_module_sources=[code])
            mod = compile_extension_module(space, name, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension

            fullmodname = os.path.join(os.path.dirname(mod), name + get_so_extension(space))
            return space.wrap(fullmodname)

        self.w_create_cdll = self.space.wrap(interp2app(create_cdll))
开发者ID:mozillazg,项目名称:pypy,代码行数:33,代码来源:test_crossing.py


示例14: patch_unicodedb

def patch_unicodedb():
    from pypy.module.unicodedata import unicodedb_4_1_0
    from pypy.module.unicodedata.interp_ucd import UCD, methods, \
         unichr_to_code_w
    from pypy.interpreter.gateway import W_Root, ObjSpace, NoneNotWrapped
    from unicodedb import _casefold
    from pypy.interpreter.typedef import TypeDef, interp_attrproperty
    from pypy.interpreter.gateway import  interp2app

    def casefold(code):
        try:
            return _casefold[code]
        except KeyError:
            return [code]

    unicodedb_4_1_0.casefold = casefold

    # patch the app-level, so it's exposed
    def interp_casefold(self, space, w_unichr):
        code = unichr_to_code_w(space, w_unichr)
        return space.newlist([space.wrap(c) for c in casefold(code)])
    unwrap_spec = ['self', ObjSpace, W_Root]
    
    UCD.casefold = interp_casefold
    methods['casefold'] = interp2app(UCD.casefold, unwrap_spec=unwrap_spec)
    UCD.typedef = TypeDef("unicodedata.UCD",
                          __doc__ = "",
                          unidata_version = interp_attrproperty('version', UCD),
                          **methods)
开发者ID:enyst,项目名称:plexnet,代码行数:29,代码来源:pypy_startup.py


示例15: setup_class

    def setup_class(cls):
        from pypy.interpreter import gateway
        import sys

        space = cls.space
        cls.w_cpython_behavior = space.wrap(not option.runappdirect)
        cls.w_cpython_version = space.wrap(tuple(sys.version_info))
        cls.w_appdirect = space.wrap(option.runappdirect)
        cls.w_cpython_apptest = space.wrap(option.runappdirect and not hasattr(sys, 'pypy_translation_info'))

        def w_unwrap_wrap_unicode(space, w_obj):
            return space.wrap(space.unicode_w(w_obj))
        cls.w_unwrap_wrap_unicode = space.wrap(gateway.interp2app(w_unwrap_wrap_unicode))
        def w_unwrap_wrap_bytes(space, w_obj):
            return space.wrapbytes(space.bytes_w(w_obj))
        cls.w_unwrap_wrap_bytes = space.wrap(gateway.interp2app(w_unwrap_wrap_bytes))
开发者ID:Qointum,项目名称:pypy,代码行数:16,代码来源:test_obj.py


示例16: test_format_traceback

    def test_format_traceback(self):
        from pypy.tool.pytest.objspace import maketestobjspace
        from pypy.interpreter.gateway import interp2app

        #
        def format_traceback(space):
            return space.format_traceback()

        #
        space = maketestobjspace()
        w_format_traceback = space.wrap(interp2app(format_traceback))
        w_tb = space.appexec(
            [w_format_traceback],
            """(format_traceback):
            def foo():
                return bar()
            def bar():
                return format_traceback()
            return foo()
        """,
        )
        tb = space.str_w(w_tb)
        expected = "\n".join(
            [
                '  File "?", line 6, in anonymous',  # this is the appexec code object
                '  File "?", line 3, in foo',
                '  File "?", line 5, in bar',
                "",
            ]
        )
        assert tb == expected
开发者ID:mozillazg,项目名称:pypy,代码行数:31,代码来源:test_objspace.py


示例17: test_with_new_with_allocate_instance_subclass

def test_with_new_with_allocate_instance_subclass():
    py.test.skip("dealloction for now segfaults")
    def mytype_new(space, w_subtype, x):
        w_obj = space.allocate_instance(W_MyType, w_subtype)
        W_MyType.__init__(space.interp_w(W_MyType, w_obj), space, x)
        return w_obj
    mytype_new.unwrap_spec = [ObjSpace, W_Root, int]

    W_MyType.typedef = TypeDef("MyType",
                               __new__ = interp2app(mytype_new),
                               x = interp_attrproperty("x", W_MyType))
    space = CPyObjSpace()

    def build():
        w_type = space.gettypefor(W_MyType)
        return space.call_function(w_type, space.wrap(42))

    fn = compile(build, [],
                 annotatorpolicy = CPyAnnotatorPolicy(space))
    res = fn(expected_extra_mallocs=1)
    assert type(res).__name__ == 'MyType'
    assert res.x == 42

    class MyType2(type(res)):
        pass

    res2 = MyType2(42)
    assert type(res2) is MyType2
    assert res2.x == 42

    del res2
    import gc
    gc.collect()
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:33,代码来源:test_typedef.py


示例18: setup_class

    def setup_class(cls):
        from pypy.interpreter import gateway

        #
        def check(space, w_func, name):
            w_code = space.getattr(w_func, space.wrap("__code__"))
            nameindex = map(space.str_w, w_code.co_names_w).index(name)
            entry = w_code._mapdict_caches[nameindex]
            entry.failure_counter = 0
            entry.success_counter = 0
            INVALID_CACHE_ENTRY.failure_counter = 0
            #
            w_res = space.call_function(w_func)
            assert space.eq_w(w_res, space.wrap(42))
            #
            entry = w_code._mapdict_caches[nameindex]
            if entry is INVALID_CACHE_ENTRY:
                failures = successes = 0
            else:
                failures = entry.failure_counter
                successes = entry.success_counter
            globalfailures = INVALID_CACHE_ENTRY.failure_counter
            return space.wrap((failures, successes, globalfailures))

        check.unwrap_spec = [gateway.ObjSpace, gateway.W_Root, str]
        cls.w_check = cls.space.wrap(gateway.interp2app(check))
开发者ID:Qointum,项目名称:pypy,代码行数:26,代码来源:test_mapdict.py


示例19: setup_method

    def setup_method(self, func):
        AppTestCpythonExtensionBase.setup_method.im_func(self, func)

        @unwrap_spec(name=str, init=str, body=str)
        def create_cdll(space, name, init, body, w_symbols):
            # the following is loosely from test_cpyext.py import_module; it
            # is copied here to be able to tweak the call to
            # compile_extension_module and to get a different return result
            # than in that function
            code = """
            #include <Python.h>
            %(body)s

            PyMODINIT_FUNC
            init%(name)s(void) {
            %(init)s
            }
            """ % dict(name=name, init=init, body=body)
            kwds = dict(separate_module_sources=[code])
            symbols = [space.str_w(w_item) for w_item in space.fixedview(w_symbols)]
            mod = compile_extension_module(space, name, symbols, **kwds)

            # explicitly load the module as a CDLL rather than as a module
            from pypy.module.imp.importing import get_so_extension
            fullmodname = os.path.join(
                os.path.dirname(mod), name + get_so_extension(space))
            return space.wrap(fullmodname)

        self.w_create_cdll = self.space.wrap(interp2app(create_cdll))
开发者ID:Darriall,项目名称:pypy,代码行数:29,代码来源:test_crossing.py


示例20: setup_class

    def setup_class(cls):
        BaseAppTestFFI.setup_class.im_func(cls)

        @unwrap_spec(addr=int, typename=str, length=int)
        def read_raw_mem(space, addr, typename, length):
            import ctypes
            addr = ctypes.cast(addr, ctypes.c_void_p)
            c_type = getattr(ctypes, typename)
            array_type = ctypes.POINTER(c_type * length)
            ptr_array = ctypes.cast(addr, array_type)
            array = ptr_array[0]
            lst = [array[i] for i in range(length)]
            return space.wrap(lst)
        if cls.runappdirect:
            cls.w_read_raw_mem = lambda self, *args: read_raw_mem(cls.space, *args)
        else:
            cls.w_read_raw_mem = cls.space.wrap(interp2app(read_raw_mem))
        #
        from rpython.rlib import clibffi
        from rpython.rlib.rarithmetic import r_uint
        from rpython.rtyper.lltypesystem import lltype, rffi
        dummy_type = lltype.malloc(clibffi.FFI_TYPE_P.TO, flavor='raw')
        dummy_type.c_size = r_uint(123)
        dummy_type.c_alignment = rffi.cast(rffi.USHORT, 0)
        dummy_type.c_type = rffi.cast(rffi.USHORT, 0)
        cls.w_dummy_type = W_FFIType('dummy', dummy_type)
        cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
开发者ID:charred,项目名称:pypy,代码行数:27,代码来源:test_struct.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python gateway.interp2app_temp函数代码示例发布时间:2022-05-27
下一篇:
Python gateway.applevel函数代码示例发布时间: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