[pypy-commit] pypy const-correctness: hg merge default

amauryfa noreply at buildbot.pypy.org
Fri Sep 13 17:41:58 CEST 2013


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: const-correctness
Changeset: r66937:eb449cec3ef8
Date: 2013-09-13 17:41 +0200
http://bitbucket.org/pypy/pypy/changeset/eb449cec3ef8/

Log:	hg merge default

diff --git a/lib-python/2.7/argparse.py b/lib-python/2.7/argparse.py
--- a/lib-python/2.7/argparse.py
+++ b/lib-python/2.7/argparse.py
@@ -1780,7 +1780,19 @@
             # error if this argument is not allowed with other previously
             # seen arguments, assuming that actions that use the default
             # value don't really count as "present"
-            if argument_values is not action.default:
+
+            # XXX PyPy bug-to-bug compatibility: "is" on primitive types
+            # is not consistent in CPython.  We'll assume it is close
+            # enough for ints (which is true only for "small ints"), but
+            # for floats and longs and complexes we'll go for the option
+            # of forcing "is" to say False, like it usually does on
+            # CPython.  A fix is pending on CPython trunk
+            # (http://bugs.python.org/issue18943) but that might change
+            # the details of the semantics and so not be applied to 2.7.
+            # See the line AA below.
+
+            if (argument_values is not action.default or
+                    type(argument_values) in (float, long, complex)):  # AA
                 seen_non_default_actions.add(action)
                 for conflict_action in action_conflicts.get(action, []):
                     if conflict_action in seen_non_default_actions:
diff --git a/pypy/module/thread/test/test_thread.py b/pypy/module/thread/test/test_thread.py
--- a/pypy/module/thread/test/test_thread.py
+++ b/pypy/module/thread/test/test_thread.py
@@ -187,9 +187,12 @@
             skip("this OS supports too many threads to check (> 1000)")
         lock = thread.allocate_lock()
         lock.acquire()
+        count = [0]
         def f():
+            count[0] += 1
             lock.acquire()
             lock.release()
+            count[0] -= 1
         try:
             try:
                 for i in range(1000):
@@ -197,11 +200,15 @@
             finally:
                 lock.release()
                 # wait a bit to allow most threads to finish now
-                self.busywait(2.0)
+                while count[0] > 10:
+                    print count[0]     # <- releases the GIL
+                print "ok."
         except (thread.error, MemoryError):
             pass
         else:
             raise Exception("could unexpectedly start 1000 threads")
+        # safety: check that we can start a new thread here
+        thread.start_new_thread(lambda: None, ())
 
     def test_stack_size(self):
         import thread
diff --git a/rpython/jit/codewriter/call.py b/rpython/jit/codewriter/call.py
--- a/rpython/jit/codewriter/call.py
+++ b/rpython/jit/codewriter/call.py
@@ -92,17 +92,6 @@
         else:
             assert op.opname == 'indirect_call'
             graphs = op.args[-1].value
-            if graphs is None:
-                # special case: handle the indirect call that goes to
-                # the 'instantiate' methods.  This check is a bit imprecise
-                # but it's not too bad if we mistake a random indirect call
-                # for the one to 'instantiate'.
-                from rpython.rtyper.lltypesystem import rclass
-                CALLTYPE = op.args[0].concretetype
-                if (op.opname == 'indirect_call' and len(op.args) == 2 and
-                    CALLTYPE == rclass.OBJECT_VTABLE.instantiate):
-                    graphs = list(self._graphs_of_all_instantiate())
-            #
             if graphs is not None:
                 result = []
                 for graph in graphs:
@@ -114,11 +103,6 @@
         # residual call case: we don't need to look into any graph
         return None
 
-    def _graphs_of_all_instantiate(self):
-        for vtable in self.rtyper.lltype2vtable.values():
-            if vtable.instantiate:
-                yield vtable.instantiate._obj.graph
-
     def guess_call_kind(self, op, is_candidate=None):
         if op.opname == 'direct_call':
             funcptr = op.args[0].value
