[pypy-svn] r74003 - in pypy/branch/cpython-extension: . dotviewer lib-python py/impl/code pypy pypy/annotation pypy/config pypy/interpreter pypy/interpreter/astcompiler pypy/interpreter/astcompiler/test pypy/interpreter/pyparser pypy/interpreter/pyparser/test pypy/interpreter/test pypy/jit/backend/cli/test pypy/jit/backend/llvm/test pypy/jit/backend/x86/test pypy/jit/metainterp pypy/jit/metainterp/test pypy/jit/tl/tinyframe pypy/module/__builtin__ pypy/module/_codecs pypy/module/_file pypy/module/_file/test pypy/module/_locale pypy/module/_locale/test pypy/module/_stackless pypy/module/bz2 pypy/module/exceptions pypy/module/posix pypy/module/posix/test pypy/module/pypyjit pypy/module/pypyjit/test pypy/module/signal pypy/module/sys pypy/module/sys/test pypy/module/termios pypy/objspace/flow pypy/objspace/flow/test pypy/objspace/std pypy/objspace/std/test pypy/rlib pypy/rlib/rsre pypy/rlib/rsre/test pypy/rlib/test pypy/rpython pypy/rpython/lltypesystem pypy/rpython/lltypesystem/test pypy/rpython/memory/gctransform pypy/rpython/test pypy/tool pypy/tool/pytest pypy/translator pypy/translator/c pypy/translator/c/src pypy/translator/c/test pypy/translator/goal pypy/translator/goal/test2 pypy/translator/jvm pypy/translator/tool pypy/translator/tool/test

benjamin at codespeak.net benjamin at codespeak.net
Fri Apr 23 02:41:41 CEST 2010


Author: benjamin
Date: Fri Apr 23 02:41:35 2010
New Revision: 74003

Added:
   pypy/branch/cpython-extension/pypy/jit/tl/tinyframe/
      - copied from r74002, pypy/trunk/pypy/jit/tl/tinyframe/
   pypy/branch/cpython-extension/pypy/rlib/rlocale.py
      - copied unchanged from r74002, pypy/trunk/pypy/rlib/rlocale.py
   pypy/branch/cpython-extension/pypy/rlib/test/test_rlocale.py
      - copied unchanged from r74002, pypy/trunk/pypy/rlib/test/test_rlocale.py
   pypy/branch/cpython-extension/pypy/translator/goal/test2/test_targetpypy.py
      - copied unchanged from r74002, pypy/trunk/pypy/translator/goal/test2/test_targetpypy.py
Removed:
   pypy/branch/cpython-extension/pypy/module/_locale/app_locale.py
   pypy/branch/cpython-extension/pypy/rlib/rsre/_rsre_platform.py
   pypy/branch/cpython-extension/pypy/rlib/rsre/test/test_rsre_platform.py
   pypy/branch/cpython-extension/pypy/translator/goal/buildcache2.py
Modified:
   pypy/branch/cpython-extension/   (props changed)
   pypy/branch/cpython-extension/dotviewer/   (props changed)
   pypy/branch/cpython-extension/lib-python/   (props changed)
   pypy/branch/cpython-extension/py/impl/code/_assertionold.py
   pypy/branch/cpython-extension/pypy/   (props changed)
   pypy/branch/cpython-extension/pypy/annotation/annrpython.py
   pypy/branch/cpython-extension/pypy/config/translationoption.py
   pypy/branch/cpython-extension/pypy/conftest.py
   pypy/branch/cpython-extension/pypy/interpreter/astcompiler/assemble.py
   pypy/branch/cpython-extension/pypy/interpreter/astcompiler/test/test_compiler.py
   pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py
   pypy/branch/cpython-extension/pypy/interpreter/function.py
   pypy/branch/cpython-extension/pypy/interpreter/gateway.py
   pypy/branch/cpython-extension/pypy/interpreter/pycode.py
   pypy/branch/cpython-extension/pypy/interpreter/pycompiler.py
   pypy/branch/cpython-extension/pypy/interpreter/pyframe.py
   pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py
   pypy/branch/cpython-extension/pypy/interpreter/pyparser/metaparser.py
   pypy/branch/cpython-extension/pypy/interpreter/pyparser/parser.py
   pypy/branch/cpython-extension/pypy/interpreter/pyparser/pyparse.py
   pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_metaparser.py
   pypy/branch/cpython-extension/pypy/interpreter/test/test_appinterp.py
   pypy/branch/cpython-extension/pypy/interpreter/test/test_compiler.py
   pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py
   pypy/branch/cpython-extension/pypy/interpreter/test/test_objspace.py
   pypy/branch/cpython-extension/pypy/interpreter/typedef.py
   pypy/branch/cpython-extension/pypy/jit/backend/cli/test/conftest.py   (props changed)
   pypy/branch/cpython-extension/pypy/jit/backend/llvm/test/conftest.py   (props changed)
   pypy/branch/cpython-extension/pypy/jit/backend/x86/test/test_gc_integration.py   (props changed)
   pypy/branch/cpython-extension/pypy/jit/metainterp/codewriter.py
   pypy/branch/cpython-extension/pypy/jit/metainterp/logger.py   (props changed)
   pypy/branch/cpython-extension/pypy/jit/metainterp/optimizefindnode.py
   pypy/branch/cpython-extension/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/cpython-extension/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizefindnode.py
   pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/cpython-extension/pypy/module/__builtin__/app_inspect.py
   pypy/branch/cpython-extension/pypy/module/_codecs/__init__.py
   pypy/branch/cpython-extension/pypy/module/_codecs/app_codecs.py
   pypy/branch/cpython-extension/pypy/module/_codecs/interp_codecs.py
   pypy/branch/cpython-extension/pypy/module/_file/interp_file.py
   pypy/branch/cpython-extension/pypy/module/_file/interp_stream.py
   pypy/branch/cpython-extension/pypy/module/_file/test/test_file.py
   pypy/branch/cpython-extension/pypy/module/_locale/__init__.py
   pypy/branch/cpython-extension/pypy/module/_locale/interp_locale.py
   pypy/branch/cpython-extension/pypy/module/_locale/test/test_locale.py
   pypy/branch/cpython-extension/pypy/module/_stackless/interp_coroutine.py
   pypy/branch/cpython-extension/pypy/module/bz2/interp_bz2.py
   pypy/branch/cpython-extension/pypy/module/exceptions/   (props changed)
   pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py
   pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py
   pypy/branch/cpython-extension/pypy/module/pypyjit/policy.py
   pypy/branch/cpython-extension/pypy/module/pypyjit/test/test_policy.py
   pypy/branch/cpython-extension/pypy/module/signal/interp_signal.py
   pypy/branch/cpython-extension/pypy/module/sys/__init__.py
   pypy/branch/cpython-extension/pypy/module/sys/app.py
   pypy/branch/cpython-extension/pypy/module/sys/interp_encoding.py
   pypy/branch/cpython-extension/pypy/module/sys/test/test_sysmodule.py
   pypy/branch/cpython-extension/pypy/module/termios/interp_termios.py
   pypy/branch/cpython-extension/pypy/objspace/flow/flowcontext.py
   pypy/branch/cpython-extension/pypy/objspace/flow/model.py
   pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py
   pypy/branch/cpython-extension/pypy/objspace/flow/operation.py
   pypy/branch/cpython-extension/pypy/objspace/flow/specialcase.py
   pypy/branch/cpython-extension/pypy/objspace/flow/test/test_objspace.py
   pypy/branch/cpython-extension/pypy/objspace/std/basestringtype.py
   pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py
   pypy/branch/cpython-extension/pypy/objspace/std/formatting.py
   pypy/branch/cpython-extension/pypy/objspace/std/frame.py
   pypy/branch/cpython-extension/pypy/objspace/std/intobject.py
   pypy/branch/cpython-extension/pypy/objspace/std/objspace.py
   pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py
   pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py
   pypy/branch/cpython-extension/pypy/objspace/std/test/test_obj.py
   pypy/branch/cpython-extension/pypy/objspace/std/test/test_setobject.py   (props changed)
   pypy/branch/cpython-extension/pypy/objspace/std/test/test_stringformat.py
   pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py
   pypy/branch/cpython-extension/pypy/rlib/nonconst.py
   pypy/branch/cpython-extension/pypy/rlib/rsre/rsre_char.py
   pypy/branch/cpython-extension/pypy/rlib/test/test_rcoroutine.py   (props changed)
   pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py
   pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py
   pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_lltype.py
   pypy/branch/cpython-extension/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/cpython-extension/pypy/rpython/rint.py
   pypy/branch/cpython-extension/pypy/rpython/test/test_llann.py
   pypy/branch/cpython-extension/pypy/rpython/test/test_rlist.py
   pypy/branch/cpython-extension/pypy/rpython/test/test_rpbc.py
   pypy/branch/cpython-extension/pypy/tool/pytest/appsupport.py
   pypy/branch/cpython-extension/pypy/tool/sourcetools.py
   pypy/branch/cpython-extension/pypy/tool/stdlib_opcode.py
   pypy/branch/cpython-extension/pypy/translator/c/database.py
   pypy/branch/cpython-extension/pypy/translator/c/gc.py
   pypy/branch/cpython-extension/pypy/translator/c/node.py
   pypy/branch/cpython-extension/pypy/translator/c/src/signals.h
   pypy/branch/cpython-extension/pypy/translator/c/test/test_refcount.py   (props changed)
   pypy/branch/cpython-extension/pypy/translator/driver.py
   pypy/branch/cpython-extension/pypy/translator/geninterplevel.py
   pypy/branch/cpython-extension/pypy/translator/goal/nanos.py
   pypy/branch/cpython-extension/pypy/translator/goal/targetpypystandalone.py
   pypy/branch/cpython-extension/pypy/translator/jvm/conftest.py
   pypy/branch/cpython-extension/pypy/translator/simplify.py
   pypy/branch/cpython-extension/pypy/translator/tool/cbuild.py
   pypy/branch/cpython-extension/pypy/translator/tool/test/test_cbuild.py
   pypy/branch/cpython-extension/pypy/translator/translator.py
Log:
merge from trunk

Modified: pypy/branch/cpython-extension/py/impl/code/_assertionold.py
==============================================================================
--- pypy/branch/cpython-extension/py/impl/code/_assertionold.py	(original)
+++ pypy/branch/cpython-extension/py/impl/code/_assertionold.py	Fri Apr 23 02:41:35 2010
@@ -447,7 +447,6 @@
 
 def check(s, frame=None):
     if frame is None:
-        import sys
         frame = sys._getframe(1)
         frame = py.code.Frame(frame)
     expr = parse(s, 'eval')
@@ -518,7 +517,6 @@
 
 def run(s, frame=None):
     if frame is None:
-        import sys
         frame = sys._getframe(1)
         frame = py.code.Frame(frame)
     module = Interpretable(parse(s, 'exec').node)

Modified: pypy/branch/cpython-extension/pypy/annotation/annrpython.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/annotation/annrpython.py	(original)
+++ pypy/branch/cpython-extension/pypy/annotation/annrpython.py	Fri Apr 23 02:41:35 2010
@@ -1,17 +1,18 @@
-from types import FunctionType
+import sys
+import types
 from pypy.tool.ansi_print import ansi_log, raise_nicer_exception
-from pypy.annotation import model as annmodel
 from pypy.tool.pairtype import pair
+from pypy.tool.error import (format_blocked_annotation_error,
+                             format_someobject_error, AnnotatorError)
+from pypy.objspace.flow.model import (Variable, Constant, FunctionGraph,
+                                      c_last_exception, checkgraph)
+from pypy.translator import simplify, transform
+from pypy.annotation import model as annmodel, signature
 from pypy.annotation.bookkeeper import Bookkeeper
-from pypy.annotation import signature
-from pypy.objspace.flow.model import Variable, Constant
-from pypy.objspace.flow.model import FunctionGraph
-from pypy.objspace.flow.model import c_last_exception, checkgraph
 import py
-log = py.log.Producer("annrpython") 
-py.log.setconsumer("annrpython", ansi_log) 
+log = py.log.Producer("annrpython")
+py.log.setconsumer("annrpython", ansi_log)
 
-from pypy.tool.error import format_blocked_annotation_error, format_someobject_error, AnnotatorError
 
 FAIL = object()
 
@@ -84,7 +85,7 @@
 
     def build_types(self, function, input_arg_types, complete_now=True):
         """Recursively build annotations about the specific entry point."""
-        assert isinstance(function, FunctionType), "fix that!"
+        assert isinstance(function, types.FunctionType), "fix that!"
 
         from pypy.annotation.policy import AnnotatorPolicy
         policy = AnnotatorPolicy()
@@ -429,10 +430,8 @@
 
     def simplify(self, block_subset=None, extra_passes=None):
         # Generic simplifications
-        from pypy.translator import transform
         transform.transform_graph(self, block_subset=block_subset,
                                   extra_passes=extra_passes)
-        from pypy.translator import simplify 
         if block_subset is None:
             graphs = self.translator.graphs
         else:
@@ -534,7 +533,6 @@
 
         except BlockedInference, e:
             if annmodel.DEBUG:
