diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2016-08-23 18:15:35 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2016-08-23 19:06:36 +0100 |
commit | 5b7c08c21449c407019f4484c91819a441e8bd9c (patch) | |
tree | 8d0da2e462920a194e09106b2b82656068e2a80e /Examples/test-suite/python | |
parent | 253a39fdffc9b3c270ba815d6e60f416a4ee46a7 (diff) | |
download | swig-builtin-hashable.tar.gz |
Make Python builtin types hashable by defaultbuiltin-hashable
Default hash is the underlying C/C++ pointer.
This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare)
which compares the pointers.
Diffstat (limited to 'Examples/test-suite/python')
-rw-r--r-- | Examples/test-suite/python/python_builtin_runme.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Examples/test-suite/python/python_builtin_runme.py b/Examples/test-suite/python/python_builtin_runme.py index c41dfc0b1..70990cbfd 100644 --- a/Examples/test-suite/python/python_builtin_runme.py +++ b/Examples/test-suite/python/python_builtin_runme.py @@ -1,6 +1,17 @@ from python_builtin import * if is_python_builtin(): + # Test 0 for default tp_hash + vs = ValueStruct(1234) + h = hash(vs) + d = dict() + d[h] = "hi" + if h not in d: + raise RuntimeError("h should be in d") + h2 = hash(ValueStruct.inout(vs)) + if h != h2: + raise RuntimeError("default tp_hash not working") + # Test 1 for tp_hash if hash(SimpleValue(222)) != 222: raise RuntimeError("tp_hash not working") |