diff --git a/rpython/jit/codewriter/effectinfo.py b/rpython/jit/codewriter/effectinfo.py
--- a/rpython/jit/codewriter/effectinfo.py
+++ b/rpython/jit/codewriter/effectinfo.py
@@ -166,9 +166,6 @@
 EffectInfo.MOST_GENERAL = EffectInfo(None, None, None, None,
                                      EffectInfo.EF_RANDOM_EFFECTS,
                                      can_invalidate=True)
-EffectInfo.LEAST_GENERAL = EffectInfo([], [], [], [],
-                                      EffectInfo.EF_ELIDABLE_CANNOT_RAISE,
-                                      can_invalidate=False)
 
 
 def effectinfo_from_writeanalyze(effects, cpu,
diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -1411,7 +1411,6 @@
         self.check_resops(call=2)
 
     def test_merge_guardclass_guardvalue(self):
-        from rpython.rlib.objectmodel import instantiate
         myjitdriver = JitDriver(greens = [], reds = ['x', 'l'])
 
         class A(object):
@@ -1438,7 +1437,6 @@
         self.check_resops(guard_class=0, guard_value=6)
 
     def test_merge_guardnonnull_guardclass(self):
-        from rpython.rlib.objectmodel import instantiate
         myjitdriver = JitDriver(greens = [], reds = ['x', 'l'])
 
         class A(object):
@@ -1468,7 +1466,6 @@
 
 
     def test_merge_guardnonnull_guardvalue(self):
-        from rpython.rlib.objectmodel import instantiate
         myjitdriver = JitDriver(greens = [], reds = ['x', 'l'])
 
         class A(object):
@@ -1497,7 +1494,6 @@
 
 
     def test_merge_guardnonnull_guardvalue_2(self):
-        from rpython.rlib.objectmodel import instantiate
         myjitdriver = JitDriver(greens = [], reds = ['x', 'l'])
 
         class A(object):
@@ -1526,7 +1522,6 @@
 
 
     def test_merge_guardnonnull_guardclass_guardvalue(self):
-        from rpython.rlib.objectmodel import instantiate
         myjitdriver = JitDriver(greens = [], reds = ['x', 'l'])
 
         class A(object):
diff --git a/rpython/rlib/rsre/rpy/__init__.py b/rpython/rlib/rsre/rpy/__init__.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rsre/rpy/__init__.py
@@ -0,0 +1,1 @@
+from ._sre import get_code
diff --git a/rpython/rlib/rsre/rpy.py b/rpython/rlib/rsre/rpy/_sre.py
rename from rpython/rlib/rsre/rpy.py
rename to rpython/rlib/rsre/rpy/_sre.py
--- a/rpython/rlib/rsre/rpy.py
+++ b/rpython/rlib/rsre/rpy/_sre.py
@@ -1,46 +1,24 @@
 
 from rpython.rlib.rsre import rsre_char
-from rpython.rlib.rsre.rsre_core import match
 from rpython.rlib.rarithmetic import intmask
 
-def get_hacked_sre_compile(my_compile):
-    """Return a copy of the sre_compile module for which the _sre
-    module is a custom module that has _sre.compile == my_compile
-    and CODESIZE == rsre_char.CODESIZE.
-    """
-    import sre_compile, sre_constants, __builtin__, new
-    sre_hacked = new.module("_sre_hacked")
-    sre_hacked.compile = my_compile
-    sre_hacked.MAGIC = sre_compile.MAGIC
-    sre_hacked.CODESIZE = rsre_char.CODESIZE
-    sre_hacked.MAXREPEAT = sre_constants.MAX_REPEAT
-    sre_hacked.getlower = rsre_char.getlower
-    def my_import(name, *args):
-        if name == '_sre':
-            return sre_hacked
-        else:
-            return default_import(name, *args)
-    src = sre_compile.__file__
-    if src.lower().endswith('.pyc') or src.lower().endswith('.pyo'):
-        src = src[:-1]
-    mod = new.module("sre_compile_hacked")
-    default_import = __import__
-    try:
-        __builtin__.__import__ = my_import
-        execfile(src, mod.__dict__)
-    finally:
-        __builtin__.__import__ = default_import
-    return mod
+
+MAGIC = 20031017
+CODESIZE = rsre_char.CODESIZE
+getlower = rsre_char.getlower
+
 
 class GotIt(Exception):
     pass
-def my_compile(pattern, flags, code, *args):
+
+def compile(pattern, flags, code, *args):
     raise GotIt([intmask(i) for i in code], flags, args)
-sre_compile_hacked = get_hacked_sre_compile(my_compile)
+
 
 def get_code(regexp, flags=0, allargs=False):
+    from . import sre_compile
     try:
-        sre_compile_hacked.compile(regexp, flags)
+        sre_compile.compile(regexp, flags)
     except GotIt, e:
         pass
     else:
diff --git a/lib-python/2.7/sre_compile.py b/rpython/rlib/rsre/rpy/sre_compile.py
copy from lib-python/2.7/sre_compile.py
copy to rpython/rlib/rsre/rpy/sre_compile.py
--- a/lib-python/2.7/sre_compile.py
+++ b/rpython/rlib/rsre/rpy/sre_compile.py
@@ -8,11 +8,11 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
-"""Internal support module for sre"""
+"""Internal support module for sre (copied from CPython 2.7.3)"""
 
-import _sre, sys
-import sre_parse
-from sre_constants import *
+import sys
+from . import _sre, sre_parse
+from .sre_constants import *
 
 assert _sre.MAGIC == MAGIC, "SRE module mismatch"
 
diff --git a/lib-python/2.7/sre_constants.py b/rpython/rlib/rsre/rpy/sre_constants.py
copy from lib-python/2.7/sre_constants.py
copy to rpython/rlib/rsre/rpy/sre_constants.py
--- a/lib-python/2.7/sre_constants.py
+++ b/rpython/rlib/rsre/rpy/sre_constants.py
@@ -9,7 +9,7 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
-"""Internal support module for sre"""
+"""Internal support module for sre (copied from CPython 2.7.3)"""
 
 # update when constants are added or removed
 
@@ -20,10 +20,8 @@
 MAXREPEAT = 65535
 
 # SRE standard exception (access as sre.error)
-# should this really be here?
-
-class error(Exception):
-    pass
+# (use the real re.error exception class)
+from re import error
 
 # operators
 
diff --git a/lib-python/2.7/sre_parse.py b/rpython/rlib/rsre/rpy/sre_parse.py
copy from lib-python/2.7/sre_parse.py
copy to rpython/rlib/rsre/rpy/sre_parse.py
--- a/lib-python/2.7/sre_parse.py
+++ b/rpython/rlib/rsre/rpy/sre_parse.py
@@ -8,19 +8,13 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
-"""Internal support module for sre"""
+"""Internal support module for sre (copied from CPython 2.7.3)"""
 
 # XXX: show string offset and offending character for all errors
 
 import sys
 
-from sre_constants import *
-
-try:
-    from __pypy__ import newdict
-except ImportError:
-    assert '__pypy__' not in sys.builtin_module_names
-    newdict = lambda _ : {}
+from .sre_constants import *
 
 SPECIAL_CHARS = ".\\[{()*+?^$|"
 REPEAT_CHARS = "*+?{"
@@ -74,7 +68,7 @@
         self.flags = 0
         self.open = []
         self.groups = 1
-        self.groupdict = newdict("module")
+        self.groupdict = {}
     def opengroup(self, name=None):
         gid = self.groups
         self.groups = gid + 1
diff --git a/rpython/rlib/rsre/rsre_re.py b/rpython/rlib/rsre/rsre_re.py
--- a/rpython/rlib/rsre/rsre_re.py
+++ b/rpython/rlib/rsre/rsre_re.py
@@ -286,8 +286,8 @@
 class Scanner:
     # This class is copied directly from re.py.
     def __init__(self, lexicon, flags=0):
-        from sre_constants import BRANCH, SUBPATTERN
-        import sre_parse
+        from rpython.rlib.rsre.rpy.sre_constants import BRANCH, SUBPATTERN
+        from rpython.rlib.rsre.rpy import sre_parse
         self.lexicon = lexicon
         # combine phrases into a compound pattern
         p = []
diff --git a/rpython/rlib/rsre/test/test_char.py b/rpython/rlib/rsre/test/test_char.py
--- a/rpython/rlib/rsre/test/test_char.py
+++ b/rpython/rlib/rsre/test/test_char.py
@@ -48,7 +48,7 @@
     assert not rsre_char.is_uni_word(ord(','))
 
 def test_category():
-    from sre_constants import CHCODES
+    from rpython.rlib.rsre.rpy.sre_constants import CHCODES
     cat = rsre_char.category_dispatch
     #
     assert     cat(CHCODES["category_digit"], ord('1'))
diff --git a/rpython/rtyper/lltypesystem/rpbc.py b/rpython/rtyper/lltypesystem/rpbc.py
--- a/rpython/rtyper/lltypesystem/rpbc.py
+++ b/rpython/rtyper/lltypesystem/rpbc.py
@@ -377,11 +377,20 @@
     # no __init__ here, AbstractClassesPBCRepr.__init__ is good enough
 
     def _instantiate_runtime_class(self, hop, vtypeptr, r_instance):
-        v_instantiate = hop.genop('getfield', [vtypeptr, hop.inputconst(Void, "instantiate")], resulttype=vtypeptr.concretetype.TO.instantiate)
-        possible_graphs = hop.inputconst(Void,
-            [desc.getclassdef(None).my_instantiate_graph for desc in self.s_pbc.descriptions]
-        )
-        v_inst = hop.genop('indirect_call', [v_instantiate, possible_graphs], resulttype=vtypeptr.concretetype.TO.instantiate.TO.RESULT)
+        graphs = []
+        for desc in self.s_pbc.descriptions:
+            classdef = desc.getclassdef(None)
+            assert hasattr(classdef, 'my_instantiate_graph')
+            graphs.append(classdef.my_instantiate_graph)
+        c_graphs = hop.inputconst(Void, graphs)
+        #
+        # "my_instantiate = typeptr.instantiate"
+        c_name = hop.inputconst(Void, 'instantiate')
+        v_instantiate = hop.genop('getfield', [vtypeptr, c_name],
+                                 resulttype = rclass.OBJECT_VTABLE.instantiate)
+        # "my_instantiate()"
+        v_inst = hop.genop('indirect_call', [v_instantiate, c_graphs],
+                           resulttype = rclass.OBJECTPTR)
         return hop.genop('cast_pointer', [v_inst], resulttype=r_instance)
 
     def getlowleveltype(self):
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -705,10 +705,6 @@
     assert isinstance(hop.args_r[0], rclass.InstanceRepr)
     return hop.args_r[0].rtype_isinstance(hop)
 
-def ll_instantiate(typeptr):   # NB. used by rpbc.ClassesPBCRepr as well
-    my_instantiate = typeptr.instantiate
-    return my_instantiate()
-
 def rtype_instantiate(hop):
     hop.exception_cannot_occur()
     s_class = hop.args_s[0]
@@ -716,10 +712,9 @@
     if len(s_class.descriptions) != 1:
         # instantiate() on a variable class
         vtypeptr, = hop.inputargs(rclass.get_type_repr(hop.rtyper))
-        v_inst = hop.gendirectcall(ll_instantiate, vtypeptr)
-        return hop.genop('cast_pointer', [v_inst],    # v_type implicit in r_result
-                         resulttype = hop.r_result.lowleveltype)
-
+        r_class = hop.args_r[0]
+        return r_class._instantiate_runtime_class(hop, vtypeptr,
+                                                  hop.r_result.lowleveltype)
     classdef = s_class.any_description().getuniqueclassdef()
     return rclass.rtype_new_instance(hop.rtyper, classdef, hop.llops)
 
diff --git a/rpython/translator/backendopt/gilanalysis.py b/rpython/translator/backendopt/gilanalysis.py
--- a/rpython/translator/backendopt/gilanalysis.py
+++ b/rpython/translator/backendopt/gilanalysis.py
@@ -26,9 +26,6 @@
             return False
         else:
             return False
-
-    def analyze_instantiate_call(self, seen=None):
-        return False
                 
     def analyze_simple_operation(self, op, graphinfo):
         return False
diff --git a/rpython/translator/backendopt/graphanalyze.py b/rpython/translator/backendopt/graphanalyze.py
--- a/rpython/translator/backendopt/graphanalyze.py
+++ b/rpython/translator/backendopt/graphanalyze.py
@@ -68,9 +68,6 @@
                         result, self.analyze_direct_call(graph, seen))
         return result
 