-                import sys
                 self.why_not_annotated[block] = sys.exc_info()
 
             if (e.op is block.operations[-1] and
@@ -611,12 +609,11 @@
                         candidates = [c for c in candidates if c not in covered]
 
         for link in exits:
-            import types
             in_except_block = False
 
             last_exception_var = link.last_exception # may be None for non-exception link
             last_exc_value_var = link.last_exc_value # may be None for non-exception link
-            
+
             if isinstance(link.exitcase, (types.ClassType, type)) \
                    and issubclass(link.exitcase, py.builtin.BaseException):
                 assert last_exception_var and last_exc_value_var

Modified: pypy/branch/cpython-extension/pypy/config/translationoption.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/config/translationoption.py	(original)
+++ pypy/branch/cpython-extension/pypy/config/translationoption.py	Fri Apr 23 02:41:35 2010
@@ -103,7 +103,7 @@
     # JIT generation: use -Ojit to enable it
     BoolOption("jit", "generate a JIT",
                default=False,
-               suggests=[("translation.gc", "hybrid"),     # or "boehm"
+               suggests=[("translation.gc", "hybrid"),
                          ("translation.gcrootfinder", "asmgcc"),
                          ("translation.list_comprehension_operations", True)]),
     ChoiceOption("jit_backend", "choose the backend for the JIT",

Modified: pypy/branch/cpython-extension/pypy/conftest.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/conftest.py	(original)
+++ pypy/branch/cpython-extension/pypy/conftest.py	Fri Apr 23 02:41:35 2010
@@ -1,5 +1,4 @@
 import py, sys, os
-from py.impl.test.outcome import Failed
 from pypy.interpreter.gateway import app2interp_temp
 from pypy.interpreter.error import OperationError
 from pypy.tool.pytest import appsupport

Modified: pypy/branch/cpython-extension/pypy/interpreter/astcompiler/assemble.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/astcompiler/assemble.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/astcompiler/assemble.py	Fri Apr 23 02:41:35 2010
@@ -400,7 +400,8 @@
                              self.first_lineno,
                              lnotab,
                              free_names,
-                             cell_names)
+                             cell_names,
+                             self.compile_info.hidden_applevel)
 
 
 def _list_from_dict(d, offset=0):

Modified: pypy/branch/cpython-extension/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/astcompiler/test/test_compiler.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/astcompiler/test/test_compiler.py	Fri Apr 23 02:41:35 2010
@@ -22,11 +22,15 @@
     """
 
     def run(self, source):
+        import sys
         source = str(py.code.Source(source))
         space = self.space
         code = compile_with_astcompiler(source, 'exec', space)
-        print
-        code.dump()
+        # 2.7 bytecode is too different, the standard `dis` module crashes
+        # when trying to display pypy (2.5-like) bytecode.
+        if sys.version_info < (2, 7):
+            print
+            code.dump()
         w_dict = space.newdict()
         code.exec_code(space, w_dict, w_dict)
         return w_dict
@@ -39,7 +43,12 @@
         pyco_expr = PyCode._from_code(space, co_expr)
         w_res = pyco_expr.exec_code(space, w_dict, w_dict)
         res = space.str_w(space.repr(w_res))
-        assert res == repr(expected)
+        if not isinstance(expected, float):
+            assert res == repr(expected)
+        else:
+            # Float representation can vary a bit between interpreter
+            # versions, compare the numbers instead.
+            assert eval(res) == expected
 
     def simple_test(self, source, evalexpr, expected):
         w_g = self.run(source)

Modified: pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py	Fri Apr 23 02:41:35 2010
@@ -13,7 +13,7 @@
 from pypy.rlib.timer import DummyTimer, Timer
 from pypy.rlib.rarithmetic import r_uint
 from pypy.rlib import jit
-import os, sys
+import os, sys, py
 
 __all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
 
@@ -42,7 +42,7 @@
     def setdictvalue(self, space, attr, w_value, shadows_type=True):
         w_dict = self.getdict()
         if w_dict is not None:
-            space.set_str_keyed_item(w_dict, attr, w_value, shadows_type)
+            space.setitem_str(w_dict, attr, w_value, shadows_type)
             return True
         return False
 
@@ -209,12 +209,6 @@
     def ready(self, result):
         pass
 
-class UnpackValueError(ValueError):
-    def __init__(self, msg):
-        self.msg = msg
-    def __str__(self):
-        return self.msg
-
 class DescrMismatch(Exception):
     pass
 
@@ -257,8 +251,10 @@
         self.actionflag.register_action(self.user_del_action)
         self.actionflag.register_action(self.frame_trace_action)
 
-        from pypy.interpreter.pyframe import PyFrame
-        self.FrameClass = PyFrame    # can be overridden to a subclass
+        from pypy.interpreter.pycode import cpython_magic, default_magic
+        self.our_magic = default_magic
+        self.host_magic = cpython_magic
+        # can be overridden to a subclass
 
         if self.config.objspace.logbytecodes:
             self.bytecodecounts = [0] * 256
@@ -628,7 +624,7 @@
         """shortcut for space.int_w(space.hash(w_obj))"""
         return self.int_w(self.hash(w_obj))
 
-    def set_str_keyed_item(self, w_obj, key, w_value, shadows_type=True):
+    def setitem_str(self, w_obj, key, w_value, shadows_type=True):
         return self.setitem(w_obj, self.wrap(key), w_value)
 
     def finditem_str(self, w_obj, key):
@@ -721,7 +717,8 @@
                     raise
                 break  # done
             if expected_length != -1 and len(items) == expected_length:
-                raise UnpackValueError("too many values to unpack")
+                raise OperationError(space.w_ValueError,
+                                     space.wrap("too many values to unpack"))
             items.append(w_item)
         if expected_length != -1 and len(items) < expected_length:
             i = len(items)
@@ -729,8 +726,9 @@
                 plural = ""
             else:
                 plural = "s"
-            raise UnpackValueError("need more than %d value%s to unpack" %
-                                   (i, plural))
+            raise OperationError(space.w_ValueError,
+                      space.wrap("need more than %d value%s to unpack" %
+                                 (i, plural)))
         return items
 
     def fixedview(self, w_iterable, expected_length=-1):
@@ -877,6 +875,9 @@
         w_objtype = self.type(w_obj)
         return self.issubtype(w_objtype, w_type)
 
+    def isinstance_w(self, w_obj, w_type):
+        return self.is_true(self.isinstance(w_obj, w_type))
+
     # The code below only works
     # for the simple case (new-style instance).
     # These methods are patched with the full logic by the __builtin__
@@ -928,23 +929,30 @@
         import types
         from pypy.interpreter.pycode import PyCode
         if isinstance(expression, str):
-            expression = compile(expression, '?', 'eval')
+            compiler = self.createcompiler()
+            expression = compiler.compile(expression, '?', 'eval', 0,
+                                         hidden_applevel=hidden_applevel)
         if isinstance(expression, types.CodeType):
-            expression = PyCode._from_code(self, expression,
-                                          hidden_applevel=hidden_applevel)
+            # XXX only used by appsupport
+            expression = PyCode._from_code(self, expression)
         if not isinstance(expression, PyCode):
             raise TypeError, 'space.eval(): expected a string, code or PyCode object'
         return expression.exec_code(self, w_globals, w_locals)
 
-    def exec_(self, statement, w_globals, w_locals, hidden_applevel=False):
+    def exec_(self, statement, w_globals, w_locals, hidden_applevel=False,
+              filename=None):
         "NOT_RPYTHON: For internal debugging."
         import types
+        if filename is None:
+            filename = '?'
         from pypy.interpreter.pycode import PyCode
         if isinstance(statement, str):
-            statement = compile(statement, '?', 'exec')
+            compiler = self.createcompiler()
+            statement = compiler.compile(statement, filename, 'exec', 0,
+                                         hidden_applevel=hidden_applevel)
         if isinstance(statement, types.CodeType):
-            statement = PyCode._from_code(self, statement,
-                                          hidden_applevel=hidden_applevel)
+            # XXX only used by appsupport
+            statement = PyCode._from_code(self, statement)
         if not isinstance(statement, PyCode):
             raise TypeError, 'space.exec_(): expected a string, code or PyCode object'
         w_key = self.wrap('__builtins__')
@@ -1095,6 +1103,17 @@
                                  self.wrap('argument must be a unicode'))
         return self.unicode_w(w_obj)
 
+    def path_w(space, w_obj):
+        """ Like str_w, but if the object is unicode, encode it using
+        filesystemencoding
+        """
+        filesystemencoding = space.sys.filesystemencoding
+        if (filesystemencoding and
+            space.is_true(space.isinstance(w_obj, space.w_unicode))):
+            w_obj = space.call_method(w_obj, "encode",
+                                      space.wrap(filesystemencoding))
+        return space.str_w(w_obj)
+
     def bool_w(self, w_obj):
         # Unwraps a bool, also accepting an int for compatibility.
         # This is here mostly just for gateway.int_unwrapping_space_method().
@@ -1162,7 +1181,7 @@
         assert source.startswith('('), "incorrect header in:\n%s" % (source,)
         source = py.code.Source("def anonymous%s\n" % source)
         w_glob = space.newdict()
-        space.exec_(source.compile(), w_glob, w_glob)
+        space.exec_(str(source), w_glob, w_glob)
         return space.getitem(w_glob, space.wrap('anonymous'))
 
 class DummyLock(object):

Modified: pypy/branch/cpython-extension/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/function.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/function.py	Fri Apr 23 02:41:35 2010
@@ -235,15 +235,17 @@
     def _freeze_(self):
         from pypy.interpreter.gateway import BuiltinCode
         if isinstance(self.code, BuiltinCode):
-            identifier = self.code.identifier
-            if Function._all.get(identifier, self) is not self:
-                print "builtin code identifier %s used twice: %s and %s" % (
-                    identifier, self, Function._all[identifier])
             # we have been seen by other means so rtyping should not choke
             # on us
-            Function._all[identifier] = self
+            identifier = self.code.identifier
+            assert Function._all.get(identifier, self) is self, ("duplicate "
+                                                                 "function ids")
+            self.add_to_table()
         return False
 
+    def add_to_table(self):
+        Function._all[self.code.identifier] = self
+
     def find(identifier):
         return Function._all[identifier]
     find = staticmethod(find)

Modified: pypy/branch/cpython-extension/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/gateway.py	Fri Apr 23 02:41:35 2010
@@ -137,6 +137,9 @@
     def visit_c_nonnegint(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
+    def visit_path(self, el, app_sig):
+        self.checked_space_method(el, app_sig)
+
     def visit__Wrappable(self, el, app_sig):
         name = el.__name__
         argname = self.orig_arg()
@@ -238,6 +241,9 @@
     def visit_bufferstr(self, typ):
         self.run_args.append("space.bufferstr_w(%s)" % (self.scopenext(),))
 
+    def visit_path(self, typ):
+        self.run_args.append("space.path_w(%s)" % (self.scopenext(),))
+
     def visit_nonnegint(self, typ):
         self.run_args.append("space.nonnegint_w(%s)" % (self.scopenext(),))
 
@@ -365,6 +371,9 @@
     def visit_bufferstr(self, typ):
         self.unwrap.append("space.bufferstr_w(%s)" % (self.nextarg(),))
 
+    def visit_path(self, typ):
+        self.unwrap.append("space.path_w(%s)" % (self.nextarg(),))
+
     def visit_nonnegint(self, typ):
         self.unwrap.append("space.nonnegint_w(%s)" % (self.nextarg(),))
 
@@ -792,8 +801,8 @@
         defs = gateway._getdefaults(space) # needs to be implemented by subclass
         code = gateway._code
         fn = FunctionWithFixedCode(space, code, None, defs, forcename = gateway.name)
-        if not space.config.translating: # for tests and py.py
-            fn._freeze_()
+        if not space.config.translating:
+            fn.add_to_table()
         if gateway.as_classmethod:
             fn = ClassMethod(space.wrap(fn))
         return fn
@@ -812,6 +821,9 @@
 # and now for something completely different ... 
 #
 
+class MyStr(str):
+    pass
+
 class ApplevelClass:
     """NOT_RPYTHON
     A container for app-level source code that should be executed
@@ -821,12 +833,14 @@
 
     hidden_applevel = True
 
-    def __init__(self, source, filename = None, modname = '__builtin__'):
+    def __init__(self, source, filename=None, modname='__builtin__'):
+        # HAAACK (but a good one)
+        if filename is None:
+            f = sys._getframe(1)
+            filename = MyStr('<%s:%d>' % (f.f_code.co_filename, f.f_lineno))
+            filename.__source__ = py.code.Source(source)
         self.filename = filename
-        if self.filename is None:
-            self.code = py.code.Source(source).compile()
-        else:
-            self.code = NiceCompile(self.filename)(source)
+        self.source = str(py.code.Source(source).deindent())
         self.modname = modname
         # look at the first three lines for a NOT_RPYTHON tag
         first = "\n".join(source.split("\n", 3)[:3])
@@ -907,11 +921,11 @@
 
 def build_applevel_dict(self, space):
     "NOT_RPYTHON"
-    from pypy.interpreter.pycode import PyCode
     w_glob = space.newdict(module=True)
     space.setitem(w_glob, space.wrap('__name__'), space.wrap(self.modname))
-    space.exec_(self.code, w_glob, w_glob,
-                hidden_applevel=self.hidden_applevel)
+    space.exec_(self.source, w_glob, w_glob,
+                hidden_applevel=self.hidden_applevel,
+                filename=self.filename)
     return w_glob
 
 # __________ geninterplevel version __________
@@ -931,7 +945,7 @@
         from pypy.translator.geninterplevel import translate_as_module
         import marshal
         scramble = md5(cls.seed)
-        scramble.update(marshal.dumps(self.code))
+        scramble.update(marshal.dumps(self.source))
         key = scramble.hexdigest()
         initfunc = cls.known_code.get(key)
         if not initfunc:
@@ -952,7 +966,7 @@
         if not initfunc:
             # build it and put it into a file
             initfunc, newsrc = translate_as_module(
-                self.code, self.filename, self.modname)
+                self.source, self.filename, self.modname)
             fname = cls.cache_path.join(name+".py").strpath
             f = file(get_tmp_file_name(fname), "w")
             print >> f, """\

Modified: pypy/branch/cpython-extension/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pycode.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pycode.py	Fri Apr 23 02:41:35 2010
@@ -117,6 +117,10 @@
 
         self._compute_flatcall()
 
+    def _freeze_(self):
+        if self.magic == cpython_magic:
+            raise Exception("CPython host codes should not be rendered")
+        return False
 
     def _init_flags(self):
         co_code = self.co_code

Modified: pypy/branch/cpython-extension/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pycompiler.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pycompiler.py	Fri Apr 23 02:41:35 2010
@@ -151,8 +151,9 @@
                                  e.wrap_info(space))
         return mod
 
-    def compile(self, source, filename, mode, flags):
+    def compile(self, source, filename, mode, flags, hidden_applevel=False):
         from pypy.interpreter.pyparser.pyparse import CompileInfo
-        info = CompileInfo(filename, mode, flags)
+        info = CompileInfo(filename, mode, flags,
+                           hidden_applevel=hidden_applevel)
         mod = self._compile_to_ast(source, info)
         return self._compile_ast(mod, info)

Modified: pypy/branch/cpython-extension/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyframe.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyframe.py	Fri Apr 23 02:41:35 2010
@@ -10,7 +10,7 @@
 from pypy.rlib.objectmodel import we_are_translated, instantiate
 from pypy.rlib.jit import hint
 from pypy.rlib.debug import make_sure_not_resized
-from pypy.rlib import jit
+from pypy.rlib import jit, rstack
 from pypy.tool import stdlib_opcode
 
 # Define some opcodes used
@@ -132,10 +132,9 @@
 
     def execute_frame(self):
         """Execute this frame.  Main entry point to the interpreter."""
-        from pypy.rlib import rstack
         # the following 'assert' is an annotation hint: it hides from
         # the annotator all methods that are defined in PyFrame but
-        # overridden in the FrameClass subclass of PyFrame.
+        # overridden in the {,Host}FrameClass subclasses of PyFrame.
         assert isinstance(self, self.space.FrameClass)
         executioncontext = self.space.getexecutioncontext()
         executioncontext.enter(self)
@@ -238,6 +237,8 @@
             self.pushvalue(w_value)
         
     def peekvalue(self, index_from_top=0):
+        # NOTE: top of the stack is peekvalue(0).
+        # Contrast this with CPython where it's PEEK(-1).
         index_from_top = hint(index_from_top, promote=True)
         index = self.valuestackdepth + ~index_from_top
         assert index >= 0, "peek past the bottom of the stack"

Modified: pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py	Fri Apr 23 02:41:35 2010
@@ -6,17 +6,17 @@
 
 import sys
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import UnpackValueError, Wrappable
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter import gateway, function, eval, pyframe, pytraceback
 from pypy.interpreter.pycode import PyCode
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.objectmodel import we_are_translated
-from pypy.rlib import jit, rstackovf
+from pypy.rlib import jit, rstackovf, rstack
 from pypy.rlib.rarithmetic import r_uint, intmask
 from pypy.rlib.unroll import unrolling_iterable
-from pypy.tool.stdlib_opcode import (opcodedesc, HAVE_ARGUMENT,
-                                     unrolling_opcode_descs,
-                                     opcode_method_names)
+from pypy.tool.stdlib_opcode import (bytecode_spec, host_bytecode_spec,
+                                     unrolling_all_opcode_descs, opmap,
+                                     host_opmap)
 
 def unaryoperation(operationname):
     """NOT_RPYTHON"""
@@ -66,12 +66,16 @@
     # for logbytecode:
     last_opcode = -1
 
+    bytecode_spec = bytecode_spec
+    opcode_method_names = bytecode_spec.method_names
+    opcodedesc = bytecode_spec.opcodedesc
+    opdescmap = bytecode_spec.opdescmap
+    HAVE_ARGUMENT = bytecode_spec.HAVE_ARGUMENT
+
     ### opcode dispatch ###
 
     def dispatch(self, pycode, next_instr, ec):
         # For the sequel, force 'next_instr' to be unsigned for performance
-        from pypy.rlib import rstack # for resume points
-
         next_instr = r_uint(next_instr)
         co_code = pycode.co_code
 
@@ -84,8 +88,6 @@
             return self.popvalue()
 
     def handle_bytecode(self, co_code, next_instr, ec):
-        from pypy.rlib import rstack # for resume points
-
         try:
             next_instr = self.dispatch_bytecode(co_code, next_instr, ec)
             rstack.resume_point("handle_bytecode", self, co_code, ec,
@@ -180,7 +182,7 @@
                 probs[opcode] = probs.get(opcode, 0) + 1
                 self.last_opcode = opcode
 
-            if opcode >= HAVE_ARGUMENT:
+            if opcode >= self.HAVE_ARGUMENT:
                 lo = ord(co_code[next_instr])
                 hi = ord(co_code[next_instr+1])
                 next_instr += 2
@@ -188,16 +190,16 @@
             else:
                 oparg = 0
 
-            while opcode == opcodedesc.EXTENDED_ARG.index:
+            while opcode == self.opcodedesc.EXTENDED_ARG.index:
                 opcode = ord(co_code[next_instr])
-                if opcode < HAVE_ARGUMENT:
+                if opcode < self.HAVE_ARGUMENT:
                     raise BytecodeCorruption
                 lo = ord(co_code[next_instr+1])
                 hi = ord(co_code[next_instr+2])
                 next_instr += 3
                 oparg = (oparg << 16) | (hi << 8) | lo
 
-            if opcode == opcodedesc.RETURN_VALUE.index:
+            if opcode == self.opcodedesc.RETURN_VALUE.index:
                 w_returnvalue = self.popvalue()
                 block = self.unrollstack(SReturnValue.kind)
                 if block is None:
@@ -208,11 +210,11 @@
                     next_instr = block.handle(self, unroller)
                     return next_instr    # now inside a 'finally' block
 
-            if opcode == opcodedesc.YIELD_VALUE.index:
+            if opcode == self.opcodedesc.YIELD_VALUE.index:
                 #self.last_instr = intmask(next_instr - 1) XXX clean up!
                 raise Yield
 
-            if opcode == opcodedesc.END_FINALLY.index:
+            if opcode == self.opcodedesc.END_FINALLY.index:
                 unroller = self.end_finally()
                 if isinstance(unroller, SuspendedUnroller):
                     # go on unrolling the stack
@@ -225,25 +227,28 @@
                         next_instr = block.handle(self, unroller)
                 return next_instr
 
-            if opcode == opcodedesc.JUMP_ABSOLUTE.index:
+            if opcode == self.opcodedesc.JUMP_ABSOLUTE.index:
                 return self.jump_absolute(oparg, next_instr, ec)
 
             if we_are_translated():
-                from pypy.rlib import rstack # for resume points
-
-                for opdesc in unrolling_opcode_descs:
+                for opdesc in unrolling_all_opcode_descs:
                     # static checks to skip this whole case if necessary
+                    if opdesc.bytecode_spec is not self.bytecode_spec:
+                        continue
                     if not opdesc.is_enabled(space):
                         continue
-                    if not hasattr(pyframe.PyFrame, opdesc.methodname):
-                        continue   # e.g. for JUMP_ABSOLUTE, implemented above
+                    if opdesc.methodname in (
+                        'EXTENDED_ARG', 'RETURN_VALUE', 'YIELD_VALUE',
+                        'END_FINALLY', 'JUMP_ABSOLUTE'):
+                        continue   # opcodes implemented above
 
                     if opcode == opdesc.index:
                         # dispatch to the opcode method
                         meth = getattr(self, opdesc.methodname)
                         res = meth(oparg, next_instr)
-                        if opdesc.index == opcodedesc.CALL_FUNCTION.index:
-                            rstack.resume_point("dispatch_call", self, co_code, next_instr, ec)
+                        if opdesc.index == self.opcodedesc.CALL_FUNCTION.index:
+                            rstack.resume_point("dispatch_call", self, co_code,
+                                                next_instr, ec)
                         # !! warning, for the annotator the next line is not
                         # comparing an int and None - you can't do that.
                         # Instead, it's constant-folded to either True or False
@@ -254,8 +259,27 @@
                     self.MISSING_OPCODE(oparg, next_instr)
 
             else:  # when we are not translated, a list lookup is much faster
-                methodname = opcode_method_names[opcode]
-                res = getattr(self, methodname)(oparg, next_instr)
+                methodname = self.opcode_method_names[opcode]
+                try:
+                    meth = getattr(self, methodname)
+                except AttributeError:
+                    raise BytecodeCorruption("unimplemented opcode, ofs=%d, "
+                                             "code=%d, name=%s" %
+                                             (self.last_instr, opcode,
+                                              methodname))
+                try:
+                    res = meth(oparg, next_instr)
+                except Exception:
+                    if 0:
+                        import dis, sys
+                        print "*** %s at offset %d (%s)" % (sys.exc_info()[0],
+                                                            self.last_instr,
+                                                            methodname)
+                        try:
+                            dis.dis(co_code)
+                        except:
+                            pass
+                    raise
                 if res is not None:
                     next_instr = res
 
@@ -536,9 +560,8 @@
             # common case
             raise operror
         else:
-            from pypy.interpreter.pytraceback import check_traceback
             msg = "raise: arg 3 must be a traceback or None"
-            tb = check_traceback(space, w_traceback, msg)
+            tb = pytraceback.check_traceback(space, w_traceback, msg)
             operror.application_traceback = tb
             # special 3-arguments raise, no new traceback obj will be attached
             raise RaiseWithExplicitTraceback(operror)
@@ -599,7 +622,7 @@
     def STORE_NAME(self, varindex, next_instr):
         varname = self.getname_u(varindex)
         w_newvalue = self.popvalue()
-        self.space.set_str_keyed_item(self.w_locals, varname, w_newvalue)
+        self.space.setitem_str(self.w_locals, varname, w_newvalue)
 
     def DELETE_NAME(self, varindex, next_instr):
         w_varname = self.getname_w(varindex)
@@ -615,11 +638,7 @@
 
     def UNPACK_SEQUENCE(self, itemcount, next_instr):
         w_iterable = self.popvalue()
-        try:
-            items = self.space.fixedview(w_iterable, itemcount)
-        except UnpackValueError, e:
-            w_msg = self.space.wrap(e.msg)
-            raise OperationError(self.space.w_ValueError, w_msg)
+        items = self.space.fixedview(w_iterable, itemcount)
         self.pushrevvalues(itemcount, items)
 
     def STORE_ATTR(self, nameindex, next_instr):
@@ -638,7 +657,7 @@
     def STORE_GLOBAL(self, nameindex, next_instr):
         varname = self.getname_u(nameindex)
         w_newvalue = self.popvalue()
-        self.space.set_str_keyed_item(self.w_globals, varname, w_newvalue)
+        self.space.setitem_str(self.w_globals, varname, w_newvalue)
 
     def DELETE_GLOBAL(self, nameindex, next_instr):
         w_varname = self.getname_w(nameindex)
@@ -690,26 +709,6 @@
         w_list = self.space.newlist(items)
         self.pushvalue(w_list)
 
-    def BUILD_MAP(self, itemcount, next_instr):
-        if not we_are_translated() and sys.version_info >= (2, 6):
-            # We could pre-allocate a dict here
-            # but for the moment this code is not translated.
-            pass
-        else:
-            if itemcount != 0:
-                raise BytecodeCorruption
-        w_dict = self.space.newdict()
-        self.pushvalue(w_dict)
-
-    def STORE_MAP(self, zero, next_instr):
-        if not we_are_translated() and sys.version_info >= (2, 6):
-            w_key = self.popvalue()
-            w_value = self.popvalue()
-            w_dict = self.peekvalue()
-            self.space.setitem(w_dict, w_key, w_value)
-        else:
-            raise BytecodeCorruption
-
     def LOAD_ATTR(self, nameindex, next_instr):
         "obj.attributename"
         w_attributename = self.getname_w(nameindex)
@@ -887,7 +886,6 @@
 
     @jit.unroll_safe
     def call_function(self, oparg, w_star=None, w_starstar=None):
-        from pypy.rlib import rstack # for resume points
         from pypy.interpreter.function import is_builtin_code
 
         n_arguments = oparg & 0xff
@@ -920,8 +918,6 @@
         self.pushvalue(w_result)
 
     def CALL_FUNCTION(self, oparg, next_instr):
-        from pypy.rlib import rstack # for resume points
-
         # XXX start of hack for performance
         if (oparg >> 8) & 0xff == 0:
             # Only positional arguments
@@ -1011,14 +1007,22 @@
         self.pushvalue(w_result)
 
     def MISSING_OPCODE(self, oparg, next_instr):
-        ofs = next_instr - 1
+        ofs = self.last_instr
         c = self.pycode.co_code[ofs]
         name = self.pycode.co_name
         raise BytecodeCorruption("unknown opcode, ofs=%d, code=%d, name=%s" %
                                  (ofs, ord(c), name) )
 
     STOP_CODE = MISSING_OPCODE
+    
+    def BUILD_MAP(self, itemcount, next_instr):
+        if itemcount != 0:
+            raise BytecodeCorruption
+        w_dict = self.space.newdict()
+        self.pushvalue(w_dict)
 
+    def STORE_MAP(self, zero, next_instr):
+        raise BytecodeCorruption
 
 ### ____________________________________________________________ ###
 

Modified: pypy/branch/cpython-extension/pypy/interpreter/pyparser/metaparser.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyparser/metaparser.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyparser/metaparser.py	Fri Apr 23 02:41:35 2010
@@ -128,6 +128,7 @@
 
     def build_grammar(self, grammar_cls):
         gram = grammar_cls()
+        gram.start = self.start_symbol
         names = self.dfas.keys()
         names.sort()
         names.remove(self.start_symbol)
@@ -146,8 +147,8 @@
                 for label, next in state.arcs.iteritems():
                     arcs.append((self.make_label(gram, label), dfa.index(next)))
                 states.append((arcs, state.is_final))
-            our_id = gram.symbol_ids[name]
-            gram.dfas[our_id] = (states, self.make_first(gram, name))
+            gram.dfas.append((states, self.make_first(gram, name)))
+            assert len(gram.dfas) - 1 == gram.symbol_ids[name] - 256
         gram.start = gram.symbol_ids[self.start_symbol]
         return gram
 
@@ -229,7 +230,8 @@
         for label, their_first in overlap_check.iteritems():
             for sub_label in their_first:
                 if sub_label in inverse:
-                    raise PgenError("ambiguous symbol %s" % (symbol,))
+                    raise PgenError("ambiguous symbol with label %s"
+                                    % (label,))
                 inverse[sub_label] = label
         self.first[name] = all_labels
         return all_labels

Modified: pypy/branch/cpython-extension/pypy/interpreter/pyparser/parser.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyparser/parser.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyparser/parser.py	Fri Apr 23 02:41:35 2010
@@ -16,9 +16,10 @@
         self.symbol_names = {}
         self.symbol_to_label = {}
         self.keyword_ids = {}
-        self.dfas = {}
+        self.dfas = []
         self.labels = [0]
         self.token_ids = {}
+        self.start = -1
 
     def shared_copy(self):
         new = self.__class__()
@@ -98,7 +99,7 @@
         self.root = None
         current_node = Node(start, None, [], 0, 0)
         self.stack = []
-        self.stack.append((self.grammar.dfas[start], 0, current_node))
+        self.stack.append((self.grammar.dfas[start - 256], 0, current_node))
 
     def add_token(self, token_type, value, lineno, column, line):
         label_index = self.classify(token_type, value, lineno, column, line)
@@ -124,7 +125,7 @@
                         state = dfa[0][state_index]
                     return False
                 elif sym_id >= 256:
-                    sub_node_dfa = self.grammar.dfas[sym_id]
+                    sub_node_dfa = self.grammar.dfas[sym_id - 256]
                     # Check if this token can start a child node.
                     if label_index in sub_node_dfa[1]:
                         self.push(sub_node_dfa, next_state, sym_id, lineno,

Modified: pypy/branch/cpython-extension/pypy/interpreter/pyparser/pyparse.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyparser/pyparse.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyparser/pyparse.py	Fri Apr 23 02:41:35 2010
@@ -65,14 +65,18 @@
     * encoding: The source encoding.
     * last_future_import: The line number and offset of the last __future__
       import.
+    * hidden_applevel: Will this code unit and sub units be hidden at the
+      applevel?
     """
 
-    def __init__(self, filename, mode="exec", flags=0, future_pos=(0, 0)):
+    def __init__(self, filename, mode="exec", flags=0, future_pos=(0, 0),
+                 hidden_applevel=False):
         self.filename = filename
         self.mode = mode
         self.encoding = None
         self.flags = flags
         self.last_future_import = future_pos
