Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r92691:be539692837f Date: 2017-10-10 01:30 +0200 http://bitbucket.org/pypy/pypy/changeset/be539692837f/
Log: hg merge default diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -13,7 +13,7 @@ ssizessizeargfunc, ssizeobjargproc, iternextfunc, initproc, richcmpfunc, cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, objobjargproc, getbufferproc, ssizessizeobjargproc) -from pypy.module.cpyext.pyobject import make_ref, decref, from_ref +from pypy.module.cpyext.pyobject import make_ref, from_ref, as_pyobj from pypy.module.cpyext.pyerrors import PyErr_Occurred from pypy.module.cpyext.memoryobject import fill_Py_buffer from pypy.module.cpyext.state import State @@ -90,20 +90,21 @@ args_w = space.fixedview(w_args) return generic_cpy_call(space, func_binary, w_self, args_w[0]) +def _get_ob_type(space, w_obj): + # please ensure that w_obj stays alive + ob_type = as_pyobj(space, space.type(w_obj)) + return rffi.cast(PyTypeObjectPtr, ob_type) + def wrap_binaryfunc_l(space, w_self, w_args, func): func_binary = rffi.cast(binaryfunc, func) check_num_args(space, w_args, 1) args_w = space.fixedview(w_args) - ref = make_ref(space, w_self) - decref(space, ref) return generic_cpy_call(space, func_binary, w_self, args_w[0]) def wrap_binaryfunc_r(space, w_self, w_args, func): func_binary = rffi.cast(binaryfunc, func) check_num_args(space, w_args, 1) args_w = space.fixedview(w_args) - ref = make_ref(space, w_self) - decref(space, ref) return generic_cpy_call(space, func_binary, args_w[0], w_self) def wrap_ternaryfunc(space, w_self, w_args, func): @@ -121,8 +122,6 @@ func_ternary = rffi.cast(ternaryfunc, func) check_num_argsv(space, w_args, 1, 2) args_w = space.fixedview(w_args) - ref = make_ref(space, w_self) - decref(space, ref) arg3 = space.w_None if len(args_w) > 1: arg3 = args_w[1] @@ -314,12 +313,10 @@ def wrap_getreadbuffer(space, w_self, w_args, func): func_target = rffi.cast(readbufferproc, func) - py_obj = make_ref(space, w_self) - py_type = py_obj.c_ob_type + py_type = _get_ob_type(space, w_self) rbp = rffi.cast(rffi.VOIDP, 0) if py_type.c_tp_as_buffer: rbp = rffi.cast(rffi.VOIDP, py_type.c_tp_as_buffer.c_bf_releasebuffer) - decref(space, py_obj) with lltype.scoped_alloc(rffi.VOIDPP.TO, 1) as ptr: index = rffi.cast(Py_ssize_t, 0) size = generic_cpy_call(space, func_target, w_self, index, ptr) @@ -332,9 +329,7 @@ def wrap_getwritebuffer(space, w_self, w_args, func): func_target = rffi.cast(readbufferproc, func) - py_obj = make_ref(space, w_self) - py_type = py_obj.c_ob_type - decref(space, py_obj) + py_type = _get_ob_type(space, w_self) rbp = rffi.cast(rffi.VOIDP, 0) if py_type.c_tp_as_buffer: rbp = rffi.cast(rffi.VOIDP, py_type.c_tp_as_buffer.c_bf_releasebuffer) @@ -350,12 +345,10 @@ def wrap_getbuffer(space, w_self, w_args, func): func_target = rffi.cast(getbufferproc, func) - py_obj = make_ref(space, w_self) - py_type = py_obj.c_ob_type + py_type = _get_ob_type(space, w_self) rbp = rffi.cast(rffi.VOIDP, 0) if py_type.c_tp_as_buffer: rbp = rffi.cast(rffi.VOIDP, py_type.c_tp_as_buffer.c_bf_releasebuffer) - decref(space, py_obj) with lltype.scoped_alloc(Py_buffer) as pybuf: _flags = 0 if space.len_w(w_args) > 0: diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py --- a/rpython/rlib/runicode.py +++ b/rpython/rlib/runicode.py @@ -877,32 +877,31 @@ ch = ord(s[pos]) pos += 1 ch2 = 0 - if 0xD800 <= ch < 0xDC00: - if not allow_surrogates: - ru, rs, pos = errorhandler(errors, public_encoding_name, - 'surrogates not allowed', - s, pos-1, pos) - if rs is not None: - # py3k only - if len(rs) % 4 != 0: - errorhandler('strict', public_encoding_name, - 'surrogates not allowed', - s, pos-1, pos) - result.append(rs) - continue - for ch in ru: - if ord(ch) < 0xD800: - _STORECHAR32(result, ord(ch), byteorder) - else: - errorhandler('strict', public_encoding_name, - 'surrogates not allowed', - s, pos-1, pos) + if not allow_surrogates and 0xD800 <= ch < 0xE000: + ru, rs, pos = errorhandler(errors, public_encoding_name, + 'surrogates not allowed', + s, pos-1, pos) + if rs is not None: + # py3k only + if len(rs) % 4 != 0: + errorhandler('strict', public_encoding_name, + 'surrogates not allowed', + s, pos-1, pos) + result.append(rs) continue - elif MAXUNICODE < 65536 and pos < size: - ch2 = ord(s[pos]) - if 0xDC00 <= ch2 < 0xE000: - ch = (((ch & 0x3FF)<<10) | (ch2 & 0x3FF)) + 0x10000; - pos += 1 + for ch in ru: + if ord(ch) < 0xD800: + _STORECHAR32(result, ord(ch), byteorder) + else: + errorhandler('strict', public_encoding_name, + 'surrogates not allowed', + s, pos-1, pos) + continue + if 0xD800 <= ch < 0xDC00 and MAXUNICODE < 65536 and pos < size: + ch2 = ord(s[pos]) + if 0xDC00 <= ch2 < 0xE000: + ch = (((ch & 0x3FF)<<10) | (ch2 & 0x3FF)) + 0x10000; + pos += 1 _STORECHAR32(result, ch, byteorder) return result.build() diff --git a/rpython/rlib/test/test_runicode.py b/rpython/rlib/test/test_runicode.py --- a/rpython/rlib/test/test_runicode.py +++ b/rpython/rlib/test/test_runicode.py @@ -2,6 +2,7 @@ import py import sys, random +import struct from rpython.rlib import runicode from hypothesis import given, settings, strategies @@ -266,11 +267,12 @@ assert replace_with(u'rep', None) == '\x00<\x00r\x00e\x00p\x00>' assert replace_with(None, '\xca\xfe') == '\x00<\xca\xfe\x00>' - def test_utf32_surrogates(self): + @py.test.mark.parametrize('unich',[u"\ud800", u"\udc80"]) + def test_utf32_surrogates(self, unich): assert runicode.unicode_encode_utf_32_be( - u"\ud800", 1, None) == '\x00\x00\xd8\x00' + unich, 1, None) == struct.pack('>i', ord(unich)) py.test.raises(UnicodeEncodeError, runicode.unicode_encode_utf_32_be, - u"\ud800", 1, None, allow_surrogates=False) + unich, 1, None, allow_surrogates=False) def replace_with(ru, rs): def errorhandler(errors, enc, msg, u, startingpos, endingpos): if errors == 'strict': @@ -278,7 +280,7 @@ endingpos, msg) return ru, rs, endingpos return runicode.unicode_encode_utf_32_be( - u"<\ud800>", 3, None, + u"<%s>" % unich, 3, None, errorhandler, allow_surrogates=False) assert replace_with(u'rep', None) == u'<rep>'.encode('utf-32-be') assert replace_with(None, '\xca\xfe\xca\xfe') == '\x00\x00\x00<\xca\xfe\xca\xfe\x00\x00\x00>' @@ -432,7 +434,7 @@ assert (self.decoder('aaaa' + seq + 'bbbb', len(seq) + 8, 'ignore', final=True) == (u'aaaabbbb', len(seq) + 8)) assert (self.decoder(seq, len(seq), 'custom', final=True, - errorhandler=self.custom_replace) == + errorhandler=self.custom_replace) == (FOO * len(seq), len(seq))) assert (self.decoder('aaaa' + seq + 'bbbb', len(seq) + 8, 'custom', final=True, errorhandler=self.custom_replace) == @@ -628,7 +630,7 @@ msg='invalid continuation byte') assert self.decoder(seq, len(seq), 'replace', final=True ) == (res, len(seq)) - assert (self.decoder('aaaa' + seq + 'bbbb', len(seq) + 8, + assert (self.decoder('aaaa' + seq + 'bbbb', len(seq) + 8, 'replace', final=True) == (u'aaaa' + res + u'bbbb', len(seq) + 8)) res = res.replace(FFFD, u'') _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit