[pypy-commit] pypy py3.5: hg merge default

arigo pypy.commits at gmail.com
Mon Feb 20 04:51:36 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r90220:ae9e485aec01
Date: 2017-02-20 10:50 +0100
http://bitbucket.org/pypy/pypy/changeset/ae9e485aec01/

Log:	hg 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
@@ -159,3 +159,7 @@
 and ``space.newtext()``: these two methods are identical on PyPy 2.7 but
 not on PyPy 3.x.  The latter is used to get an app-level unicode string
 by decoding the RPython string, assumed to be utf-8.
+
+.. branch: fix_bool_restype
+
+Fix for ``ctypes.c_bool``-returning ctypes functions
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
@@ -3835,7 +3835,7 @@
         assert (b > a) is False
         assert (b >= a) is True
         assert hash(a) == hash(b)
-    def assert_lt(a, b):
+    def assert_lt(a, b, check_hash=True):
         assert (a == b) is False
         assert (b == a) is False
         assert (a != b) is True
@@ -3848,9 +3848,10 @@
         assert (b <= a) is False
         assert (b > a) is True
         assert (b >= a) is True
-        assert hash(a) != hash(b)    # (or at least, it is unlikely)
-    def assert_gt(a, b):
-        assert_lt(b, a)
+        if check_hash:
+            assert hash(a) != hash(b)    # (or at least, it is unlikely)
+    def assert_gt(a, b, check_hash=True):
+        assert_lt(b, a, check_hash)
     def assert_ne(a, b):
         assert (a == b) is False
         assert (b == a) is False
@@ -3889,8 +3890,8 @@
     assert_eq(cast(t3, 65), 65)
     assert_ne(cast(t3, 65), b'A')
     assert_ne(cast(t3, 65), cast(t1, 65))
-    assert_gt(cast(t4, -1), -1)
-    assert_gt(cast(t4, -1), cast(t2, -1))
+    assert_gt(cast(t4, -1), -1, check_hash=False)
+    assert_gt(cast(t4, -1), cast(t2, -1), check_hash=False)
     assert_gt(cast(t4, -1), 99999)
     assert_eq(cast(t4, -1), 256 ** size_of_int() - 1)
     assert_eq(cast(t5, 3.0), 3)
diff --git a/pypy/module/cpyext/userslot.py b/pypy/module/cpyext/userslot.py
--- a/pypy/module/cpyext/userslot.py
+++ b/pypy/module/cpyext/userslot.py
@@ -26,7 +26,7 @@
 
 @slot_function([PyObject, Py_ssize_t], PyObject)
 def slot_sq_item(space, w_obj, index):
-    return space.getitem(w_obj, space.wrap(index))
+    return space.getitem(w_obj, space.newint(index))
 
 @slot_function([PyTypeObjectPtr, PyObject, PyObject], PyObject)
 def slot_tp_new(space, w_type, w_args, w_kwds):
@@ -39,12 +39,12 @@
     #     we know (since we are in this function) that self is not a cpytype
     from pypy.module.cpyext.typeobject import W_PyCTypeObject
     w_type0 = w_type
-    mro_w = space.listview(space.getattr(w_type0, space.wrap('__mro__')))
+    mro_w = space.listview(space.getattr(w_type0, space.newtext('__mro__')))
     for w_m in mro_w[1:]:
         if not w_type0.is_cpytype():
             break
         w_type0 = w_m
-    w_impl = space.getattr(w_type0, space.wrap('__new__'))
+    w_impl = space.getattr(w_type0, space.newtext('__new__'))
     args = Arguments(space, [w_type],
                      w_stararg=w_args, w_starstararg=w_kwds)
     return space.call_args(w_impl, args)
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -1536,9 +1536,26 @@
     def descr_iter(self, space):
         return W_DictMultiIterItemsObject(space, self.w_dict.iteritems())
 
+    def descr_contains(self, space, w_item):
+        if not space.isinstance_w(w_item, space.w_tuple):
+            return space.w_False
+        try:
+            w_key, w_value = space.fixedview_unroll(w_item, 2)
+        except OperationError as e:
+            if e.async(space):
+                raise
+            w_found = None
+        else:
+            w_found = self.w_dict.getitem(w_key)
+        if w_found is None:
+            return space.w_False
+        return space.eq(w_value, w_found)
+
 class W_DictViewKeysObject(W_DictViewObject, SetLikeDictView):
     def descr_iter(self, space):
         return W_DictMultiIterKeysObject(space, self.w_dict.iterkeys())
+    def descr_contains(self, space, w_key):
+        return self.w_dict.descr_contains(space, w_key)
 
 class W_DictViewValuesObject(W_DictViewObject):
     def descr_iter(self, space):
@@ -1549,6 +1566,7 @@
     __repr__ = interp2app(W_DictViewItemsObject.descr_repr),
     __len__ = interp2app(W_DictViewItemsObject.descr_len),
     __iter__ = interp2app(W_DictViewItemsObject.descr_iter),
+    __contains__ = interp2app(W_DictViewItemsObject.descr_contains),
 
     __eq__ = interp2app(W_DictViewItemsObject.descr_eq),
     __ne__ = interp2app(W_DictViewItemsObject.descr_ne),
@@ -1573,6 +1591,7 @@
     __repr__ = interp2app(W_DictViewKeysObject.descr_repr),
     __len__ = interp2app(W_DictViewKeysObject.descr_len),
     __iter__ = interp2app(W_DictViewKeysObject.descr_iter),
+    __contains__ = interp2app(W_DictViewKeysObject.descr_contains),
 
     __eq__ = interp2app(W_DictViewKeysObject.descr_eq),
     __ne__ = interp2app(W_DictViewKeysObject.descr_ne),
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -778,6 +778,8 @@
         assert "a" in keys
         assert 10 not in keys
         assert "Z" not in keys
+        raises(TypeError, "[] in keys")     # [] is unhashable
+        raises(TypeError, keys.__contains__, [])
         assert d.keys() == d.keys()
         e = {1: 11, "a": "def"}
         assert d.keys() == e.keys()
@@ -803,6 +805,8 @@
         assert () not in items
         assert (1,) not in items
         assert (1, 2, 3) not in items
+        raises(TypeError, "([], []) not in items")     # [] is unhashable
+        raises(TypeError, items.__contains__, ([], []))
         assert d.items() == d.items()
         e = d.copy()
         assert d.items() == e.items()
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -698,8 +698,18 @@
         enc = s_enc.const
         if enc not in ('ascii', 'latin-1', 'utf-8'):
             raise AnnotatorError("Encoding %s not supported for unicode" % (enc,))
+        if enc == 'utf-8':
+            from rpython.rlib import runicode
+            bookkeeper = getbookkeeper()
+            s_func = bookkeeper.immutablevalue(
+                             runicode.unicode_encode_utf_8_elidable)
+            s_errors = bookkeeper.immutablevalue('strict')
+            s_errorhandler = bookkeeper.immutablevalue(None)
+            s_allow_surr = bookkeeper.immutablevalue(True)
+            args = [self, self.len(), s_errors, s_errorhandler, s_allow_surr]
+            bookkeeper.emulate_pbc_call(bookkeeper.position_key, s_func, args)
         return SomeString(no_nul=self.no_nul)
-    method_encode.can_only_throw = []
+    method_encode.can_only_throw = [UnicodeEncodeError]
 
 
 class __extend__(SomeString):
@@ -731,6 +741,19 @@
         enc = s_enc.const
         if enc not in ('ascii', 'latin-1', 'utf-8'):
             raise AnnotatorError("Encoding %s not supported for strings" % (enc,))
