Exemple #1
0
def _run_eval_string(source, filename, space, eval):
    if eval:
        cmd = 'eval'
    else:
        cmd = 'exec'

    try:
        if space is None:
            from pypy.objspace.std.objspace import StdObjSpace
            space = StdObjSpace()

        pycode = compilecode(space, source, filename or '<string>', cmd)

        mainmodule = ensure__main__(space)
        w_globals = mainmodule.w_dict

        space.setitem(w_globals, space.newtext('__builtins__'), space.builtin)
        if filename is not None:
            space.setitem(w_globals, space.newtext('__file__'), space.newtext(filename))

        retval = pycode.exec_code(space, w_globals, w_globals)
        if eval:
            return retval
        else:
            return

    except OperationError as operationerr:
        operationerr.record_interpreter_traceback()
        raise
Exemple #2
0
    def __init__(self, *args, **kwds):
        StdObjSpace.__init__(self, *args, **kwds)
        w_dict = self.newdict()
        self.setitem(w_dict, self.wrap("__doc__"), self.wrap("""\
Exception that is raised when an operation revealing information on a tainted
object is performed."""))
        self.w_TaintError = self.call_function(
            self.w_type,
            self.wrap("TaintError"),
            self.newtuple([self.w_Exception]),
            w_dict
            )
        w___pypy__ = self.getbuiltinmodule("__pypy__")
        self.setattr(w___pypy__, self.wrap('taint'),
                     self.wrap(app_taint))
        self.setattr(w___pypy__, self.wrap('is_tainted'),
                     self.wrap(app_is_tainted))
        self.setattr(w___pypy__, self.wrap('untaint'),
                     self.wrap(app_untaint))
        self.w_fn_taint_atomic_function = self.wrap(app_taint_atomic_function)
        self.setattr(w___pypy__, self.wrap('taint_atomic'),
                     self.wrap(app_taint_atomic))
        self.setattr(w___pypy__, self.wrap('TaintError'),
                     self.w_TaintError)
        self.setattr(w___pypy__, self.wrap('_taint_debug'),
                     self.wrap(app_taint_debug))
        self.setattr(w___pypy__, self.wrap('_taint_look'),
                     self.wrap(app_taint_look))
        patch_space_in_place(self, 'taint', proxymaker)

        # XXX may leak info, perfomance hit, what about taint bombs?
        from pypy.objspace.std.typeobject import W_TypeObject

        def taint_lookup(w_obj, name):
            if isinstance(w_obj, W_Tainted):
                w_obj = w_obj.w_obj
            w_type = self.type(w_obj)
            assert isinstance(w_type, W_TypeObject)
            return w_type.lookup(name)

        def taint_lookup_in_type_where(w_obj, name):
            if isinstance(w_obj, W_Tainted):
                w_type = w_obj.w_obj
            else:
                w_type = w_obj
            assert isinstance(w_type, W_TypeObject)
            return w_type.lookup_where(name)

        self.lookup = taint_lookup
        self.lookup_in_type_where = taint_lookup_in_type_where