+        self.hidden_applevel = hidden_applevel
 
 
 _targets = {

Modified: pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_metaparser.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_metaparser.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_metaparser.py	Fri Apr 23 02:41:35 2010
@@ -33,9 +33,8 @@
         g = self.gram_for("eval: NAME\n")
         assert len(g.dfas) == 1
         eval_sym = g.symbol_ids["eval"]
-        assert eval_sym in g.dfas
         assert g.start == eval_sym
-        states, first = g.dfas[eval_sym]
+        states, first = g.dfas[eval_sym - 256]
         assert states == [([(1, 1)], False), ([], True)]
         assert g.labels[0] == 0
 
@@ -52,7 +51,7 @@
     def test_items(self):
         g = self.gram_for("foo: NAME STRING OP '+'")
         assert len(g.dfas) == 1
-        states = g.dfas[g.symbol_ids["foo"]][0]
+        states = g.dfas[g.symbol_ids["foo"] - 256][0]
         last = states[0][0][0][1]
         for state in states[1:-1]:
             assert last < state[0][0][1]

Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_appinterp.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_appinterp.py	Fri Apr 23 02:41:35 2010
@@ -1,6 +1,7 @@
 
 import py
 from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp, applevelinterp_temp
+from pypy.interpreter.error import OperationError
 
 def test_execwith_novars(space): 
     val = space.appexec([], """ 
@@ -18,11 +19,11 @@
     assert space.eq_w(val, space.wrap(42))
 
 def test_execwith_compile_error(space): 
-    excinfo = py.test.raises(SyntaxError, space.appexec, [], """
+    excinfo = py.test.raises(OperationError, space.appexec, [], """
     (): 
         y y 
     """)
-    assert str(excinfo.value).find('y y') != -1 
+    assert str(excinfo.value.errorstr(space)).find('y y') != -1 
 
 def test_simple_applevel(space):
     app = appdef("""app(x,y): 

Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_compiler.py	Fri Apr 23 02:41:35 2010
@@ -54,6 +54,14 @@
             space.raises_w(space.w_SyntaxError, self.compiler.compile_command,
                            ')', '?', mode, 0)
 
+    def test_hidden_applevel(self):
+        code = self.compiler.compile("def f(x): pass", "<test>", "exec", 0,
+                                     True)
+        assert code.hidden_applevel
+        for w_const in code.co_consts_w:
+            if isinstance(w_const, PyCode):
+                assert code.hidden_applevel
+
     def test_indentation_error(self):
         space = self.space
         space.raises_w(space.w_SyntaxError, self.compiler.compile_command,

Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,6 @@
+
+# -*- coding: utf-8 -*-
+
 from pypy.conftest import gettestobjspace
 from pypy.interpreter import gateway
 from pypy.interpreter import argument
@@ -451,6 +454,16 @@
         assert len(l) == 1
         assert space.eq_w(l[0], w("foo"))
 
+    def test_interp2app_unwrap_spec_path(self, monkeypatch):
+        space = self.space
+        def g(space, p):
+            return p
+
+        app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, 'path'])
+        w_app_g = space.wrap(app_g)
+        monkeypatch.setattr(space.sys, "filesystemencoding", "utf-8")
+        w_res = space.call_function(w_app_g, space.wrap(u"ą"))
+
     def test_interp2app_classmethod(self):
         space = self.space
         w = space.wrap

Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_objspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_objspace.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_objspace.py	Fri Apr 23 02:41:35 2010
@@ -12,7 +12,18 @@
 INT32_MAX = 2147483648
 
 
-class TestObjSpace: 
+class TestObjSpace:
+
+    def test_isinstance(self):
+        space = self.space
+        w_i = space.wrap(4)
+        w_result = space.isinstance(w_i, space.w_int)
+        assert space.is_true(w_result)
+        assert space.isinstance_w(w_i, space.w_int)
+        w_result = space.isinstance(w_i, space.w_str)
+        assert not space.is_true(w_result)
+        assert not space.isinstance_w(w_i, space.w_str)
+
     def test_newlist(self):
         w = self.space.wrap
         l = range(10)
@@ -50,31 +61,40 @@
         assert self.space.newbool(1) == self.space.w_True
 
     def test_unpackiterable(self):
-        w = self.space.wrap
+        space = self.space
+        w = space.wrap
         l = [w(1), w(2), w(3), w(4)]
-        w_l = self.space.newlist(l)
-        assert self.space.unpackiterable(w_l) == l
-        assert self.space.unpackiterable(w_l, 4) == l
-        raises(ValueError, self.space.unpackiterable, w_l, 3)
-        raises(ValueError, self.space.unpackiterable, w_l, 5)
+        w_l = space.newlist(l)
+        assert space.unpackiterable(w_l) == l
+        assert space.unpackiterable(w_l, 4) == l
+        err = raises(OperationError, space.unpackiterable, w_l, 3)
+        assert err.value.match(space, space.w_ValueError)
+        err = raises(OperationError, space.unpackiterable, w_l, 5)
+        assert err.value.match(space, space.w_ValueError)
 
     def test_fixedview(self):
-        w = self.space.wrap
+        space = self.space
+        w = space.wrap
         l = [w(1), w(2), w(3), w(4)]
-        w_l = self.space.newtuple(l)
-        assert self.space.fixedview(w_l) == l
-        assert self.space.fixedview(w_l, 4) == l
-        raises(ValueError, self.space.fixedview, w_l, 3)
-        raises(ValueError, self.space.fixedview, w_l, 5)
+        w_l = space.newtuple(l)
+        assert space.fixedview(w_l) == l
+        assert space.fixedview(w_l, 4) == l
+        err = raises(OperationError, space.fixedview, w_l, 3)
+        assert err.value.match(space, space.w_ValueError)
+        err = raises(OperationError, space.fixedview, w_l, 5)
+        assert err.value.match(space, space.w_ValueError)
 
     def test_listview(self):
-        w = self.space.wrap
+        space = self.space
+        w = space.wrap
         l = [w(1), w(2), w(3), w(4)]
-        w_l = self.space.newtuple(l)
-        assert self.space.listview(w_l) == l
-        assert self.space.listview(w_l, 4) == l
-        raises(ValueError, self.space.listview, w_l, 3)
-        raises(ValueError, self.space.listview, w_l, 5)
+        w_l = space.newtuple(l)
+        assert space.listview(w_l) == l
+        assert space.listview(w_l, 4) == l
+        err = raises(OperationError, space.listview, w_l, 3)
+        assert err.value.match(space, space.w_ValueError)
+        err = raises(OperationError, space.listview, w_l, 5)
+        assert err.value.match(space, space.w_ValueError)
 
     def test_exception_match(self):
         assert self.space.exception_match(self.space.w_ValueError,

Modified: pypy/branch/cpython-extension/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/cpython-extension/pypy/interpreter/typedef.py	Fri Apr 23 02:41:35 2010
@@ -904,6 +904,3 @@
 
 SuspendedUnroller.typedef = TypeDef("SuspendedUnroller")
 SuspendedUnroller.typedef.acceptable_as_base_class = False
-
-
-interptypes = [ val.typedef for name,val in globals().items() if hasattr(val,'__bases__') and hasattr(val,'typedef')  ]

Modified: pypy/branch/cpython-extension/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/cpython-extension/pypy/jit/metainterp/codewriter.py	Fri Apr 23 02:41:35 2010
@@ -394,7 +394,6 @@
         self.assembler = []
         self.constants = []
         self.positions = {}
-        self.blocks = {}
         self.seen_blocks = {}
         self.dont_minimize_variables = 0
         self.pending_exception_handlers = []

Modified: pypy/branch/cpython-extension/pypy/jit/metainterp/optimizefindnode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/metainterp/optimizefindnode.py	(original)
+++ pypy/branch/cpython-extension/pypy/jit/metainterp/optimizefindnode.py	Fri Apr 23 02:41:35 2010
@@ -63,13 +63,14 @@
         # invariant: if escaped=True, then dependencies is None
         if not self.escaped:
             self.escaped = True
+            self.unique = UNIQUE_NO
+            # ^^^ always set unique to UNIQUE_NO when we set escaped to True.
+            # See for example test_find_nodes_store_into_loop_constant_2.
             if self.dependencies is not None:
                 deps = self.dependencies
                 self.dependencies = None
                 for box in deps:
                     box.mark_escaped()
-                    # see test_find_nodes_store_into_loop_constant_1 for this:
-                    box.unique = UNIQUE_NO
 
     def set_unique_nodes(self):
         if self.fromstart:
@@ -342,12 +343,16 @@
         # computed by NodeFinder.find_nodes().
         op = loop.operations[-1]
         assert op.opnum == rop.JUMP
-        specnodes = []
         assert len(self.inputnodes) == len(op.args)
-        for i in range(len(op.args)):
-            inputnode = self.inputnodes[i]
-            exitnode = self.getnode(op.args[i])
-            specnodes.append(self.intersect(inputnode, exitnode))
+        while True:
+            self.restart_needed = False
+            specnodes = []
+            for i in range(len(op.args)):
+                inputnode = self.inputnodes[i]
+                exitnode = self.getnode(op.args[i])
+                specnodes.append(self.intersect(inputnode, exitnode))
+            if not self.restart_needed:
+                break
         loop.token.specnodes = specnodes
 
     def intersect(self, inputnode, exitnode):
@@ -362,6 +367,15 @@
             return prebuiltNotSpecNode
         unique = exitnode.unique
         if unique == UNIQUE_NO:
+            if inputnode is not self.node_fromstart:
+                # Mark the input node as escaped, and schedule a complete
+                # restart of intersect().  This is needed because there is
+                # an order dependency: calling inputnode.mark_escaped()
+                # might set the field exitnode.unique to UNIQUE_NO in some
+                # other node.  If inputnode is node_fromstart, there is no
+                # problem (and it must not be mutated by mark_escaped() then).
+                inputnode.mark_escaped()
+                self.restart_needed = True
             return prebuiltNotSpecNode
         if unique == UNIQUE_INST:
             return self.intersect_instance(inputnode, exitnode)

Modified: pypy/branch/cpython-extension/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/cpython-extension/pypy/jit/metainterp/optimizeopt.py	Fri Apr 23 02:41:35 2010
@@ -216,17 +216,8 @@
         self._fields[ofs] = fieldvalue
 
     def _really_force(self):
-        if self.source_op is None:
-            # this case should not occur; I only managed to get it once
-            # in pypy-c-jit and couldn't reproduce it.  The point is
-            # that it relies on optimizefindnode.py computing exactly
-            # the right level of specialization, and it seems that there
-            # is still a corner case where it gets too specialized for
-            # optimizeopt.py.  Let's not crash in release-built
-            # pypy-c-jit's.  XXX find out when
-            from pypy.rlib.debug import ll_assert
-            ll_assert(False, "_really_force: source_op is None")
-            raise InvalidLoop
+        assert self.source_op is not None
+        # ^^^ This case should not occur any more (see test_bug_3).
         #
         newoperations = self.optimizer.newoperations
         newoperations.append(self.source_op)

Modified: pypy/branch/cpython-extension/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/cpython-extension/pypy/jit/metainterp/pyjitpl.py	Fri Apr 23 02:41:35 2010
@@ -1933,11 +1933,6 @@
         # boxes, in whichever direction is appropriate
         if expect_virtualizable:
             self.virtualizable_boxes = virtualizable_boxes
-            if self._already_allocated_resume_virtuals is not None:
-                # resuming from a ResumeGuardForcedDescr: load the new values
-                # currently stored on the virtualizable fields
-                self.load_fields_from_virtualizable()
-                return
             # just jumped away from assembler (case 4 in the comment in
             # virtualizable.py) into tracing (case 2); check that vable_token
             # is and stays 0.  Note the call to reset_vable_token() in

Modified: pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizefindnode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizefindnode.py	(original)
+++ pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizefindnode.py	Fri Apr 23 02:41:35 2010
@@ -301,8 +301,8 @@
         boxes, getnode = self.find_nodes(ops,
                                          'Virtual(node_vtable, nextdescr=Not)')
         assert not getnode(boxes.p0).escaped
-        assert not getnode(boxes.p1).escaped
-        assert not getnode(boxes.p2).escaped
+        assert getnode(boxes.p1).escaped
+        assert getnode(boxes.p2).escaped
         assert getnode(boxes.p0).fromstart
         assert getnode(boxes.p1).fromstart
         assert getnode(boxes.p2).fromstart

Modified: pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/cpython-extension/pypy/jit/metainterp/test/test_optimizeopt.py	Fri Apr 23 02:41:35 2010
@@ -1740,7 +1740,6 @@
         self.optimize_loop(ops, 'Not, VArray(arraydescr2, Not)',
                            expected)
 
-    @py.test.mark.xfail
     def test_bug_3(self):
         ops = """
         [p1]
@@ -1761,7 +1760,49 @@
         setfield_gc(p1a, p3a, descr=otherdescr)
         jump(p1a)
         """
-        self.optimize_loop(ops, 'Virtual(node_vtable2, nextdescr=Virtual(node_vtable), otherdescr=Not)', None)
+        expected = """
+        [p2, p3]
+        guard_class(p2, ConstClass(node_vtable)) []
+        guard_class(p3, ConstClass(node_vtable)) []
+        setfield_gc(p3, p2, descr=otherdescr)
+        p3a = new_with_vtable(ConstClass(node_vtable))
+        escape(p3a)
+        p2a = new_with_vtable(ConstClass(node_vtable))
+        jump(p2a, p3a)
+        """
+        self.optimize_loop(ops, 'Virtual(node_vtable2, nextdescr=Not, otherdescr=Not)', expected)
+
+    def test_bug_3bis(self):
+        ops = """
+        [p1]
+        guard_nonnull(p1) []
+        guard_class(p1, ConstClass(node_vtable2)) []
+        p2 = getfield_gc(p1, descr=nextdescr)
+        guard_nonnull(12) []
+        guard_class(p2, ConstClass(node_vtable)) []
+        p3 = getfield_gc(p1, descr=otherdescr)
+        guard_nonnull(12) []
+        guard_class(p3, ConstClass(node_vtable)) []
+        p1a = new_with_vtable(ConstClass(node_vtable2))
+        p2a = new_with_vtable(ConstClass(node_vtable))
+        setfield_gc(p3, p2a, descr=otherdescr)
+        p3a = new_with_vtable(ConstClass(node_vtable))
+        escape(p3a)
+        setfield_gc(p1a, p2a, descr=nextdescr)
+        setfield_gc(p1a, p3a, descr=otherdescr)
+        jump(p1a)
+        """
+        expected = """
+        [p2, p3]
+        guard_class(p2, ConstClass(node_vtable)) []
+        guard_class(p3, ConstClass(node_vtable)) []
+        p2a = new_with_vtable(ConstClass(node_vtable))
+        setfield_gc(p3, p2a, descr=otherdescr)
+        p3a = new_with_vtable(ConstClass(node_vtable))
+        escape(p3a)
+        jump(p2a, p3a)
+        """
+        self.optimize_loop(ops, 'Virtual(node_vtable2, nextdescr=Not, otherdescr=Not)', expected)
 
     def test_invalid_loop_1(self):
         ops = """

Modified: pypy/branch/cpython-extension/pypy/module/__builtin__/app_inspect.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/__builtin__/app_inspect.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/__builtin__/app_inspect.py	Fri Apr 23 02:41:35 2010
@@ -64,9 +64,7 @@
 
     if isinstance(obj, types.ModuleType):
         try:
-            result = obj.__dict__.keys()
-            if not isinstance(result, list):
-                raise TypeError("expected __dict__.keys() to be a list")
+            result = list(obj.__dict__.keys())
             result.sort()
             return result
         except AttributeError:

Modified: pypy/branch/cpython-extension/pypy/module/_codecs/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_codecs/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_codecs/__init__.py	Fri Apr 23 02:41:35 2010
@@ -1,5 +1,6 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.rlib import runicode
+from pypy.module._codecs import interp_codecs
 
 class Module(MixedModule):
     appleveldefs = {
@@ -16,7 +17,6 @@
          'unicode_internal_encode' :  'app_codecs.unicode_internal_encode',
          'utf_7_decode' :  'app_codecs.utf_7_decode',
          'utf_7_encode' :  'app_codecs.utf_7_encode',
-         '_register_existing_errors': 'app_codecs._register_existing_errors',
          'charmap_build' : 'app_codecs.charmap_build'
     }
     interpleveldefs = {
@@ -57,9 +57,4 @@
 
         MixedModule.__init__(self, space, *args)
 
-    def setup_after_space_initialization(self):
-        "NOT_RPYTHON"
-        self.space.appexec([], """():
-            import _codecs
-            _codecs._register_existing_errors()
-        """)
+        interp_codecs.register_builtin_error_handlers(space)

Modified: pypy/branch/cpython-extension/pypy/module/_codecs/app_codecs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_codecs/app_codecs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_codecs/app_codecs.py	Fri Apr 23 02:41:35 2010
@@ -1,7 +1,3 @@
-# NOT_RPYTHON
-# Note:
-# This *is* now explicitly RPython.
-# Please make sure not to break this.
 
 """
 
@@ -218,79 +214,6 @@
     res = ''.join(res)
     return res, len(res)
 
-def check_exception(exc):
-    try:
-        delta = exc.end - exc.start
-        if delta < 0 or not isinstance(exc.object, (unicode, str)):
-            raise TypeError("wrong exception")
-    except AttributeError:
-        raise TypeError("wrong exception")
-
-def strict_errors(exc):
-    if isinstance(exc, Exception):
-        raise exc
-    else:
-        raise TypeError("codec must pass exception instance")
-    
-def ignore_errors(exc):
-    check_exception(exc)
-    if isinstance(exc, UnicodeEncodeError):
-        return u'', exc.end
-    elif isinstance(exc, (UnicodeDecodeError, UnicodeTranslateError)):
-        return u'', exc.end
-    else: 
-        raise TypeError("don't know how to handle %.400s in error callback"%exc)
-
-Py_UNICODE_REPLACEMENT_CHARACTER = u"\ufffd"
-
-def replace_errors(exc):
-    check_exception(exc)
-    if isinstance(exc, UnicodeEncodeError):
-        return u'?'*(exc.end-exc.start), exc.end
-    elif isinstance(exc, (UnicodeTranslateError, UnicodeDecodeError)):
-        return Py_UNICODE_REPLACEMENT_CHARACTER*(exc.end-exc.start), exc.end
-    else:
-        raise TypeError("don't know how to handle %.400s in error callback"%exc)
-
-def xmlcharrefreplace_errors(exc):
-    if isinstance(exc, UnicodeEncodeError):
-        res = []
-        for ch in exc.object[exc.start:exc.end]:
-            res += '&#'
-            res += str(ord(ch))
-            res += ';'
-        return u''.join(res), exc.end
-    else:
-        raise TypeError("don't know how to handle %.400s in error callback"%type(exc))
-    
-def backslashreplace_errors(exc):
-    if isinstance(exc, UnicodeEncodeError):
-        p = []
-        for c in exc.object[exc.start:exc.end]:
-            p += '\\'
-            oc = ord(c)
-            if (oc >= 0x00010000):
-                p += 'U'
-                p += "%.8x" % ord(c)
-            elif (oc >= 0x100):
-                p += 'u'
-                p += "%.4x" % ord(c)
-            else:
-                p += 'x'
-                p += "%.2x" % ord(c)
-        return u''.join(p), exc.end
-    else:
-        raise TypeError("don't know how to handle %.400s in error callback"%type(exc))
-
-
-def _register_existing_errors():
-    import _codecs
-    _codecs.register_error("strict", strict_errors)
-    _codecs.register_error("ignore", ignore_errors)
-    _codecs.register_error("replace", replace_errors)
-    _codecs.register_error("xmlcharrefreplace", xmlcharrefreplace_errors)
-    _codecs.register_error("backslashreplace", backslashreplace_errors)
-
 #  ----------------------------------------------------------------------
 
 ##import sys
@@ -356,6 +279,7 @@
     bitsleft = 0
     charsleft = 0
     surrogate = 0
+    startinpos = 0
     p = []
     errorHandler = None
     exc = None

Modified: pypy/branch/cpython-extension/pypy/module/_codecs/interp_codecs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_codecs/interp_codecs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_codecs/interp_codecs.py	Fri Apr 23 02:41:35 2010
@@ -1,5 +1,5 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import ObjSpace, NoneNotWrapped
+from pypy.interpreter.gateway import ObjSpace, NoneNotWrapped, applevel
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
 
@@ -107,7 +107,80 @@
         space.w_LookupError,
         "unknown encoding: %s", encoding)
 lookup_codec.unwrap_spec = [ObjSpace, str]
-    
+
+app_errors = applevel("""
+def check_exception(exc):
+    try:
+        delta = exc.end - exc.start
+        if delta < 0 or not isinstance(exc.object, (unicode, str)):
+            raise TypeError("wrong exception")
+    except AttributeError:
+        raise TypeError("wrong exception")
+
+def strict_errors(exc):
+    if isinstance(exc, Exception):
+        raise exc
+    else:
+        raise TypeError("codec must pass exception instance")
+
+def ignore_errors(exc):
+    check_exception(exc)
+    if isinstance(exc, UnicodeEncodeError):
+        return u'', exc.end
+    elif isinstance(exc, (UnicodeDecodeError, UnicodeTranslateError)):
+        return u'', exc.end
+    else: 
+        raise TypeError("don't know how to handle %.400s in error callback"%exc)
+
+Py_UNICODE_REPLACEMENT_CHARACTER = u"\ufffd"
+
+def replace_errors(exc):
+    check_exception(exc)
+    if isinstance(exc, UnicodeEncodeError):
+        return u'?'*(exc.end-exc.start), exc.end
+    elif isinstance(exc, (UnicodeTranslateError, UnicodeDecodeError)):
+        return Py_UNICODE_REPLACEMENT_CHARACTER*(exc.end-exc.start), exc.end
+    else:
+        raise TypeError("don't know how to handle %.400s in error callback"%exc)
+
+def xmlcharrefreplace_errors(exc):
+    if isinstance(exc, UnicodeEncodeError):
+        res = []
+        for ch in exc.object[exc.start:exc.end]:
+            res += '&#'
+            res += str(ord(ch))
+            res += ';'
+        return u''.join(res), exc.end
+    else:
+        raise TypeError("don't know how to handle %.400s in error callback"%type(exc))
+
+def backslashreplace_errors(exc):
+    if isinstance(exc, UnicodeEncodeError):
+        p = []
+        for c in exc.object[exc.start:exc.end]:
+            p += '\\\\'
+            oc = ord(c)
+            if (oc >= 0x00010000):
+                p += 'U'
+                p += "%.8x" % ord(c)
+            elif (oc >= 0x100):
+                p += 'u'
+                p += "%.4x" % ord(c)
+            else:
+                p += 'x'
+                p += "%.2x" % ord(c)
+        return u''.join(p), exc.end
+    else:
+        raise TypeError("don't know how to handle %.400s in error callback"%type(exc))
+""")
+
+def register_builtin_error_handlers(space):
+    state = space.fromcache(CodecState)
+    for error in ("strict", "ignore", "replace", "xmlcharrefreplace",
+                  "backslashreplace"):
+        name = error + "_errors"
+        state.codec_error_registry[error] = app_errors.wget(space, name)
+
 
 def lookup_error(space, errors):
     """lookup_error(errors) -> handler

Modified: pypy/branch/cpython-extension/pypy/module/_file/interp_file.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_file/interp_file.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_file/interp_file.py	Fri Apr 23 02:41:35 2010
@@ -24,9 +24,10 @@
 
     # Default values until the file is successfully opened
     stream   = None
-    name     = "<uninitialized file>"
+    w_name   = None
     mode     = "<uninitialized file>"
-    encoding = None
+    softspace= 0     # Required according to file object docs
+    encoding = None  # This is not used internally by file objects
     fd       = -1
 
     def __init__(self, space):
@@ -38,12 +39,11 @@
         self.clear_all_weakrefs()
         self.direct_close()
 
-    def fdopenstream(self, stream, fd, mode, w_name):
+    def fdopenstream(self, stream, fd, mode, w_name=None):
         self.fd = fd
-        self.w_name = w_name
-        self.softspace = 0    # Required according to file object docs
-        self.encoding = None  # This is not used internally by file objects
         self.mode = mode
+        if w_name is not None:
+            self.w_name = w_name
         self.stream = stream
         if stream.flushable():
             getopenstreams(self.space)[stream] = None
@@ -83,10 +83,11 @@
     def direct___init__(self, w_name, mode='r', buffering=-1):
         name = self.space.str_w(w_name)
         self.direct_close()
+        self.w_name = w_name
         self.check_mode_ok(mode)
         stream = streamio.open_file_as_stream(name, mode, buffering)
         fd = stream.try_to_find_file_descriptor()
-        self.fdopenstream(stream, fd, mode, w_name)
+        self.fdopenstream(stream, fd, mode)
 
     def direct___enter__(self):
         if self.stream is None:
@@ -102,9 +103,10 @@
 
     def direct_fdopen(self, fd, mode='r', buffering=-1):
         self.direct_close()
+        self.w_name = self.space.wrap('<fdopen>')
         self.check_mode_ok(mode)
         stream = streamio.fdopen_as_stream(fd, mode, buffering)
-        self.fdopenstream(stream, fd, mode, self.space.wrap('<fdopen>'))
+        self.fdopenstream(stream, fd, mode)
 
     def direct_close(self):
         space = self.space
@@ -239,7 +241,7 @@
         try:
             self.direct_fdopen(fd, mode, buffering)
         except StreamErrors, e:
-            raise wrap_streamerror(self.space, e)
+            raise wrap_streamerror(self.space, e, self.w_name)
 
     _exposed_method_names = []
 
@@ -275,7 +277,7 @@
                     try:
                         result = self.direct_%(name)s(%(callsig)s)
                     except StreamErrors, e:
-                        raise wrap_streamerror(space, e)
+                        raise wrap_streamerror(space, e, self.w_name)
                 finally:
                     self.unlock()
                 return %(wrapresult)s
@@ -387,20 +389,23 @@
             head = "closed"
         else:
             head = "open"
-        if self.space.is_true(self.space.isinstance(self.w_name,
-                                                    self.space.w_str)):
-            info = "%s file '%s', mode '%s'" % (
-                head,
-                self.space.str_w(self.w_name),
-                self.mode)
-        else:
-            info = "%s file %s, mode '%s'" % (
-                head,
-                self.space.str_w(self.space.repr(self.w_name)),
-                self.mode)
+        info = "%s file %s, mode '%s'" % (
+            head,
+            self.getdisplayname(),
+            self.mode)
         return self.getrepr(self.space, info)
     file__repr__.unwrap_spec = ['self']
 
+    def getdisplayname(self):
+        w_name = self.w_name
+        if w_name is None:
+            return '?'
+        elif self.space.is_true(self.space.isinstance(w_name,
+                                                      self.space.w_str)):
+            return "'%s'" % self.space.str_w(w_name) 
+        else:
+            return self.space.str_w(self.space.repr(w_name))
+
     def file_readinto(self, w_rwbuffer):
         """readinto() -> Undocumented.  Don't use this; it may go away."""
         # XXX not the most efficient solution as it doesn't avoid the copying

Modified: pypy/branch/cpython-extension/pypy/module/_file/interp_stream.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_file/interp_stream.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_file/interp_stream.py	Fri Apr 23 02:41:35 2010
@@ -10,16 +10,16 @@
 
 import os
 
-def wrap_streamerror(space, e):
+def wrap_streamerror(space, e, w_filename=None):
     if isinstance(e, streamio.StreamError):
         return OperationError(space.w_ValueError,
                               space.wrap(e.message))
     elif isinstance(e, OSError):
-        return wrap_oserror_as_ioerror(space, e)
+        return wrap_oserror_as_ioerror(space, e, w_filename)
     else:
         return OperationError(space.w_IOError, space.w_None)
 
-def wrap_oserror_as_ioerror(space, e):
+def wrap_oserror_as_ioerror(space, e, w_filename=None):
     assert isinstance(e, OSError)
     errno = e.errno
     try:
@@ -28,7 +28,8 @@
         msg = 'error %d' % errno
     w_error = space.call_function(space.w_IOError,
                                   space.wrap(errno),
-                                  space.wrap(msg))
+                                  space.wrap(msg),
+                                  w_filename)
     return OperationError(space.w_IOError, w_error)
 
 

Modified: pypy/branch/cpython-extension/pypy/module/_file/test/test_file.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_file/test/test_file.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_file/test/test_file.py	Fri Apr 23 02:41:35 2010
@@ -125,6 +125,13 @@
         assert type(res) is str
         f.close()
 
+    def test_oserror_has_filename(self):
+        try:
+            f = self.file("file that is clearly not there")
+        except IOError, e:
+            assert e.filename == 'file that is clearly not there'
+        else:
+            raise Exception("did not raise")
 
     def test_readline_mixed_with_read(self):
         s = '''From MAILER-DAEMON Wed Jan 14 14:42:30 2009

Modified: pypy/branch/cpython-extension/pypy/module/_locale/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_locale/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_locale/__init__.py	Fri Apr 23 02:41:35 2010
@@ -1,27 +1,29 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.module._locale import interp_locale
+from pypy.rlib import rlocale
 import sys
 
 class Module(MixedModule):
     """Support for POSIX locales."""
 
     interpleveldefs  = {
-            'setlocale':                'interp_locale.setlocale',
-            'localeconv':               'interp_locale.localeconv',
-            'strcoll':                  'interp_locale.strcoll',
-            'strxfrm':                  'interp_locale.strxfrm',
-            }
+        'setlocale':  'interp_locale.setlocale',
+        'localeconv': 'interp_locale.localeconv',
+        'strcoll':    'interp_locale.strcoll',
+        'strxfrm':    'interp_locale.strxfrm',
+        'Error':      'interp_locale.W_Error',
+    }
 
     if sys.platform == 'win32':
         interpleveldefs.update({
             '_getdefaultlocale':        'interp_locale.getdefaultlocale',
             })
 
-    if interp_locale.HAVE_LANGINFO:
+    if rlocale.HAVE_LANGINFO:
         interpleveldefs.update({
             'nl_langinfo':              'interp_locale.nl_langinfo',
             })
-    if interp_locale.HAVE_LIBINTL:
+    if rlocale.HAVE_LIBINTL:
         interpleveldefs.update({
             'gettext':                  'interp_locale.gettext',
             'dgettext':                 'interp_locale.dgettext',
@@ -29,18 +31,16 @@
             'textdomain':               'interp_locale.textdomain',
             'bindtextdomain':           'interp_locale.bindtextdomain',
             })
-        if interp_locale.HAVE_BIND_TEXTDOMAIN_CODESET:
+        if rlocale.HAVE_BIND_TEXTDOMAIN_CODESET:
             interpleveldefs.update({
             'bind_textdomain_codeset':'interp_locale.bind_textdomain_codeset',
             })
 
     appleveldefs  = {
-            'Error':                'app_locale.Error',
-            '_fixup_ulcase':        'app_locale._fixup_ulcase',
             }
 
     def buildloaders(cls):
-        for constant, value in interp_locale.constants.iteritems():
+        for constant, value in rlocale.constants.iteritems():
             Module.interpleveldefs[constant] = "space.wrap(%r)" % value
         super(Module, cls).buildloaders()
     buildloaders = classmethod(buildloaders)

Modified: pypy/branch/cpython-extension/pypy/module/_locale/interp_locale.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_locale/interp_locale.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_locale/interp_locale.py	Fri Apr 23 02:41:35 2010
@@ -1,188 +1,72 @@
 from pypy.rpython.tool import rffi_platform as platform
-from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rlib import rposix
 from pypy.rlib.rarithmetic import intmask
 
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import ObjSpace, W_Root
 
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.rlib import rlocale
+from pypy.module.exceptions.interp_exceptions import _new_exception, W_Exception
+from pypy.rpython.lltypesystem import lltype, rffi
 
-import sys
-
-HAVE_LANGINFO = sys.platform != 'win32'
-HAVE_LIBINTL  = sys.platform != 'win32'
-
-class CConfig:
-    includes = ['locale.h', 'limits.h']
-    if HAVE_LANGINFO:
-        includes += ['langinfo.h']
-    if HAVE_LIBINTL:
-        includes += ['libintl.h']
-    if sys.platform == 'win32':
-        includes += ['windows.h']
-    _compilation_info_ = ExternalCompilationInfo(
-        includes=includes,
-    )
-    HAVE_BIND_TEXTDOMAIN_CODESET = platform.Has('bind_textdomain_codeset')
-    lconv = platform.Struct("struct lconv", [
-            # Numeric (non-monetary) information.
-            ("decimal_point", rffi.CCHARP),    # Decimal point character.
-            ("thousands_sep", rffi.CCHARP),    # Thousands separator.
-
-            ## Each element is the number of digits in each group;
-            ## elements with higher indices are farther left.
-            ## An element with value CHAR_MAX means that no further grouping is done.
-            ## An element with value 0 means that the previous element is used
-            ## for all groups farther left.  */
-            ("grouping", rffi.CCHARP),
-
-            ## Monetary information.
-
-            ## First three chars are a currency symbol from ISO 4217.
-            ## Fourth char is the separator.  Fifth char is '\0'.
-            ("int_curr_symbol", rffi.CCHARP),
-            ("currency_symbol", rffi.CCHARP),   # Local currency symbol.
-            ("mon_decimal_point", rffi.CCHARP), # Decimal point character.
-            ("mon_thousands_sep", rffi.CCHARP), # Thousands separator.
-            ("mon_grouping", rffi.CCHARP),      # Like `grouping' element (above).
-            ("positive_sign", rffi.CCHARP),     # Sign for positive values.
-            ("negative_sign", rffi.CCHARP),     # Sign for negative values.
-            ("int_frac_digits", rffi.UCHAR),    # Int'l fractional digits.
-
-            ("frac_digits", rffi.UCHAR),        # Local fractional digits.
-            ## 1 if currency_symbol precedes a positive value, 0 if succeeds.
-            ("p_cs_precedes", rffi.UCHAR),
-            ## 1 iff a space separates currency_symbol from a positive value.
-            ("p_sep_by_space", rffi.UCHAR),
-            ## 1 if currency_symbol precedes a negative value, 0 if succeeds.
-            ("n_cs_precedes", rffi.UCHAR),
-            ## 1 iff a space separates currency_symbol from a negative value.
-            ("n_sep_by_space", rffi.UCHAR),
-
-            ## Positive and negative sign positions:
-            ## 0 Parentheses surround the quantity and currency_symbol.
-            ## 1 The sign string precedes the quantity and currency_symbol.
-            ## 2 The sign string follows the quantity and currency_symbol.
-            ## 3 The sign string immediately precedes the currency_symbol.
-            ## 4 The sign string immediately follows the currency_symbol.
-            ("p_sign_posn", rffi.UCHAR),
-            ("n_sign_posn", rffi.UCHAR),
-            ])
-
-
-constants = {}
-constant_names = (
-        'LC_CTYPE',
-        'LC_NUMERIC',
-        'LC_TIME',
-        'LC_COLLATE',
-        'LC_MONETARY',
-        'LC_MESSAGES',
-        'LC_ALL',
-        'LC_PAPER',
-        'LC_NAME',
-        'LC_ADDRESS',
-        'LC_TELEPHONE',
-        'LC_MEASUREMENT',
-        'LC_IDENTIFICATION',
-        'LC_MIN',
-        'LC_MAX',
-        # from limits.h
-        'CHAR_MAX',
-        )
-
-for name in constant_names:
-    setattr(CConfig, name, platform.DefinedConstantInteger(name))
-
-langinfo_names = []
-if HAVE_LANGINFO:
-    # some of these consts have an additional #ifdef directives
-    # should we support them?
-    langinfo_names.extend('RADIXCHAR THOUSEP CRNCYSTR D_T_FMT D_FMT T_FMT '
-                        'AM_STR PM_STR CODESET T_FMT_AMPM ERA ERA_D_FMT '
-                        'ERA_D_T_FMT ERA_T_FMT ALT_DIGITS YESEXPR NOEXPR '
-                        '_DATE_FMT'.split())
-    for i in range(1, 8):
-        langinfo_names.append("DAY_%d" % i)
-        langinfo_names.append("ABDAY_%d" % i)
-    for i in range(1, 13):
-        langinfo_names.append("MON_%d" % i)
-        langinfo_names.append("ABMON_%d" % i)
-
-if sys.platform == 'win32':
-    langinfo_names.extend('LOCALE_USER_DEFAULT LOCALE_SISO639LANGNAME '
-                      'LOCALE_SISO3166CTRYNAME LOCALE_IDEFAULTLANGUAGE '
-                      ''.split())
-
-
-for name in langinfo_names:
-    setattr(CConfig, name, platform.DefinedConstantInteger(name))
-
-class cConfig(object):
-    pass
-
-for k, v in platform.configure(CConfig).items():
-    setattr(cConfig, k, v)
+W_Error = _new_exception('Error', W_Exception, 'locale error')
 
-# needed to export the constants inside and outside. see __init__.py
-for name in constant_names:
-    value = getattr(cConfig, name)
-    if value is not None:
-        constants[name] = value
-
-for name in langinfo_names:
-    value = getattr(cConfig, name)
-    if value is not None and sys.platform != 'win32':
-        constants[name] = value
-
-locals().update(constants)
-
-HAVE_BIND_TEXTDOMAIN_CODESET = cConfig.HAVE_BIND_TEXTDOMAIN_CODESET
-
-def external(name, args, result, calling_conv='c'):
-    return rffi.llexternal(name, args, result,
-                           compilation_info=CConfig._compilation_info_,
-                           calling_conv=calling_conv)
+import sys
 
 def make_error(space, msg):
-    w_module = space.getbuiltinmodule('_locale')
-    w_exception_class = space.getattr(w_module, space.wrap('Error'))
-    w_exception = space.call_function(w_exception_class, space.wrap(msg))
-    return OperationError(w_exception_class, w_exception)
+    return OperationError(space.gettypeobject(W_Error.typedef), space.wrap(msg))
 
-_setlocale = external('setlocale', [rffi.INT, rffi.CCHARP], rffi.CCHARP)
+def rewrap_error(space, e):
+    return OperationError(space.gettypeobject(W_Error.typedef),
+                          space.wrap(e.message))
+
+def _fixup_ulcase(space):
+    stringmod = space.call_function(
+        space.getattr(space.getbuiltinmodule('__builtin__'),
+                      space.wrap('__import__')), space.wrap('string'))
+    # create uppercase map string
+    ul = []
+    for c in xrange(256):
+        if rlocale.isupper(c):
+            ul.append(chr(c))
+    space.setattr(stringmod, space.wrap('uppercase'), space.wrap(''.join(ul)))
+
+    # create lowercase string
+    ul = []
+    for c in xrange(256):
+        if rlocale.islower(c):
+            ul.append(chr(c))
+    space.setattr(stringmod, space.wrap('lowercase'), space.wrap(''.join(ul)))
+
+    # create letters string
+    ul = []
+    for c in xrange(256):
+        if rlocale.isalpha(c):
+            ul.append(chr(c))
+    space.setattr(stringmod, space.wrap('letters'), space.wrap(''.join(ul)))
 
 def setlocale(space, category, w_locale=None):
     "(integer,string=None) -> string. Activates/queries locale processing."
 
-    if cConfig.LC_MAX is not None:
-        if not cConfig.LC_MIN <= category <= cConfig.LC_MAX:
-            raise make_error(space, "invalid locale category")
-
     if space.is_w(w_locale, space.w_None) or w_locale is None:
-        result = _setlocale(rffi.cast(rffi.INT, category), None)
-        if not result:
-            raise make_error(space, "locale query failed")
+        locale = None
     else:
-        locale = rffi.str2charp(space.str_w(w_locale))
-
-        result = _setlocale(rffi.cast(rffi.INT, category), locale)
-        if not result:
-            raise make_error(space, "unsupported locale setting")
-
-        # record changes to LC_CTYPE
-        if category in (LC_CTYPE, LC_ALL):
-            w_module = space.getbuiltinmodule('_locale')
-            w_fun = space.getattr(w_module, space.wrap('_fixup_ulcase'))
-            space.call_function(w_fun)
+        locale = space.str_w(w_locale)
+    try:
+        result = rlocale.setlocale(category, locale)
+    except rlocale.LocaleError, e:
+        raise rewrap_error(space, e)
+
+    # record changes to LC_CTYPE
+    if category in (rlocale.LC_CTYPE, rlocale.LC_ALL):
+        _fixup_ulcase(space)
 
-    return space.wrap(rffi.charp2str(result))
+    return space.wrap(result)
 
 setlocale.unwrap_spec = [ObjSpace, int, W_Root]
 
-_lconv = lltype.Ptr(cConfig.lconv)
-_localeconv = external('localeconv', [], _lconv)
+_lconv = lltype.Ptr(rlocale.cConfig.lconv)
+_localeconv = rlocale.external('localeconv', [], _lconv)
 
 def _w_copy_grouping(space, text):
     groups = [ space.wrap(ord(group)) for group in text ]
@@ -238,8 +122,8 @@
 
 localeconv.unwrap_spec = [ObjSpace]
 
-_strcoll = external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)
-_wcscoll = external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)
+_strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)
+_wcscoll = rlocale.external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)
 
 def strcoll(space, w_s1, w_s2):
     "string,string -> int. Compares two strings according to the locale."
@@ -264,7 +148,7 @@
 
 strcoll.unwrap_spec = [ObjSpace, W_Root, W_Root]
 
-_strxfrm = external('strxfrm',
+_strxfrm = rlocale.external('strxfrm',
                     [rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T], rffi.SIZE_T)
 
 def strxfrm(space, s):
@@ -287,27 +171,25 @@
 
 strxfrm.unwrap_spec = [ObjSpace, str]
 
-if HAVE_LANGINFO:
-    nl_item = rffi.INT
-    _nl_langinfo = external('nl_langinfo', [nl_item], rffi.CCHARP)
+if rlocale.HAVE_LANGINFO:
 
     def nl_langinfo(space, key):
         """nl_langinfo(key) -> string
         Return the value for the locale information associated with key."""
 
-        if key in constants.values():
-            result = _nl_langinfo(rffi.cast(nl_item, key))
-            return space.wrap(rffi.charp2str(result))
-        raise OperationError(space.w_ValueError,
-                             space.wrap("unsupported langinfo constant"))
+        try:
+            return space.wrap(rlocale.nl_langinfo(key))
+        except ValueError:
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("unsupported langinfo constant"))
 
     nl_langinfo.unwrap_spec = [ObjSpace, int]
 
 #___________________________________________________________________
 # HAVE_LIBINTL dependence
 
-if HAVE_LIBINTL:
-    _gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP)
+if rlocale.HAVE_LIBINTL:
+    _gettext = rlocale.external('gettext', [rffi.CCHARP], rffi.CCHARP)
 
     def gettext(space, msg):
         """gettext(msg) -> string
@@ -316,7 +198,7 @@
 
     gettext.unwrap_spec = [ObjSpace, str]
 
-    _dgettext = external('dgettext', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
+    _dgettext = rlocale.external('dgettext', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
 
     def dgettext(space, w_domain, msg):
         """dgettext(domain, msg) -> string
@@ -332,7 +214,7 @@
 
     dgettext.unwrap_spec = [ObjSpace, W_Root, str]
 
-    _dcgettext = external('dcgettext', [rffi.CCHARP, rffi.CCHARP, rffi.INT],
+    _dcgettext = rlocale.external('dcgettext', [rffi.CCHARP, rffi.CCHARP, rffi.INT],
                                                                 rffi.CCHARP)
 
     def dcgettext(space, w_domain, msg, category):
@@ -353,7 +235,7 @@
     dcgettext.unwrap_spec = [ObjSpace, W_Root, str, int]
 
 
-    _textdomain = external('textdomain', [rffi.CCHARP], rffi.CCHARP)
+    _textdomain = rlocale.external('textdomain', [rffi.CCHARP], rffi.CCHARP)
 
     def textdomain(space, w_domain):
         """textdomain(domain) -> string
@@ -370,7 +252,7 @@
 
     textdomain.unwrap_spec = [ObjSpace, W_Root]
 
-    _bindtextdomain = external('bindtextdomain', [rffi.CCHARP, rffi.CCHARP],
+    _bindtextdomain = rlocale.external('bindtextdomain', [rffi.CCHARP, rffi.CCHARP],
                                                                 rffi.CCHARP)
 
     def bindtextdomain(space, domain, w_dir):
@@ -392,10 +274,10 @@
 
     bindtextdomain.unwrap_spec = [ObjSpace, str, W_Root]
 
-    _bind_textdomain_codeset = external('bind_textdomain_codeset',
+    _bind_textdomain_codeset = rlocale.external('bind_textdomain_codeset',
                                     [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
 
-    if HAVE_BIND_TEXTDOMAIN_CODESET:
+    if rlocale.HAVE_BIND_TEXTDOMAIN_CODESET:
         def bind_textdomain_codeset(space, domain, w_codeset):
             """bind_textdomain_codeset(domain, codeset) -> string
             Bind the C library's domain to codeset."""
@@ -422,10 +304,10 @@
 if sys.platform == 'win32':
     from pypy.rlib import rwin32
     LCID = LCTYPE = rwin32.DWORD
-    GetACP = external('GetACP',
+    GetACP = rlocale.external('GetACP',
                       [], rffi.INT,
                       calling_conv='win')
-    GetLocaleInfo = external('GetLocaleInfoA',
+    GetLocaleInfo = rlocale.external('GetLocaleInfoA',
                              [LCID, LCTYPE, rwin32.LPSTR, rffi.INT], rffi.INT,
                              calling_conv='win')
 

Modified: pypy/branch/cpython-extension/pypy/module/_locale/test/test_locale.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_locale/test/test_locale.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_locale/test/test_locale.py	Fri Apr 23 02:41:35 2010
@@ -7,9 +7,9 @@
     def setup_class(cls):
         cls.space = space = gettestobjspace(usemodules=['_locale'])
         if sys.platform != 'win32':
-            cls.w_language_en = cls.space.wrap("en_US")
-            cls.w_language_utf8 = cls.space.wrap("en_US.UTF-8")
-            cls.w_language_pl = cls.space.wrap("pl_PL.UTF-8")
+            cls.w_language_en = cls.space.wrap("C")
+            cls.w_language_utf8 = cls.space.wrap("en_US.utf8")
+            cls.w_language_pl = cls.space.wrap("pl_PL.utf8")
             cls.w_encoding_pl = cls.space.wrap("utf-8")
         else:
             cls.w_language_en = cls.space.wrap("English_US")
@@ -118,11 +118,11 @@
         assert string.lowercase == lcase
         assert string.uppercase == ucase
 
-        if self.language_en != self.language_utf8:
-            _locale.setlocale(_locale.LC_ALL, self.language_en)
+        _locale.setlocale(_locale.LC_ALL, self.language_en)
 
-            assert string.lowercase != lcase
-            assert string.uppercase != ucase
+        # the asserts below are just plain wrong
+        #    assert string.lowercase != lcase
+        #    assert string.uppercase != ucase
 
     def test_localeconv(self):
         import _locale

Modified: pypy/branch/cpython-extension/pypy/module/_stackless/interp_coroutine.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_stackless/interp_coroutine.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/_stackless/interp_coroutine.py	Fri Apr 23 02:41:35 2010
@@ -15,7 +15,7 @@
 experience to decide where to set the limits.
 """
 
-from pypy.interpreter.baseobjspace import Wrappable, UnpackValueError
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.typedef import GetSetProperty, TypeDef
 from pypy.interpreter.typedef import interp_attrproperty, interp_attrproperty_w
@@ -173,11 +173,8 @@
         return nt([w_new_inst, nt(tup_base), nt(tup_state)])
 
     def descr__setstate__(self, space, w_args):
-        try:
-            w_flags, w_state, w_thunk, w_parent = space.unpackiterable(w_args,
-                                                             expected_length=4)
-        except UnpackValueError, e:
-            raise OperationError(space.w_ValueError, space.wrap(e.msg))
+        w_flags, w_state, w_thunk, w_parent = space.unpackiterable(w_args,
+                                                        expected_length=4)
         self.flags = space.int_w(w_flags)
         if space.is_w(w_parent, space.w_None):
             w_parent = self.w_getmain(space)
@@ -188,11 +185,8 @@
         if space.is_w(w_thunk, space.w_None):
             self.thunk = None
         else:
-            try:
-                w_func, w_args, w_kwds = space.unpackiterable(w_thunk,
-                                                             expected_length=3)
-            except UnpackValueError, e:
-                raise OperationError(space.w_ValueError, space.wrap(e.msg))
+            w_func, w_args, w_kwds = space.unpackiterable(w_thunk,
+                                                          expected_length=3)
             args = Arguments.frompacked(space, w_args, w_kwds)
             self.bind(_AppThunk(space, self.costate, w_func, args))
 

Modified: pypy/branch/cpython-extension/pypy/module/bz2/interp_bz2.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/bz2/interp_bz2.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/bz2/interp_bz2.py	Fri Apr 23 02:41:35 2010
@@ -222,7 +222,11 @@
             head = "closed"
         else:
             head = "open"
-        info = "%s bz2.BZ2File '%s', mode '%s'" % (head, self.name, self.mode)
+        w_name = self.w_name
+        if w_name is None:
+            w_name = self.space.wrap('?')
+        info = "%s bz2.BZ2File %s, mode '%s'" % (head, self.getdisplayname(),
+                                                 self.mode)
         return self.getrepr(self.space, info)
     file_bz2__repr__.unwrap_spec = ['self']
 

Modified: pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py	Fri Apr 23 02:41:35 2010
@@ -20,7 +20,7 @@
     except OSError, e: 
         raise wrap_oserror(space, e, fname)
     return space.wrap(fd)
-open.unwrap_spec = [ObjSpace, str, "c_int", "c_int"]
+open.unwrap_spec = [ObjSpace, 'path', "c_int", "c_int"]
 
 def lseek(space, fd, pos, how):
     """Set the current position of a file descriptor.  Return the new position.
@@ -180,7 +180,7 @@
         raise wrap_oserror(space, e, path)
     else: 
         return build_stat_result(space, st)
-stat.unwrap_spec = [ObjSpace, str]
+stat.unwrap_spec = [ObjSpace, 'path']
 
 def lstat(space, path):
     "Like stat(path), but do no follow symbolic links."
@@ -190,7 +190,7 @@
         raise wrap_oserror(space, e, path)
     else:
         return build_stat_result(space, st)
-lstat.unwrap_spec = [ObjSpace, str]
+lstat.unwrap_spec = [ObjSpace, 'path']
 
 class StatState(object):
     def __init__(self, space):
@@ -284,7 +284,7 @@
         os.unlink(path)
     except OSError, e: 
         raise wrap_oserror(space, e, path)
-unlink.unwrap_spec = [ObjSpace, str]
+unlink.unwrap_spec = [ObjSpace, 'path']
 
 def remove(space, path):
     """Remove a file (same as unlink(path))."""
@@ -292,7 +292,7 @@
         os.unlink(path)
     except OSError, e: 
         raise wrap_oserror(space, e, path)
-remove.unwrap_spec = [ObjSpace, str]
+remove.unwrap_spec = [ObjSpace, 'path']
 
 def _getfullpathname(space, path):
     """helper for ntpath.abspath """

Modified: pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,6 @@
+
+# -*- coding: utf-8 -*-
+
 from pypy.objspace.std import StdObjSpace 
 from pypy.tool.udir import udir
 from pypy.conftest import gettestobjspace
@@ -35,10 +38,12 @@
     if os.name == 'nt':
         py.test.skip("no sparse files on Windows")
 
+GET_POSIX = "(): import %s as m ; return m" % os.name
+
 class AppTestPosix: 
     def setup_class(cls): 
         cls.space = space 
-        cls.w_posix = space.appexec([], "(): import %s as m ; return m" % os.name)
+        cls.w_posix = space.appexec([], GET_POSIX)
         cls.w_path = space.wrap(str(path))
         cls.w_path2 = space.wrap(str(path2))
         cls.w_pdir = space.wrap(str(pdir))
@@ -637,6 +642,46 @@
         assert isinstance(f, file)
         assert f.read() == 'xxx'
 
+class AppTestPosixUnicode:
+
+    def setup_class(cls):
+        cls.space = space
+        cls.w_posix = space.appexec([], GET_POSIX)
+        if py.test.config.option.runappdirect:
+            # Can't change encoding
+            try:
+                u"ą".encode(sys.getfilesystemencoding())
+            except UnicodeEncodeError:
+                py.test.skip("encoding not good enough")
+        else:
+            cls.save_fs_encoding = space.sys.filesystemencoding
+            space.sys.filesystemencoding = "utf-8"
+
+    def teardown_class(cls):
+        cls.space.sys.filesystemencoding = cls.save_fs_encoding
+
+    def test_stat_unicode(self):
+        # test that passing unicode would not raise UnicodeDecodeError
+        try:
+            self.posix.stat(u"ą")
+        except OSError:
+            pass
+
+    def test_open_unicode(self):
+        # Ensure passing unicode doesn't raise UnicodeEncodeError
+        try:
+            self.posix.open(u"ą", self.posix.O_WRONLY)
+        except OSError:
+            pass
+
+    def test_remove_unicode(self):
+        # See 2 above ;)
+        try:
+            self.posix.remove(u"ą")
+        except OSError:
+            pass
+
+
 class TestPexpect(object):
     # XXX replace with AppExpectTest class as soon as possible
     def setup_class(cls):

Modified: pypy/branch/cpython-extension/pypy/module/pypyjit/policy.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/pypyjit/policy.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/pypyjit/policy.py	Fri Apr 23 02:41:35 2010
@@ -24,8 +24,7 @@
             # gc_id operation
             if func.__name__ == 'id__ANY':
                 return False
-        if mod == 'pypy.rlib.rbigint':
-            #if func.__name__ == '_bigint_true_divide':
+        if mod == 'pypy.rlib.rbigint' or mod == 'pypy.rlib.rlocale':
             return False
         if '_geninterp_' in func.func_globals: # skip all geninterped stuff
             return False

Modified: pypy/branch/cpython-extension/pypy/module/pypyjit/test/test_policy.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/pypyjit/test/test_policy.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/pypyjit/test/test_policy.py	Fri Apr 23 02:41:35 2010
@@ -10,6 +10,10 @@
     from pypy.rlib.rbigint import rbigint
     assert not pypypolicy.look_inside_function(rbigint.lt.im_func)
 
+def test_rlocale():
+    from pypy.rlib.rlocale import setlocale
+    assert not pypypolicy.look_inside_function(setlocale)    
+
 def test_geninterp():
     d = {'_geninterp_': True}
     exec """def f():

Modified: pypy/branch/cpython-extension/pypy/module/signal/interp_signal.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/signal/interp_signal.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/signal/interp_signal.py	Fri Apr 23 02:41:35 2010
@@ -39,7 +39,10 @@
 # pointless and a performance issue
 
 # don't use rffi.LONGP because the JIT doesn't support raw arrays so far
-LONG_STRUCT = lltype.Struct('LONG_STRUCT', ('value', lltype.Signed))
+struct_name = 'pypysig_long_struct'
+LONG_STRUCT = lltype.Struct(struct_name, ('c_value', lltype.Signed),
+                            hints={'c_name' : struct_name, 'external' : 'C'})
+del struct_name
 
 pypysig_getaddr_occurred = external('pypysig_getaddr_occurred', [],
                                     lltype.Ptr(LONG_STRUCT), _nowrapper=True,
@@ -51,10 +54,10 @@
 class SignalActionFlag(AbstractActionFlag):
     def get(self):
         p = pypysig_getaddr_occurred()
-        return p.value
+        return p.c_value
     def set(self, value):
         p = pypysig_getaddr_occurred()
-        p.value = value
+        p.c_value = value
 
 
 class CheckSignalAction(AsyncAction):

Modified: pypy/branch/cpython-extension/pypy/module/sys/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/sys/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/sys/__init__.py	Fri Apr 23 02:41:35 2010
@@ -1,4 +1,4 @@
-from pypy.interpreter.mixedmodule import MixedModule 
+from pypy.interpreter.mixedmodule import MixedModule
 from pypy.interpreter.error import OperationError
 
 class Module(MixedModule):
@@ -10,6 +10,7 @@
         self.recursionlimit = 100
         self.w_default_encoder = None
         self.defaultencoding = "ascii"
+        self.filesystemencoding = None
         
     interpleveldefs = {
         '__name__'              : '(space.wrap("sys"))', 
@@ -68,13 +69,14 @@
         
         'getdefaultencoding'    : 'interp_encoding.getdefaultencoding', 
         'setdefaultencoding'    : 'interp_encoding.setdefaultencoding',
-}
+        'getfilesystemencoding' : 'interp_encoding.getfilesystemencoding',
+        }
+    
     appleveldefs = {
         'excepthook'            : 'app.excepthook', 
         '__excepthook__'        : 'app.excepthook', 
         'exit'                  : 'app.exit', 
         'exitfunc'              : 'app.exitfunc',
-        'getfilesystemencoding' : 'app.getfilesystemencoding', 
         'callstats'             : 'app.callstats',
         'copyright'             : 'app.copyright_str', 
     }
@@ -84,6 +86,10 @@
         w_modules = self.get('modules')
         self.space.setitem(w_modules, w_name, w_module)
 
+    def startup(self, space):
+        from pypy.module.sys.interp_encoding import _getfilesystemencoding
+        self.filesystemencoding = _getfilesystemencoding(space)
+
     def getmodule(self, name): 
         space = self.space
         w_modules = self.get('modules') 

Modified: pypy/branch/cpython-extension/pypy/module/sys/app.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/sys/app.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/sys/app.py	Fri Apr 23 02:41:35 2010
@@ -26,24 +26,12 @@
 
 #import __builtin__
 
-def getfilesystemencoding():
-    """Return the encoding used to convert Unicode filenames in
-operating system filenames.
-    """
-    if sys.platform == "win32":
-        encoding = "mbcs"
-    elif sys.platform == "darwin":
-        encoding = "utf-8"
-    else:
-        encoding = None
-    return encoding
-
 def callstats():
     """Not implemented."""
     return None
 
 copyright_str = """
-Copyright 2003-2009 PyPy development team.
+Copyright 2003-2010 PyPy development team.
 All rights reserved.
 For further information see http://www.codespeak.net/pypy.
 

Modified: pypy/branch/cpython-extension/pypy/module/sys/interp_encoding.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/sys/interp_encoding.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/sys/interp_encoding.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,6 @@
+import sys
+from pypy.rlib import rlocale
+
 def getdefaultencoding(space):
     """Return the current default string encoding used by the Unicode 
 implementation."""
@@ -22,3 +25,31 @@
     w_encoder = space.getitem(w_functuple, space.wrap(0))
     space.sys.w_default_encoder = w_encoder    # cache it
     return w_encoder
+
+if sys.platform == "win32":
+    base_encoding = "mbcs"
+elif sys.platform == "darwin":
+    base_encoding = "utf-8"
+else:
+    base_encoding = None
+
+def _getfilesystemencoding(space):
+    encoding = base_encoding
+    if rlocale.HAVE_LANGINFO and rlocale.CODESET:
+        oldlocale = rlocale.setlocale(rlocale.LC_CTYPE, None)
+        rlocale.setlocale(rlocale.LC_CTYPE, "")
+        loc_codeset = rlocale.nl_langinfo(rlocale.CODESET)
+        if loc_codeset:
+            codecmod = space.getbuiltinmodule('_codecs')
+            w_res = space.call_function(space.getattr(codecmod,
+                                                      space.wrap('lookup')),
+                                        space.wrap(loc_codeset))
+            if space.is_true(w_res):
+                encoding = loc_codeset
+    return encoding
+
+def getfilesystemencoding(space):
+    """Return the encoding used to convert Unicode filenames in
+    operating system filenames.
+    """
+    return space.wrap(space.sys.filesystemencoding)

Modified: pypy/branch/cpython-extension/pypy/module/sys/test/test_sysmodule.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/sys/test/test_sysmodule.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/sys/test/test_sysmodule.py	Fri Apr 23 02:41:35 2010
@@ -3,6 +3,7 @@
 from pypy.conftest import option
 from py.test import raises
 from pypy.interpreter.gateway import app2interp_temp
+import sys
 
 def init_globals_via_builtins_hack(space):
     space.appexec([], """():
@@ -24,6 +25,7 @@
 
     def setup_class(cls):
         cls.w_appdirect = cls.space.wrap(option.runappdirect)
+        cls.w_filesystemenc = cls.space.wrap(sys.getfilesystemencoding())
     
     def test_sys_in_modules(self):
         import sys
@@ -108,6 +110,10 @@
         assert isinstance(sys.stderr, file)
         assert isinstance(sys.stdin, file)
 
+    def test_getfilesystemencoding(self):
+        import sys
+        assert sys.getfilesystemencoding() == self.filesystemenc
+
 class AppTestSysModulePortedFromCPython:
 
     def setup_class(cls):

Modified: pypy/branch/cpython-extension/pypy/module/termios/interp_termios.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/termios/interp_termios.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/termios/interp_termios.py	Fri Apr 23 02:41:35 2010
@@ -28,14 +28,8 @@
     return OperationError(w_exception_class, w_exception)
 
 def tcsetattr(space, fd, when, w_attributes):
-    from pypy.interpreter.baseobjspace import UnpackValueError
-    try:
-        w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed, w_cc = \
-                 space.unpackiterable(w_attributes, expected_length=7)
-    except UnpackValueError, e:
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("tcsetattr, arg 3: must be 7 element list"))
+    w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed, w_cc = \
+             space.unpackiterable(w_attributes, expected_length=7)
     w_builtin = space.getbuiltinmodule('__builtin__')
     cc = []
     for w_c in space.unpackiterable(w_cc):

Modified: pypy/branch/cpython-extension/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/flowcontext.py	Fri Apr 23 02:41:35 2010
@@ -1,18 +1,14 @@
 import collections
+import sys
 from pypy.interpreter.executioncontext import ExecutionContext
 from pypy.interpreter.error import OperationError
-from pypy.interpreter import pyframe
+from pypy.interpreter import pyframe, nestedscope
 from pypy.interpreter.argument import ArgumentsForTranslation
+from pypy.objspace.flow import operation
 from pypy.objspace.flow.model import *
 from pypy.objspace.flow.framestate import FrameState
 from pypy.rlib import jit
-
-
-class OperationThatShouldNotBePropagatedError(OperationError):
-    pass
-
-class ImplicitOperationError(OperationError):
-    pass
+from pypy.tool.stdlib_opcode import host_bytecode_spec
 
 class StopFlowing(Exception):
     pass
@@ -200,8 +196,8 @@
         if closure is None:
             self.closure = None
         else:
-            from pypy.interpreter.nestedscope import Cell
-            self.closure = [Cell(Constant(value)) for value in closure]
+            self.closure = [nestedscope.Cell(Constant(value))
+                            for value in closure]
         frame = self.create_frame()
         formalargcount = code.getformalargcount()
         arg_list = [Variable() for i in range(formalargcount)]
@@ -270,13 +266,13 @@
                     self.crnt_frame = None
                     self.topframeref = old_frameref
 
-            except OperationThatShouldNotBePropagatedError, e:
+            except operation.OperationThatShouldNotBePropagatedError, e:
                 raise Exception(
                     'found an operation that always raises %s: %s' % (
                         self.space.unwrap(e.w_type).__name__,
                         self.space.unwrap(e.get_w_value(self.space))))
 
-            except ImplicitOperationError, e:
+            except operation.ImplicitOperationError, e:
                 if isinstance(e.w_type, Constant):
                     exc_cls = e.w_type.value
                 else:
@@ -379,7 +375,7 @@
 
     def sys_exc_info(self):
         operr = ExecutionContext.sys_exc_info(self)
-        if isinstance(operr, ImplicitOperationError):
+        if isinstance(operr, operation.ImplicitOperationError):
             # re-raising an implicit operation makes it an explicit one
             w_value = operr.get_w_value(self.space)
             operr = OperationError(operr.w_type, w_value)
@@ -399,6 +395,90 @@
                     stack_items_w[i] = w_new
 
 class FlowSpaceFrame(pyframe.PyFrame):
+    """
+    Execution of host (CPython) opcodes.
+    """
+    bytecode_spec = host_bytecode_spec
+    opcode_method_names = host_bytecode_spec.method_names
+    opcodedesc = host_bytecode_spec.opcodedesc
+    opdescmap = host_bytecode_spec.opdescmap
+    HAVE_ARGUMENT = host_bytecode_spec.HAVE_ARGUMENT
+
+    def BUILD_MAP(self, itemcount, next_instr):
+        if sys.version_info >= (2, 6):
+            # We could pre-allocate a dict here
+            # but for the moment this code is not translated.
+            pass
+        else:
+            if itemcount != 0:
+                raise BytecodeCorruption
+        w_dict = self.space.newdict()
+        self.pushvalue(w_dict)
+
+    def STORE_MAP(self, zero, next_instr):
+        if sys.version_info >= (2, 6):
+            w_key = self.popvalue()
+            w_value = self.popvalue()
+            w_dict = self.peekvalue()
+            self.space.setitem(w_dict, w_key, w_value)
+        else:
+            raise BytecodeCorruption
+
+    def POP_JUMP_IF_FALSE(self, jumpto, next_instr):
+        w_cond = self.popvalue()
+        if not self.space.is_true(w_cond):
+            next_instr = jumpto
+        return next_instr
+
+    def POP_JUMP_IF_TRUE(self, jumpto, next_instr):
+        w_cond = self.popvalue()
+        if self.space.is_true(w_cond):
+            return jumpto
+        return next_instr
+
+    def JUMP_IF_FALSE_OR_POP(self, jumpto, next_instr):
+        w_cond = self.peekvalue()
+        if not self.space.is_true(w_cond):
+            return jumpto
+        self.popvalue()
+        return next_instr
+
+    def JUMP_IF_TRUE_OR_POP(self, jumpto, next_instr):
+        w_cond = self.peekvalue()
+        if self.space.is_true(w_cond):
+            return jumpto
+        self.popvalue()
+        return next_instr
+
+    def LIST_APPEND(self, oparg, next_instr):
+        w = self.popvalue()
+        if sys.version_info < (2, 7):
+            v = self.popvalue()
+        else:
+            v = self.peekvalue(oparg - 1)
+        self.space.call_method(v, 'append', w)
+    
+    # XXX Unimplemented 2.7 opcodes ----------------
+
+    # Set literals, set comprehensions
+
+    def BUILD_SET(self, oparg, next_instr):
+        raise NotImplementedError("BUILD_SET")
+
+    def SET_ADD(self, oparg, next_instr):
+        raise NotImplementedError("SET_ADD")
+
+    # Dict comprehensions
+
+    def MAP_ADD(self, oparg, next_instr):
+        raise NotImplementedError("MAP_ADD")
+
+    # `with` statement
+
+    def SETUP_WITH(self, oparg, next_instr):
+        raise NotImplementedError("SETUP_WITH")
+
+    
     def make_arguments(self, nargs):
         return ArgumentsForTranslation(self.space, self.peekvalues(nargs))
     def argument_factory(self, *args):
@@ -406,7 +486,7 @@
 
     def handle_operation_error(self, ec, operr, *args, **kwds):
         # see test_propagate_attribute_error for why this is here
-        if isinstance(operr, OperationThatShouldNotBePropagatedError):
+        if isinstance(operr, operation.OperationThatShouldNotBePropagatedError):
             raise operr
         return pyframe.PyFrame.handle_operation_error(self, ec, operr,
                                                       *args, **kwds)

Modified: pypy/branch/cpython-extension/pypy/objspace/flow/model.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/model.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/model.py	Fri Apr 23 02:41:35 2010
@@ -322,6 +322,14 @@
             self.concretetype = concretetype
 
 
+class UnwrapException(Exception):
+    """Attempted to unwrap a Variable."""
+
+class WrapException(Exception):
+    """Attempted wrapping of a type that cannot sanely appear in flow graph or
+    during its construction"""
+
+
 class SpaceOperation(object):
     __slots__ = "opname args result offset".split()
 

Modified: pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py	Fri Apr 23 02:41:35 2010
@@ -1,22 +1,19 @@
 # ______________________________________________________________________
-import sys, operator, types
+import __builtin__
+import sys
+import operator
+import types
+from pypy.tool import error
 from pypy.interpreter.baseobjspace import ObjSpace, Wrappable
 from pypy.interpreter.pycode import PyCode, cpython_code_signature
 from pypy.interpreter.module import Module
 from pypy.interpreter.error import OperationError
+from pypy.interpreter import pyframe, argument
 from pypy.objspace.flow.model import *
-from pypy.objspace.flow import flowcontext
-from pypy.objspace.flow.operation import FunctionByName
+from pypy.objspace.flow import flowcontext, operation, specialcase
 from pypy.rlib.unroll import unrolling_iterable, _unroller
-from pypy.rlib import rstackovf
+from pypy.rlib import rstackovf, rarithmetic
 
-debug = 0
-
-class UnwrapException(Exception):
-    "Attempted to unwrap a Variable."
-
-class WrapException(Exception):
-    """Attempted wrapping of a type that cannot sanely appear in flow graph or during its construction"""
 
 # method-wrappers have not enough introspection in CPython
 if hasattr(complex.real.__get__, 'im_self'):
@@ -24,6 +21,21 @@
 else:
     type_with_bad_introspection = type(complex.real.__get__)
 
+# the following gives us easy access to declare more for applications:
+NOT_REALLY_CONST = {
+    Constant(sys): {
+        Constant('maxint'): True,
+        Constant('maxunicode'): True,
+        Constant('api_version'): True,
+        Constant('exit'): True,
+        Constant('exc_info'): True,
+        Constant('getrefcount'): True,
+        Constant('getdefaultencoding'): True,
+        # this is an incomplete list of true constants.
+        # if we add much more, a dedicated class
+        # might be considered for special objects.
+        }
+    }
 
 # ______________________________________________________________________
 class FlowObjSpace(ObjSpace):
@@ -32,15 +44,16 @@
     the space operations that the interpreter generates when it interprets
     (the bytecode of) some function.
     """
-    
+
     full_exceptions = False
     do_imports_immediately = True
+    FrameClass = flowcontext.FlowSpaceFrame
 
     def initialize(self):
-        import __builtin__
         self.concrete_mode = 1
         self.w_None     = Constant(None)
-        self.builtin    = Module(self, Constant('__builtin__'), Constant(__builtin__.__dict__))
+        self.builtin    = Module(self, Constant('__builtin__'),
+                                 Constant(__builtin__.__dict__))
         def pick_builtin(w_globals):
             return self.builtin
         self.builtin.pick_builtin = pick_builtin
@@ -125,9 +138,8 @@
 
     def uint_w(self, w_obj):
         if isinstance(w_obj, Constant):
-            from pypy.rlib.rarithmetic import r_uint
             val = w_obj.value
-            if type(val) is not r_uint:
+            if type(val) is not rarithmetic.r_uint:
                 raise TypeError("expected unsigned: " + repr(w_obj))
             return val
         return self.unwrap(w_obj)
@@ -191,7 +203,6 @@
 
     def setup_executioncontext(self, ec):
         self.executioncontext = ec
-        from pypy.objspace.flow import specialcase
         specialcase.setup(self)
 
     def exception_match(self, w_exc_type, w_check_class):
@@ -254,15 +265,15 @@
         graph.defaults = func.func_defaults or ()
         self.setup_executioncontext(ec)
 
-        from pypy.tool.error import FlowingError, format_global_error
-
         try:
             ec.build_flow()
-        except FlowingError, a:
+        except error.FlowingError, a:
             # attach additional source info to AnnotatorError
             _, _, tb = sys.exc_info()
-            e = FlowingError(format_global_error(ec.graph, ec.crnt_offset, str(a)))
-            raise FlowingError, e, tb
+            formated = error.format_global_error(ec.graph, ec.crnt_offset,
+                                                 str(a))
+            e = error.FlowingError(formated)
+            raise error.FlowingError, e, tb
         checkgraph(graph)
         return graph
 
@@ -300,7 +311,7 @@
 
     def do_operation_with_implicit_exceptions(self, name, *args_w):
         w_result = self.do_operation(name, *args_w)
-        self.handle_implicit_exceptions(implicit_exceptions.get(name))
+        self.handle_implicit_exceptions(operation.implicit_exceptions.get(name))
         return w_result
 
     def is_true(self, w_obj):
@@ -346,8 +357,8 @@
         if outcome is StopIteration:
             raise OperationError(self.w_StopIteration, w_exc_value)
         elif outcome is RuntimeError:
-            raise flowcontext.ImplicitOperationError(Constant(RuntimeError),
-                                                     w_exc_value)
+            raise operation.ImplicitOperationError(Constant(RuntimeError),
+                                                    w_exc_value)
         else:
             return w_item
 
@@ -365,9 +376,8 @@
                                                           w_key, w_val)
 
     def call_function(self, w_func, *args_w):
-        from pypy.interpreter.argument import ArgumentsForTranslation
         nargs = len(args_w)
-        args = ArgumentsForTranslation(self, list(args_w))
+        args = argument.ArgumentsForTranslation(self, list(args_w))
         return self.call_args(w_func, args)
 
     def call_args(self, w_callable, args):
@@ -403,7 +413,7 @@
         #    raise SomeError(x)
         #
         # as shown by test_objspace.test_raise3.
-        
+
         exceptions = [Exception]   # *any* exception by default
         if isinstance(w_callable, Constant):
             c = w_callable.value
@@ -413,7 +423,7 @@
                                    types.ClassType,
                                    types.TypeType)) and
                       c.__module__ in ['__builtin__', 'exceptions']):
-                    exceptions = implicit_exceptions.get(c, None)
+                    exceptions = operation.implicit_exceptions.get(c)
         self.handle_implicit_exceptions(exceptions)
         return w_res
 
@@ -441,11 +451,9 @@
                 #if outcome is not Exception:
                     #w_exc_cls = Constant(outcome) Now done by guessexception itself
                     #pass
-                 raise flowcontext.ImplicitOperationError(w_exc_cls,
-                                                         w_exc_value)
+                 raise operation.ImplicitOperationError(w_exc_cls, w_exc_value)
 
     def w_KeyboardInterrupt(self):
-        # XXX XXX Ha Ha
         # the reason to do this is: if you interrupt the flowing of a function
         # with <Ctrl-C> the bytecode interpreter will raise an applevel
         # KeyboardInterrupt and you will get an AttributeError: space does not
@@ -458,84 +466,8 @@
         raise RuntimeError("the interpreter raises RuntimeError during "
                            "flow graph construction")
     w_RuntimeError = prebuilt_recursion_error = property(w_RuntimeError)
+operation.add_operations(FlowObjSpace)
 
-# the following gives us easy access to declare more for applications:
-NOT_REALLY_CONST = {
-    Constant(sys): {
-        Constant('maxint'): True,
-        Constant('maxunicode'): True,
-        Constant('api_version'): True,
-        Constant('exit'): True,
-        Constant('exc_info'): True,
-        Constant('getrefcount'): True,
-        Constant('getdefaultencoding'): True,
-        # this is an incomplete list of true constants.
-        # if we add much more, a dedicated class
-        # might be considered for special objects.
-        }
-    }
-
-# ______________________________________________________________________
-
-op_appendices = {
-    OverflowError: 'ovf',
-    IndexError: 'idx',
-    KeyError: 'key',
-    AttributeError: 'att',
-    TypeError: 'typ',
-    ZeroDivisionError: 'zer',
-    ValueError: 'val',
-    }
-
-implicit_exceptions = {
-    int: [ValueError],      # built-ins that can always raise exceptions
-    float: [ValueError],
-    chr: [ValueError],
-    unichr: [ValueError],
-    # specifying IndexError, and KeyError beyond Exception,
-    # allows the annotator to be more precise, see test_reraiseAnything/KeyError in
-    # the annotator tests
-    'getitem': [IndexError, KeyError, Exception],
-    'setitem': [IndexError, KeyError, Exception],
-    'delitem': [IndexError, KeyError, Exception],
-    'contains': [Exception],    # from an r_dict
-    }
-
-def _add_exceptions(names, exc):
-    for name in names.split():
-        lis = implicit_exceptions.setdefault(name, [])
-        if exc in lis:
-            raise ValueError, "your list is causing duplication!"
-        lis.append(exc)
-        assert exc in op_appendices
-
-def _add_except_ovf(names):
-    # duplicate exceptions and add OverflowError
-    for name in names.split():
-        lis = implicit_exceptions.setdefault(name, [])[:]
-        lis.append(OverflowError)
-        implicit_exceptions[name+"_ovf"] = lis
-
-for _name in 'getattr', 'delattr':
-    _add_exceptions(_name, AttributeError)
-for _name in 'iter', 'coerce':
-    _add_exceptions(_name, TypeError)
-del _name
-
-_add_exceptions("""div mod divmod truediv floordiv pow
-                   inplace_div inplace_mod inplace_divmod inplace_truediv
-                   inplace_floordiv inplace_pow""", ZeroDivisionError)
-_add_exceptions("""pow inplace_pow lshift inplace_lshift rshift
-                   inplace_rshift""", ValueError)
-_add_exceptions("""truediv divmod
-                   inplace_add inplace_sub inplace_mul inplace_truediv
-                   inplace_floordiv inplace_div inplace_mod inplace_pow
-                   inplace_lshift""", OverflowError) # without a _ovf version
-_add_except_ovf("""neg abs add sub mul
-                   floordiv div mod pow lshift""")   # with a _ovf version
-_add_exceptions("""pow""",
-                OverflowError) # for the float case
-del _add_exceptions, _add_except_ovf
 
 def extract_cell_content(c):
     """Get the value contained in a CPython 'cell', as read through
@@ -558,127 +490,5 @@
             return x.other    # crashes if the cell is actually empty
         except AttributeError:
             raise ValueError("empty cell")
-
-def make_op(name, symbol, arity, specialnames):
-    if hasattr(FlowObjSpace, name):
-        return # Shouldn't do it
-
-    import __builtin__
-
-    op = None
-    skip = False
-    arithmetic = False
-
-    if name.startswith('del') or name.startswith('set') or name.startswith('inplace_'):
-        # skip potential mutators
-        if debug: print "Skip", name
-        skip = True
-    elif name in ['id', 'hash', 'iter', 'userdel']: 
-        # skip potential runtime context dependecies
-        if debug: print "Skip", name
-        skip = True
-    elif name in ['repr', 'str']:
-        rep = getattr(__builtin__, name)
-        def op(obj):
-            s = rep(obj)
-            if s.find("at 0x") > -1:
-                print >>sys.stderr, "Warning: captured address may be awkward"
-            return s
-    else:
-        op = FunctionByName[name]
-        arithmetic = (name + '_ovf') in FunctionByName
-
-    if not op:
-        if not skip:
-            if debug: print >> sys.stderr, "XXX missing operator:", name
-    else:
-        if debug: print "Can constant-fold operation: %s" % name
-
-    def generic_operator(self, *args_w):
-        assert len(args_w) == arity, name+" got the wrong number of arguments"
-        if op:
-            args = []
-            for w_arg in args_w:
-                try:
-                    arg = self.unwrap_for_computation(w_arg)
-                except UnwrapException:
-                    break
-                else:
-                    args.append(arg)
-            else:
-                # All arguments are constants: call the operator now
-                #print >> sys.stderr, 'Constant operation', op
-                try:
-                    result = op(*args)
-                except:
-                    etype, evalue, etb = sys.exc_info()
-                    msg = "generated by a constant operation:  %s%r" % (
-                        name, tuple(args))
-                    raise flowcontext.OperationThatShouldNotBePropagatedError(
-                        self.wrap(etype), self.wrap(msg))
-                else:
-                    # don't try to constant-fold operations giving a 'long'
-                    # result.  The result is probably meant to be sent to
-                    # an intmask(), but the 'long' constant confuses the
-                    # annotator a lot.
-                    if arithmetic and type(result) is long:
-                        pass
-                    # don't constant-fold getslice on lists, either
-                    elif name == 'getslice' and type(result) is list:
-                        pass
-                    # otherwise, fine
-                    else:
-                        try:
-                            return self.wrap(result)
-                        except WrapException:
-                            # type cannot sanely appear in flow graph,
-                            # store operation with variable result instead
-                            pass
-
-        #print >> sys.stderr, 'Variable operation', name, args_w
-        w_result = self.do_operation_with_implicit_exceptions(name, *args_w)
-        return w_result
-
-    setattr(FlowObjSpace, name, generic_operator)
-
-for line in ObjSpace.MethodTable:
-    make_op(*line)
-
-"""
-This is just a placeholder for some code I'm checking in elsewhere.
-It is provenly possible to determine constantness of certain expressions
-a little later. I introduced this a bit too early, together with tieing
-this to something being global, which was a bad idea.
-The concept is still valid, and it can  be used to force something to
-be evaluated immediately because it is supposed to be a constant.
-One good possible use of this is loop unrolling.
-This will be found in an 'experimental' folder with some use cases.
-"""
-
-def override():
-    def getattr(self, w_obj, w_name):
-        # handling special things like sys
-        # unfortunately this will never vanish with a unique import logic :-(
-        if w_obj in self.not_really_const:
-            const_w = self.not_really_const[w_obj]
-            if w_name not in const_w:
-                return self.do_operation_with_implicit_exceptions('getattr', w_obj, w_name)
-        return self.regular_getattr(w_obj, w_name)
-
-    FlowObjSpace.regular_getattr = FlowObjSpace.getattr
-    FlowObjSpace.getattr = getattr
-
-    # protect us from globals write access
-    def setitem(self, w_obj, w_key, w_val):
-        ec = self.getexecutioncontext()
-        if not (ec and w_obj is ec.w_globals):
-            return self.regular_setitem(w_obj, w_key, w_val)
-        raise SyntaxError, "attempt to modify global attribute %r in %r" % (w_key, ec.graph.func)
-
-    FlowObjSpace.regular_setitem = FlowObjSpace.setitem
-    FlowObjSpace.setitem = setitem
-
-override()
-
 # ______________________________________________________________________
 # End of objspace.py

Modified: pypy/branch/cpython-extension/pypy/objspace/flow/operation.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/operation.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/operation.py	Fri Apr 23 02:41:35 2010
@@ -2,10 +2,25 @@
 This module defines mappings between operation names and Python's
 built-in functions (or type constructors) implementing them.
 """
+
+import __builtin__
+import __future__
+import operator
+import types
+import sys
 from pypy.interpreter.baseobjspace import ObjSpace
-import operator, types, __future__
+from pypy.interpreter.error import OperationError
 from pypy.tool.sourcetools import compile2
 from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.objspace.flow import model
+
+
+class OperationThatShouldNotBePropagatedError(OperationError):
+    pass
+
+class ImplicitOperationError(OperationError):
+    pass
+
 
 FunctionByName = {}   # dict {"operation_name": <built-in function>}
 OperationName  = {}   # dict {<built-in function>: "operation_name"}
@@ -216,8 +231,6 @@
     ]
 
 def setup():
-    if not hasattr(operator, 'is_'):   # Python 2.2
-        Table.append(('is_', lambda x, y: x is y))
     # insert all operators
     for line in ObjSpace.MethodTable:
         name = line[0]
@@ -235,4 +248,183 @@
         Arity[name] = line[2]
         assert name in FunctionByName
 setup()
-del Table   # INTERNAL ONLY, use the dicts declared at the top of the file
+del Table, setup # INTERNAL ONLY, use the dicts declared at the top of the file
+
+op_appendices = {
+    OverflowError: 'ovf',
+    IndexError: 'idx',
+    KeyError: 'key',
+    AttributeError: 'att',
+    TypeError: 'typ',
+    ZeroDivisionError: 'zer',
+    ValueError: 'val',
+    }
+
+implicit_exceptions = {
+    int: [ValueError],      # built-ins that can always raise exceptions
+    float: [ValueError],
+    chr: [ValueError],
+    unichr: [ValueError],
+    unicode: [UnicodeDecodeError],
+    # specifying IndexError, and KeyError beyond Exception,
+    # allows the annotator to be more precise, see test_reraiseAnything/KeyError in
+    # the annotator tests
+    'getitem': [IndexError, KeyError, Exception],
+    'setitem': [IndexError, KeyError, Exception],
+    'delitem': [IndexError, KeyError, Exception],
+    'contains': [Exception],    # from an r_dict
+    }
+
+def _add_exceptions(names, exc):
+    for name in names.split():
+        lis = implicit_exceptions.setdefault(name, [])
+        if exc in lis:
+            raise ValueError, "your list is causing duplication!"
+        lis.append(exc)
+        assert exc in op_appendices
+
+def _add_except_ovf(names):
+    # duplicate exceptions and add OverflowError
+    for name in names.split():
+        lis = implicit_exceptions.setdefault(name, [])[:]
+        lis.append(OverflowError)
+        implicit_exceptions[name+"_ovf"] = lis
+
+for _name in 'getattr', 'delattr':
+    _add_exceptions(_name, AttributeError)
+for _name in 'iter', 'coerce':
+    _add_exceptions(_name, TypeError)
+del _name
+
+_add_exceptions("""div mod divmod truediv floordiv pow
+                   inplace_div inplace_mod inplace_divmod inplace_truediv
+                   inplace_floordiv inplace_pow""", ZeroDivisionError)
+_add_exceptions("""pow inplace_pow lshift inplace_lshift rshift
+                   inplace_rshift""", ValueError)
+_add_exceptions("""truediv divmod
+                   inplace_add inplace_sub inplace_mul inplace_truediv
+                   inplace_floordiv inplace_div inplace_mod inplace_pow
+                   inplace_lshift""", OverflowError) # without a _ovf version
+_add_except_ovf("""neg abs add sub mul
+                   floordiv div mod pow lshift""")   # with a _ovf version
+_add_exceptions("""pow""",
+                OverflowError) # for the float case
+del _add_exceptions, _add_except_ovf
+
+def make_op(fs, name, symbol, arity, specialnames):
+    if hasattr(fs, name):
+        return
+
+    op = None
+    skip = False
+    arithmetic = False
+
+    if (name.startswith('del') or
+        name.startswith('set') or
+        name.startswith('inplace_')):
+        # skip potential mutators
+        skip = True
+    elif name in ('id', 'hash', 'iter', 'userdel'):
+        # skip potential runtime context dependecies
+        skip = True
+    elif name in ('repr', 'str'):
+        rep = getattr(__builtin__, name)
+        def op(obj):
+            s = rep(obj)
+            if "at 0x" in s:
+                print >>sys.stderr, "Warning: captured address may be awkward"
+            return s
+    else:
+        op = FunctionByName[name]
+        arithmetic = (name + '_ovf') in FunctionByName
+
+    if not op and not skip:
+        raise ValueError("XXX missing operator: %s" % (name,))
+
+    def generic_operator(self, *args_w):
+        assert len(args_w) == arity, name + " got the wrong number of arguments"
+        if op:
+            args = []
+            for w_arg in args_w:
+                try:
+                    arg = self.unwrap_for_computation(w_arg)
+                except model.UnwrapException:
+                    break
+                else:
+                    args.append(arg)
+            else:
+                # All arguments are constants: call the operator now
+                try:
+                    result = op(*args)
+                except:
+                    etype, evalue, etb = sys.exc_info()
+                    msg = "generated by a constant operation:  %s%r" % (
+                        name, tuple(args))
+                    raise OperationThatShouldNotBePropagatedError(
+                        self.wrap(etype), self.wrap(msg))
+                else:
+                    # don't try to constant-fold operations giving a 'long'
+                    # result.  The result is probably meant to be sent to
+                    # an intmask(), but the 'long' constant confuses the
+                    # annotator a lot.
+                    if arithmetic and type(result) is long:
+                        pass
+                    # don't constant-fold getslice on lists, either
+                    elif name == 'getslice' and type(result) is list:
+                        pass
+                    # otherwise, fine
+                    else:
+                        try:
+                            return self.wrap(result)
+                        except model.WrapException:
+                            # type cannot sanely appear in flow graph,
+                            # store operation with variable result instead
+                            pass
+        w_result = self.do_operation_with_implicit_exceptions(name, *args_w)
+        return w_result
+
+    setattr(fs, name, generic_operator)
+
+
+"""
+This is just a placeholder for some code I'm checking in elsewhere.
+It is provenly possible to determine constantness of certain expressions
+a little later. I introduced this a bit too early, together with tieing
+this to something being global, which was a bad idea.
+The concept is still valid, and it can  be used to force something to
+be evaluated immediately because it is supposed to be a constant.
+One good possible use of this is loop unrolling.
+This will be found in an 'experimental' folder with some use cases.
+"""
+
+def special_overrides(fs):
+    def getattr(self, w_obj, w_name):
+        # handling special things like sys
+        # unfortunately this will never vanish with a unique import logic :-(
+        if w_obj in self.not_really_const:
+            const_w = self.not_really_const[w_obj]
+            if w_name not in const_w:
+                return self.do_operation_with_implicit_exceptions('getattr',
+                                                                  w_obj, w_name)
+        return self.regular_getattr(w_obj, w_name)
+
+    fs.regular_getattr = fs.getattr
+    fs.getattr = getattr
+
+    # protect us from globals write access
+    def setitem(self, w_obj, w_key, w_val):
+        ec = self.getexecutioncontext()
+        if not (ec and w_obj is ec.w_globals):
+            return self.regular_setitem(w_obj, w_key, w_val)
+        raise SyntaxError("attempt to modify global attribute %r in %r"
+                          % (w_key, ec.graph.func))
+
+    fs.regular_setitem = fs.setitem
+    fs.setitem = setitem
+
+
+def add_operations(fs):
+    """Add function operations to the flow space."""
+    for line in ObjSpace.MethodTable:
+        make_op(fs, *line)
+    special_overrides(fs)

Modified: pypy/branch/cpython-extension/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/specialcase.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/specialcase.py	Fri Apr 23 02:41:35 2010
@@ -1,9 +1,9 @@
-from pypy.objspace.flow.objspace import UnwrapException
-from pypy.objspace.flow.model import Constant
+from pypy.objspace.flow.model import Constant, UnwrapException
 from pypy.objspace.flow.operation import OperationName, Arity
 from pypy.interpreter.gateway import ApplevelClass
 from pypy.interpreter.error import OperationError
 from pypy.tool.cache import Cache
+import py
 
 def sc_import(space, fn, args):
     args_w, kwds_w = args.unpack()
@@ -73,7 +73,7 @@
         if app.filename is not None:
             dic['__file__'] = app.filename
         dic['__name__'] = app.modname
-        exec app.code in dic
+        exec py.code.Source(app.source).compile() in dic
         return dic
     _build = staticmethod(_build)
 

Modified: pypy/branch/cpython-extension/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/test/test_objspace.py	Fri Apr 23 02:41:35 2010
@@ -1,12 +1,14 @@
 import new
 import py
 from pypy.objspace.flow.model import Constant, Block, Link, Variable, traverse
-from pypy.objspace.flow.model import flatten, mkentrymap
+from pypy.objspace.flow.model import flatten, mkentrymap, c_last_exception
 from pypy.interpreter.argument import Arguments
 from pypy.translator.simplify import simplify_graph
 from pypy.objspace.flow.objspace import FlowObjSpace 
-from pypy.objspace.flow import objspace
+from pypy.objspace.flow import objspace, flowcontext
 from pypy import conftest
+from pypy.tool.stdlib_opcode import bytecode_spec
+from pypy.interpreter.pyframe import PyFrame
 
 import os
 import operator
@@ -728,7 +730,18 @@
             return unicode("1234")
         graph = self.codetest(myfunc)
         assert graph.startblock.exits[0].target is graph.returnblock
-        
+
+    def test_unicode(self):
+        def myfunc(n):
+            try:
+                return unicode(chr(n))
+            except UnicodeDecodeError:
+                return None
+        graph = self.codetest(myfunc)
+        simplify_graph(graph)
+        assert graph.startblock.exitswitch == c_last_exception
+        assert graph.startblock.exits[0].target is graph.returnblock
+        assert graph.startblock.exits[1].target is graph.returnblock
 
     def test_getitem(self):
         def f(c, x):
@@ -826,23 +839,34 @@
         """ Tests code generated by pypy-c compiled with CALL_METHOD
         bytecode
         """
-        class X:
-            def m(self):
-                return 3
-
-        def f():
-            x = X()
-            return x.m()
-
-        # this code is generated by pypy-c when compiling above f
-        pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\x91\x02\x00\x92\x00\x00Sd\x00\x00S'
-        new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
-        f2 = new.function(new_c, locals(), 'f')
-        
-        graph = self.codetest(f2)
-        all_ops = self.all_operations(graph)
-        assert all_ops['simple_call'] == 2
-        assert all_ops['getattr'] == 1
+        flow_meth_names = flowcontext.FlowSpaceFrame.opcode_method_names
+        pyframe_meth_names = PyFrame.opcode_method_names
+        for name in ['CALL_METHOD', 'LOOKUP_METHOD']:
+            num = bytecode_spec.opmap[name]
+            locals()['old_' + name] = flow_meth_names[num]
+            flow_meth_names[num] = pyframe_meth_names[num]
+        try:
+            class X:
+                def m(self):
+                    return 3
+
+            def f():
+                x = X()
+                return x.m()
+
+            # this code is generated by pypy-c when compiling above f
+            pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\x91\x02\x00\x92\x00\x00Sd\x00\x00S'
+            new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
+            f2 = new.function(new_c, locals(), 'f')
+
+            graph = self.codetest(f2)
+            all_ops = self.all_operations(graph)
+            assert all_ops['simple_call'] == 2
+            assert all_ops['getattr'] == 1
+        finally:
+            for name in ['CALL_METHOD', 'LOOKUP_METHOD']:
+                num = bytecode_spec.opmap[name]
+                flow_meth_names[num] = locals()['old_' + name]
 
     def test_generator(self):
         def f():

Modified: pypy/branch/cpython-extension/pypy/objspace/std/basestringtype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/basestringtype.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/basestringtype.py	Fri Apr 23 02:41:35 2010
@@ -1,9 +1,7 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.stdtypedef import StdTypeDef
 
 
-# ____________________________________________________________
-
 basestring_typedef = StdTypeDef("basestring",
-    __doc__ =  '''Type basestring cannot be instantiated; it is the base for str and unicode.'''                        
+    __doc__ =  ("basestring cannot be instantiated; "
+                "it is the base for str and unicode.")
     )
-

Modified: pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py	Fri Apr 23 02:41:35 2010
@@ -102,9 +102,6 @@
         else:
             return None
 
-    def set_str_keyed_item(w_dict, key, w_value, shadows_type=True):
-        w_dict.setitem_str(key, w_value, shadows_type)
-
     # _________________________________________________________________ 
     # implementation methods
     def impl_getitem(self, w_key):

Modified: pypy/branch/cpython-extension/pypy/objspace/std/formatting.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/formatting.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/formatting.py	Fri Apr 23 02:41:35 2010
@@ -329,7 +329,8 @@
             length = len(r)
             if do_unicode and isinstance(r, str):
                 # convert string to unicode explicitely here
-                r = unicode(r)
+                from pypy.objspace.std.unicodetype import plain_str2unicode
+                r = plain_str2unicode(self.space, r)
             prec = self.prec
             if prec == -1 and self.width == 0:
                 # fast path
@@ -488,7 +489,8 @@
             result = formatter.format()
         except NeedUnicodeFormattingError:
             # fall through to the unicode case
-            fmt = unicode(fmt)
+            from pypy.objspace.std.unicodetype import plain_str2unicode
+            fmt = plain_str2unicode(space, fmt)
         else:
             return space.wrap(result)
     else:

Modified: pypy/branch/cpython-extension/pypy/objspace/std/frame.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/frame.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/frame.py	Fri Apr 23 02:41:35 2010
@@ -3,17 +3,20 @@
 import operator
 
 from pypy.rlib.unroll import unrolling_iterable
-from pypy.interpreter import pyframe, pyopcode, function
+from pypy.interpreter import pyopcode, function
+from pypy.interpreter.pyframe import PyFrame
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module
+from pypy.objspace.std import intobject, smallintobject
 from pypy.objspace.std.multimethod import FailedToImplement
+from pypy.objspace.std.dictmultiobject import W_DictMultiObject
+from pypy.objspace.std.listobject import W_ListObject
 
 
-class BaseFrame(pyframe.PyFrame):
+class BaseFrame(PyFrame):
     """These opcodes are always overridden."""
 
     def LIST_APPEND(f, oparg, next_instr):
-        from pypy.objspace.std.listobject import W_ListObject
         w = f.popvalue()
         v = f.popvalue()
         if type(v) is W_ListObject:
@@ -23,13 +26,12 @@
 
 
 def small_int_BINARY_ADD(f, oparg, next_instr):
-    from pypy.objspace.std.smallintobject import (W_SmallIntObject,
-                                                  add__SmallInt_SmallInt)
     w_2 = f.popvalue()
     w_1 = f.popvalue()
-    if type(w_1) is W_SmallIntObject and type(w_2) is W_SmallIntObject:
+    if (type(w_1) is smallintobject.W_SmallIntObject and
+        type(w_2) is smallintobject.W_SmallIntObject):
         try:
-            w_result = add__SmallInt_SmallInt(f.space, w_1, w_2)
+            w_result = smallintobject.add__SmallInt_SmallInt(f.space, w_1, w_2)
         except FailedToImplement:
             w_result = f.space.add(w_1, w_2)
     else:
@@ -38,12 +40,12 @@
 
 
 def int_BINARY_ADD(f, oparg, next_instr):
-    from pypy.objspace.std.intobject import W_IntObject, add__Int_Int
     w_2 = f.popvalue()
     w_1 = f.popvalue()
-    if type(w_1) is W_IntObject and type(w_2) is W_IntObject:
+    if (type(w_1) is intobject.W_IntObject and
+        type(w_2) is intobject.W_IntObject):
         try:
-            w_result = add__Int_Int(f.space, w_1, w_2)
+            w_result = intobject.add__Int_Int(f.space, w_1, w_2)
         except FailedToImplement:
             w_result = f.space.add(w_1, w_2)
     else:
@@ -52,11 +54,9 @@
 
 
 def list_BINARY_SUBSCR(f, oparg, next_instr):
-    from pypy.objspace.std.intobject import W_IntObject
-    from pypy.objspace.std.listobject import W_ListObject
     w_2 = f.popvalue()
     w_1 = f.popvalue()
-    if type(w_1) is W_ListObject and type(w_2) is W_IntObject:
+    if type(w_1) is W_ListObject and type(w_2) is intobject.W_IntObject:
         try:
             w_result = w_1.wrappeditems[w_2.intval]
         except IndexError:
@@ -67,7 +67,6 @@
     f.pushvalue(w_result)
 
 def CALL_LIKELY_BUILTIN(f, oparg, next_instr):
-    from pypy.objspace.std.dictmultiobject import W_DictMultiObject
     w_globals = f.w_globals
     num = oparg >> 8
     assert isinstance(w_globals, W_DictMultiObject)
@@ -75,7 +74,7 @@
     if w_value is None:
         builtins = f.get_builtin()
         assert isinstance(builtins, Module)
-        w_builtin_dict = builtins.w_dict
+        w_builtin_dict = builtins.getdict()
         assert isinstance(w_builtin_dict, W_DictMultiObject)
         w_value = w_builtin_dict.get_builtin_indexed(num)
     if w_value is None:
@@ -113,12 +112,12 @@
 unrolling_compare_ops = unrolling_iterable(enumerate(compare_table))
 
 def fast_COMPARE_OP(f, testnum, next_instr):
-    from pypy.objspace.std.intobject import W_IntObject
     w_2 = f.popvalue()
     w_1 = f.popvalue()
     w_result = None
-    if (type(w_2) is W_IntObject and type(w_1) is W_IntObject
-        and testnum < len(compare_table)):
+    if (type(w_2) is intobject.W_IntObject and
+        type(w_1) is intobject.W_IntObject and
+        testnum < len(compare_table)):
         for i, attr in unrolling_compare_ops:
             if i == testnum:
                 op = getattr(operator, attr)

Modified: pypy/branch/cpython-extension/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/intobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/intobject.py	Fri Apr 23 02:41:35 2010
@@ -34,6 +34,10 @@
 
 registerimplementation(W_IntObject)
 
+# NB: This code is shared by smallintobject.py, and thus no other Int
+# multimethods should be invoked from these implementations. Instead, add an
+# alias and then teach copy_multimethods in smallintobject.py to override
+# it. See int__Int for example.
 
 def int_w__Int(space, w_int1):
     return int(w_int1.intval)
@@ -56,8 +60,7 @@
 
 str__Int = repr__Int
 
-def declare_new_int_comparison(opname, clsname):
-    # also used by smallintobject.py
+def declare_new_int_comparison(opname):
     import operator
     from pypy.tool.sourcetools import func_with_new_name
     op = getattr(operator, opname)
@@ -65,18 +68,18 @@
         i = w_int1.intval
         j = w_int2.intval
         return space.newbool(op(i, j))
-    name = "%s__%s_%s" % (opname, clsname, clsname)
+    name = "%s__Int_Int" % (opname,)
     return func_with_new_name(f, name), name
 
 for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
-    func, name = declare_new_int_comparison(op, "Int")
+    func, name = declare_new_int_comparison(op)
     globals()[name] = func
 
 def hash__Int(space, w_int1):
     # unlike CPython, we don't special-case the value -1 in most of our
     # hash functions, so there is not much sense special-casing it here either.
     # Make sure this is consistent with the hash of floats and longs.
-    return int__Int(space, w_int1)
+    return get_integer(space, w_int1)
 
 # coerce
 def coerce__Int_Int(space, w_int1, w_int2):
@@ -217,13 +220,14 @@
         raise FailedToImplementArgs(space.w_OverflowError,
                                 space.wrap("integer negation"))
     return wrapint(space, x)
+get_negint = neg__Int
 
 
 def abs__Int(space, w_int1):
     if w_int1.intval >= 0:
-        return pos__Int(space, w_int1)
+        return get_integer(space, w_int1)
     else:
-        return neg__Int(space, w_int1)
+        return get_negint(space, w_int1)
 
 def nonzero__Int(space, w_int1):
     return space.newbool(w_int1.intval != 0)
@@ -240,7 +244,7 @@
         raise OperationError(space.w_ValueError,
                              space.wrap("negative shift count"))
     if a == 0 or b == 0:
-        return int__Int(space, w_int1)
+        return get_integer(space, w_int1)
     if b >= LONG_BIT:
         raise FailedToImplementArgs(space.w_OverflowError,
                                 space.wrap("integer left shift"))
@@ -258,7 +262,7 @@
         raise OperationError(space.w_ValueError,
                              space.wrap("negative shift count"))
     if a == 0 or b == 0:
-        return int__Int(space, w_int1)
+        return get_integer(space, w_int1)
     if b >= LONG_BIT:
         if a < 0:
             a = -1
@@ -294,10 +298,11 @@
         return w_int1
     a = w_int1.intval
     return wrapint(space, a)
+get_integer = int__Int
 pos__Int = int__Int
 
 def index__Int(space, w_int1):
-    return int__Int(space, w_int1)
+    return get_integer(space, w_int1)
 
 def float__Int(space, w_int1):
     a = w_int1.intval

Modified: pypy/branch/cpython-extension/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/objspace.py	Fri Apr 23 02:41:35 2010
@@ -1,7 +1,7 @@
 import __builtin__
 import types
 from pypy.interpreter import pyframe, function, special
-from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, UnpackValueError
+from pypy.interpreter.baseobjspace import ObjSpace, Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.typedef import get_unique_interplevel_subclass
 from pypy.objspace.std import (builtinshortcut, stdtypedef, frame, model,
@@ -133,7 +133,7 @@
         if not we_are_translated() and isinstance(code, CPythonFakeCode):
             return CPythonFakeFrame(self, code, w_globals)
         else:
-            return self.FrameClass(self, code, w_globals, closure)
+            return ObjSpace.createframe(self, code, w_globals, closure)
 
     def gettypefor(self, cls):
         return self.gettypeobject(cls.typedef)
@@ -252,9 +252,6 @@
         raise model.UnwrapError, "cannot unwrap: %r" % w_obj
 
     def newint(self, intval):
-        # this time-critical and circular-imports-funny method was stored
-        # on 'self' by initialize()
-        # not sure how bad this is:
         return wrapint(self, intval)
 
     def newfloat(self, floatval):
@@ -338,6 +335,10 @@
     # have different return type. First one is a resizable list, second
     # one is not
 
+    def _wrap_expected_length(self, expected, got):
+        return OperationError(self.w_ValueError,
+                self.wrap("Expected length %d, got %d" % (expected, got)))
+
     def unpackiterable(self, w_obj, expected_length=-1):
         if isinstance(w_obj, W_TupleObject):
             t = w_obj.wrappeditems[:]
@@ -346,7 +347,7 @@
         else:
             return ObjSpace.unpackiterable(self, w_obj, expected_length)
         if expected_length != -1 and len(t) != expected_length:
-            raise UnpackValueError("Expected length %d, got %d" % (expected_length, len(t)))
+            raise self._wrap_expected_length(expected_length, len(t))
         return t
 
     def fixedview(self, w_obj, expected_length=-1):
@@ -359,7 +360,7 @@
         else:
             return ObjSpace.fixedview(self, w_obj, expected_length)
         if expected_length != -1 and len(t) != expected_length:
-            raise UnpackValueError("Expected length %d, got %d" % (expected_length, len(t)))
+            raise self._wrap_expected_length(expected_length, len(t))
         return t
 
     def listview(self, w_obj, expected_length=-1):
@@ -370,7 +371,7 @@
         else:
             return ObjSpace.listview(self, w_obj, expected_length)
         if expected_length != -1 and len(t) != expected_length:
-            raise UnpackValueError("Expected length %d, got %d" % (expected_length, len(t)))
+            raise self._wrap_expected_length(expected_length, len(t))
         return t
 
     def sliceindices(self, w_slice, w_length):
@@ -465,11 +466,11 @@
             return w_obj.getitem(w_key)
         return ObjSpace.finditem(self, w_obj, w_key)
 
-    def set_str_keyed_item(self, w_obj, key, w_value, shadows_type=True):
+    def setitem_str(self, w_obj, key, w_value, shadows_type=True):
         # performance shortcut to avoid creating the OperationError(KeyError)
         if (isinstance(w_obj, W_DictMultiObject) and
                 not w_obj.user_overridden_class):
-            w_obj.set_str_keyed_item(key, w_value, shadows_type)
+            w_obj.setitem_str(key, w_value, shadows_type)
         else:
             self.setitem(w_obj, self.wrap(key), w_value)
 

Modified: pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py	Fri Apr 23 02:41:35 2010
@@ -2,18 +2,18 @@
 Implementation of small ints, stored as odd-valued pointers in the
 translated PyPy.  To enable them, see inttype.py.
 """
+import types
 from pypy.interpreter.error import OperationError
+from pypy.objspace.std import intobject
 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.multimethod import FailedToImplementArgs
 from pypy.objspace.std.noneobject import W_NoneObject
 from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
 from pypy.objspace.std.inttype import wrapint
-from pypy.objspace.std.intobject import W_IntObject, declare_new_int_comparison
+from pypy.objspace.std.intobject import W_IntObject, _impl_int_int_pow
 from pypy.rlib.objectmodel import UnboxedValue
-
-# XXX this is a complete copy of intobject.py.  Find a better but still
-# XXX annotator-friendly way to share code...
+from pypy.rlib.rbigint import rbigint
 
 
 class W_SmallIntObject(W_Object, UnboxedValue):
@@ -39,215 +39,19 @@
 def delegate_SmallInt2Complex(space, w_small):
     return space.newcomplex(float(w_small.intval), 0.0)
 
+def copy_multimethods(ns):
+    """Copy integer multimethods for small int."""
+    for name, func in intobject.__dict__.iteritems():
+        if "__Int" in name:
+            new_name = name.replace("Int", "SmallInt")
+            # Copy the function, so the annotator specializes it for
+            # W_SmallIntObject.
+            ns[new_name] = types.FunctionType(func.func_code, ns, new_name,
+                                              func.func_defaults,
+                                              func.func_closure)
+    ns["get_integer"] = ns["pos__SmallInt"] = ns["int__SmallInt"]
+    ns["get_negint"] = ns["neg__SmallInt"]
 
-def int_w__SmallInt(space, w_int1):
-    return int(w_int1.intval)
-
-def uint_w__SmallInt(space, w_int1):
-    intval = w_int1.intval
-    if intval < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("cannot convert negative integer to unsigned"))
-    else:
-        return r_uint(intval)
-
-def repr__SmallInt(space, w_int1):
-    a = w_int1.intval
-    res = str(a)
-    return space.wrap(res)
-
-str__SmallInt = repr__SmallInt
-
-for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
-    func, name = declare_new_int_comparison(op, "SmallInt")
-    globals()[name] = func
-
-def hash__SmallInt(space, w_int1):
-    # unlike CPython, we don't special-case the value -1 in most of our
-    # hash functions, so there is not much sense special-casing it here either.
-    # Make sure this is consistent with the hash of floats and longs.
-    return int__SmallInt(space, w_int1)
-
-# coerce
-def coerce__SmallInt_SmallInt(space, w_int1, w_int2):
-    return space.newtuple([w_int1, w_int2])
-
-
-def add__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = w_int1.intval
-    y = w_int2.intval
-    # note that no overflow checking is necessary here: x and y fit into 31
-    # bits (or 63 bits respectively), so their sum fits into 32 (or 64) bits.
-    # wrapint then makes sure that either a tagged int or a normal int is
-    # created
-    return wrapint(space, x + y)
-
-def sub__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = w_int1.intval
-    y = w_int2.intval
-    # see comment in add__SmallInt_SmallInt
-    return wrapint(space, x - y)
-
-def mul__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = w_int1.intval
-    y = w_int2.intval
-    try:
-        z = ovfcheck(x * y)
-    except OverflowError:
-        raise FailedToImplementArgs(space.w_OverflowError,
-                                space.wrap("integer multiplication"))
-    return wrapint(space, z)
-
-def div__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = w_int1.intval
-    y = w_int2.intval
-    if y == 0:
-        raise OperationError(space.w_ZeroDivisionError,
-                             space.wrap("integer division by zero"))
-    # no overflow possible
-    return wrapint(space, x // y)
-
-floordiv__SmallInt_SmallInt = div__SmallInt_SmallInt
-
-def truediv__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = float(w_int1.intval)
-    y = float(w_int2.intval)
-    if y == 0.0:
-        raise FailedToImplementArgs(space.w_ZeroDivisionError, space.wrap("float division"))    
-    return space.wrap(x / y)
-
-def mod__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = w_int1.intval
-    y = w_int2.intval
-    if y == 0:
-        raise OperationError(space.w_ZeroDivisionError,
-                             space.wrap("integer modulo by zero"))
-    # no overflow possible
-    return wrapint(space, x % y)
-
-def divmod__SmallInt_SmallInt(space, w_int1, w_int2):
-    x = w_int1.intval
-    y = w_int2.intval
-    if y == 0:
-        raise OperationError(space.w_ZeroDivisionError,
-                             space.wrap("integer divmod by zero"))
-    # no overflow possible
-    z = x // y
-    m = x % y
-    return space.newtuple([space.wrap(z), space.wrap(m)])
-
-def pow__SmallInt_SmallInt_SmallInt(space, w_int1, w_int2, w_int3):
-    from pypy.objspace.std.intobject import _impl_int_int_pow
-    x = w_int1.intval
-    y = w_int2.intval
-    z = w_int3.intval
-    if z == 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("pow() 3rd argument cannot be 0"))
-    return _impl_int_int_pow(space, x, y, z)
-
-def pow__SmallInt_SmallInt_None(space, w_int1, w_int2, w_int3):
-    from pypy.objspace.std.intobject import _impl_int_int_pow
-    x = w_int1.intval
-    y = w_int2.intval
-    return _impl_int_int_pow(space, x, y)
-
-def neg__SmallInt(space, w_int1):
-    a = w_int1.intval
-    # no overflow possible since a fits into 31/63 bits
-    return wrapint(space, -a)
-
-
-def abs__SmallInt(space, w_int1):
-    if w_int1.intval >= 0:
-        return pos__SmallInt(space, w_int1)
-    else:
-        return neg__SmallInt(space, w_int1)
-
-def nonzero__SmallInt(space, w_int1):
-    return space.newbool(w_int1.intval != 0)
-
-def invert__SmallInt(space, w_int1):
-    x = w_int1.intval
-    a = ~x
-    return wrapint(space, a)
-
-def lshift__SmallInt_SmallInt(space, w_int1, w_int2):
-    a = w_int1.intval
-    b = w_int2.intval
-    if b < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("negative shift count"))
-    if a == 0 or b == 0:
-        return int__SmallInt(space, w_int1)
-    if b >= LONG_BIT:
-        raise FailedToImplementArgs(space.w_OverflowError,
-                                space.wrap("integer left shift"))
-    try:
-        c = ovfcheck_lshift(a, b)
-    except OverflowError:
-        raise FailedToImplementArgs(space.w_OverflowError,
-                                space.wrap("integer left shift"))
-    return wrapint(space, c)
-
-def rshift__SmallInt_SmallInt(space, w_int1, w_int2):
-    a = w_int1.intval
-    b = w_int2.intval
-    if b < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("negative shift count"))
-    if a == 0 or b == 0:
-        return int__SmallInt(space, w_int1)
-    if b >= LONG_BIT:
-        if a < 0:
-            a = -1
-        else:
-            a = 0
-    else:
-        a = a >> b
-    return wrapint(space, a)
-
-def and__SmallInt_SmallInt(space, w_int1, w_int2):
-    a = w_int1.intval
-    b = w_int2.intval
-    res = a & b
-    return wrapint(space, res)
-
-def xor__SmallInt_SmallInt(space, w_int1, w_int2):
-    a = w_int1.intval
-    b = w_int2.intval
-    res = a ^ b
-    return wrapint(space, res)
-
-def or__SmallInt_SmallInt(space, w_int1, w_int2):
-    a = w_int1.intval
-    b = w_int2.intval
-    res = a | b
-    return wrapint(space, res)
-
-# int__SmallInt is supposed to do nothing, unless it has
-# a derived integer object, where it should return
-# an exact one.
-def int__SmallInt(space, w_int1):
-    if space.is_w(space.type(w_int1), space.w_int):
-        return w_int1
-    a = w_int1.intval
-    return W_SmallIntObject(a)
-pos__SmallInt = int__SmallInt
-
-def float__SmallInt(space, w_int1):
-    a = w_int1.intval
-    x = float(a)
-    return space.newfloat(x)
-
-def oct__SmallInt(space, w_int1):
-    return space.wrap(oct(w_int1.intval))
-
-def hex__SmallInt(space, w_int1):
-    return space.wrap(hex(w_int1.intval))
-
-def getnewargs__SmallInt(space, w_int1):
-    return space.newtuple([wrapint(space, w_int1.intval)])
-
+copy_multimethods(globals())
 
 register_all(vars())

Modified: pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py	Fri Apr 23 02:41:35 2010
@@ -39,25 +39,10 @@
 W_StringObject.PREBUILT = [W_StringObject(chr(i)) for i in range(256)]
 del i
 
-def _decode_ascii(space, s):
-    try:
-        return s.decode("ascii")
-    except UnicodeDecodeError:
-        for i in range(len(s)):
-            if ord(s[i]) > 127:
-                raise OperationError(
-                    space.w_UnicodeDecodeError,
-                    space.newtuple([
-                    space.wrap('ascii'),
-                    space.wrap(s),
-                    space.wrap(i),
-                    space.wrap(i+1),
-                    space.wrap("ordinal not in range(128)")]))
-        assert False, "unreachable"
-
 def unicode_w__String(space, w_self):
     # XXX should this use the default encoding?
-    return _decode_ascii(space, w_self._value)
+    from pypy.objspace.std.unicodetype import plain_str2unicode
+    return plain_str2unicode(space, w_self._value)
 
 def _is_generic(space, w_self, fun): 
     v = w_self._value

Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_obj.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_obj.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_obj.py	Fri Apr 23 02:41:35 2010
@@ -7,11 +7,14 @@
         cpython_behavior = (not option.runappdirect
                             or not hasattr(sys, 'pypy_translation_info'))
                 
-        cls.w_cpython_behavior = cls.space.wrap(cpython_behavior)        
+        cls.w_cpython_behavior = cls.space.wrap(cpython_behavior)
+        cls.w_cpython_version = cls.space.wrap(tuple(sys.version_info))
     
     def test_hash_builtin(self):
         if not self.cpython_behavior:
             skip("on pypy-c id == hash is not guaranteed")
+        if self.cpython_version >= (2, 7):
+            skip("on CPython >= 2.7, id != hash")
         import sys
         o = object()
         assert (hash(o) & sys.maxint) == (id(o) & sys.maxint)
@@ -33,7 +36,7 @@
         class X(object):
             pass
         x = X()
-        if self.cpython_behavior:
+        if self.cpython_behavior and self.cpython_version < (2, 7):
             assert (hash(x) & sys.maxint) == (id(x) & sys.maxint)
         assert hash(x) == object.__hash__(x)
 

Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_stringformat.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_stringformat.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_stringformat.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,4 @@
+# coding: utf-8
 
 
 class AppTestStringObjectWithDict:
@@ -170,6 +171,9 @@
         raises(TypeError, '%c'.__mod__, ("bla",))
         raises(TypeError, '%c'.__mod__, ("",))
         raises(TypeError, '%c'.__mod__, (['c'],))
+    
+    def test_broken_unicode(self):
+        raises(UnicodeDecodeError, 'Názov: %s'.__mod__, u'Jerry')
 
 class AppTestWidthPrec:
     def test_width(self):

Modified: pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py	(original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py	Fri Apr 23 02:41:35 2010
@@ -13,6 +13,22 @@
         return wrapunicode(space, uni)
     return W_UnicodeObject(uni)
 
+def plain_str2unicode(space, s):
+    try:
+        return unicode(s)
+    except UnicodeDecodeError:
+        for i in range(len(s)):
+            if ord(s[i]) > 127:
+                raise OperationError(
+                    space.w_UnicodeDecodeError,
+                    space.newtuple([
+                    space.wrap('ascii'),
+                    space.wrap(s),
+                    space.wrap(i),
+                    space.wrap(i+1),
+                    space.wrap("ordinal not in range(128)")]))
+        assert False, "unreachable"
+
 
 unicode_capitalize = SMM('capitalize', 1,
                          doc='S.capitalize() -> unicode\n\nReturn a'

Modified: pypy/branch/cpython-extension/pypy/rlib/nonconst.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/nonconst.py	(original)
+++ pypy/branch/cpython-extension/pypy/rlib/nonconst.py	Fri Apr 23 02:41:35 2010
@@ -3,9 +3,7 @@
 """
 
 from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.annotation.bookkeeper import getbookkeeper
-from pypy.objspace.flow.model import Variable, Constant
-from pypy.rpython.lltypesystem import lltype
+from pypy.objspace.flow.model import Constant
 
 class NonConstant(object):
     def __init__(self, _constant):
@@ -22,7 +20,7 @@
 
 class EntryNonConstant(ExtRegistryEntry):
     _about_ = NonConstant
-    
+
     def compute_result_annotation(self, arg):
         if hasattr(arg, 'const'):
             return self.bookkeeper.immutablevalue(arg.const, False)

Modified: pypy/branch/cpython-extension/pypy/rlib/rsre/rsre_char.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rsre/rsre_char.py	(original)
+++ pypy/branch/cpython-extension/pypy/rlib/rsre/rsre_char.py	Fri Apr 23 02:41:35 2010
@@ -2,7 +2,7 @@
 Character categories and charsets.
 """
 import sys
-from pypy.rlib.rsre._rsre_platform import tolower, isalnum
+from pypy.rlib.rlocale import tolower, isalnum
 from pypy.rlib.unroll import unrolling_iterable
 
 # Note: the unicode parts of this module require you to call

Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py	Fri Apr 23 02:41:35 2010
@@ -3,9 +3,9 @@
 import sys
 
 import py
-from pypy.rlib.rarithmetic import r_int, r_uint, intmask, r_singlefloat
-from pypy.rlib.rarithmetic import r_ulonglong, r_longlong, base_int
-from pypy.rlib.rarithmetic import normalizedinttype
+from pypy.rlib.rarithmetic import (r_int, r_uint, intmask, r_singlefloat,
+                                   r_ulonglong, r_longlong, base_int,
+                                   normalizedinttype)
 from pypy.rlib.objectmodel import Symbolic
 from pypy.tool.uid import Hashable
 from pypy.tool.tls import tlsobject
@@ -15,8 +15,6 @@
 import struct
 import weakref
 
-log = py.log.Producer('lltype')
-
 TLS = tlsobject()
 TRACK_ALLOCATIONS = False
 

Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py	Fri Apr 23 02:41:35 2010
@@ -19,9 +19,6 @@
 from pypy.rpython.lltypesystem import llmemory
 import os, sys
 
-class UnhandledRPythonException(Exception):
-    pass
-
 class CConstant(Symbolic):
     """ A C-level constant, maybe #define, rendered directly.
     """

Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_lltype.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_lltype.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,4 @@
+import py
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.lib.identity_dict import identity_dict
 

Modified: pypy/branch/cpython-extension/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/memory/gctransform/framework.py	Fri Apr 23 02:41:35 2010
@@ -445,11 +445,7 @@
         self.c_const_gc = rmodel.inputconst(r_gc, self.gcdata.gc)
         self.malloc_zero_filled = GCClass.malloc_zero_filled
 
-        HDR = self._gc_HDR = self.gcdata.gc.gcheaderbuilder.HDR
-        self._gc_fields = fields = []
-        for fldname in HDR._names:
-            FLDTYPE = getattr(HDR, fldname)
-            fields.append(('_' + fldname, FLDTYPE))
+        HDR = self.HDR = self.gcdata.gc.gcheaderbuilder.HDR
 
         size_gc_header = self.gcdata.gc.gcheaderbuilder.size_gc_header
         vtableinfo = (HDR, size_gc_header, self.gcdata.gc.typeid_is_in_field)
@@ -472,26 +468,20 @@
     def finalizer_funcptr_for_type(self, TYPE):
         return self.layoutbuilder.finalizer_funcptr_for_type(TYPE)
 
-    def gc_fields(self):
-        return self._gc_fields
-
-    def gc_field_values_for(self, obj, needs_hash=False):
+    def gc_header_for(self, obj, needs_hash=False):
         hdr = self.gcdata.gc.gcheaderbuilder.header_of_object(obj)
-        HDR = self._gc_HDR
+        HDR = self.HDR
         withhash, flag = self.gcdata.gc.withhash_flag_is_in_field
-        result = []
-        for fldname in HDR._names:
-            x = getattr(hdr, fldname)
-            if fldname == withhash:
-                TYPE = lltype.typeOf(x)
-                x = lltype.cast_primitive(lltype.Signed, x)
-                if needs_hash:
-                    x |= flag       # set the flag in the header
-                else:
-                    x &= ~flag      # clear the flag in the header
-                x = lltype.cast_primitive(TYPE, x)
-            result.append(x)
-        return result
+        x = getattr(hdr, withhash)
+        TYPE = lltype.typeOf(x)
+        x = lltype.cast_primitive(lltype.Signed, x)
+        if needs_hash:
+            x |= flag       # set the flag in the header
+        else:
+            x &= ~flag      # clear the flag in the header
+        x = lltype.cast_primitive(TYPE, x)
+        setattr(hdr, withhash, x)
+        return hdr
 
     def get_hash_offset(self, T):
         type_id = self.get_type_id(T)

Modified: pypy/branch/cpython-extension/pypy/rpython/rint.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/rint.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/rint.py	Fri Apr 23 02:41:35 2010
@@ -1,7 +1,7 @@
 import sys
 from pypy.tool.pairtype import pairtype
 from pypy.annotation import model as annmodel
-from pypy.objspace.flow.objspace import op_appendices
+from pypy.objspace.flow.operation import op_appendices
 from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Bool, Float, \
      Void, Char, UniChar, malloc, pyobjectptr, UnsignedLongLong, \
      SignedLongLong, build_number, Number, cast_primitive, typeOf

Modified: pypy/branch/cpython-extension/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/test/test_llann.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/test/test_llann.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,4 @@
+import py
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.lltypesystem.rclass import OBJECTPTR

Modified: pypy/branch/cpython-extension/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/test/test_rlist.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/test/test_rlist.py	Fri Apr 23 02:41:35 2010
@@ -1,4 +1,6 @@
 import sys
+import re
+import py
 from pypy.translator.translator import TranslationContext
 from pypy.rpython.error import TyperError
 from pypy.rpython.lltypesystem.lltype import *
@@ -11,7 +13,6 @@
 from pypy.translator.translator import TranslationContext
 from pypy.objspace.flow.model import Constant, Variable
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
-import re
 
 # undo the specialization parameter
 for n1 in 'get set del'.split():

Modified: pypy/branch/cpython-extension/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/branch/cpython-extension/pypy/rpython/test/test_rpbc.py	Fri Apr 23 02:41:35 2010
@@ -1,3 +1,4 @@
+import py
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.rpython.rtyper import RPythonTyper
 from pypy.rpython.ootypesystem import ootype

Modified: pypy/branch/cpython-extension/pypy/tool/pytest/appsupport.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/tool/pytest/appsupport.py	(original)
+++ pypy/branch/cpython-extension/pypy/tool/pytest/appsupport.py	Fri Apr 23 02:41:35 2010
@@ -87,7 +87,7 @@
         if debug_excs:
             self._excinfo = debug_excs[0]
 
-    def exconly(self, tryshort=True): 
+    def exconly(self, tryshort=True):
         return '(application-level) ' + self.operr.errorstr(self.space)
 
     def errisinstance(self, exc): 
@@ -218,7 +218,8 @@
         for key, w_value in kwds_w.items():
             space.setitem(w_locals, space.wrap(key), w_value)
         try:
-            space.exec_(source.compile(), frame.w_globals, w_locals)
+            space.exec_(str(source), frame.w_globals, w_locals,
+                        filename=__file__)
         except OperationError, e:
             if e.match(space, w_ExpectedException):
                 return _exc_info(space, e)

Modified: pypy/branch/cpython-extension/pypy/tool/sourcetools.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/tool/sourcetools.py	(original)
+++ pypy/branch/cpython-extension/pypy/tool/sourcetools.py	Fri Apr 23 02:41:35 2010
@@ -17,7 +17,7 @@
         indentation. The shorter triple quotes are
         choosen automatically.
         The result is returned as a 1-tuple."""
-    if type(func) is not str:
+    if not isinstance(func, str):
         doc = func.__doc__
     else:
         doc = func
@@ -217,20 +217,15 @@
 
 # ____________________________________________________________
 
-if sys.version_info >= (2, 3):
-    def func_with_new_name(func, newname):
-        """Make a renamed copy of a function."""
-        f = new.function(func.func_code, func.func_globals,
-                            newname, func.func_defaults,
-                            func.func_closure)
-        if func.func_dict: 
-            f.func_dict = {}
-            f.func_dict.update(func.func_dict) 
-        return f 
-else:
-    raise Exception("sorry, Python 2.2 not supported")
-    # because we need to return a new function object -- impossible in 2.2,
-    # cannot create functions with closures without using veeeery strange code
+def func_with_new_name(func, newname):
+    """Make a renamed copy of a function."""
+    f = new.function(func.func_code, func.func_globals,
+                        newname, func.func_defaults,
+                        func.func_closure)
+    if func.func_dict:
+        f.func_dict = {}
+        f.func_dict.update(func.func_dict)
+    return f
 
 PY_IDENTIFIER = ''.join([(('0' <= chr(i) <= '9' or
                            'a' <= chr(i) <= 'z' or

Modified: pypy/branch/cpython-extension/pypy/tool/stdlib_opcode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/tool/stdlib_opcode.py	(original)
+++ pypy/branch/cpython-extension/pypy/tool/stdlib_opcode.py	Fri Apr 23 02:41:35 2010
@@ -1,44 +1,25 @@
+"""
+Opcodes PyPy compiles Python source to.
+Also gives access to opcodes of the host Python PyPy was bootstrapped with
+(module attributes with the `host_` prefix).
+"""
+
 # load opcode.py as pythonopcode from our own lib
 
 __all__ = ['opmap', 'opname', 'HAVE_ARGUMENT',
            'hasconst', 'hasname', 'hasjrel', 'hasjabs',
            'haslocal', 'hascompare', 'hasfree', 'cmp_op']
 
-def load_opcode():
-    import py
-    opcode_path = py.path.local(__file__).dirpath().dirpath().dirpath('lib-python/modified-2.5.2/opcode.py')
-    d = {}
-    execfile(str(opcode_path), d)
-    return d
-
-opcode_dict = load_opcode()
-del load_opcode
-
-# copy some stuff from opcode.py directly into our globals
-for name in __all__:
-    if name in opcode_dict:
-        globals()[name] = opcode_dict[name]
-globals().update(opmap)
-SLICE = opmap["SLICE+0"]
-STORE_SLICE = opmap["STORE_SLICE+0"]
-DELETE_SLICE = opmap["DELETE_SLICE+0"]
-
-opcode_method_names = ['MISSING_OPCODE'] * 256
-for name, index in opmap.items():
-    opcode_method_names[index] = name.replace('+', '_')
-
 # ____________________________________________________________
 # RPython-friendly helpers and structures
 
-from pypy.rlib.unroll import unrolling_iterable
-
-
-class OpcodeDesc(object):
-    def __init__(self, name, index):
+class _BaseOpcodeDesc(object):
+    def __init__(self, bytecode_spec, name, index, methodname):
+        self.bytecode_spec = bytecode_spec
         self.name = name
-        self.methodname = opcode_method_names[index]
+        self.methodname = methodname
         self.index = index
-        self.hasarg = index >= HAVE_ARGUMENT
+        self.hasarg = index >= self.HAVE_ARGUMENT
 
     def _freeze_(self):
         return True
@@ -64,24 +45,87 @@
         return (cmp(self.__class__, other.__class__) or
                 cmp(self.sortkey(), other.sortkey()))
 
-opdescmap = {}
+    def __str__(self):
+        return "<OpcodeDesc code=%d name=%s at %x>" % (self.index, self.name, id(self))
+    
+    __repr__ = __str__
+
+class _baseopcodedesc:
+    """A namespace mapping OPCODE_NAME to _BaseOpcodeDescs."""
+    pass
+
+
+class BytecodeSpec(object):
+    """A bunch of mappings describing a bytecode instruction set."""
+
+    def __init__(self, name, opmap, HAVE_ARGUMENT):
+        """NOT_RPYTHON."""
+        class OpcodeDesc(_BaseOpcodeDesc):
+            HAVE_ARGUMENT = HAVE_ARGUMENT
+        class opcodedesc(_baseopcodedesc):
+            """A namespace mapping OPCODE_NAME to OpcodeDescs."""
+        
+        self.name = name
+        self.OpcodeDesc = OpcodeDesc
+        self.opcodedesc = opcodedesc
+        self.HAVE_ARGUMENT = HAVE_ARGUMENT
+        # opname -> opcode
+        self.opmap = opmap
+        # opcode -> method name
+        self.method_names = tbl = ['MISSING_OPCODE'] * 256
+        # opcode -> opdesc
+        self.opdescmap = {}
+        for name, index in opmap.items():
+            tbl[index] = methodname = name.replace('+', '_')
+            desc = OpcodeDesc(self, name, index, methodname)
+            setattr(self.opcodedesc, name, desc)
+            self.opdescmap[index] = desc
+        # fill the ordered opdesc list
+        self.ordered_opdescs = lst = self.opdescmap.values() 
+        lst.sort()
+    
+    def to_globals(self):
+        """NOT_RPYTHON. Add individual opcodes to the module constants."""
+        g = globals()
+        g.update(self.opmap)
+        g['SLICE'] = self.opmap["SLICE+0"]
+        g['STORE_SLICE'] = self.opmap["STORE_SLICE+0"]
+        g['DELETE_SLICE'] = self.opmap["DELETE_SLICE+0"]
+
+    def __str__(self):
+        return "<%s bytecode>" % (self.name,)
+    
+    __repr__ = __str__
+
+
+# Initialization
+
+from pypy.rlib.unroll import unrolling_iterable
+
+from opcode import (
+    opmap as host_opmap, HAVE_ARGUMENT as host_HAVE_ARGUMENT)
 
-class opcodedesc:
-    """A namespace mapping OPCODE_NAME to OpcodeDescs."""
+def load_pypy_opcode():
+    import py
+    opcode_path = py.path.local(__file__).dirpath().dirpath().dirpath('lib-python/modified-2.5.2/opcode.py')
+    d = {}
+    execfile(str(opcode_path), d)
+    for name in __all__:
+        if name in d:
+            globals()[name] = d[name]
+    return d
 
-for name, index in opmap.items():
-    desc = OpcodeDesc(name, index)
-    setattr(opcodedesc, name, desc)
-    opdescmap[index] = desc
-
-lst = opdescmap.values()
-lst.sort()
-unrolling_opcode_descs = unrolling_iterable(lst)
-
-# Allow non-translated code to interpret the new 2.6 bytecodes
-import sys
-if sys.version_info >= (2, 6):
-    import opcode
-    opcode_method_names[opcode.opmap['STORE_MAP']] = 'STORE_MAP'
+load_pypy_opcode()
+del load_pypy_opcode
 
-del name, index, desc, lst
+bytecode_spec = BytecodeSpec('pypy', opmap, HAVE_ARGUMENT)
+host_bytecode_spec = BytecodeSpec('host', host_opmap, host_HAVE_ARGUMENT)
+bytecode_spec.to_globals()
+
+opcode_method_names = bytecode_spec.method_names
+opcodedesc = bytecode_spec.opcodedesc
+
+unrolling_all_opcode_descs = unrolling_iterable(
+    bytecode_spec.ordered_opdescs + host_bytecode_spec.ordered_opdescs)
+unrolling_opcode_descs = unrolling_iterable(
+    bytecode_spec.ordered_opdescs)

Modified: pypy/branch/cpython-extension/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/database.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/c/database.py	Fri Apr 23 02:41:35 2010
@@ -177,58 +177,56 @@
         return node
 
     def get(self, obj):
-        # XXX extra indent is preserve svn blame - kind of important IMHO (rxe)
-        if 1:
-            if isinstance(obj, CConstant):
-                return obj.c_name  # without further checks
-            T = typeOf(obj)
-            if isinstance(T, Primitive) or T == GCREF:
-                return PrimitiveName[T](obj, self)
-            elif isinstance(T, Ptr):
-                if obj:   # test if the ptr is non-NULL
-                    try:
-                        container = obj._obj
-                    except lltype.DelayedPointer:
-                        # hack hack hack
-                        name = obj._obj0
-                        assert name.startswith('delayed!')
-                        n = len('delayed!')
-                        if len(name) == n:
-                            raise
-                        if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
-                            if obj in self.idelayedfunctionnames:
-                                return self.idelayedfunctionnames[obj][0]
-                            funcname = name[n:]
-                            funcname = self.namespace.uniquename('g_'+funcname)
-                            self.idelayedfunctionnames[obj] = funcname, obj
-                        else:
-                            funcname = None      # can't use the name of a
-                                                 # delayed non-function ptr
-                        self.delayedfunctionptrs.append(obj)
-                        return funcname
-                        # /hack hack hack
-                    else:
-                        # hack hack hack
+        if isinstance(obj, CConstant):
+            return obj.c_name  # without further checks
+        T = typeOf(obj)
+        if isinstance(T, Primitive) or T == GCREF:
+            return PrimitiveName[T](obj, self)
+        elif isinstance(T, Ptr):
+            if obj:   # test if the ptr is non-NULL
+                try:
+                    container = obj._obj
+                except lltype.DelayedPointer:
+                    # hack hack hack
+                    name = obj._obj0
+                    assert name.startswith('delayed!')
+                    n = len('delayed!')
+                    if len(name) == n:
+                        raise
+                    if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
                         if obj in self.idelayedfunctionnames:
-                            # this used to be a delayed function,
-                            # make sure we use the same name
-                            forcename = self.idelayedfunctionnames[obj][0]
-                            node = self.getcontainernode(container,
-                                                         forcename=forcename)
-                            assert node.ptrname == forcename
-                            return forcename
-                        # /hack hack hack
-
-                    if isinstance(container, int):
-                        # special case for tagged odd-valued pointers
-                        return '((%s) %d)' % (cdecl(self.gettype(T), ''),
-                                              obj._obj)
-                    node = self.getcontainernode(container)
-                    return node.ptrname
+                            return self.idelayedfunctionnames[obj][0]
+                        funcname = name[n:]
+                        funcname = self.namespace.uniquename('g_'+funcname)
+                        self.idelayedfunctionnames[obj] = funcname, obj
+                    else:
+                        funcname = None      # can't use the name of a
+                                             # delayed non-function ptr
+                    self.delayedfunctionptrs.append(obj)
+                    return funcname
+                    # /hack hack hack
                 else:
-                    return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
+                    # hack hack hack
+                    if obj in self.idelayedfunctionnames:
+                        # this used to be a delayed function,
+                        # make sure we use the same name
+                        forcename = self.idelayedfunctionnames[obj][0]
+                        node = self.getcontainernode(container,
+                                                     forcename=forcename)
+                        assert node.ptrname == forcename
+                        return forcename
+                    # /hack hack hack
+
+                if isinstance(container, int):
+                    # special case for tagged odd-valued pointers
+                    return '((%s) %d)' % (cdecl(self.gettype(T), ''),
+                                          obj._obj)
+                node = self.getcontainernode(container)
+                return node.ptrname
             else:
-                raise Exception("don't know about %r" % (obj,))
+                return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
+        else:
+            raise Exception("don't know about %r" % (obj,))
 
     def complete(self, show_progress=True):
         assert not self.completed
@@ -304,7 +302,7 @@
                     self.getcontainernode(value)
                 else:
                     self.get(value)
-        
+
         while True:
             while True:
                 while self.pendingsetupnodes:

Modified: pypy/branch/cpython-extension/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/gc.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/c/gc.py	Fri Apr 23 02:41:35 2010
@@ -20,16 +20,13 @@
 
     def common_gcheader_definition(self, defnode):
         if defnode.db.gctransformer is not None:
-            HDR = defnode.db.gctransformer.HDR
-            return [(name, HDR._flds[name]) for name in HDR._names]
-        else:
-            return []
+            return defnode.db.gctransformer.HDR
+        return None
 
     def common_gcheader_initdata(self, defnode):
         if defnode.db.gctransformer is not None:
             raise NotImplementedError
-        else:
-            return []
+        return None
 
     def struct_gcheader_definition(self, defnode):
         return self.common_gcheader_definition(defnode)
@@ -113,11 +110,9 @@
     def common_gcheader_initdata(self, defnode):
         if defnode.db.gctransformer is not None:
             gct = defnode.db.gctransformer
-            hdr = gct.gcheaderbuilder.header_of_object(top_container(defnode.obj))
-            HDR = gct.HDR
-            return [getattr(hdr, fldname) for fldname in HDR._names]
-        else:
-            return []
+            top = top_container(defnode.obj)
+            return gct.gcheaderbuilder.header_of_object(top)._obj
+        return None
 
     # for structs
 
@@ -196,9 +191,10 @@
 
     def common_gcheader_initdata(self, defnode):
         if defnode.db.gctransformer is not None:
-            return [lltype.identityhash_nocache(defnode.obj._as_ptr())]
-        else:
-            return []
+            hdr = lltype.malloc(defnode.db.gctransformer.HDR, immortal=True)
+            hdr.hash = lltype.identityhash_nocache(defnode.obj._as_ptr())
+            return hdr._obj
+        return None
 
     def array_setup(self, arraydefnode):
         pass
@@ -333,13 +329,11 @@
             args = [funcgen.expr(v) for v in op.args]
             return '%s = %s; /* for moving GCs */' % (args[1], args[0])
 
-    def common_gcheader_definition(self, defnode):
-        return defnode.db.gctransformer.gc_fields()
-
     def common_gcheader_initdata(self, defnode):
         o = top_container(defnode.obj)
         needs_hash = self.get_prebuilt_hash(o) is not None
-        return defnode.db.gctransformer.gc_field_values_for(o, needs_hash)
+        hdr = defnode.db.gctransformer.gc_header_for(o, needs_hash)
+        return hdr._obj
 
     def get_prebuilt_hash(self, obj):
         # for prebuilt objects that need to have their hash stored and
@@ -362,9 +356,14 @@
         # all implemented by a single call to a C macro.
         [v_obj, c_grpptr, c_skipoffset, c_vtableinfo] = op.args
         typename = funcgen.db.gettype(op.result.concretetype)
-        fieldname = c_vtableinfo.value[2]
+        tid_field = c_vtableinfo.value[2]
+        # Fish out the C name of the tid field.
+        HDR = self.db.gctransformer.HDR
+        hdr_node = self.db.gettypedefnode(HDR)
+        fieldname = hdr_node.c_struct_field_name(tid_field)
         return (
-        '%s = (%s)_OP_GET_NEXT_GROUP_MEMBER(%s, (pypy_halfword_t)%s->_%s, %s);'
+        '%s = (%s)_OP_GET_NEXT_GROUP_MEMBER(%s, (pypy_halfword_t)%s->'
+            '_gcheader.%s, %s);'
             % (funcgen.expr(op.result),
                cdecl(typename, ''),
                funcgen.expr(c_grpptr),

Modified: pypy/branch/cpython-extension/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/node.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/c/node.py	Fri Apr 23 02:41:35 2010
@@ -89,8 +89,10 @@
         if self.varlength != 1:
             self.normalizedtypename = db.gettype(STRUCT, who_asks=self)
         if needs_gcheader(self.STRUCT):
-            for fname, T in db.gcpolicy.struct_gcheader_definition(self):
-                self.fields.append((fname, db.gettype(T, who_asks=self)))
+            HDR = db.gcpolicy.struct_gcheader_definition(self)
+            if HDR is not None:
+                gc_field = ("_gcheader", db.gettype(HDR, who_asks=self))
+                self.fields.append(gc_field)
         for name in self.fieldnames:
             T = self.c_struct_field_type(name)
             if name == STRUCT._arrayfld:
@@ -219,8 +221,10 @@
         if self.varlength != 1:
             self.normalizedtypename = db.gettype(ARRAY, who_asks=self)
         if needs_gcheader(ARRAY):
-            for fname, T in db.gcpolicy.array_gcheader_definition(self):
-                self.gcfields.append((fname, db.gettype(T, who_asks=self)))
+            HDR = db.gcpolicy.array_gcheader_definition(self)
+            if HDR is not None:
+                gc_field = ("_gcheader", db.gettype(HDR, who_asks=self))
+                self.gcfields.append(gc_field)
         self.itemtypename = db.gettype(ARRAY.OF, who_asks=self)
 
     def computegcinfo(self):
@@ -563,12 +567,12 @@
         data = []
 
         if needs_gcheader(self.T):
-            for i, thing in enumerate(self.db.gcpolicy.struct_gcheader_initdata(self)):
-                data.append(('gcheader%d'%i, thing))
-        
+            gc_init = self.db.gcpolicy.struct_gcheader_initdata(self)
+            data.append(('gcheader', gc_init))
+
         for name in defnode.fieldnames:
             data.append((name, getattr(self.obj, name)))
-        
+
         # Reasonably, you should only initialise one of the fields of a union
         # in C.  This is possible with the syntax '.fieldname value' or
         # '.fieldname = value'.  But here we don't know which of the
@@ -670,12 +674,11 @@
         defnode = self.db.gettypedefnode(self.T)
         yield '{'
         if needs_gcheader(self.T):
-            for i, thing in enumerate(self.db.gcpolicy.array_gcheader_initdata(self)):
-                lines = generic_initializationexpr(self.db, thing,
-                                                   'gcheader%d'%i,
-                                                   '%sgcheader%d' % (decoration, i))
-                for line in lines:
-                    yield line
+            gc_init = self.db.gcpolicy.array_gcheader_initdata(self)
+            lines = generic_initializationexpr(self.db, gc_init, 'gcheader',
+                                               '%sgcheader' % (decoration,))
+            for line in lines:
+                yield line
         if self.T._hints.get('nolength', False):
             length = ''
         else:

Modified: pypy/branch/cpython-extension/pypy/translator/c/src/signals.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/src/signals.h	(original)
+++ pypy/branch/cpython-extension/pypy/translator/c/src/signals.h	Fri Apr 23 02:41:35 2010
@@ -70,7 +70,11 @@
    cleared again.  The variable is exposed and RPython code is free to
    use the other bits in any way. */
 #define PENDING_SIGNAL_BIT   (LONG_MIN)   /* high bit */
-extern long pypysig_occurred;
+/* This is a struct for the JIT. See interp_signal.py. */
+struct pypysig_long_struct {
+    long value;
+};
+extern struct pypysig_long_struct pypysig_occurred;
 
 /* some C tricks to get/set the variable as efficiently as possible:
    use macros when compiling as a stand-alone program, but still
@@ -87,9 +91,8 @@
 
 #ifndef PYPY_NOT_MAIN_FILE
 
-
-long pypysig_occurred;
-static volatile long *pypysig_occurred_v = (volatile long *)&pypysig_occurred;
+struct pypysig_long_struct pypysig_occurred;
+static volatile long *pypysig_occurred_v = (volatile long *)&pypysig_occurred.value;
 static volatile int pypysig_flags[NSIG];
 
 void pypysig_ignore(int signum)
@@ -159,7 +162,7 @@
             {
                 pypysig_flags[i] = 0;
                 /* maybe another signal is pending: */
-                pypysig_occurred |= PENDING_SIGNAL_BIT;
+                pypysig_occurred.value |= PENDING_SIGNAL_BIT;
                 return i;
             }
     }

Modified: pypy/branch/cpython-extension/pypy/translator/driver.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/driver.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/driver.py	Fri Apr 23 02:41:35 2010
@@ -308,6 +308,8 @@
         return res
 
     def task_annotate(self):
+        """ Annotate
+        """
         # includes annotation and annotatation simplifications
         translator = self.translator
         policy = self.policy
@@ -365,6 +367,8 @@
 
 
     def task_rtype_lltype(self):
+        """ RTyping - lltype version
+        """
         rtyper = self.translator.buildrtyper(type_system='lltype')
         insist = not self.config.translation.insist
         rtyper.specialize(dont_simplify_again=True,
@@ -374,6 +378,8 @@
     RTYPE = 'rtype_lltype'
 
     def task_rtype_ootype(self):
+        """ RTyping - ootype version
+        """
         # Maybe type_system should simply be an option used in task_rtype
         insist = not self.config.translation.insist
         rtyper = self.translator.buildrtyper(type_system="ootype")
@@ -384,6 +390,9 @@
     OOTYPE = 'rtype_ootype'
 
     def task_pyjitpl_lltype(self):
+        """ Generate bytecodes for JIT and flow the JIT helper functions
+        ootype version
+        """
         get_policy = self.extra['jitpolicy']
         self.jitpolicy = get_policy(self)
         #
@@ -399,6 +408,9 @@
                                   "JIT compiler generation")
 
     def task_pyjitpl_ootype(self):
+        """ Generate bytecodes for JIT and flow the JIT helper functions
+        ootype version
+        """
         get_policy = self.extra['jitpolicy']
         self.jitpolicy = get_policy(self)
         #
@@ -414,6 +426,8 @@
                                   "JIT compiler generation")
 
     def task_backendopt_lltype(self):
+        """ Run all backend optimizations - lltype version
+        """
         from pypy.translator.backendopt.all import backend_optimizations
         backend_optimizations(self.translator)
     #
@@ -423,6 +437,8 @@
     BACKENDOPT = 'backendopt_lltype'
 
     def task_backendopt_ootype(self):
+        """ Run all backend optimizations - ootype version
+        """
         from pypy.translator.backendopt.all import backend_optimizations
         backend_optimizations(self.translator)
     #
@@ -453,6 +469,8 @@
                 raise Exception(str(e) + '\n' + i)
 
     def task_database_c(self):
+        """ Create a database for further backend generation
+        """
         translator = self.translator
         if translator.annotator is not None:
             translator.frozen = True
@@ -484,7 +502,9 @@
                             "Creating database for generating c source",
                             earlycheck = possibly_check_for_boehm)
     
-    def task_source_c(self):  # xxx messy
+    def task_source_c(self):
+        """ Create C source files from the generated database
+        """
         translator = self.translator
         cbuilder = self.cbuilder
         database = self.database
@@ -512,6 +532,8 @@
         return mkexename(py.path.local(newexename))
 
     def create_exe(self):
+        """ Copy the compiled executable into translator/goal
+        """
         if self.exe_name is not None:
             exename = mkexename(self.c_entryp)
             newexename = self.compute_exe_name()
@@ -523,7 +545,10 @@
             self.c_entryp = newexename
         self.log.info("created: %s" % (self.c_entryp,))
 
-    def task_compile_c(self): # xxx messy
+    def task_compile_c(self):
+        """ Compile the generated C code using either makefile or
+        translator/platform
+        """
         cbuilder = self.cbuilder
         kwds = {}
         if self.standalone:

Modified: pypy/branch/cpython-extension/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/geninterplevel.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/geninterplevel.py	Fri Apr 23 02:41:35 2010
@@ -71,7 +71,7 @@
 log = py.log.Producer("geninterp")
 py.log.setconsumer("geninterp", ansi_log)
 
-GI_VERSION = '1.2.7'  # bump this for substantial changes
+GI_VERSION = '1.2.8'  # bump this for substantial changes
 # ____________________________________________________________
 
 try:
@@ -161,11 +161,11 @@
                          Constant(OperationError).key: late_OperationError,
                          Constant(Arguments).key: late_Arguments,
                        }
-        u = UniqueList
-        self.initcode = u()    # list of lines for the module's initxxx()
-        self.latercode = u()   # list of generators generating extra lines
-                               #   for later in initxxx() -- for recursive
-                               #   objects
+        self.initcode = UniqueList() # list of lines for the module's initxxx()
+        self.latercode = UniqueList()
+        # list of generators generating extra lines
+        #   for later in initxxx() -- for recursive
+        #   objects
         self.namespace = NameManager()
         self.namespace.make_reserved_names('__doc__ __args__ space goto')
         self.globaldecl = []
@@ -1475,10 +1475,7 @@
     """
     # create something like a module
     if type(sourcetext) is str:
-        if filename is None: 
-            code = py.code.Source(sourcetext).compile()
-        else: 
-            code = NiceCompile(filename)(sourcetext)
+        code = py.code.Source(sourcetext).compile()
     else:
         # assume we got an already compiled source
         code = sourcetext

Modified: pypy/branch/cpython-extension/pypy/translator/goal/nanos.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/goal/nanos.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/goal/nanos.py	Fri Apr 23 02:41:35 2010
@@ -26,7 +26,7 @@
 """
 
 from pypy.interpreter.gateway import applevel, ObjSpace, W_Root, interp2app
-import os
+import os, py
 
 app_os_path = applevel(r'''
     from os.path import dirname, join, abspath, isfile, islink
@@ -59,6 +59,6 @@
 path_module_for_testing = type(os)("os.path")
 os_module_for_testing = type(os)("os")
 os_module_for_testing.path = path_module_for_testing
-eval(app_os_path.code, path_module_for_testing.__dict__)
-eval(app_os.code, os_module_for_testing.__dict__)
+eval(py.code.Source(app_os_path.source).compile(), path_module_for_testing.__dict__)
+eval(py.code.Source(app_os.source).compile(), os_module_for_testing.__dict__)
 

Modified: pypy/branch/cpython-extension/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/goal/targetpypystandalone.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/goal/targetpypystandalone.py	Fri Apr 23 02:41:35 2010
@@ -233,15 +233,17 @@
 
         # manually imports app_main.py
         filename = os.path.join(this_dir, 'app_main.py')
-        w_dict = space.newdict()
-        space.exec_(open(filename).read(), w_dict, w_dict)
+        app = gateway.applevel(open(filename).read(), 'app_main.py', 'app_main')
+        app.hidden_applevel = False
+        app.can_use_geninterp = False
+        w_dict = app.getwdict(space)
         entry_point = create_entry_point(space, w_dict)
 
         return entry_point, None, PyPyAnnotatorPolicy(single_space = space)
 
     def interface(self, ns):
         for name in ['take_options', 'handle_config', 'print_help', 'target',
-                     'jitpolicy',
+                     'jitpolicy', 'get_entry_point',
                      'get_additional_config_options']:
             ns[name] = getattr(self, name)
 

Modified: pypy/branch/cpython-extension/pypy/translator/jvm/conftest.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/jvm/conftest.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/jvm/conftest.py	Fri Apr 23 02:41:35 2010
@@ -1,4 +1,12 @@
 
+import py, sys
+
+class Module(py.test.collect.Module):
+    def collect(self):
+        if sys.maxint > 2147483647: # 64bit platform
+            py.test.skip("jvm backend on 64bit unsupported")
+        return super(Module, self).collect()
+
 def pytest_addoption(parser):
     group = parser.getgroup("pypy-jvm options")
     group.addoption('--java', action='store', dest='java', default='java',

Modified: pypy/branch/cpython-extension/pypy/translator/simplify.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/simplify.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/simplify.py	Fri Apr 23 02:41:35 2010
@@ -6,16 +6,20 @@
 """
 
 import py
-from pypy.objspace.flow.model import SpaceOperation
-from pypy.objspace.flow.model import Variable, Constant, Block, Link
-from pypy.objspace.flow.model import c_last_exception
-from pypy.objspace.flow.model import checkgraph, traverse, mkentrymap
+from pypy.objspace.flow import operation
+from pypy.objspace.flow.model import (SpaceOperation, Variable, Constant, Block,
+                                      Link, c_last_exception, checkgraph,
+                                      traverse, mkentrymap)
+from pypy.rlib import rarithmetic
+from pypy.translator import unsimplify
+from pypy.translator.backendopt import ssa
 from pypy.rpython.lltypesystem import lloperation, lltype
 from pypy.rpython.ootypesystem import ootype
 
 def get_funcobj(func):
     """
-    Return an object which is supposed to have attributes such as graph and _callable
+    Return an object which is supposed to have attributes such as graph and
+    _callable
     """
     if hasattr(func, '_obj'): 
         return func._obj # lltypesystem
@@ -30,12 +34,9 @@
     assert False
 
 def get_graph(arg, translator):
-    from pypy.translator.translator import graphof
     if isinstance(arg, Variable):
         return None
     f = arg.value
-    from pypy.rpython.lltypesystem import lltype
-    from pypy.rpython.ootypesystem import ootype
     if not isinstance(f, lltype._ptr) and not isinstance(f, ootype._callable):
         return None
     funcobj = get_funcobj(f)
@@ -49,7 +50,7 @@
         return None
     try:
         callable = funcobj._callable
-        return graphof(translator, callable)
+        return translator._graphof(callable)
     except (AttributeError, KeyError, AssertionError):
         return None
 
@@ -109,13 +110,11 @@
     ovfcheck_lshift is special because there is no preceding operation.
     Instead, it will be replaced by an OP_LSHIFT_OVF operation.
     """
-    from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
-    from pypy.objspace.flow.objspace import implicit_exceptions
-    covf = Constant(ovfcheck)
-    covfls = Constant(ovfcheck_lshift)
+    covf = Constant(rarithmetic.ovfcheck)
+    covfls = Constant(rarithmetic.ovfcheck_lshift)
 
     def check_syntax(opname):
-        exlis = implicit_exceptions.get("%s_ovf" % (opname,), [])
+        exlis = operation.implicit_exceptions.get("%s_ovf" % (opname,), [])
         if OverflowError not in exlis:
             raise Exception("ovfcheck in %s: Operation %s has no"
                             " overflow variant" % (graph.name, opname))
@@ -558,8 +557,7 @@
     #    when for all possible incoming paths they would get twice the same
     #    value (this is really the purpose of remove_identical_vars()).
     #
-    from pypy.translator.backendopt.ssa import DataFlowFamilyBuilder
-    builder = DataFlowFamilyBuilder(graph)
+    builder = ssa.DataFlowFamilyBuilder(graph)
     variable_families = builder.get_variable_families()  # vertical removal
     while True:
         if not builder.merge_identical_phi_nodes():    # horizontal removal
@@ -655,8 +653,7 @@
     # NB. this assumes RPythonicity: we can only iterate over something
     # that has a len(), and this len() cannot change as long as we are
     # using the iterator.
-    from pypy.translator.backendopt.ssa import DataFlowFamilyBuilder
-    builder = DataFlowFamilyBuilder(graph)
+    builder = ssa.DataFlowFamilyBuilder(graph)
     variable_families = builder.get_variable_families()
     c_append = Constant('append')
     newlist_v = {}
@@ -964,7 +961,6 @@
                 link.args[i] = vlist2
 
         # - wherever the list exits the loop body, add a 'hint({fence})'
-        from pypy.translator.unsimplify import insert_empty_block
         for block in loopbody:
             for link in block.exits:
                 if link.target not in loopbody:
@@ -976,7 +972,7 @@
                         link.target in stopblocks):
                         hints['exactlength'] = True
                     chints = Constant(hints)
-                    newblock = insert_empty_block(None, link)
+                    newblock = unsimplify.insert_empty_block(None, link)
                     index = link.args.index(vlist)
                     vlist2 = newblock.inputargs[index]
                     vlist3 = Variable(vlist2)

Modified: pypy/branch/cpython-extension/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/tool/cbuild.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/tool/cbuild.py	Fri Apr 23 02:41:35 2010
@@ -1,17 +1,10 @@
-import os, sys, inspect, re, imp
-
 import py
 
 from pypy.tool.autopath import pypydir
 from pypy.translator.platform import host
-from pypy.tool.ansi_print import ansi_log
 from pypy.tool.udir import udir
 
 
-log = py.log.Producer("cbuild")
-py.log.setconsumer("cbuild", ansi_log)
-
-
 class ExternalCompilationInfo(object):
 
     _ATTRIBUTES = ['pre_include_bits', 'includes', 'include_dirs',

Modified: pypy/branch/cpython-extension/pypy/translator/tool/test/test_cbuild.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/tool/test/test_cbuild.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/tool/test/test_cbuild.py	Fri Apr 23 02:41:35 2010
@@ -1,6 +1,6 @@
-import py, sys
+import py
 
-from pypy.tool.udir import udir 
+from pypy.tool.udir import udir
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from subprocess import Popen, PIPE, STDOUT
 

Modified: pypy/branch/cpython-extension/pypy/translator/translator.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/translator.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/translator.py	Fri Apr 23 02:41:35 2010
@@ -6,9 +6,9 @@
 """
 import autopath, os, sys, types, copy
 
-from pypy.objspace.flow.model import *
 from pypy.translator import simplify
 from pypy.objspace.flow.objspace import FlowObjSpace
+from pypy.objspace.flow.model import FunctionGraph, checkgraph
 from pypy.tool.ansi_print import ansi_log
 from pypy.tool.sourcetools import nice_repr_for_func
 from pypy.config.pypyoption import pypy_optiondescription



More information about the Pypy-commit mailing list