[pypy-commit] pypy refactor-str-types: hg merge default

Manuel Jacob noreply at buildbot.pypy.org
Wed Aug 21 03:09:21 CEST 2013


Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r66273:13bf2a4c394b
Date: 2013-08-21 03:08 +0200
http://bitbucket.org/pypy/pypy/changeset/13bf2a4c394b/

Log:	hg merge default

diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst
--- a/pypy/doc/coding-guide.rst
+++ b/pypy/doc/coding-guide.rst
@@ -339,9 +339,10 @@
 
 + methods and other class attributes do not change after startup
 + single inheritance is fully supported
-+ simple mixins somewhat work too, but the mixed in class needs a
-  ``_mixin_ = True`` class attribute. isinstance checks against the
-  mixin type will fail when translated.
++ use `rpython.rlib.objectmodel.import_from_mixin(M)` in a class
+  body to copy the whole content of a class `M`.  This can be used
+  to implement mixins: functions and staticmethods are duplicated
+  (the other class attributes are just copied unmodified).
 
 + classes are first-class objects too
 
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -257,6 +257,7 @@
 
     def test_rint(self):
         from numpypy import array, complex, rint, isnan
+        import sys
 
         nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf')
 
@@ -271,6 +272,8 @@
         assert rint(complex(inf, 1.5)) == complex(inf, 2.)
         assert rint(complex(0.5, inf)) == complex(0., inf)
 
+        assert rint(sys.maxint) == sys.maxint
+
     def test_sign(self):
         from numpypy import array, sign, dtype
 
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -309,8 +309,8 @@
 
     @simple_unary_op
     def rint(self, v):
-        if isfinite(v):
-            return rfloat.round_double(v, 0, half_even=True)
+        if isfinite(float(v)):
+            return rfloat.round_double(float(v), 0, half_even=True)
         else:
             return v
 
diff --git a/pypy/tool/gcdump.py b/pypy/tool/gcdump.py
--- a/pypy/tool/gcdump.py
+++ b/pypy/tool/gcdump.py
@@ -29,6 +29,8 @@
         for num, line in enumerate(iter):
             if num == 0:
                 continue
+            if not line:
+                continue
             words = line.split()
             if words[0].startswith('member'):
                 del words[0]
diff --git a/rpython/rlib/rsre/rsre_char.py b/rpython/rlib/rsre/rsre_char.py
--- a/rpython/rlib/rsre/rsre_char.py
+++ b/rpython/rlib/rsre/rsre_char.py
@@ -115,7 +115,10 @@
     for function, negate in category_dispatch_unroll:
         if category_code == i:
             result = function(char_code)
-            return result ^ negate
+            if negate:
+                return not result # XXX this might lead to a guard
+            else:
+                return result
         i = i + 1
     else:
         return False
@@ -157,7 +160,9 @@
                 ppos += 1
             else:
                 return False
-    return result ^ negated
+    if negated:
+        return not result
+    return result
 
 def set_literal(pat, index, char_code):
     # <LITERAL> <code>
@@ -187,39 +192,39 @@
 
 def set_bigcharset(pat, index, char_code):
     # <BIGCHARSET> <blockcount> <256 blockindices> <blocks>
-    # XXX this function needs a makeover, it's very bad
     count = pat[index+1]
     index += 2
-    if char_code < 65536:
-        block_index = char_code >> 8
-        # NB: there are CODESIZE block indices per bytecode
-        a = to_byte_array(pat[index+(block_index / CODESIZE)])
-        block = a[block_index % CODESIZE]
-        index += 256 / CODESIZE  # skip block indices
-        if CODESIZE == 2:
-            shift = 4
-        else:
-            shift = 5
-        block_value = pat[index+(block * (32 / CODESIZE)
-                                 + ((char_code & 255) >> shift))]
-        match = (block_value & (1 << (char_code & ((8 * CODESIZE) - 1)))) != 0
+
+    if CODESIZE == 2:
+        # One bytecode is 2 bytes, so contains 2 of the blockindices.
+        # So the 256 blockindices are packed in 128 bytecodes, but
+        # we need to unpack it as a byte.
+        assert char_code < 65536
+        shift = 4
     else:
-        index += 256 / CODESIZE  # skip block indices
-        match = False
+        # One bytecode is 4 bytes, so contains 4 of the blockindices.
+        # So the 256 blockindices are packed in 64 bytecodes, but
+        # we need to unpack it as a byte.
+        if char_code >= 65536:
+            index += 256 / CODESIZE + count * (32 / CODESIZE)
+            return False, index
+        shift = 5
+
+    block = pat[index + (char_code >> (shift + 5))]
+
+    block_shift = char_code >> 5
+    if BIG_ENDIAN:
+        block_shift = ~block_shift
+    block_shift &= (CODESIZE - 1) * 8
+    block = (block >> block_shift) & 0xFF
+
+    index += 256 / CODESIZE
+    block_value = pat[index+(block * (32 / CODESIZE)
+                             + ((char_code & 255) >> shift))]
+    match = (block_value & (1 << (char_code & ((8 * CODESIZE) - 1))))
     index += count * (32 / CODESIZE)  # skip blocks
     return match, index
 
-def to_byte_array(int_value):
-    """Creates a list of bytes out of an integer representing data that is
-    CODESIZE bytes wide."""
-    byte_array = [0] * CODESIZE
-    for i in range(CODESIZE):
-        byte_array[i] = int_value & 0xff
-        int_value = int_value >> 8
-    if BIG_ENDIAN:
-        byte_array.reverse()
-    return byte_array
-
 set_dispatch_table = [
     None, # FAILURE
     None, None, None, None, None, None, None, None,
diff --git a/rpython/rlib/rsre/test/test_match.py b/rpython/rlib/rsre/test/test_match.py
--- a/rpython/rlib/rsre/test/test_match.py
+++ b/rpython/rlib/rsre/test/test_match.py
@@ -1,4 +1,4 @@
-import re
+import re, random
 from rpython.rlib.rsre import rsre_core
 from rpython.rlib.rsre.rpy import get_code
 
@@ -241,3 +241,19 @@
     def test_match_bug3(self):
         r = get_code(r'([ax]*?x*)?$')
         assert rsre_core.match(r, "aaxaa")
+
+    def test_bigcharset(self):
+        for i in range(100):
+            chars = [unichr(random.randrange(0x100, 0xD000))
+                         for n in range(random.randrange(1, 25))]
+            pattern = u'[%s]' % (u''.join(chars),)
+            r = get_code(pattern)
+            for c in chars:
+                assert rsre_core.match(r, c)
+            for i in range(200):
+                c = unichr(random.randrange(0x0, 0xD000))
+                res = rsre_core.match(r, c)
+                if c in chars:
+                    assert res is not None
+                else:
+                    assert res is None


More information about the pypy-commit mailing list