[pypy-commit] pypy py3k: Merge default

amauryfa noreply at buildbot.pypy.org
Wed Oct 19 23:11:18 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48243:e6393bbc25cf
Date: 2011-10-19 22:50 +0200
http://bitbucket.org/pypy/pypy/changeset/e6393bbc25cf/

Log:	Merge default

diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -106,10 +106,9 @@
             self.make_equal_to(op.result, v1)
         else:
             self.emit_operation(op)
-
-        # Synthesize the reverse ops for optimize_default to reuse
-        self.pure(rop.INT_ADD, [op.result, op.getarg(1)], op.getarg(0))
-        self.pure(rop.INT_SUB, [op.getarg(0), op.result], op.getarg(1))
+            # Synthesize the reverse ops for optimize_default to reuse
+            self.pure(rop.INT_ADD, [op.result, op.getarg(1)], op.getarg(0))
+            self.pure(rop.INT_SUB, [op.getarg(0), op.result], op.getarg(1))
 
     def optimize_INT_ADD(self, op):
         v1 = self.getvalue(op.getarg(0))
@@ -122,10 +121,9 @@
             self.make_equal_to(op.result, v1)
         else:
             self.emit_operation(op)
-
-        # Synthesize the reverse op for optimize_default to reuse
-        self.pure(rop.INT_SUB, [op.result, op.getarg(1)], op.getarg(0))
-        self.pure(rop.INT_SUB, [op.result, op.getarg(0)], op.getarg(1))
+            # Synthesize the reverse op for optimize_default to reuse
+            self.pure(rop.INT_SUB, [op.result, op.getarg(1)], op.getarg(0))
+            self.pure(rop.INT_SUB, [op.result, op.getarg(0)], op.getarg(1))
 
     def optimize_INT_MUL(self, op):
         v1 = self.getvalue(op.getarg(0))
@@ -141,13 +139,13 @@
             self.make_constant_int(op.result, 0)
         else:
             for lhs, rhs in [(v1, v2), (v2, v1)]:
-                # x & (x -1) == 0 is a quick test for power of 2
-                if (lhs.is_constant() and
-                    (lhs.box.getint() & (lhs.box.getint() - 1)) == 0):
-                    new_rhs = ConstInt(highest_bit(lhs.box.getint()))
-                    op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs])
-                    break
-
+                if lhs.is_constant():
+                    x = lhs.box.getint()
+                    # x & (x - 1) == 0 is a quick test for power of 2
+                    if x & (x - 1) == 0:
+                        new_rhs = ConstInt(highest_bit(lhs.box.getint()))
+                        op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs])
+                        break
             self.emit_operation(op)
 
     def optimize_UINT_FLOORDIV(self, op):
@@ -462,6 +460,14 @@
         self.optimizer.opaque_pointers[value] = True
         self.make_equal_to(op.result, value)
 
