[pypy-commit] pypy default: merge

fijal noreply at buildbot.pypy.org
Tue Aug 11 16:57:01 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r78916:af4f9dce75b8
Date: 2015-08-11 16:56 +0200
http://bitbucket.org/pypy/pypy/changeset/af4f9dce75b8/

Log:	merge

diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -416,6 +416,9 @@
     arg_driver = jit.JitDriver(name='numpy_' + op_name,
                                greens = ['shapelen', 'dtype'],
                                reds = 'auto')
+    arg_flat_driver = jit.JitDriver(name='numpy_flat_' + op_name,
+                                    greens = ['shapelen', 'dtype'],
+                                    reds = 'auto')
 
     def argmin_argmax(space, w_arr, w_out, axis):
         from pypy.module.micronumpy.descriptor import get_dtype_cache
@@ -457,7 +460,7 @@
         state = iter.next(state)
         shapelen = len(w_arr.get_shape())
         while not iter.done(state):
-            arg_driver.jit_merge_point(shapelen=shapelen, dtype=dtype)
+            arg_flat_driver.jit_merge_point(shapelen=shapelen, dtype=dtype)
             w_val = iter.getitem(state)
             new_best = getattr(dtype.itemtype, op_name)(cur_best, w_val)
             if dtype.itemtype.ne(new_best, cur_best):
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -425,8 +425,9 @@
 class __extend__(pairtype(SomeString, SomeObject),
                  pairtype(SomeUnicodeString, SomeObject)):
 
-    def mod((s_string, args)):
-        return s_string.__class__()
+    def mod((s_string, s_arg)):
+        assert not isinstance(s_arg, SomeTuple)
+        return pair(s_string, SomeTuple([s_arg])).mod()
 
 class __extend__(pairtype(SomeFloat, SomeFloat)):
 
diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -2124,6 +2124,16 @@
         assert isinstance(s, annmodel.SomeString)
         assert s.no_nul
 
+    def test_no_nul_mod(self):
+        def f(x):
+            s = "%d" % x
+            return s
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int])
+        assert isinstance(s, annmodel.SomeString)
+        assert s.no_nul
+
+
     def test_mul_str0(self):
         def f(s):
             return s*10
diff --git a/rpython/jit/codewriter/support.py b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -79,6 +79,9 @@
             assert methname == 'jit_merge_point', (
                 "reds='auto' is supported only for jit drivers which "
                 "calls only jit_merge_point. Found a call to %s" % methname)
+            if jitdriver.numreds is not None:
+                raise AssertionError("there are multiple jit_merge_points "
+                                     "with the same jitdriver")
             #
             # compute the set of live variables across the jit_marker
             alive_v = set()
@@ -96,10 +99,7 @@
                                            v.concretetype is not lltype.Void]
             reds_v = sort_vars(reds_v)
             op.args.extend(reds_v)
-            if jitdriver.numreds is None:
-                jitdriver.numreds = len(reds_v)
-            else:
-                assert jitdriver.numreds == len(reds_v), 'inconsistent number of reds_v'
+            jitdriver.numreds = len(reds_v)
 
 def split_before_jit_merge_point(graph, portalblock, portalopindex):
     """Split the block just before the 'jit_merge_point',
diff --git a/rpython/jit/metainterp/test/test_warmspot.py b/rpython/jit/metainterp/test/test_warmspot.py
--- a/rpython/jit/metainterp/test/test_warmspot.py
+++ b/rpython/jit/metainterp/test/test_warmspot.py
@@ -558,6 +558,22 @@
         assert res == 7 - 3
         self.check_trace_count(2)
 
+    def test_jitdriver_single_jit_merge_point(self):
+        jitdriver = JitDriver(greens=[], reds='auto')
+        def g1(n):
+            jitdriver.jit_merge_point()
+            return n
+        def g2():
+            jitdriver.jit_merge_point()
+        def f(n):
+            if n:
+                g1(n)
+            else:
+                g2()
+        e = py.test.raises(AssertionError, self.meta_interp, f, [42])
+        assert str(e.value) == ("there are multiple jit_merge_points "
+                                "with the same jitdriver")
+
 
 class TestLLWarmspot(WarmspotTests, LLJitMixin):
     CPUClass = runner.LLGraphCPU
diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -442,19 +442,26 @@
             eci = ExternalCompilationInfo(includes=['string.h', 'assert.h',
                                                     'sys/prctl.h'],
                                           post_include_bits=["""
+/* If we have an old Linux kernel (or compile with old system headers),
+   the following two macros are not defined.  But we would still like
+   a pypy translated on such a system to run on a more modern system. */
+#ifndef PR_SET_PTRACER
+#  define PR_SET_PTRACER 0x59616d61
+#endif
+#ifndef PR_SET_PTRACER_ANY
+#  define PR_SET_PTRACER_ANY ((unsigned long)-1)
+#endif
 static void pypy__allow_attach(void) {
     prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
-    return;
 }
 """])
+            allow_attach = rffi.llexternal(
+                "pypy__allow_attach", [], lltype.Void,
+                compilation_info=eci, _nowrapper=True)
         else:
             # Do nothing, there's no prctl
-            eci = ExternalCompilationInfo(post_include_bits=[
-                "static void pypy__allow_attach(void) { return; }"])
-
-        allow_attach = rffi.llexternal(
-            "pypy__allow_attach", [], lltype.Void,
-            compilation_info=eci, _nowrapper=True)
+            def allow_attach():
+                pass
 
         def impl_attach_gdb():
             import os
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -806,10 +806,14 @@
     flatten = {}
     caller = sys._getframe(1)
     caller_name = caller.f_globals.get('__name__')
+    immutable_fields = []
     for base in inspect.getmro(M):
         if base is object:
             continue
         for key, value in base.__dict__.items():
+            if key == '_immutable_fields_':
+                immutable_fields.extend(value)
+                continue
             if key.startswith('__') and key.endswith('__'):
                 if key not in special_methods:
                     continue
@@ -835,4 +839,9 @@
         if key in target:
             raise Exception("import_from_mixin: would overwrite the value "
                             "already defined locally for %r" % (key,))
+        if key == '_mixin_':
+            raise Exception("import_from_mixin(M): class M should not "
+                            "have '_mixin_ = True'")
         target[key] = value
+    if immutable_fields:
+        target['_immutable_fields_'] = target.get('_immutable_fields_', []) + immutable_fields
diff --git a/rpython/rlib/test/test_objectmodel.py b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -675,3 +675,44 @@
         import_from_mixin(M)
     assert A.f is not M.f
     assert A.f.__module__ != M.f.__module__
+
+
+def test_import_from_mixin_immutable_fields():
+    class A(object):
+        _immutable_fields_ = ['a']
+
+    class B(object):
+        _immutable_fields_ = ['b']
+        import_from_mixin(A)
+
+    assert B._immutable_fields_ == ['b', 'a']
+    assert A._immutable_fields_ == ['a']
+
+
+    class B(object):
+        import_from_mixin(A)
+
+    assert B._immutable_fields_ == ['a']
+
+    class C(A):
+        _immutable_fields_ = ['c']
+
+
+    class B(object):
+        import_from_mixin(C)
+
+    assert B._immutable_fields_ == ['c', 'a']
+
+    class B(object):
+        _immutable_fields_ = ['b']
+        import_from_mixin(C)
+
+    assert B._immutable_fields_ == ['b', 'c', 'a']
+
+
+    class B(object):
+        _immutable_fields_ = ['b']
+    class BA(B):
+        import_from_mixin(C)
+
+    assert BA._immutable_fields_ == ['c', 'a']


More information about the pypy-commit mailing list