-    def analyze_instantiate_call(self, seen=None):
-        return self.top_result()
-
     def analyze_link(self, graph, link):
         return self.bottom_result()
 
@@ -79,7 +76,7 @@
     def compute_graph_info(self, graph):
         return None
 
-    def analyze(self, op, seen=None, graphinfo=None, block=None):
+    def analyze(self, op, seen=None, graphinfo=None):
         if op.opname == "direct_call":
             graph = get_graph(op.args[0], self.translator)
             if graph is None:
@@ -94,18 +91,6 @@
         elif op.opname == "indirect_call":
             graphs = op.args[-1].value
             if graphs is None:
-                if block is not None:
-                    v_func = op.args[0]
-                    for op1 in block.operations:
-                        if (v_func is op1.result and
-                            op1.opname == 'getfield' and
-                            op1.args[0].concretetype == rclass.CLASSTYPE and
-                            op1.args[1].value == 'instantiate'):
-                            x = self.analyze_instantiate_call(seen)
-                            if self.verbose and x:
-                                self.dump_info('analyze_instantiate(%s): %r' % (
-                                    graphs, x))
-                            return x
                 if self.verbose:
                     self.dump_info('%s to unknown' % (op,))
                 return self.top_result()
@@ -143,7 +128,7 @@
                 for op in block.operations:
                     result = self.add_to_result(
                         result,
-                        self.analyze(op, seen, graphinfo, block=block)
+                        self.analyze(op, seen, graphinfo)
                     )
                     if self.is_top_result(result):
                         break
@@ -177,7 +162,7 @@
             graphs = self.translator.graphs
         for graph in graphs:
             for block, op in graph.iterblockops():
-                self.analyze(op, block=block)
+                self.analyze(op)
 
 
 class Dependency(object):
diff --git a/rpython/translator/backendopt/test/test_writeanalyze.py b/rpython/translator/backendopt/test/test_writeanalyze.py
--- a/rpython/translator/backendopt/test/test_writeanalyze.py
+++ b/rpython/translator/backendopt/test/test_writeanalyze.py
@@ -169,8 +169,6 @@
         assert not wa.analyze(op_call_m)
 
     def test_instantiate(self):
-        # instantiate is interesting, because it leads to one of the few cases of
-        # an indirect call without a list of graphs
         from rpython.rlib.objectmodel import instantiate
         class A:
             pass
@@ -187,7 +185,7 @@
         t, wa = self.translate(f, [int])
         fgraph = graphof(t, f)
         result = wa.analyze(fgraph.startblock.operations[0])
-        assert result is top_set
+        assert not result
 
     def test_llexternal(self):
         from rpython.rtyper.lltypesystem.rffi import llexternal


More information about the pypy-commit mailing list