예제 #1
0
    def test_wrapper_cannot_be_removed(self):
        SMALL = lltype.OpaqueType('SMALL')
        BIG = lltype.GcStruct('BIG', ('z', lltype.Signed), ('s', SMALL))

        def g(small):
            return -1

        def fn():
            b = lltype.malloc(BIG)
            g(b.s)

        self.check(fn, [], [], None, must_be_removed=False)
예제 #2
0
    def test_wrapper_cannot_be_removed(self):
        SMALL = lltype.OpaqueType('SMALL')
        BIG = lltype.GcStruct('BIG', ('z', lltype.Signed), ('s', SMALL))

        def g(small):
            return -1
        def fn():
            b = lltype.malloc(BIG)
            g(b.s)

        self.check(fn, [], [], None,
                   expected_mallocs=1,   # no support for interior opaques
                   expected_calls=1)
예제 #3
0
def COpaque(name, hints=None, compilation_info=None):
    if compilation_info is None:
        compilation_info = ExternalCompilationInfo()
    if hints is None:
        hints = {}
    else:
        hints = hints.copy()
    hints['external'] = 'C'
    hints['c_name'] = name
    def lazy_getsize():
        from pypy.rpython.tool import rffi_platform
        k = {}
        return rffi_platform.sizeof(name, compilation_info)
    
    hints['getsize'] = lazy_getsize
    return lltype.OpaqueType(name, hints)
예제 #4
0
def COpaque(name, hints=None, compilation_info=None):
    if compilation_info is None:
        compilation_info = ExternalCompilationInfo()
    if hints is None:
        hints = {}
    else:
        hints = hints.copy()
    hints['external'] = 'C'
    hints['c_name'] = name

    def lazy_getsize(cache={}):
        from pypy.rpython.tool import rffi_platform
        try:
            return cache[name]
        except KeyError:
            val = rffi_platform.sizeof(name, compilation_info)
            cache[name] = val
            return val

    hints['getsize'] = lazy_getsize
    return lltype.OpaqueType(name, hints)
예제 #5
0
# the obtained address will not keep the object alive. e.g. if the object is
# only reachable through an address, it might get collected
def cast_ptr_to_adr(obj):
    assert isinstance(lltype.typeOf(obj), lltype.Ptr)
    return obj._cast_to_adr()


def cast_adr_to_ptr(adr, EXPECTED_TYPE):
    return adr._cast_to_ptr(EXPECTED_TYPE)


def cast_adr_to_int(adr):
    return adr._cast_to_int()


_NONGCREF = lltype.Ptr(lltype.OpaqueType('NONGCREF'))


def cast_int_to_adr(int):
    ptr = lltype.cast_int_to_ptr(_NONGCREF, int)
    return cast_ptr_to_adr(ptr)


# ____________________________________________________________
# Weakrefs.
#
# An object of type WeakRef is a small GC-managed object that contains
# a weak reference to another GC-managed object, as in regular Python.
#

예제 #6
0
    return testgengraph(graph, args, viewbefore, executor)


def show_incremental_progress(gv_func):
    from pypy import conftest
    graph = _getgraph(gv_func)
    fixduplicatevars(graph)
    flowmodel.checkgraph(graph)
    if conftest.option.view:
        eliminate_empty_blocks(graph)
        graph.show()


# ____________________________________________________________

CONSTORVAR = lltype.Ptr(lltype.OpaqueType("ConstOrVar"))
BLOCK = lltype.Ptr(lltype.OpaqueType("Block"))
LINK = lltype.Ptr(lltype.OpaqueType("Link"))
GRAPH = lltype.Ptr(lltype.OpaqueType("FunctionGraph"))

_TO_OPAQUE[flowmodel.Block] = BLOCK.TO
_TO_OPAQUE[flowmodel.Constant] = CONSTORVAR.TO
_TO_OPAQUE[flowmodel.Variable] = CONSTORVAR.TO
_TO_OPAQUE[InteriorPtrVariable] = CONSTORVAR.TO
_TO_OPAQUE[flowmodel.Link] = LINK.TO
_TO_OPAQUE[flowmodel.FunctionGraph] = GRAPH.TO

# support constants and types

nullvar = lltype.nullptr(CONSTORVAR.TO)
nullblock = lltype.nullptr(BLOCK.TO)
예제 #7
0
def define_ptr(type_name):
    type = lltype.OpaqueType(type_name)
    ptr = lltype.Ptr(type)
    null = lltype.nullptr(ptr.TO)
    return type, ptr, null