Пример #1
0
def new_funcnode(db, T, obj, forcename=None):
    from rpython.rtyper.rtyper import llinterp_backend
    if db.sandbox:
        if (getattr(obj, 'external', None) is not None and
                not obj._safe_not_sandboxed):
            from rpython.translator.sandbox import rsandbox
            obj.__dict__['graph'] = rsandbox.get_sandbox_stub(
                obj, db.translator.rtyper)
            obj.__dict__.pop('_safe_not_sandboxed', None)
            obj.__dict__.pop('external', None)
    if forcename:
        name = forcename
    else:
        name = _select_name(db, obj)
    if hasattr(obj, 'graph'):
        return FuncNode(db, T, obj, name)
    elif getattr(obj, 'external', None) is not None:
        assert obj.external == 'C'
        if db.sandbox:
            assert obj._safe_not_sandboxed
        return ExternalFuncNode(db, T, obj, name)
    elif hasattr(obj._callable, "c_name"):
        return ExternalFuncNode(db, T, obj, name)  # this case should only be used for entrypoints
    elif db.translator.rtyper.backend is llinterp_backend:
        # on llinterp, anything goes
        return ExternalFuncNode(db, T, obj, name)
    else:
        raise ValueError("don't know how to generate code for %r" % (obj,))
Пример #2
0
Файл: node.py Проект: sota/pypy
def new_funcnode(db, T, obj, forcename=None):
    from rpython.rtyper.rtyper import llinterp_backend
    if db.sandbox:
        if (getattr(obj, 'external', None) is not None and
                not obj._safe_not_sandboxed):
            from rpython.translator.sandbox import rsandbox
            obj.__dict__['graph'] = rsandbox.get_sandbox_stub(
                obj, db.translator.rtyper)
            obj.__dict__.pop('_safe_not_sandboxed', None)
            obj.__dict__.pop('external', None)
    if forcename:
        name = forcename
    else:
        name = _select_name(db, obj)
    if hasattr(obj, 'graph'):
        return FuncNode(db, T, obj, name)
    elif getattr(obj, 'external', None) is not None:
        assert obj.external == 'C'
        if db.sandbox:
            assert obj._safe_not_sandboxed
        return ExternalFuncNode(db, T, obj, name)
    elif hasattr(obj._callable, "c_name"):
        return ExternalFuncNode(db, T, obj, name)  # this case should only be used for entrypoints
    elif db.translator.rtyper.backend is llinterp_backend:
        # on llinterp, anything goes
        return ExternalFuncNode(db, T, obj, name)
    else:
        raise ValueError("don't know how to generate code for %r" % (obj,))