Exemple #3
0
    def __init__(self, *args, **kwds):
        StdObjSpace.__init__(self, *args, **kwds)
        w_dict = self.newdict()
        self.setitem(
            w_dict, self.wrap("__doc__"),
            self.wrap("""\
Exception that is raised when an operation revealing information on a tainted
object is performed."""))
        self.w_TaintError = self.call_function(
            self.w_type, self.wrap("TaintError"),
            self.newtuple([self.w_Exception]), w_dict)
        w___pypy__ = self.getbuiltinmodule("__pypy__")
        self.setattr(w___pypy__, self.wrap('taint'), self.wrap(app_taint))
        self.setattr(w___pypy__, self.wrap('is_tainted'),
                     self.wrap(app_is_tainted))
        self.setattr(w___pypy__, self.wrap('untaint'), self.wrap(app_untaint))
        self.w_fn_taint_atomic_function = self.wrap(app_taint_atomic_function)
        self.setattr(w___pypy__, self.wrap('taint_atomic'),
                     self.wrap(app_taint_atomic))
        self.setattr(w___pypy__, self.wrap('TaintError'), self.w_TaintError)
        self.setattr(w___pypy__, self.wrap('_taint_debug'),
                     self.wrap(app_taint_debug))
        self.setattr(w___pypy__, self.wrap('_taint_look'),
                     self.wrap(app_taint_look))
        patch_space_in_place(self, 'taint', proxymaker)

        # XXX may leak info, perfomance hit, what about taint bombs?
        from pypy.objspace.std.typeobject import W_TypeObject

        def taint_lookup(w_obj, name):
            if isinstance(w_obj, W_Tainted):
                w_obj = w_obj.w_obj
            w_type = self.type(w_obj)
            assert isinstance(w_type, W_TypeObject)
            return w_type.lookup(name)

        def taint_lookup_in_type_where(w_obj, name):
            if isinstance(w_obj, W_Tainted):
                w_type = w_obj.w_obj
            else:
                w_type = w_obj
            assert isinstance(w_type, W_TypeObject)
            return w_type.lookup_where(name)

        self.lookup = taint_lookup
        self.lookup_in_type_where = taint_lookup_in_type_where
Exemple #4
0
 def setup_class(cls):
     init_extmodule_code()
     conf = get_pypy_config()
     conf.objspace.extmodules = 'testext.extmod'
     old_sys_path[:] = sys.path[:]
     sys.path.insert(0, str(udir))
     space = StdObjSpace(conf)
     cls.space = space
Exemple #5
0
 def wrap(self, x):
     w_res = StdObjSpace.wrap(self, x)
     self.dumper.dump_returned_wrapped('           wrap', w_res)
     return w_res
Exemple #6
0
 def startup(self):
     StdObjSpace.startup(self)
     self.dumper.open()
Exemple #7
0
 def finish(self):
     self.dumper.close()
     StdObjSpace.finish(self)
Exemple #8
0
 def __init__(self, *args, **kwds):
     self.dumper = Dumper(self)
     StdObjSpace.__init__(self, *args, **kwds)
     patch_space_in_place(self, 'dump', proxymaker)
Exemple #9
0
 def _freeze_(self):
     # remove strange things from the caches of self.dumper
     # before we annotate
     self.dumper.close()
     return StdObjSpace._freeze_(self)
Exemple #10
0
def make_objspace(config):
    from pypy.objspace.std.objspace import StdObjSpace
    return StdObjSpace(config)
    def get_entry_point(self, config):
        global space1, space2, w_entry_point_1, w_entry_point_2
        space1 = StdObjSpace(config)
        space2 = StdObjSpace(config)

        space1.setattr(space1.getbuiltinmodule('sys'),
                       space1.wrap('pypy_space'),
                       space1.wrap(1))
        space2.setattr(space2.getbuiltinmodule('sys'),
                       space2.wrap('pypy_space'),
                       space2.wrap(2))

        # manually imports app_main.py
        filename = os.path.join(this_dir, 'app_main.py')
        w_dict = space1.newdict()
        space1.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_1 = space1.getitem(w_dict, space1.wrap('entry_point'))

        w_dict = space2.newdict()
        space2.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_2 = space2.getitem(w_dict, space2.wrap('entry_point'))

        # sanity-check: call the entry point
        res = entry_point(["pypy", "app_basic_example.py"])
        assert res == 0
        res = entry_point(["pypy", "--space2", "app_basic_example.py"])
        assert res == 0

        return entry_point, None, PyPyAnnotatorPolicy()
Exemple #12
0
    def get_entry_point(self, config):
        global space1, space2, w_entry_point_1, w_entry_point_2
        space1 = StdObjSpace(config)
        space2 = StdObjSpace(config)

        space1.setattr(space1.getbuiltinmodule("sys"), space1.wrap("pypy_space"), space1.wrap(1))
        space2.setattr(space2.getbuiltinmodule("sys"), space2.wrap("pypy_space"), space2.wrap(2))

        # manually imports app_main.py
        filename = os.path.join(this_dir, "app_main.py")
        w_dict = space1.newdict()
        space1.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_1 = space1.getitem(w_dict, space1.wrap("entry_point"))

        w_dict = space2.newdict()
        space2.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_2 = space2.getitem(w_dict, space2.wrap("entry_point"))

        return entry_point, None, PyPyAnnotatorPolicy()
Exemple #13
0
        w_typ.getdict()
        print "*%s*" % typedef.name

    for typedef in space.model.pythontypes:
        w_typ = getattr(space, 'w_' + typedef.name)
        w_typ.getdict()

        print "*%s*" % typedef.name
        #print w_typ.dict_w.keys()

    space.builtin.get('file').getdict()

    space.appexec([], """():
    try:
       raise ValueError
    except ValueError:
       pass
    exec 'pass'    
""")
    # freeze caches?
    print "cache build finished"


if __name__ == '__main__':
    import autopath
    from pypy.objspace.std.objspace import StdObjSpace

    space = StdObjSpace()

    buildcache(space)
Exemple #14
0
 def wrap(self, x):
     w_res = StdObjSpace.wrap(self, x)
     self.dumper.dump_returned_wrapped('           wrap', w_res)
     return w_res
Exemple #15
0
 def finish(self):
     self.dumper.close()
     StdObjSpace.finish(self)
Exemple #16
0
 def startup(self):
     StdObjSpace.startup(self)
     self.dumper.open()
Exemple #17
0
 def _freeze_(self):
     # remove strange things from the caches of self.dumper
     # before we annotate
     self.dumper.close()
     return StdObjSpace._freeze_(self)
Exemple #18
0
 def __init__(self, *args, **kwds):
     self.dumper = Dumper(self)
     StdObjSpace.__init__(self, *args, **kwds)
     patch_space_in_place(self, 'dump', proxymaker)
Exemple #19
0
def run_module(module_name, args, space=None):
    """Implements PEP 338 'Executing modules as scripts', overwriting
    sys.argv[1:] using `args` and executing the module `module_name`.
    sys.argv[0] always is `module_name`.

    Delegates the real work to the runpy module provided as the reference
    implementation.
    """
    if space is None:
        from pypy.objspace.std.objspace import StdObjSpace
        space = StdObjSpace()
    argv = [module_name]
    if args is not None:
        argv.extend(args)
    space.setitem(space.sys.w_dict, space.newtext('argv'), space.wrap(argv))
    w_import = space.builtin.get('__import__')
    runpy = space.call_function(w_import, space.newtext('runpy'))
    w_run_module = space.getitem(runpy.w_dict, space.newtext('run_module'))
    return space.call_function(w_run_module, space.newtext(module_name),
                               space.w_None, space.newtext('__main__'),
                               space.w_True)
Exemple #20
0
    def get_entry_point(self, config):
        global space1, space2, w_entry_point_1, w_entry_point_2
        space1 = StdObjSpace(config)
        space2 = StdObjSpace(config)

        space1.setattr(space1.getbuiltinmodule('sys'),
                       space1.wrap('pypy_space'),
                       space1.wrap(1))
        space2.setattr(space2.getbuiltinmodule('sys'),
                       space2.wrap('pypy_space'),
                       space2.wrap(2))

        # manually imports app_main.py
        filename = os.path.join(this_dir, 'app_main.py')
        w_dict = space1.newdict()
        space1.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_1 = space1.getitem(w_dict, space1.wrap('entry_point'))

        w_dict = space2.newdict()
        space2.exec_(open(filename).read(), w_dict, w_dict)
        w_entry_point_2 = space2.getitem(w_dict, space2.wrap('entry_point'))

        return entry_point, None, PyPyAnnotatorPolicy()