]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2010-05-14 Phil Muldoon <pmuldoon@redhat.com>
authorPhil Muldoon <pmuldoon@redhat.com>
Fri, 14 May 2010 11:11:28 +0000 (11:11 +0000)
committerPhil Muldoon <pmuldoon@redhat.com>
Fri, 14 May 2010 11:11:28 +0000 (11:11 +0000)
  PR python/11482

* python/py-value.c (valpy_hash): New function.
(value_object_type): Register valpy_hash.

2010-05-14  Phil Muldoon  <pmuldoon@redhat.com>

  PR python/11482

* gdb.python/py-value.exp (test_value_hash): New function

gdb/ChangeLog
gdb/python/py-value.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-value.exp

index 48098a1fe63669d5e921d87cbdfa814bb928ae47..fe0581b73c9690b1cadc9727c27bdced7205b34a 100644 (file)
@@ -1,3 +1,10 @@
+2010-05-14  Phil Muldoon  <pmuldoon@redhat.com>
+
+       PR python/11482
+
+       * python/py-value.c (valpy_hash): New function.
+       (value_object_type): Register valpy_hash.
+
 2010-05-14  Hui Zhu  <teawater@gmail.com>
             Michael Snyder  <msnyder@vmware.com>
 
index 173b3c95dcd23b275c99a13b087b8874c12d4ff7..abf50ffb7eefc67c4c81cb90b83736bb0a8c9368 100644 (file)
@@ -432,6 +432,14 @@ valpy_get_is_optimized_out (PyObject *self, void *closure)
   Py_RETURN_FALSE;
 }
 
+/* Calculate and return the address of the PyObject as the value of
+   the builtin __hash__ call.  */
+static long 
+valpy_hash (PyObject *self)
+{
+  return (long) (intptr_t) self;
+}
+
 enum valpy_opcode
 {
   VALPY_ADD,
@@ -1097,7 +1105,7 @@ PyTypeObject value_object_type = {
   &value_object_as_number,       /*tp_as_number*/
   0,                             /*tp_as_sequence*/
   &value_object_as_mapping,      /*tp_as_mapping*/
-  0,                             /*tp_hash */
+  valpy_hash,                    /*tp_hash*/
   0,                             /*tp_call*/
   valpy_str,                     /*tp_str*/
   0,                             /*tp_getattro*/
index dd049b37b29a38402dc438bf76081ca519dd1bb2..b6f36d799f22e2dffddd9fef76ce4e536e3674ac 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-14  Phil Muldoon  <pmuldoon@redhat.com>
+
+       PR python/11482
+
+       * gdb.python/py-value.exp (test_value_hash): New function.
+
 2010-05-11  Pierre Muller  <muller@ics.u-strasbg.fr>
 
        PR exp/11530.
index 3bfa17317cc8299020bb7dc96f497507cfd71a1b..67a2ff9d147308d5a132d7033eaf56330a1e8c52 100644 (file)
@@ -393,6 +393,23 @@ proc test_parse_and_eval {} {
     "parse_and_eval type test"
 }
 
+# Test that values are hashable.
+proc test_value_hash {} {
+  gdb_py_test_multiple "Simple Python value dictionary" \
+    "python" "" \
+    "one = gdb.Value(1)" "" \
+    "two = gdb.Value(2)" "" \
+    "three = gdb.Value(3)" "" \
+    "vdict = {one:\"one str\",two:\"two str\",three:\"three str\"}" "" \
+    "end"
+    gdb_test "python print vdict\[one\]" "one str" "Test dictionary hash"
+    gdb_test "python print vdict\[two\]" "two str" "Test dictionary hash"
+    gdb_test "python print vdict\[three\]" "three str" "Test dictionary hash"
+    gdb_test "python print one.__hash__() == hash(one)" "True" "Test inbuilt hash"
+    gdb_test "python print one.__hash__() == id(one)" "True" "Test inbuilt id"
+}
+
+
 # Start with a fresh gdb.
 
 gdb_exit
@@ -409,6 +426,7 @@ test_value_boolean
 test_value_compare
 test_objfiles
 test_parse_and_eval
+test_value_hash
 
 # The following tests require execution.