+    def optimize_CAST_PTR_TO_INT(self, op):
+        self.pure(rop.CAST_INT_TO_PTR, [op.result], op.getarg(0))
+        self.emit_operation(op)
+
+    def optimize_CAST_INT_TO_PTR(self, op):
+        self.pure(rop.CAST_PTR_TO_INT, [op.result], op.getarg(0))
+        self.emit_operation(op)
+
 dispatch_opt = make_dispatcher_method(OptRewrite, 'optimize_',
         default=OptRewrite.emit_operation)
 optimize_guards = _findall(OptRewrite, 'optimize_', 'GUARD')
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -234,6 +234,30 @@
             """ % expected_value
             self.optimize_loop(ops, expected)
 
+    def test_reverse_of_cast(self):
+        ops = """
+        [i0]
+        p0 = cast_int_to_ptr(i0)
+        i1 = cast_ptr_to_int(p0)
+        jump(i1)
+        """
+        expected = """
+        [i0]
+        jump(i0)
+        """
+        self.optimize_loop(ops, expected)
+        ops = """
+        [p0]
+        i1 = cast_ptr_to_int(p0)
+        p1 = cast_int_to_ptr(i1)
+        jump(p1)
+        """
+        expected = """
+        [p0]
+        jump(p0)
+        """
+        self.optimize_loop(ops, expected)
+
     # ----------
 
     def test_remove_guard_class_1(self):
diff --git a/pypy/jit/metainterp/quasiimmut.py b/pypy/jit/metainterp/quasiimmut.py
--- a/pypy/jit/metainterp/quasiimmut.py
+++ b/pypy/jit/metainterp/quasiimmut.py
@@ -74,12 +74,10 @@
         self.looptokens_wrefs.append(wref_looptoken)
 
     def compress_looptokens_list(self):
-        newlist = []
-        for wref in self.looptokens_wrefs:
-            looptoken = wref()
-            if looptoken is not None and not looptoken.invalidated:
-                newlist.append(wref)
-        self.looptokens_wrefs = newlist
+        self.looptokens_wrefs = [wref for wref in self.looptokens_wrefs
+                                      if wref() is not None]
+        # NB. we must keep around the looptoken_wrefs that are
+        # already invalidated; see below
         self.compress_limit = (len(self.looptokens_wrefs) + 15) * 2
 
     def invalidate(self):
@@ -90,9 +88,14 @@
         self.looptokens_wrefs = []
         for wref in wrefs:
             looptoken = wref()
-            if looptoken is not None and not looptoken.invalidated:
+            if looptoken is not None:
                 looptoken.invalidated = True
                 self.cpu.invalidate_loop(looptoken)
+                # NB. we must call cpu.invalidate_loop() even if
+                # looptoken.invalidated was already set to True.
+                # It's possible to invalidate several times the
+                # same looptoken; see comments in jit.backend.model
+                # in invalidate_loop().
                 if not we_are_translated():
                     self.cpu.stats.invalidated_token_numbers.add(
                         looptoken.number)
diff --git a/pypy/module/pyexpat/__init__.py b/pypy/module/pyexpat/__init__.py
--- a/pypy/module/pyexpat/__init__.py
+++ b/pypy/module/pyexpat/__init__.py
@@ -4,12 +4,8 @@
 
 class ErrorsModule(MixedModule):
     "Definition of pyexpat.errors module."
-
-    appleveldefs = {
-        }
-
-    interpleveldefs = {
-        }
+    appleveldefs = {}
+    interpleveldefs = {}
 
     def setup_after_space_initialization(self):
         from pypy.module.pyexpat import interp_pyexpat
@@ -18,6 +14,18 @@
                     interp_pyexpat.ErrorString(self.space,
                     getattr(interp_pyexpat, name)))
 
+class ModelModule(MixedModule):
+    "Definition of pyexpat.model module."
+    appleveldefs = {}
+    interpleveldefs = {}
+
+    def setup_after_space_initialization(self):
+        from pypy.module.pyexpat import interp_pyexpat
+        space = self.space
+        for name in interp_pyexpat.xml_model_list:
+            value = getattr(interp_pyexpat, name)
+            space.setattr(self, space.wrap(name), space.wrap(value))
+
 class Module(MixedModule):
     "Python wrapper for Expat parser."
 
@@ -39,6 +47,7 @@
 
     submodules = {
         'errors': ErrorsModule,
+        'model':  ModelModule,
     }
 
     for name in ['XML_PARAM_ENTITY_PARSING_NEVER',
diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -76,6 +76,18 @@
     "XML_ERROR_FINISHED",
     "XML_ERROR_SUSPEND_PE",
     ]
+xml_model_list = [
+    "XML_CTYPE_EMPTY",
+    "XML_CTYPE_ANY",
+    "XML_CTYPE_MIXED",
+    "XML_CTYPE_NAME",
+    "XML_CTYPE_CHOICE",
+    "XML_CTYPE_SEQ",
+    "XML_CQUANT_NONE",
+    "XML_CQUANT_OPT",
+    "XML_CQUANT_REP",
+    "XML_CQUANT_PLUS",
+    ]
 
 class CConfigure:
     _compilation_info_ = eci
@@ -104,6 +116,8 @@
 
     for name in xml_error_list:
         locals()[name] = rffi_platform.ConstantInteger(name)
+    for name in xml_model_list:
+        locals()[name] = rffi_platform.ConstantInteger(name)
 
 for k, v in rffi_platform.configure(CConfigure).items():
     globals()[k] = v
diff --git a/pypy/module/pyexpat/test/test_parser.py b/pypy/module/pyexpat/test/test_parser.py
--- a/pypy/module/pyexpat/test/test_parser.py
+++ b/pypy/module/pyexpat/test/test_parser.py
@@ -131,3 +131,7 @@
                'encoding specified in XML declaration is incorrect')
         assert (pyexpat.errors.XML_ERROR_XML_DECL ==
                 'XML declaration not well-formed')
+
+    def test_model(self):
+        import pyexpat
+        assert isinstance(pyexpat.model.XML_CTYPE_EMPTY, int)
diff --git a/pypy/objspace/std/strutil.py b/pypy/objspace/std/strutil.py
--- a/pypy/objspace/std/strutil.py
+++ b/pypy/objspace/std/strutil.py
@@ -35,7 +35,7 @@
 
     def error(self):
         raise ParseStringError("invalid literal for %s() with base %d: '%s'" %
-                               (self.fname, self.base, self.literal))
+                               (self.fname, self.original_base, self.literal))
 
     def __init__(self, s, literal, base, fname):
         self.literal = literal
@@ -47,7 +47,8 @@
         elif s.startswith('+'):
             s = strip_spaces(s[1:])
         self.sign = sign
-        
+        self.original_base = base
+
         if base == 0:
             if s.startswith('0x') or s.startswith('0X'):
                 base = 16
diff --git a/pypy/objspace/std/test/test_strutil.py b/pypy/objspace/std/test/test_strutil.py
--- a/pypy/objspace/std/test/test_strutil.py
+++ b/pypy/objspace/std/test/test_strutil.py
@@ -89,6 +89,8 @@
 
         exc = raises(ParseStringError, string_to_int, '')
         assert exc.value.msg == "invalid literal for int() with base 10: ''"
+        exc = raises(ParseStringError, string_to_int, '', 0)
+        assert exc.value.msg == "invalid literal for int() with base 0: ''"
 
     def test_string_to_int_overflow(self):
         import sys
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -8,6 +8,8 @@
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.tool.sourcetools import func_with_new_name
 
+DEBUG_ELIDABLE_FUNCTIONS = False
+
 
 def elidable(func):
     """ Decorate a function as "trace-elidable". This means precisely that:
@@ -24,6 +26,18 @@
     If a particular call to this function ends up raising an exception, then it
     is handled like a normal function call (this decorator is ignored).
     """
+    if DEBUG_ELIDABLE_FUNCTIONS:
+        cache = {}
+        oldfunc = func
+        def func(*args):
+            result = oldfunc(*args)    # if it raises, no caching
+            try:
+                oldresult = cache.setdefault(args, result)
+            except TypeError:
+                pass           # unhashable args
+            else:
+                assert oldresult == result
+            return result
     func._elidable_function_ = True
     return func
 
diff --git a/pypy/rpython/memory/gc/minimark.py b/pypy/rpython/memory/gc/minimark.py
--- a/pypy/rpython/memory/gc/minimark.py
+++ b/pypy/rpython/memory/gc/minimark.py
@@ -1292,10 +1292,12 @@
         # if a prebuilt GcStruct contains a pointer to a young object,
         # then the write_barrier must have ensured that the prebuilt
         # GcStruct is in the list self.old_objects_pointing_to_young.
+        debug_start("gc-minor-walkroots")
         self.root_walker.walk_roots(
             MiniMarkGC._trace_drag_out1,  # stack roots
             MiniMarkGC._trace_drag_out1,  # static in prebuilt non-gc
             None)                         # static in prebuilt gc
+        debug_stop("gc-minor-walkroots")
 
     def collect_cardrefs_to_nursery(self):
         size_gc_header = self.gcheaderbuilder.size_gc_header
diff --git a/pypy/tool/release/package.py b/pypy/tool/release/package.py
--- a/pypy/tool/release/package.py
+++ b/pypy/tool/release/package.py
@@ -56,8 +56,8 @@
     binaries = [(pypy_c, rename_pypy_c)]
     #
     if sys.platform == 'win32':
-        # Can't rename a DLL: it is always called 'libpypy_c.dll'
-        for extra in ['libpypy_c.dll',
+        # Can't rename a DLL: it is always called 'libpypy-c.dll'
+        for extra in ['libpypy-c.dll',
                       'libexpat.dll', 'sqlite3.dll', 'msvcr90.dll']:
             p = pypy_c.dirpath().join(extra)
             if not p.check():
diff --git a/pypy/translator/platform/posix.py b/pypy/translator/platform/posix.py
--- a/pypy/translator/platform/posix.py
+++ b/pypy/translator/platform/posix.py
@@ -157,7 +157,7 @@
 
         rules = [
             ('all', '$(DEFAULT_TARGET)', []),
-            ('$(TARGET)', '$(OBJECTS)', '$(CC_LINK) $(LDFLAGS) $(LDFLAGSEXTRA) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) $(LINKFILES)'),
+            ('$(TARGET)', '$(OBJECTS)', '$(CC_LINK) $(LDFLAGSEXTRA) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) $(LINKFILES) $(LDFLAGS)'),
             ('%.o', '%.c', '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'),
             ]
 


More information about the pypy-commit mailing list