Author: Matti Picus <[email protected]>
Branch: cpyext-unhashable
Changeset: r91416:46815e12a7df
Date: 2017-05-22 23:04 +0300
http://bitbucket.org/pypy/pypy/changeset/46815e12a7df/

Log:    more places to ensure cpyext hashing an empty string-like does not
        return -1

diff --git a/pypy/objspace/std/bufferobject.py 
b/pypy/objspace/std/bufferobject.py
--- a/pypy/objspace/std/bufferobject.py
+++ b/pypy/objspace/std/bufferobject.py
@@ -112,7 +112,9 @@
     descr_ge = _make_descr__cmp('ge')
 
     def descr_hash(self, space):
-        return space.newint(compute_hash(self.buf.as_str()))
+        x = compute_hash(self.buf.as_str())
+        x -= (x == -1)
+        return space.newint(x)
 
     def descr_mul(self, space, w_times):
         # xxx not the most efficient implementation
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -236,6 +236,7 @@
 
     def descr_hash(self, space):
         x = compute_hash(self._value)
+        x -= (x == -1)
         return space.newint(x)
 
     def descr_eq(self, space, w_other):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to