Commits

David Schneider  committed babd02f Merge

merge default

  • Participants
  • Parent commits 3388232, 63c4e73
  • Branches arm-backend-2

Comments (0)

Files changed (8)

File pypy/doc/whatsnew-head.rst

 .. branch: better-enforceargs
 .. branch: rpython-unicode-formatting
 .. branch: jit-opaque-licm
+.. branch: rpython-utf8
+Support for utf-8 encoding in RPython

File pypy/module/_cffi_backend/__init__.py

         'offsetof': 'func.offsetof',
         '_getfields': 'func._getfields',
         'getcname': 'func.getcname',
+        '_get_types': 'func._get_types',
 
         'string': 'func.string',
         'buffer': 'cbuffer.buffer',

File pypy/module/_cffi_backend/func.py

 @unwrap_spec(cdata=cdataobj.W_CData, maxlen=int)
 def string(space, cdata, maxlen=-1):
     return cdata.ctype.string(cdata, maxlen)
+
+# ____________________________________________________________
+
+def _get_types(space):
+    return space.newtuple([space.gettypefor(cdataobj.W_CData),
+                           space.gettypefor(ctypeobj.W_CType)])

File pypy/module/_cffi_backend/newtype.py

     if is_union:
         assert offset == 0
         offset = maxsize
-    offset = (offset + alignment - 1) & ~(alignment-1)
 
     # Like C, if the size of this structure would be zero, we compute it
     # as 1 instead.  But for ctypes support, we allow the manually-
     # specified totalsize to be zero in this case.
     if totalsize < 0:
+        offset = (offset + alignment - 1) & ~(alignment-1)
         totalsize = offset or 1
     elif totalsize < offset:
         raise operationerrfmt(space.w_TypeError,

File pypy/module/_cffi_backend/test/_backend_test_c.py

     mandatory_b_prefix = 'b'
     mandatory_u_prefix = ''
     readbuf = lambda buf: buf.tobytes()
-    bufchar = ord
+    if sys.version_info < (3, 3):
+        bufchar = lambda x: bytes([ord(x)])
+    else:
+        bufchar = ord
     bytechr = lambda n: bytes([n])
     u = ""
 
                                        ('j', BInt, -1)])
     BFunc21 = new_function_type((BStruct,), BInt, False)
     f = cast(BFunc21, _testfunc(21))
-    res = f(range(13, 3, -1))
+    res = f(list(range(13, 3, -1)))
     lst = [(n << i) for (i, n) in enumerate(range(13, 3, -1))]
     assert res == sum(lst)
 
                                        ('i', BInt, -1),
                                        ('j', BInt, -1)])
     def cb():
-        return newp(BStructPtr, range(13, 3, -1))[0]
+        return newp(BStructPtr, list(range(13, 3, -1)))[0]
     BFunc = new_function_type((), BStruct)
     f = callback(BFunc, cb)
     s = f()
     c[2] = b'-'
     buf[:2] = b'HI'
     assert string(c) == b'HI-there'
-    assert buf[:4:2] == b'H-'
-    if '__pypy__' not in sys.builtin_module_names:
-        # XXX pypy doesn't support the following assignment so far
-        buf[:4:2] = b'XY'
-        assert string(c) == b'XIYthere'
+    if sys.version_info < (3,) or sys.version_info >= (3, 3):
+        assert buf[:4:2] == b'H-'
+        if '__pypy__' not in sys.builtin_module_names:
+            # XXX pypy doesn't support the following assignment so far
+            buf[:4:2] = b'XY'
+            assert string(c) == b'XIYthere'
 
 def test_getcname():
     BUChar = new_primitive_type("unsigned char")
                                       ('i', BShort)])
     assert sizeof(BUnion) == 4
     assert alignof(BUnion) == 2
+
+def test_unaligned_struct():
+    BInt = new_primitive_type("int")
+    BStruct = new_struct_type("foo")
+    complete_struct_or_union(BStruct, [('b', BInt, -1, 1)],
+                             None, 5, 1)
+
+def test_CData_CType():
+    CData, CType = _get_types()
+    BChar = new_primitive_type("char")
+    BCharP = new_pointer_type(BChar)
+    nullchr = cast(BChar, 0)
+    chrref = newp(BCharP, None)
+    assert isinstance(nullchr, CData)
+    assert isinstance(chrref, CData)
+    assert not isinstance(BChar, CData)
+    assert not isinstance(nullchr, CType)
+    assert not isinstance(chrref, CType)
+    assert isinstance(BChar, CType)

File pypy/module/_sre/interp_sre.py

         if last_pos < ctx.end:
             sublist_w.append(slice_w(space, ctx, last_pos, ctx.end,
                                      space.w_None))
-        if n == 0:
-            # not just an optimization -- see test_sub_unicode
-            return w_string, n
 
         if space.is_true(space.isinstance(w_string, space.w_unicode)):
             w_emptystr = space.wrap(u'')

File pypy/module/_sre/test/test_app_sre.py

             return ''
         assert (u"bb\u3039b", 2) == re.subn("[aA]", call_me, "babAb")
 
+    def test_sub_subclass_of_str(self):
+        import re
+        class MyString(str):
+            pass
+        class MyUnicode(unicode):
+            pass
+        s1 = MyString('zz')
+        s2 = re.sub('aa', 'bb', s1)
+        assert s2 == s1
+        assert type(s2) is str       # and not MyString
+        s2 = re.sub(u'aa', u'bb', s1)
+        assert s2 == s1
+        assert type(s2) is str       # and not MyString
+        u1 = MyUnicode(u'zz')
+        u2 = re.sub(u'aa', u'bb', u1)
+        assert u2 == u1
+        assert type(u2) is unicode   # and not MyUnicode
+
     def test_match_array(self):
         import re, array
         a = array.array('c', 'hello')

File pypy/translator/platform/linux.py

File contents unchanged.