+        if enc == 'utf-8':
+            from rpython.rlib import runicode
+            bookkeeper = getbookkeeper()
+            s_func = bookkeeper.immutablevalue(
+                            runicode.str_decode_utf_8_elidable)
+            s_errors = bookkeeper.immutablevalue('strict')
+            s_final = bookkeeper.immutablevalue(True)
+            s_errorhandler = bookkeeper.immutablevalue(
+                                    runicode.default_unicode_error_decode)
+            s_allow_surr = bookkeeper.immutablevalue(True)
+            args = [self, self.len(), s_errors, s_final, s_errorhandler,
+                    s_allow_surr]
+            bookkeeper.emulate_pbc_call(bookkeeper.position_key, s_func, args)
         return SomeUnicodeString(no_nul=self.no_nul)
     method_decode.can_only_throw = [UnicodeDecodeError]
 
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -6,7 +6,6 @@
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib import jit
-from rpython.rlib.nonconst import NonConstant
 
 
 if rffi.sizeof(lltype.UniChar) == 4:
@@ -107,9 +106,6 @@
         return u'', None, endingpos
     raise UnicodeEncodeError(encoding, u, startingpos, endingpos, msg)
 
-def ll_unicode_error_decode(errors, encoding, msg, s, startingpos, endingpos):
-    raise UnicodeDecodeError(encoding, s, startingpos, endingpos, msg)
-
 # ____________________________________________________________
 # utf-8
 
@@ -131,15 +127,6 @@
                      errorhandler=None, allow_surrogates=allow_surrogate_by_default):
     if errorhandler is None:
         errorhandler = default_unicode_error_decode
-    # NB. a bit messy because rtyper/rstr.py also calls the same
-    # function.  Make sure we annotate for the args it passes, too
-    if NonConstant(False):
-        s = NonConstant('?????')
-        size = NonConstant(12345)
-        errors = NonConstant('strict')
-        final = NonConstant(True)
-        errorhandler = ll_unicode_error_decode
-        allow_surrogates = NonConstant(True)
     return str_decode_utf_8_elidable(s, size, errors, final, errorhandler,
                                      allow_surrogates=allow_surrogates)
 
@@ -348,14 +335,6 @@
     #
     if errorhandler is None:
         errorhandler = default_unicode_error_encode
-    # NB. a bit messy because rtyper/rstr.py also calls the same
-    # function.  Make sure we annotate for the args it passes, too
-    if NonConstant(False):
-        s = NonConstant(u'?????')
-        size = NonConstant(12345)
-        errors = NonConstant('strict')
-        # no errorhandler needed for rtyper/rstr.py
-        allow_surrogates = NonConstant(True)
     return unicode_encode_utf_8_elidable(s, size, errors, errorhandler,
                                          allow_surrogates=allow_surrogates)
 
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -13,17 +13,14 @@
 
 class AbstractStringRepr(Repr):
 
-    def __init__(self, *args):
-        Repr.__init__(self, *args)
-        self.rstr_decode_utf_8 = None
-
     @jit.elidable
     def ll_decode_utf8(self, llvalue):
         from rpython.rtyper.annlowlevel import hlstr
         from rpython.rlib import runicode
         value = hlstr(llvalue)
         assert value is not None
-        errorhandler = runicode.ll_unicode_error_decode
+        errorhandler = runicode.default_unicode_error_decode
+        # NB. keep the arguments in sync with annotator/unaryop.py
         u, pos = runicode.str_decode_utf_8_elidable(
             value, len(value), 'strict', True, errorhandler, True)
         # XXX maybe the whole ''.decode('utf-8') should be not RPython.
@@ -374,10 +371,6 @@
 
 class AbstractUnicodeRepr(AbstractStringRepr):
 
-    def __init__(self, *args):
-        AbstractStringRepr.__init__(self, *args)
-        self.runicode_encode_utf_8 = None
-
     def rtype_method_upper(self, hop):
         raise TyperError("Cannot do toupper on unicode string")
 
@@ -390,6 +383,7 @@
         from rpython.rlib import runicode
         s = hlunicode(ll_s)
         assert s is not None
+        # NB. keep the arguments in sync with annotator/unaryop.py
         bytes = runicode.unicode_encode_utf_8_elidable(
             s, len(s), 'strict', None, True)
         return self.ll.llstr(bytes)


More information about the pypy-commit mailing list