Maciej Fijalkowski avatar Maciej Fijalkowski committed 3c7f989

merge from trunk:
svn merge -r 70153:HEAD svn+ssh://codespeak.net/svn/pypy/trunk .

Comments (0)

Files changed (194)

     DEALINGS IN THE SOFTWARE.
 
 
-PyPy Copyright holders 2003-2009
+PyPy Copyright holders 2003-2010
 ----------------------------------- 
 
 Except when otherwise stated (look for LICENSE files or information at
     Guenter Jantzen
     Dinu Gherman
     Georg Brandl
+    Benjamin Peterson
     Ben Young
     Nicolas Chauvat
     Jean-Paul Calderone

ctypes_configure/cbuild.py

 
 debug = 0
 
-log = py.log.Producer("cbuild")
-
 configdir = py.path.local.make_numbered_dir(prefix='ctypes_configure')
 
 class ExternalCompilationInfo(object):
 def log_spawned_cmd(spawn):
     def spawn_and_log(cmd, *args, **kwds):
         if debug:
-            log.execute(' '.join(cmd))
+            print ' '.join(cmd)
         return spawn(cmd, *args, **kwds)
     return spawn_and_log
 

lib-python/conftest.py

     RegrTest('test_normalization.py'),
     RegrTest('test_ntpath.py'),
     RegrTest('test_opcodes.py', core=True),
-    RegrTest('test_openpty.py', skip="unsupported extension module"),
+    RegrTest('test_openpty.py'),
     RegrTest('test_operations.py', core=True),
     RegrTest('test_operator.py', core=True),
     RegrTest('test_optparse.py'),

lib-python/modified-2.5.2/test/infinite_reload.py

 #  reload()ing. This module is imported by test_import.py:test_infinite_reload
 #  to make sure this doesn't happen any more.
 
-print 1
 import infinite_reload
-print 2
 reload(infinite_reload)
-print 3

lib-python/modified-2.5.2/test/test___all__.py

-import unittest
-from test import test_support
-
-from test.test_support import verify, verbose
-import sys
-import warnings
-
-warnings.filterwarnings("ignore",
-                        "the gopherlib module is deprecated",
-                        DeprecationWarning,
-                        "<string>")
-
-class AllTest(unittest.TestCase):
-
-    def check_all(self, modname):
-        names = {}
-        original_sys_modules = sys.modules.copy()
-        try:
-            exec "import %s" % modname in names
-        except ImportError:
-            # Silent fail here seems the best route since some modules
-            # may not be available in all environments.
-            # We restore sys.modules to avoid leaving broken modules behind,
-            # but we must not remove built-in modules from sys.modules
-            # (because they can't be re-imported, typically)
-            for name in sys.modules.keys():
-                if name in original_sys_modules:
-                    continue
-                # XXX hackish
-                mod = sys.modules[name]
-                if not hasattr(mod, '__file__'):
-                    continue
-                if (mod.__file__.lower().endswith('.py') or
-                    mod.__file__.lower().endswith('.pyc') or
-                    mod.__file__.lower().endswith('.pyo')):
-                    del sys.modules[name]
-            return
-        verify(hasattr(sys.modules[modname], "__all__"),
-               "%s has no __all__ attribute" % modname)
-        names = {}
-        exec "from %s import *" % modname in names
-        if names.has_key("__builtins__"):
-            del names["__builtins__"]
-        keys = set(names)
-        all = set(sys.modules[modname].__all__)
-        verify(keys==all, "%s != %s" % (keys, all))
-
-    def test_all(self):
-        if not sys.platform.startswith('java'):
-            # In case _socket fails to build, make this test fail more gracefully
-            # than an AttributeError somewhere deep in CGIHTTPServer.
-            import _socket
-
-        self.check_all("BaseHTTPServer")
-        self.check_all("Bastion")
-        self.check_all("CGIHTTPServer")
-        self.check_all("ConfigParser")
-        self.check_all("Cookie")
-        self.check_all("MimeWriter")
-        self.check_all("Queue")
-        self.check_all("SimpleHTTPServer")
-        self.check_all("SocketServer")
-        self.check_all("StringIO")
-        self.check_all("UserString")
-        self.check_all("aifc")
-        self.check_all("atexit")
-        self.check_all("audiodev")
-        self.check_all("base64")
-        self.check_all("bdb")
-        self.check_all("binhex")
-        self.check_all("calendar")
-        self.check_all("cgi")
-        self.check_all("cmd")
-        self.check_all("code")
-        self.check_all("codecs")
-        self.check_all("codeop")
-        self.check_all("colorsys")
-        self.check_all("commands")
-        self.check_all("compileall")
-        self.check_all("copy")
-        self.check_all("copy_reg")
-        self.check_all("csv")
-        self.check_all("dbhash")
-        self.check_all("decimal")
-        self.check_all("difflib")
-        self.check_all("dircache")
-        self.check_all("dis")
-        self.check_all("doctest")
-        self.check_all("dummy_thread")
-        self.check_all("dummy_threading")
-        self.check_all("filecmp")
-        self.check_all("fileinput")
-        self.check_all("fnmatch")
-        self.check_all("fpformat")
-        self.check_all("ftplib")
-        self.check_all("getopt")
-        self.check_all("getpass")
-        self.check_all("gettext")
-        self.check_all("glob")
-        self.check_all("gopherlib")
-        self.check_all("gzip")
-        self.check_all("heapq")
-        self.check_all("htmllib")
-        self.check_all("httplib")
-        self.check_all("ihooks")
-        self.check_all("imaplib")
-        self.check_all("imghdr")
-        self.check_all("imputil")
-        self.check_all("keyword")
-        self.check_all("linecache")
-        self.check_all("locale")
-        self.check_all("macpath")
-        self.check_all("macurl2path")
-        self.check_all("mailbox")
-        self.check_all("mailcap")
-        self.check_all("mhlib")
-        self.check_all("mimetools")
-        self.check_all("mimetypes")
-        self.check_all("mimify")
-        self.check_all("multifile")
-        self.check_all("netrc")
-        self.check_all("nntplib")
-        self.check_all("ntpath")
-        self.check_all("opcode")
-        self.check_all("optparse")
-        self.check_all("os")
-        self.check_all("os2emxpath")
-        self.check_all("pdb")
-        self.check_all("pickle")
-        self.check_all("pickletools")
-        self.check_all("pipes")
-        self.check_all("popen2")
-        self.check_all("poplib")
-        self.check_all("posixpath")
-        self.check_all("pprint")
-        self.check_all("profile")
-        self.check_all("pstats")
-        self.check_all("pty")
-        self.check_all("py_compile")
-        self.check_all("pyclbr")
-        self.check_all("quopri")
-        self.check_all("random")
-        self.check_all("re")
-        self.check_all("repr")
-        self.check_all("rexec")
-        self.check_all("rfc822")
-        self.check_all("rlcompleter")
-        self.check_all("robotparser")
-        self.check_all("sched")
-        self.check_all("sets")
-        self.check_all("sgmllib")
-        self.check_all("shelve")
-        self.check_all("shlex")
-        self.check_all("shutil")
-        self.check_all("smtpd")
-        self.check_all("smtplib")
-        self.check_all("sndhdr")
-        self.check_all("socket")
-        self.check_all("_strptime")
-        self.check_all("symtable")
-        self.check_all("tabnanny")
-        self.check_all("tarfile")
-        self.check_all("telnetlib")
-        self.check_all("tempfile")
-        self.check_all("textwrap")
-        self.check_all("threading")
-        self.check_all("timeit")
-        self.check_all("toaiff")
-        self.check_all("tokenize")
-        self.check_all("traceback")
-        self.check_all("tty")
-        self.check_all("unittest")
-        self.check_all("urllib")
-        self.check_all("urlparse")
-        self.check_all("uu")
-        self.check_all("warnings")
-        self.check_all("wave")
-        self.check_all("weakref")
-        self.check_all("webbrowser")
-        self.check_all("xdrlib")
-        self.check_all("zipfile")
-
-        # rlcompleter needs special consideration; it import readline which
-        # initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-(
-        try:
-            self.check_all("rlcompleter")
-        finally:
-            try:
-                import locale
-            except ImportError:
-                pass
-            else:
-                locale.setlocale(locale.LC_CTYPE, 'C')
-
-
-def test_main():
-    test_support.run_unittest(AllTest)
-
-if __name__ == "__main__":
-    test_main()

lib-python/modified-2.5.2/test/test_import.py

-from test.test_support import TESTFN, TestFailed, check_impl_detail
+from test.test_support import TESTFN, TestFailed
 
 import os
 import random
         os.unlink(source)
 
     try:
+        #--- the block below is to check that "reload" manages to import
+        #--- the .pyc file alone.  We don't support it in PyPy in the default
+        #--- configuration.
+        return
+
         try:
             reload(mod)
         except ImportError, err:
     finally:
         sys.path.pop(0)
 
-if check_impl_detail():
-    test_infinite_reload()
+test_infinite_reload()

lib-python/modified-2.5.2/test/test_importhooks.py

-import sys
-import imp
-import os
-import unittest
-from test import test_support
-
-
-test_src = """\
-def get_name():
-    return __name__
-def get_file():
-    return __file__
-"""
-
-absimp = "import sub\n"
-relimp = "from . import sub\n"
-deeprelimp = "from .... import sub\n"
-futimp = "from __future__ import absolute_import\n"
-
-reload_src = test_src+"""\
-reloaded = True
-"""
-
-test_co = compile(test_src, "<???>", "exec")
-reload_co = compile(reload_src, "<???>", "exec")
-
-test2_oldabs_co = compile(absimp + test_src, "<???>", "exec")
-test2_newabs_co = compile(futimp + absimp + test_src, "<???>", "exec")
-test2_newrel_co = compile(relimp + test_src, "<???>", "exec")
-test2_deeprel_co = compile(deeprelimp + test_src, "<???>", "exec")
-test2_futrel_co = compile(futimp + relimp + test_src, "<???>", "exec")
-
-test_path = "!!!_test_!!!"
-
-
-class ImportTracker:
-    """Importer that only tracks attempted imports."""
-    def __init__(self):
-        self.imports = []
-    def find_module(self, fullname, path=None):
-        self.imports.append(fullname)
-        return None
-
-
-class TestImporter:
-
-    modules = {
-        "hooktestmodule": (False, test_co),
-        "hooktestpackage": (True, test_co),
-        "hooktestpackage.sub": (True, test_co),
-        "hooktestpackage.sub.subber": (True, test_co),
-        "hooktestpackage.oldabs": (False, test2_oldabs_co),
-        "hooktestpackage.newabs": (False, test2_newabs_co),
-        "hooktestpackage.newrel": (False, test2_newrel_co),
-        "hooktestpackage.sub.subber.subest": (True, test2_deeprel_co),
-        "hooktestpackage.futrel": (False, test2_futrel_co),
-        "sub": (False, test_co),
-        "reloadmodule": (False, test_co),
-    }
-
-    def __init__(self, path=test_path):
-        if path != test_path:
-            # if out class is on sys.path_hooks, we must raise
-            # ImportError for any path item that we can't handle.
-            raise ImportError
-        self.path = path
-
-    def _get__path__(self):
-        raise NotImplementedError
-
-    def find_module(self, fullname, path=None):
-        if fullname in self.modules:
-            return self
-        else:
-            return None
-
-    def load_module(self, fullname):
-        ispkg, code = self.modules[fullname]
-        mod = sys.modules.setdefault(fullname,imp.new_module(fullname))
-        mod.__file__ = "<%s>" % self.__class__.__name__
-        mod.__loader__ = self
-        if ispkg:
-            mod.__path__ = self._get__path__()
-        exec code in mod.__dict__
-        return mod
-
-
-class MetaImporter(TestImporter):
-    def _get__path__(self):
-        return []
-
-class PathImporter(TestImporter):
-    def _get__path__(self):
-        return [self.path]
-
-
-class ImportBlocker:
-    """Place an ImportBlocker instance on sys.meta_path and you
-    can be sure the modules you specified can't be imported, even
-    if it's a builtin."""
-    def __init__(self, *namestoblock):
-        self.namestoblock = dict.fromkeys(namestoblock)
-    def find_module(self, fullname, path=None):
-        if fullname in self.namestoblock:
-            return self
-        return None
-    def load_module(self, fullname):
-        raise ImportError, "I dare you"
-
-
-class ImpWrapper:
-
-    def __init__(self, path=None):
-        if path is not None and not os.path.isdir(path):
-            raise ImportError
-        self.path = path
-
-    def find_module(self, fullname, path=None):
-        subname = fullname.split(".")[-1]
-        if subname != fullname and self.path is None:
-            return None
-        if self.path is None:
-            path = None
-        else:
-            path = [self.path]
-        try:
-            file, filename, stuff = imp.find_module(subname, path)
-        except ImportError:
-            return None
-        return ImpLoader(file, filename, stuff)
-
-
-class ImpLoader:
-
-    def __init__(self, file, filename, stuff):
-        self.file = file
-        self.filename = filename
-        self.stuff = stuff
-
-    def load_module(self, fullname):
-        mod = imp.load_module(fullname, self.file, self.filename, self.stuff)
-        if self.file:
-            self.file.close()
-        mod.__loader__ = self  # for introspection
-        return mod
-
-
-class ImportHooksBaseTestCase(unittest.TestCase):
-
-    def setUp(self):
-        self.path = sys.path[:]
-        self.meta_path = sys.meta_path[:]
-        self.path_hooks = sys.path_hooks[:]
-        sys.path_importer_cache.clear()
-        self.tracker = ImportTracker()
-        sys.meta_path.insert(0, self.tracker)
-
-    def tearDown(self):
-        sys.path[:] = self.path
-        sys.meta_path[:] = self.meta_path
-        sys.path_hooks[:] = self.path_hooks
-        sys.path_importer_cache.clear()
-        for fullname in self.tracker.imports:
-            if fullname in sys.modules:
-                del sys.modules[fullname]
-
-
-class ImportHooksTestCase(ImportHooksBaseTestCase):
-
-    def doTestImports(self, importer=None):
-        import hooktestmodule
-        import hooktestpackage
-        import hooktestpackage.sub
-        import hooktestpackage.sub.subber
-        self.assertEqual(hooktestmodule.get_name(),
-                         "hooktestmodule")
-        self.assertEqual(hooktestpackage.get_name(),
-                         "hooktestpackage")
-        self.assertEqual(hooktestpackage.sub.get_name(),
-                         "hooktestpackage.sub")
-        self.assertEqual(hooktestpackage.sub.subber.get_name(),
-                         "hooktestpackage.sub.subber")
-        if importer:
-            self.assertEqual(hooktestmodule.__loader__, importer)
-            self.assertEqual(hooktestpackage.__loader__, importer)
-            self.assertEqual(hooktestpackage.sub.__loader__, importer)
-            self.assertEqual(hooktestpackage.sub.subber.__loader__, importer)
-
-        TestImporter.modules['reloadmodule'] = (False, test_co)
-        import reloadmodule
-        self.failIf(hasattr(reloadmodule,'reloaded'))
-
-        TestImporter.modules['reloadmodule'] = (False, reload_co)
-        reload(reloadmodule)
-        self.failUnless(hasattr(reloadmodule,'reloaded'))
-
-        import hooktestpackage.oldabs
-        self.assertEqual(hooktestpackage.oldabs.get_name(),
-                         "hooktestpackage.oldabs")
-        self.assertEqual(hooktestpackage.oldabs.sub,
-                         hooktestpackage.sub)
-
-        import hooktestpackage.newrel
-        self.assertEqual(hooktestpackage.newrel.get_name(),
-                         "hooktestpackage.newrel")
-        self.assertEqual(hooktestpackage.newrel.sub,
-                         hooktestpackage.sub)
-
-        import hooktestpackage.sub.subber.subest as subest
-        self.assertEqual(subest.get_name(),
-                         "hooktestpackage.sub.subber.subest")
-        self.assertEqual(subest.sub,
-                         hooktestpackage.sub)
-
-        import hooktestpackage.futrel
-        self.assertEqual(hooktestpackage.futrel.get_name(),
-                         "hooktestpackage.futrel")
-        self.assertEqual(hooktestpackage.futrel.sub,
-                         hooktestpackage.sub)
-
-        import sub
-        self.assertEqual(sub.get_name(), "sub")
-
-        import hooktestpackage.newabs
-        self.assertEqual(hooktestpackage.newabs.get_name(),
-                         "hooktestpackage.newabs")
-        self.assertEqual(hooktestpackage.newabs.sub, sub)
-
-    def testMetaPath(self):
-        i = MetaImporter()
-        sys.meta_path.append(i)
-        self.doTestImports(i)
-
-    def testPathHook(self):
-        sys.path_hooks.append(PathImporter)
-        sys.path.append(test_path)
-        self.doTestImports()
-
-    def testBlocker(self):
-        mname = "exceptions"  # an arbitrary harmless builtin module
-        mod = None
-        if mname in sys.modules:
-            mod = sys.modules[mname]
-            del sys.modules[mname]
-        blocker = ImportBlocker(mname)
-        sys.meta_path.append(blocker)
-        try:
-            __import__(mname)
-        except ImportError:
-            pass
-        else:
-            self.fail("'%s' was not supposed to be importable" % mname)
-        finally:
-            # try hard to re-insert exceptions into sys.modules, else pypy-c
-            # complains before exiting
-            assert sys.meta_path[-1] is blocker
-            sys.meta_path.pop()
-            self.tracker.imports.remove(mname)
-            if mod:
-                sys.modules[mname] = mod
-
-    def testImpWrapper(self):
-        i = ImpWrapper()
-        sys.meta_path.append(i)
-        sys.path_hooks.append(ImpWrapper)
-        mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
-        for mname in mnames:
-            parent = mname.split(".")[0]
-            for n in sys.modules.keys():
-                if n.startswith(parent):
-                    del sys.modules[n]
-        for mname in mnames:
-            m = __import__(mname, globals(), locals(), ["__dummy__"])
-            m.__loader__  # to make sure we actually handled the import
-        # Delete urllib from modules because urlparse was imported above.
-        # Without this hack, test_socket_ssl fails if run in this order:
-        # regrtest.py test_codecmaps_tw test_importhooks test_socket_ssl
-        try:
-            del sys.modules['urllib']
-        except KeyError:
-            pass
-
-def test_main():
-    test_support.run_unittest(ImportHooksTestCase)
-
-if __name__ == "__main__":
-    test_main()

lib-python/modified-2.5.2/test/test_runpy.py

+# Test the runpy module
+import unittest
+import os
+import os.path
+import sys
+import tempfile
+from test.test_support import verbose, run_unittest
+from runpy import _run_module_code, run_module
+
+# Set up the test code and expected results
+
+class RunModuleCodeTest(unittest.TestCase):
+
+    expected_result = ["Top level assignment", "Lower level reference"]
+    test_source = (
+        "# Check basic code execution\n"
+        "result = ['Top level assignment']\n"
+        "def f():\n"
+        "    result.append('Lower level reference')\n"
+        "f()\n"
+        "# Check the sys module\n"
+        "import sys\n"
+        "run_argv0 = sys.argv[0]\n"
+        "if __name__ in sys.modules:\n"
+        "    run_name = sys.modules[__name__].__name__\n"
+        "# Check nested operation\n"
+        "import runpy\n"
+        "nested = runpy._run_module_code('x=1\\n', mod_name='<run>',\n"
+        "                                          alter_sys=True)\n"
+    )
+
+
+    def test_run_module_code(self):
+        initial = object()
+        name = "<Nonsense>"
+        file = "Some other nonsense"
+        loader = "Now you're just being silly"
+        d1 = dict(initial=initial)
+        saved_argv0 = sys.argv[0]
+        d2 = _run_module_code(self.test_source,
+                              d1,
+                              name,
+                              file,
+                              loader,
+                              True)
+        self.failUnless("result" not in d1)
+        self.failUnless(d2["initial"] is initial)
+        self.failUnless(d2["result"] == self.expected_result)
+        self.failUnless(d2["nested"]["x"] == 1)
+        self.failUnless(d2["__name__"] is name)
+        self.failUnless(d2["run_name"] is name)
+        self.failUnless(d2["__file__"] is file)
+        self.failUnless(d2["run_argv0"] is file)
+        self.failUnless(d2["__loader__"] is loader)
+        self.failUnless(sys.argv[0] is saved_argv0)
+        self.failUnless(name not in sys.modules)
+
+    def test_run_module_code_defaults(self):
+        saved_argv0 = sys.argv[0]
+        d = _run_module_code(self.test_source)
+        self.failUnless(d["result"] == self.expected_result)
+        self.failUnless(d["__name__"] is None)
+        self.failUnless(d["__file__"] is None)
+        self.failUnless(d["__loader__"] is None)
+        self.failUnless(d["run_argv0"] is saved_argv0)
+        self.failUnless("run_name" not in d)
+        self.failUnless(sys.argv[0] is saved_argv0)
+
+class RunModuleTest(unittest.TestCase):
+
+    def expect_import_error(self, mod_name):
+        try:
+            run_module(mod_name)
+        except ImportError:
+            pass
+        else:
+            self.fail("Expected import error for " + mod_name)
+
+    def test_invalid_names(self):
+        self.expect_import_error("sys")
+        self.expect_import_error("sys.imp.eric")
+        self.expect_import_error("os.path.half")
+        self.expect_import_error("a.bee")
+        self.expect_import_error(".howard")
+        self.expect_import_error("..eaten")
+
+    def test_library_module(self):
+        run_module("runpy")
+
+    def _make_pkg(self, source, depth):
+        pkg_name = "__runpy_pkg__"
+        init_fname = "__init__"+os.extsep+"py"
+        test_fname = "runpy_test"+os.extsep+"py"
+        pkg_dir = sub_dir = tempfile.mkdtemp()
+        if verbose: print "  Package tree in:", sub_dir
+        sys.path.insert(0, pkg_dir)
+        if verbose: print "  Updated sys.path:", sys.path[0]
+        for i in range(depth):
+            sub_dir = os.path.join(sub_dir, pkg_name)
+            os.mkdir(sub_dir)
+            if verbose: print "  Next level in:", sub_dir
+            pkg_fname = os.path.join(sub_dir, init_fname)
+            pkg_file = open(pkg_fname, "w")
+            pkg_file.close()
+            if verbose: print "  Created:", pkg_fname
+        mod_fname = os.path.join(sub_dir, test_fname)
+        mod_file = open(mod_fname, "w")
+        mod_file.write(source)
+        mod_file.close()
+        if verbose: print "  Created:", mod_fname
+        mod_name = (pkg_name+".")*depth + "runpy_test"
+        return pkg_dir, mod_fname, mod_name
+
+    def _del_pkg(self, top, depth, mod_name):
+        for i in range(depth+1): # Don't forget the module itself
+            parts = mod_name.rsplit(".", i)
+            entry = parts[0]
+            try:
+                del sys.modules[entry]
+            except KeyError, ex:
+                if verbose: print ex # Persist with cleaning up
+        if verbose: print "  Removed sys.modules entries"
+        del sys.path[0]
+        if verbose: print "  Removed sys.path entry"
+        for root, dirs, files in os.walk(top, topdown=False):
+            for name in files:
+                try:
+                    os.remove(os.path.join(root, name))
+                except OSError, ex:
+                    if verbose: print ex # Persist with cleaning up
+            for name in dirs:
+                fullname = os.path.join(root, name)
+                try:
+                    os.rmdir(fullname)
+                except OSError, ex:
+                    if verbose: print ex # Persist with cleaning up
+        try:
+            os.rmdir(top)
+            if verbose: print "  Removed package tree"
+        except OSError, ex:
+            if verbose: print ex # Persist with cleaning up
+
+    def _check_module(self, depth):
+        pkg_dir, mod_fname, mod_name = (
+               self._make_pkg("x=1\n", depth))
+        try:
+            if verbose: print "Running from source:", mod_name
+            d1 = run_module(mod_name) # Read from source
+            self.failUnless(d1["x"] == 1)
+            del d1 # Ensure __loader__ entry doesn't keep file open
+            __import__(mod_name)
+            os.remove(mod_fname)
+
+            #--- the block below is to check that "imp.find_module"
+            #--- manages to import the .pyc file alone.  We don't
+            #--- support it in PyPy in the default configuration.
+            return
+
+            if verbose: print "Running from compiled:", mod_name
+            d2 = run_module(mod_name) # Read from bytecode
+            self.failUnless(d2["x"] == 1)
+            del d2 # Ensure __loader__ entry doesn't keep file open
+        finally:
+            self._del_pkg(pkg_dir, depth, mod_name)
+        if verbose: print "Module executed successfully"
+
+    def test_run_module(self):
+        for depth in range(4):
+            if verbose: print "Testing package depth:", depth
+            self._check_module(depth)
+
+
+def test_main():
+    run_unittest(RunModuleCodeTest)
+    run_unittest(RunModuleTest)
+
+if __name__ == "__main__":
+    test_main()

pypy/config/pypyoption.py

 
 default_modules = essential_modules.copy()
 default_modules.update(dict.fromkeys(
-    ["_codecs", "gc", "_weakref", "marshal", "errno",
+    ["_codecs", "gc", "_weakref", "marshal", "errno", "imp",
      "math", "_sre", "_pickle_support", "operator",
      "parser", "symbol", "token", "_ast", "_random", "__pypy__",
      "_testing"]))
         config.objspace.std.suggest(withprebuiltint=True)
         config.objspace.std.suggest(withrangelist=True)
         config.objspace.std.suggest(withprebuiltchar=True)
-        config.objspace.std.suggest(withsharingdict=True)
+        config.objspace.std.suggest(withinlineddict=True)
         config.objspace.std.suggest(withstrslice=True)
         config.objspace.std.suggest(withstrjoin=True)
         # xxx other options? ropes maybe?

pypy/doc/coding-guide.txt

 An example can be found in the current implementation which is quite
 elegant: For the definition of all the opcodes of the Python
 interpreter, the module ``dis`` is imported and used to initialize our
-bytecode interpreter.  (See ``__initclass__`` in `pyopcode.py`_).  This
+bytecode interpreter.  (See ``__initclass__`` in
+`pypy/interpreter/pyopcode.py`_).  This
 saves us from adding extra modules to PyPy. The import code is run at
 startup time, and we are allowed to use the CPython builtin import
 function.
 enables the code generator to emit efficient machine level replacements
 for pure integer objects, for instance.
 
-.. _`pyopcode.py`: http://codespeak.net/svn/pypy/dist/pypy/interpreter/pyopcode.py
-
 Restricted Python
 =================
 

pypy/doc/config/objspace.std.withcelldict.txt

-Enable cell-dicts. This makes global lookups nearly as fast as the lookup of a
-local.
+Enable cell-dicts. This optimization is not helpful without the JIT. In the
+presence of the JIT, it greatly helps looking up globals.

pypy/doc/config/objspace.usemodules.imp.txt

+Use the 'imp' module.
+This module is included by default.

pypy/doc/confrest.py

 html = py.xml.html
 
 class PyPyPage(Page): 
+    googlefragment = """
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-7778406-2");
+pageTracker._trackPageview();
+} catch(err) {}</script>
+"""
     def fill_menubar(self):
         self.menubar = html.div(
             html.a("home", 
     def get_doclink(self, target):
         return relpath(self.targetpath.strpath,
                        self.project.docpath.join(target).strpath)
+
+    def unicode(self, doctype=True): 
+        page = self._root.unicode() 
+        page = page.replace("</body>", self.googlefragment + "</body>")
+        if doctype: 
+            return self.doctype + page 
+        else: 
+            return page 
         
 
 class Project(Project): 

pypy/doc/getting-started.txt

 Before you can play with PyPy, you will need to obtain a copy
 of the sources.  This can be done either by `downloading them
 from the download page`_ or by checking them out from the
-repository using subversion.  We suggest using subversion as it
-offers access to the most recent versions.
+repository using subversion.  We suggest using subversion if one
+wants to access the current development.
 
 .. _`downloading them from the download page`: download.html
 
 If you choose to use subversion, you must issue the following command on your
 command line, DOS box, or terminal::
 
-    svn co http://codespeak.net/svn/pypy/dist pypy-dist
+    svn co http://codespeak.net/svn/pypy/trunk pypy-trunk
 
-This will check out the most recent stable release from subversion and
-place it into a directory named ``pypy-dist``, and will get you the PyPy
-source in ``pypy-dist/pypy`` and documentation files in
-``pypy-dist/pypy/doc``.  If you would prefer to check out the "cutting edge"
-version of PyPy - which may not always be stable! - then check out
-from ``http://codespeak.net/svn/pypy/trunk`` intead.
+This will check out the subversion head and place it into a directory
+named ``pypy-trunk``, and will get you the PyPy source in
+``pypy-trunk/pypy`` and documentation files in ``pypy-trunk/pypy/doc``.
+We try to ensure that the head is always stable, but it might
+occasionally be broken.  You may want to check out `our nightly tests:`_
+find a revision (5-digit number) that passed at least the
+``{own}`` and ``{applevel}`` tests (corresponding to a ``+`` sign on the
+line ``success``) and then check out using::
+
+    svn co -rXXXXX http://codespeak.net/svn/pypy/trunk pypy-trunk
+
+where XXXXX is the revision number.
+
+.. _`our nightly tests:`: http://codespeak.net:8099/summary?branch=<trunk>
+
 
 Where to go from here
 ----------------------

pypy/doc/jit/pyjitpl5.txt

  PyJitPl5
 ==========
 
-This document describes the fith generation of PyPy's JIT.
+This document describes the fifth generation of PyPy's JIT.
 
 
 Implementation of the JIT

pypy/interpreter/argument.py

 
 from pypy.interpreter.error import OperationError
 from pypy.rlib.debug import make_sure_not_resized
-from pypy.rlib.jit import purefunction, unroll_safe
+from pypy.rlib import jit
 
 
 class Signature(object):
         self.varargname = varargname
         self.kwargname = kwargname
 
-    @purefunction
+    @jit.purefunction
     def find_argname(self, name):
         try:
             return self.argnames.index(name)
         make_sure_not_resized(self.arguments_w)
         if w_stararg is not None or w_starstararg is not None:
             self._combine_wrapped(w_stararg, w_starstararg)
+            # if we have a call where * or ** args are used at the callsite
+            # we shouldn't let the JIT see the argument matching
+            self._dont_jit = True
+        else:
+            self._dont_jit = False
         
     def __repr__(self):
         """ NOT_RPYTHON """
         
     ###  Parsing for function calls  ###
 
-    @unroll_safe # XXX not true always, but for now
     def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=[],
                          blindargs=0):
         """Parse args and kwargs according to the signature of a code object,
         or raise an ArgErr in case of failure.
         Return the number of arguments filled in.
         """
+        if jit.we_are_jitted() and self._dont_jit:
+            return self._match_signature_jit_opaque(w_firstarg, scope_w,
+                                                    signature, defaults_w,
+                                                    blindargs)
+        return self._really_match_signature(w_firstarg, scope_w, signature,
+                                            defaults_w, blindargs)
+
+    @jit.dont_look_inside
+    def _match_signature_jit_opaque(self, w_firstarg, scope_w, signature,
+                                    defaults_w, blindargs):
+        return self._really_match_signature(w_firstarg, scope_w, signature,
+                                            defaults_w, blindargs)
+
+    @jit.unroll_safe
+    def _really_match_signature(self, w_firstarg, scope_w, signature, defaults_w=[],
+                                blindargs=0):
         #
         #   args_w = list of the normal actual parameters, wrapped
         #   kwds_w = real dictionary {'keyword': wrapped parameter}

pypy/interpreter/baseobjspace.py

 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib.timer import DummyTimer, Timer
-from pypy.rlib.jit import we_are_jitted, dont_look_inside, unroll_safe
+from pypy.rlib import jit
 import os, sys
 
 __all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
             config = get_pypy_config(translating=False)
         self.config = config
 
+        self.builtin_modules = {}
+        self.reloading_modules = {}
+
         # import extra modules for side-effects
         import pypy.interpreter.nestedscope     # register *_DEREF bytecodes
 
     def startup(self):
         # To be called before using the space
 
-        # Initialize all builtin modules
+        # Initialize already imported builtin modules
         from pypy.interpreter.module import Module
+        w_modules = self.sys.get('modules')
         for w_modname in self.unpackiterable(
                                 self.sys.get('builtin_module_names')):
+            try:
+                w_mod = self.getitem(w_modules, w_modname)
+            except OperationError, e:
+                if e.match(self, self.w_KeyError):
+                    continue
+                raise
             modname = self.str_w(w_modname)
-            mod = self.interpclass_w(self.getbuiltinmodule(modname))
+            mod = self.interpclass_w(w_mod)
             if isinstance(mod, Module):
-                import time
                 self.timer.start("startup " + modname)
-                mod.startup(self)
+                mod.init(self)
                 self.timer.stop("startup " + modname)
 
     def finish(self):
         if w_exitfunc is not None:
             self.call_function(w_exitfunc)
         from pypy.interpreter.module import Module
-        for w_modname in self.unpackiterable(
-                                self.sys.get('builtin_module_names')):
-            modname = self.str_w(w_modname)
-            mod = self.interpclass_w(self.getbuiltinmodule(modname))
-            if isinstance(mod, Module):
+        for w_mod in self.builtin_modules.values():
+            mod = self.interpclass_w(w_mod)
+            if isinstance(mod, Module) and mod.startup_called:
                 mod.shutdown(self)
         if self.config.objspace.std.withdictmeasurement:
             from pypy.objspace.std.dictmultiobject import report
 
         w_name = self.wrap(name)
         w_mod = self.wrap(Module(self, w_name))
-        w_modules = self.sys.get('modules')
-        self.setitem(w_modules, w_name, w_mod)
+        self.builtin_modules[name] = w_mod
         return name
 
-    def getbuiltinmodule(self, name):
+    def getbuiltinmodule(self, name, force_init=False):
         w_name = self.wrap(name)
         w_modules = self.sys.get('modules')
-        return self.getitem(w_modules, w_name)
+        try:
+            w_mod = self.getitem(w_modules, w_name)
+        except OperationError, e:
+            if not e.match(self, self.w_KeyError):
+                raise
+        else:
+            if not force_init:
+                return w_mod
+
+        # If the module is a builtin but not yet imported,
+        # retrieve it and initialize it
+        try:
+            w_mod = self.builtin_modules[name]
+        except KeyError:
+            raise OperationError(
+                self.w_SystemError,
+                self.wrap("getbuiltinmodule() called "
+                          "with non-builtin module %s" % name))
+        else:
+            # Add the module to sys.modules
+            self.setitem(w_modules, w_name, w_mod)
+
+            # And initialize it
+            from pypy.interpreter.module import Module
+            mod = self.interpclass_w(w_mod)
+            if isinstance(mod, Module):
+                self.timer.start("startup " + name)
+                mod.init(self)
+                self.timer.stop("startup " + name)
+            return w_mod
 
     def get_builtinmodule_to_install(self):
         """NOT_RPYTHON"""
         "NOT_RPYTHON: only for initializing the space."
 
         from pypy.module.exceptions import Module
-        w_name_exceptions = self.wrap('exceptions')
-        self.exceptions_module = Module(self, w_name_exceptions)
+        w_name = self.wrap('exceptions')
+        self.exceptions_module = Module(self, w_name)
+        self.builtin_modules['exceptions'] = self.wrap(self.exceptions_module)
 
         from pypy.module.sys import Module
         w_name = self.wrap('sys')
         self.sys = Module(self, w_name)
-        w_modules = self.sys.get('modules')
-        self.setitem(w_modules, w_name, self.wrap(self.sys))
+        self.builtin_modules['sys'] = self.wrap(self.sys)
 
-        self.setitem(w_modules, w_name_exceptions,
-                     self.wrap(self.exceptions_module))
+        from pypy.module.imp import Module
+        w_name = self.wrap('imp')
+        self.builtin_modules['imp'] = self.wrap(Module(self, w_name))
 
         from pypy.module.__builtin__ import Module
         w_name = self.wrap('__builtin__')
         self.builtin = Module(self, w_name)
         w_builtin = self.wrap(self.builtin)
-        self.setitem(w_modules, w_name, w_builtin)
+        self.builtin_modules['__builtin__'] = self.wrap(w_builtin)
         self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin)
 
-        bootstrap_modules = ['sys', '__builtin__', 'exceptions']
+        bootstrap_modules = ['sys', 'imp', '__builtin__', 'exceptions']
         installed_builtin_modules = bootstrap_modules[:]
 
         self.export_builtin_exceptions()
 
     def setup_builtin_modules(self):
         "NOT_RPYTHON: only for initializing the space."
-        from pypy.interpreter.module import Module
-        for w_modname in self.unpackiterable(self.sys.get('builtin_module_names')):
-            modname = self.unwrap(w_modname)
-            mod = self.getbuiltinmodule(modname)
-            if isinstance(mod, Module):
-                mod.setup_after_space_initialization()
+        self.getbuiltinmodule('sys')
+        self.getbuiltinmodule('imp')
+        self.getbuiltinmodule('__builtin__')
+        for mod in self.builtin_modules.values():
+            mod.setup_after_space_initialization()
 
     def initialize(self):
         """NOT_RPYTHON: Abstract method that should put some minimal
     def leave_cache_building_mode(self, val):
         "hook for the flow object space"
 
+    @jit.loop_invariant
     def getexecutioncontext(self):
         "Return what we consider to be the active execution context."
         # Important: the annotator must not see a prebuilt ExecutionContext:
         """
         return self.unpackiterable(w_iterable, expected_length)
 
-    @unroll_safe
+    @jit.unroll_safe
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
         if self.is_w(w_exc_type, w_check_class):
 
     def call_valuestack(self, w_func, nargs, frame):
         from pypy.interpreter.function import Function, Method, is_builtin_code
-        if (not we_are_jitted() and frame.is_being_profiled and
-            is_builtin_code(w_func)):
+        if frame.is_being_profiled and is_builtin_code(w_func):
             # XXX: this code is copied&pasted :-( from the slow path below
             # call_valuestack().
             args = frame.make_arguments(nargs)
         args = frame.make_arguments(nargs)
         return self.call_args(w_func, args)
 
-    @dont_look_inside 
     def call_args_and_c_profile(self, frame, w_func, args):
         ec = self.getexecutioncontext()
         ec.c_call_trace(frame, w_func)

pypy/interpreter/error.py

             w_instclass = space.exception_getclass(w_inst)
             if not space.exception_is_valid_class_w(w_instclass):
                 instclassname = w_instclass.getname(space, '?')
-                msg = ("exceptions must be classes, or instances,"
-                       "or strings (deprecated) not %s" % (instclassname,))
+                msg = ("exceptions must be classes, or instances, "
+                       "or strings (deprecated), not %s" % (instclassname,))
                 raise OperationError(space.w_TypeError, space.wrap(msg))
 
             if not space.is_w(w_value, space.w_None):

pypy/interpreter/executioncontext.py

 from pypy.interpreter.error import OperationError
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.jit import we_are_jitted
 from pypy.rlib import jit
 
 def app_profile_call(space, w_callable, frame, event, w_arg):
     """An ExecutionContext holds the state of an execution thread
     in the Python interpreter."""
 
+    # XXX JIT: when tracing (but not when blackholing!), the following
+    # XXX fields should be known to a constant None or False:
+    # XXX   self.w_tracefunc, self.profilefunc
+    # XXX   frame.is_being_profiled
+
     def __init__(self, space):
         self.space = space
-        self._init_frame_chain()
+        self.topframeref = jit.vref_None
+        self.framestackdepth = 0
         # tracing: space.frame_trace_action.fire() must be called to ensure
         # that tracing occurs whenever self.w_tracefunc or self.is_tracing
         # is modified.
-        self.w_tracefunc = None
+        self.w_tracefunc = None        # if not None, no JIT
         self.is_tracing = 0
         self.compiler = space.createcompiler()
-        self.profilefunc = None
+        self.profilefunc = None        # if not None, no JIT
         self.w_profilefuncarg = None
 
+    def gettopframe(self):
+        return self.topframeref()
+
     def gettopframe_nohidden(self):
-        frame = self.gettopframe()
-        # I guess this should just use getnextframe_nohidden XXX
+        frame = self.topframeref()
         while frame and frame.hide():
-            frame = frame.f_back()
+            frame = frame.f_backref()
         return frame
 
     @staticmethod
     def getnextframe_nohidden(frame):
-        frame = frame.f_back()
+        frame = frame.f_backref()
         while frame and frame.hide():
-            frame = frame.f_back()
+            frame = frame.f_backref()
         return frame
 
     def enter(self, frame):
         if self.framestackdepth > self.space.sys.recursionlimit:
             raise OperationError(self.space.w_RuntimeError,
                                  self.space.wrap("maximum recursion depth exceeded"))
-        self._chain(frame)
+        self.framestackdepth += 1
+        frame.f_backref = self.topframeref
+        self.topframeref = jit.virtual_ref(frame)
 
     def leave(self, frame):
-        if self.profilefunc:
-            self._trace(frame, 'leaveframe', self.space.w_None)
+        try:
+            if self.profilefunc:
+                self._trace(frame, 'leaveframe', self.space.w_None)
+        finally:
+            self.topframeref = frame.f_backref
+            self.framestackdepth -= 1
+            jit.virtual_ref_finish(frame)
 
-        self._unchain(frame)
-        
         if self.w_tracefunc is not None and not frame.hide():
             self.space.frame_trace_action.fire()
 
     # ________________________________________________________________
-    # the methods below are used for chaining frames in JIT-friendly way
-    # part of that stuff is obscure
-
-    @jit.unroll_safe
-    def gettopframe(self):
-        frame = self.some_frame
-        if frame is not None:
-            while frame.f_forward is not None:
-                frame = frame.f_forward
-        return frame
-
-    def _init_frame_chain(self):
-        # 'some_frame' points to any frame from this thread's frame stack
-        # (although in general it should point to the top one).
-        # XXX not true: some_frame must point to a frame from which we can
-        # reach the top frame by following the chain of f_forward
-        self.some_frame = None
-        self.framestackdepth = 0
-
-    @staticmethod
-    def _init_chaining_attributes(frame):
-        """
-        explanation of the f_back handling:
-        -----------------------------------
-
-        in the non-JIT case, the frames simply form a doubly linked list via the
-        attributes f_back_some and f_forward.
-
-        When the JIT is used, things become more complex, as functions can be
-        inlined into each other. In this case a frame chain can look like this:
-
-        +---------------+
-        | real_frame    |
-        +---------------+
-           |      
-           | f_back_some
-           |      
-           |      
-           |  +--------------+
-           |  | virtual frame|
-           |  +--------------+
-           |      ^ 
-           |      | f_forward
-           |  +--------------+
-           |  | virtual frame|
-           |  +--------------+
-           |      ^
-           |      |
-           v      | f_forward
-        +---------------+
-        | real_frame    |
-        +---------------+
-           |
-           |
-           v
-          ...
-        
-        This ensures that the virtual frames don't escape via the f_back of the
-        real frames. For the same reason, the executioncontext's some_frame
-        attribute should only point to real frames.
-
-        All places where a frame can become accessed from applevel-code (like
-        sys._getframe and traceback catching) need to call force_f_back to ensure
-        that the intermediate virtual frames are forced to be real ones.
-
-        """ 
-        frame.f_back_some = None
-        frame.f_forward = None
-        frame.f_back_forced = False
-
-    def _chain(self, frame):
-        self.framestackdepth += 1
-        #
-        frame.f_back_some = self.some_frame
-        if self._we_are_jitted():
-            curtopframe = self.gettopframe()
-            assert curtopframe is not None
-            curtopframe.f_forward = frame
-        else:
-            self.some_frame = frame
-
-    def _unchain(self, frame):
-        #assert frame is self.gettopframe() --- slowish
-        if self.some_frame is frame:
-            self.some_frame = frame.f_back_some
-        else:
-            f_back = frame.f_back()
-            if f_back is not None:
-                f_back.f_forward = None
-
-        self.framestackdepth -= 1
-
-    @staticmethod
-    def _jit_rechain_frame(ec, frame):
-        # this method is called after the jit has seen enter (and thus _chain)
-        # of a frame, but then does not actually inline it. This method thus
-        # needs to make sure that the state is as if the _chain method had been
-        # executed outside of the jit. Note that this makes it important that
-        # _unchain does not call we_are_jitted
-        frame.f_back().f_forward = None
-        ec.some_frame = frame
-
-    @staticmethod
-    @jit.unroll_safe
-    def _extract_back_from_frame(frame):
-        back_some = frame.f_back_some
-        if frame.f_back_forced:
-            # don't check back_some.f_forward in this case
-            return back_some
-        if back_some is None:
-            return None
-        while True:
-            f_forward = back_some.f_forward
-            if f_forward is frame or f_forward is None:
-                return back_some
-            back_some = f_forward
-
-    @staticmethod
-    def _force_back_of_frame(frame):
-        orig_frame = frame
-        while frame is not None and not frame.f_back_forced:
-            frame.f_back_some = f_back = ExecutionContext._extract_back_from_frame(frame)
-            frame.f_back_forced = True
-            # now that we force the whole chain, we also have to set the
-            # forward links to None
-            frame.f_forward = None
-            frame = f_back
-        return orig_frame.f_back_some
-
-    _we_are_jitted = staticmethod(we_are_jitted) # indirection for testing
-    
-    # the methods above are used for chaining frames in JIT-friendly way
-    # ________________________________________________________________
 
 
     class Subcontext(object):
             self.is_tracing = 0
 
         def enter(self, ec):
-            ec.some_frame = self.topframe
+            ec.topframeref = jit.non_virtual_ref(self.topframe)
             ec.framestackdepth = self.framestackdepth
             ec.w_tracefunc = self.w_tracefunc
             ec.profilefunc = self.profilefunc
             while index > 0:
                 index -= 1
                 lst[index] = f
-                f = f.f_back()
+                f = f.f_backref()
             assert f is None
             return lst
         # coroutine: I think this is all, folks!
 
-
-    def get_builtin(self):
-        frame = self.gettopframe_nohidden()
-        if frame is not None:
-            return frame.builtin
-        else:
-            return self.space.builtin
-
-    # XXX this one should probably be dropped in favor of a module
-    def make_standard_w_globals(self):
-        "Create a new empty 'globals' dictionary."
-        w_key = self.space.wrap("__builtins__")
-        w_value = self.space.wrap(self.get_builtin())
-        w_globals = self.space.newdict()
-        space.setitem(w_globals, w_key, w_value)
-        return w_globals
-
-    @jit.dont_look_inside
     def c_call_trace(self, frame, w_func):
         "Profile the call of a builtin function"
         if self.profilefunc is None:
         else:
             self._trace(frame, 'c_call', w_func)
 
-    @jit.dont_look_inside
     def c_return_trace(self, frame, w_retval):
         "Profile the return from a builtin function"
         if self.profilefunc is None:
         else:
             self._trace(frame, 'c_return', w_retval)
 
-    @jit.dont_look_inside
     def c_exception_trace(self, frame, w_exc):
         "Profile function called upon OperationError."
         if self.profilefunc is None:
         else:
             self._trace(frame, 'c_exception', w_exc)
 
-    @jit.dont_look_inside
     def call_trace(self, frame):
         "Trace the call of a function"
         if self.w_tracefunc is not None or self.profilefunc is not None:
             if self.profilefunc:
                 frame.is_being_profiled = True
 
-    @jit.dont_look_inside
     def return_trace(self, frame, w_retval):
         "Trace the return from a function"
         if self.w_tracefunc is not None:
             actionflag.action_dispatcher(self, frame)     # slow path
     bytecode_trace._always_inline_ = True
 
-    @jit.dont_look_inside
+    def bytecode_trace_after_exception(self, frame):
+        "Like bytecode_trace(), but without increasing the ticker."
+        actionflag = self.space.actionflag
+        ticker = actionflag.get()
+        if ticker & actionflag.interesting_bits:  # fast check
+            actionflag.action_dispatcher(self, frame)     # slow path
+    bytecode_trace_after_exception._always_inline_ = True
+
     def exception_trace(self, frame, operationerr):
         "Trace function called upon OperationError."
         operationerr.record_interpreter_traceback()
         if self.space.is_w(w_func, self.space.w_None):
             self.w_tracefunc = None
         else:
+            self.force_all_frames()
             self.w_tracefunc = w_func
             self.space.frame_trace_action.fire()
 
             self.setllprofile(app_profile_call, w_func)
 
     def setllprofile(self, func, w_arg):
-        self.profilefunc = func
         if func is not None:
             if w_arg is None:
                 raise ValueError("Cannot call setllprofile with real None")
-            frame = self.gettopframe_nohidden()
-            while frame:
+            self.force_all_frames(is_being_profiled=True)
+        self.profilefunc = func
+        self.w_profilefuncarg = w_arg
+
+    def force_all_frames(self, is_being_profiled=False):
+        # "Force" all frames in the sense of the jit, and optionally
+        # set the flag 'is_being_profiled' on them.  A forced frame is
+        # one out of which the jit will exit: if it is running so far,
+        # in a piece of assembler currently running a CALL_MAY_FORCE,
+        # then being forced means that it will fail the following
+        # GUARD_NOT_FORCED operation, and so fall back to interpreted
+        # execution.  (We get this effect simply by reading the f_back
+        # field of all frames, during the loop below.)
+        frame = self.gettopframe_nohidden()
+        while frame:
+            if is_being_profiled:
                 frame.is_being_profiled = True
-                frame = self.getnextframe_nohidden(frame)
-        self.w_profilefuncarg = w_arg
+            frame = self.getnextframe_nohidden(frame)
 
     def call_tracing(self, w_func, w_args):
         is_tracing = self.is_tracing
                              'c_return', 'c_exception']:
                 return
 
-            last_exception = None
+            last_exception = frame.last_exception
             if event == 'leaveframe':
-                last_exception = frame.last_exception
                 event = 'return'
 
             assert self.is_tracing == 0 
 
     def fire_after_thread_switch(self):
         """Bit of a hack: fire() the action but only the next time the GIL
-        is released and re-acquired (i.e. after a portential thread switch).
+        is released and re-acquired (i.e. after a potential thread switch).
         Don't call this if threads are not enabled.
         """
         from pypy.module.thread.gil import spacestate

pypy/interpreter/function.py

         
 class StaticMethod(Wrappable):
     """The staticmethod objects."""
+    _immutable_ = True
 
     def __init__(self, w_function):
         self.w_function = w_function
 
 class ClassMethod(Wrappable):
     """The classmethod objects."""
+    _immutable_ = True
 
     def __init__(self, w_function):
         self.w_function = w_function

pypy/interpreter/gateway.py

     else:
         return typ.__name__ + '_w'
 
+
+def unwrap_spec(*spec):
+    """A decorator which attaches the unwrap_spec attribute."""
+    def decorator(func):
+        func.unwrap_spec = spec
+        return func
+    return decorator
+
+
 class BuiltinCode(eval.Code):
     "The code object implementing a built-in (interpreter-level) hook."
     _immutable_ = True
     """ 
     if not isinstance(source, str): 
         source = str(py.code.Source(source).strip())
+        while source.startswith('@py.test.mark.'):
+            # these decorators are known to return the same function
+            # object, we may ignore them
+            assert '\n' in source
+            source = source[source.find('\n') + 1:]
         assert source.startswith("def "), "can only transform functions" 
         source = source[4:]
     p = source.find('(')

pypy/interpreter/generator.py

 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.gateway import NoneNotWrapped
 from pypy.rlib.rarithmetic import intmask
+from pypy.rlib import jit
 from pypy.interpreter.pyopcode import LoopBlock
 
 
             else:
                 return w_result     # YIELDed
         finally:
-            self.frame.f_back_some = None
+            self.frame.f_backref = jit.vref_None
             self.running = False
 
     def descr_throw(self, w_type, w_val=None, w_tb=None):

pypy/interpreter/mixedmodule.py

 
     applevel_name = None
     expose__file__attribute = True
-    
+    w_initialdict = None
+
     def __init__(self, space, w_name): 
         """ NOT_RPYTHON """ 
         Module.__init__(self, space, w_name) 
         self.__class__.buildloaders()
         self.loaders = self.loaders.copy()    # copy from the class to the inst
 
+    def init(self, space):
+        """This is called each time the module is imported or reloaded
+        """
+        if self.w_initialdict is not None:
+            space.call_method(self.w_dict, 'update', self.w_initialdict)
+        Module.init(self, space)
+
     def get_applevel_name(cls):
         """ NOT_RPYTHON """
         if cls.applevel_name is not None:
             for name in self.loaders: 
                 w_value = self.get(name)  
                 space.setitem(self.w_dict, space.new_interned_str(name), w_value) 
-            self.lazy = False 
+            self.lazy = False
+            self.w_initialdict = space.call_method(self.w_dict, 'items')
         return self.w_dict 
 
     def _freeze_(self):
         self.getdict()
+        self.startup_called = False
         # hint for the annotator: Modules can hold state, so they are
         # not constant
         return False

pypy/interpreter/module.py

         self.w_dict = w_dict 
         self.w_name = w_name 
         if w_name is not None:
-            space.setitem(w_dict, space.new_interned_str('__name__'), w_name) 
+            space.setitem(w_dict, space.new_interned_str('__name__'), w_name)
+        self.startup_called = False
 
     def setup_after_space_initialization(self):
         """NOT_RPYTHON: to allow built-in modules to do some more setup
         after the space is fully initialized."""
 
+    def init(self, space):
+        """This is called each time the module is imported or reloaded
+        """
+        if not self.startup_called:
+            self.startup_called = True
+            self.startup(space)
+
     def startup(self, space):
-        """This is called at runtime before the space gets uses to allow
-        the module to do initialization at runtime.
+        """This is called at runtime on import to allow the module to
+        do initialization when it is imported for the first time.
         """
 
     def shutdown(self, space):
         """This is called when the space is shut down, just after
-        sys.exitfunc().
+        sys.exitfunc(), if the module has been imported.
         """
-        
+
     def getdict(self):
         return self.w_dict
 

pypy/interpreter/pycode.py

 
 
 # Magic numbers for the bytecode version in code objects.
-# See comments in pypy/module/__builtin__/importing.
+# See comments in pypy/module/imp/importing.
 cpython_magic, = struct.unpack("<i", imp.get_magic())   # host magic number
 default_magic = (62131+2) | 0x0a0d0000                  # this PyPy's magic
                                                         # (62131=CPython 2.5.1)
 
         self._compute_flatcall()
 
-        if self.space.config.objspace.std.withcelldict:
-            from pypy.objspace.std.celldict import init_code
-            init_code(self)
 
     def _init_flags(self):
         co_code = self.co_code

pypy/interpreter/pyframe.py

 from pypy.interpreter import pytraceback
 import opcode
 from pypy.rlib.objectmodel import we_are_translated, instantiate
-from pypy.rlib.jit import we_are_jitted, hint
+from pypy.rlib.jit import hint
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
 
      * 'builtin' is the attached built-in module
      * 'valuestack_w', 'blockstack', control the interpretation
     """
-    
 
     __metaclass__ = extendabletype
 
     frame_finished_execution = False
     last_instr               = -1
     last_exception           = None
+    f_backref                = jit.vref_None
     w_f_trace                = None
     # For tracing
     instr_lb                 = 0
         self.fastlocals_w = [None]*self.numlocals
         make_sure_not_resized(self.fastlocals_w)
         self.f_lineno = code.co_firstlineno
-        ExecutionContext._init_chaining_attributes(self)
 
     def append_block(self, block):
         block.previous = self.lastblock
         executioncontext = self.space.getexecutioncontext()
         executioncontext.enter(self)
         try:
-            if not we_are_jitted():
-                executioncontext.call_trace(self)
+            executioncontext.call_trace(self)
             # Execution starts just after the last_instr.  Initially,
             # last_instr is -1.  After a generator suspends it points to
             # the YIELD_VALUE instruction.
                 rstack.resume_point("execute_frame", self, executioncontext,
                                     returns=w_exitvalue)
             except Exception:
-                if not we_are_jitted():
-                    executioncontext.return_trace(self, self.space.w_None)
+                executioncontext.return_trace(self, self.space.w_None)
                 raise
-            if not we_are_jitted():
-                executioncontext.return_trace(self, w_exitvalue)
+            executioncontext.return_trace(self, w_exitvalue)
+            # clean up the exception, might be useful for not
+            # allocating exception objects in some cases
+            self.last_exception = None
         finally:
             executioncontext.leave(self)
         return w_exitvalue
             w_tb = w(self.last_exception.application_traceback)
         
         tup_state = [
-            w(self.f_back()),
+            w(self.f_backref()),
             w(self.get_builtin()),
             w(self.pycode),
             w_valuestack,
         # do not use the instance's __init__ but the base's, because we set
         # everything like cells from here
         PyFrame.__init__(self, space, pycode, w_globals, closure)
-        new_frame.f_back_some = space.interp_w(PyFrame, w_f_back, can_be_None=True)
-        new_frame.f_back_forced = True
+        f_back = space.interp_w(PyFrame, w_f_back, can_be_None=True)
+        new_frame.f_backref = jit.non_virtual_ref(f_back)
 
         new_frame.builtin = space.interp_w(Module, w_builtin)
         new_frame.set_blocklist([unpickle_block(space, w_blk)