Author: David Schneider <david.schnei...@picle.org> Branch: arm-backend-2 Changeset: r57144:babd02f339ec Date: 2012-09-05 13:26 +0200 http://bitbucket.org/pypy/pypy/changeset/babd02f339ec/
Log: merge default diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -35,3 +35,5 @@ .. branch: better-enforceargs .. branch: rpython-unicode-formatting .. branch: jit-opaque-licm +.. branch: rpython-utf8 +Support for utf-8 encoding in RPython diff --git a/pypy/module/_cffi_backend/__init__.py b/pypy/module/_cffi_backend/__init__.py --- a/pypy/module/_cffi_backend/__init__.py +++ b/pypy/module/_cffi_backend/__init__.py @@ -30,6 +30,7 @@ 'offsetof': 'func.offsetof', '_getfields': 'func._getfields', 'getcname': 'func.getcname', + '_get_types': 'func._get_types', 'string': 'func.string', 'buffer': 'cbuffer.buffer', diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py --- a/pypy/module/_cffi_backend/func.py +++ b/pypy/module/_cffi_backend/func.py @@ -75,3 +75,9 @@ @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)]) diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py --- a/pypy/module/_cffi_backend/newtype.py +++ b/pypy/module/_cffi_backend/newtype.py @@ -211,12 +211,12 @@ 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, diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py --- a/pypy/module/_cffi_backend/test/_backend_test_c.py +++ b/pypy/module/_cffi_backend/test/_backend_test_c.py @@ -21,7 +21,10 @@ 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 = "" @@ -906,7 +909,7 @@ ('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) @@ -1076,7 +1079,7 @@ ('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() @@ -1810,11 +1813,12 @@ 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") @@ -2053,3 +2057,22 @@ ('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) diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py --- a/pypy/module/_sre/interp_sre.py +++ b/pypy/module/_sre/interp_sre.py @@ -275,9 +275,6 @@ 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'') diff --git a/pypy/module/_sre/test/test_app_sre.py b/pypy/module/_sre/test/test_app_sre.py --- a/pypy/module/_sre/test/test_app_sre.py +++ b/pypy/module/_sre/test/test_app_sre.py @@ -220,6 +220,24 @@ 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') _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit