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


Python test_genc.compile函数代码示例

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


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

示例1: test_translate

def test_translate():
    from pypy.translator.c.test.test_genc import compile

    def func():
        poll({})

    compile(func, [])
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rpoll.py

示例2: test_translated

    def test_translated(self):
        from pypy.translator.c.test.test_genc import compile

        def func(no):
            m = mmap.mmap(no, 1)
            r = m.read_byte()
            m.close()
            return r

        compile(func, [int])
开发者ID:gorakhargosh,项目名称:pypy,代码行数:10,代码来源:test_rmmap.py

示例3: test_stringstar

def test_stringstar():
    c_source = """
    #include <string.h>
    
    int f(char *args[]) {
        char **p = args;
        int l = 0;
        while (*p) {
            l += strlen(*p);
            p++;
        }
        return (l);
    }
    """
    c_file = udir.join("stringstar.c")
    c_file.write(c_source)
    z = llexternal('f', [CCHARPP], Signed, sources=[str(c_file)])

    def f():
        l = ["xxx", "x", "xxxx"]
        ss = liststr2charpp(l)
        result = z(ss)
        free_charpp(ss)
        return result

    xf = compile(f, [], backendopt=False)
    assert xf() == 8
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:27,代码来源:test_rffi.py

示例4: test_with_new_with_allocate_instance

def test_with_new_with_allocate_instance():
    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))

    w_obj = build()
    w_name = space.getattr(space.type(w_obj), space.wrap('__name__'))
    assert space.unwrap(w_name) == 'MyType'
    assert space.int_w(space.getattr(w_obj, space.wrap('x'))) == 42

    fn = compile(build, [],
                 annotatorpolicy = CPyAnnotatorPolicy(space))
    res = fn(expected_extra_mallocs=1)
    assert type(res).__name__ == 'MyType'
    assert res.x == 42
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:test_typedef.py

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

示例6: test_string_reverse

def test_string_reverse():
    c_source = py.code.Source("""
    #include <string.h>

    char *f(char* arg)
    {
        char *ret;
        ret = (char*)malloc(strlen(arg) + 1);
        strcpy(ret, arg);
        return ret;
    }
    """)
    c_file = udir.join("stringrev.c")
    c_file.write(c_source)
    z = llexternal('f', [CCHARP], CCHARP, sources=[str(c_file)])    

    def f():
        s = str2charp("xxx")
        l_res = z(s)
        res = charp2str(l_res)
        lltype.free(l_res, flavor='raw')
        free_charp(s)
        return len(res)

    xf = compile(f, [], backendopt=False)
    assert xf(expected_extra_mallocs=-1) == 3
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:test_rffi.py

示例7: test_expose_types

def test_expose_types():
    W_MyType.typedef = TypeDef("MyType")

    class W_MyType2(Wrappable):
        def __init__(self, space, x=1):
            self.space = space
            self.x = x
    W_MyType2.typedef = TypeDef("MyType2")
    space = CPyObjSpace()

    def get_mytype(n):
        if n:
            return space.gettypefor(W_MyType2)
        else:
            return space.gettypefor(W_MyType)
        return None
    fn = compile(get_mytype, [int],
                 annotatorpolicy = CPyAnnotatorPolicy(space))

    w_mytype2 = get_mytype(1)
    w_name = space.getattr(w_mytype2, space.wrap('__name__'))
    assert space.unwrap(w_name) == 'MyType2'
    w_mytype = get_mytype(0)
    w_name = space.getattr(w_mytype, space.wrap('__name__'))
    assert space.unwrap(w_name) == 'MyType'

    res2 = fn(1)
    assert type(res2) == type
    assert res2.__name__ == 'MyType2'
    res = fn(0)
    assert res.__name__ == 'MyType'
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:31,代码来源:test_typedef.py

示例8: test_math

def test_math():
    f = compile(fn, [])
    res = f()
    if res >= 0:
        py.test.fail(repr(test_direct.MathTests.TESTCASES[res]))
    else:
        assert res == -42
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_zmath.py

示例9: test_os_setpgrp

    def test_os_setpgrp():
        def does_stuff():
            return os.setpgrp()

        f1 = compile(does_stuff, [])
        res = f1()
        assert res == os.setpgrp()
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_extfunc.py

示例10: test_compile_pythonapi

    def test_compile_pythonapi(self):
        from pypy.rpython.rctypes import apyobject
        class W_Object(py_object):
            pass
        apyobject.register_py_object_subclass(W_Object)
        PyInt_AsLong = pythonapi.PyInt_AsLong
        PyInt_AsLong.argtypes = [W_Object]
        PyInt_AsLong.restype = c_long
        assert PyInt_AsLong._flags_ & _FUNCFLAG_PYTHONAPI

        PyNumber_Add = pythonapi.PyNumber_Add
        PyNumber_Add.argtypes = [W_Object, W_Object]
        PyNumber_Add.restype = W_Object

        def fn1(x, crash):
            pyobj = W_Object(x)
            pyobj = PyNumber_Add(pyobj, pyobj)
            x = PyInt_AsLong(pyobj)
            if crash:
                # fn(sys.maxint, 1) should crash on PyInt_AsLong before
                # it arrives here.  If by mistake it arrives here then
                # we get a TypeError instead of the OverflowError
                PyNumber_Add(W_Object(5), W_Object("x"))
            return x

        fn = compile(fn1, [int, int])
        res = fn(17, 0)
        assert res == 34
        py.test.raises(OverflowError, 'fn(sys.maxint, 1)')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:test_rfunc.py

示例11: test_rarith_float_to_str

def test_rarith_float_to_str():
    def fn(f):
        return str(f)

    f = compile(fn, [float])
    res = f(1.5)
    assert eval(res) == 1.5
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_extfunc.py

示例12: test_os_getpid

    def test_os_getpid():
        def does_stuff():
            return os.getpid()

        f1 = compile(does_stuff, [])
        res = f1()
        assert res == os.getpid()
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_extfunc.py

示例13: test_system

def test_system():
    def does_stuff(cmd):
        return os.system(cmd)

    f1 = compile(does_stuff, [str])
    res = f1("echo hello")
    assert res == 0
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_extfunc.py

示例14: test_strerror

def test_strerror():
    def does_stuff():
        return os.strerror(2)

    f1 = compile(does_stuff, [])
    res = f1()
    assert res == os.strerror(2)
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_extfunc.py

示例15: test_os_stat

def test_os_stat():
    filename = str(py.path.local(__file__))
    has_blksize = hasattr(os.stat_result, "st_blksize")
    has_blocks = hasattr(os.stat_result, "st_blocks")

    def call_stat():
        st = os.stat(filename)
        res = (st[0], st.st_ino, st.st_ctime)
        if has_blksize:
            res += (st.st_blksize,)
        if has_blocks:
            res += (st.st_blocks,)
        return res

    f = compile(call_stat, [])
    res = f()
    assert res[0] == os.stat(filename).st_mode
    assert res[1] == os.stat(filename).st_ino
    st_ctime = res[2]
    if isinstance(st_ctime, float):
        assert st_ctime == os.stat(filename).st_ctime
    else:
        assert st_ctime == int(os.stat(filename).st_ctime)
    if has_blksize:
        assert res[3] == os.stat(filename).st_blksize
        if has_blocks:
            assert res[4] == os.stat(filename).st_blocks
开发者ID:alkorzt,项目名称:pypy,代码行数:27,代码来源:test_extfunc.py


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