[pypy-commit] pypy cpyext-unhashable: test, fix for cpytext hash of empty string subclass not returning -1
mattip
pypy.commits at gmail.com
Mon May 22 03:44:22 EDT 2017
Author: Matti Picus <matti.picus at gmail.com>
Branch: cpyext-unhashable
Changeset: r91360:c2f5f5816876
Date: 2017-05-22 10:43 +0300
http://bitbucket.org/pypy/pypy/changeset/c2f5f5816876/
Log: test, fix for cpytext hash of empty string subclass not returning -1
diff --git a/pypy/module/cpyext/test/test_bytesobject.py b/pypy/module/cpyext/test/test_bytesobject.py
--- a/pypy/module/cpyext/test/test_bytesobject.py
+++ b/pypy/module/cpyext/test/test_bytesobject.py
@@ -452,6 +452,7 @@
assert 3 == module.get_len(a)
b = module.newsubstr('')
assert 0 == module.get_len(b)
+ assert hash(b) in [0, -2]
class TestBytes(BaseApiTest):
def test_bytes_resize(self, space):
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -366,7 +366,6 @@
add_tp_new_wrapper(space, dict_w, pto)
if not pto.c_tp_hash:
dict_w['__hash__'] = space.w_None
- print 'pto', rffi.charp2str(pto.c_tp_name), 'c_tp_hash', pto.c_tp_hash, dict_w['__hash__']
@slot_function([PyObject, PyObject, PyObject], PyObject)
def tp_new_wrapper(space, self, w_args, w_kwds):
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -592,6 +592,7 @@
def descr_hash(self, space):
x = compute_hash(self._value)
+ x -= (x == -1)
return space.newint(x)
def descr_format(self, space, __args__):
diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -744,6 +744,7 @@
# disabled: assert hash('') == 0 --- different special case
assert hash('hello') & 0x7fffffff == 0x347697fd
assert hash('hello world!') & 0x7fffffff == 0x2f0bb411
+ assert hash('') in [0, -2]
def test_buffer(self):
x = b"he"
More information about the pypy-commit
mailing list