]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: make gdb.Symtab comparable for equality
authorJan Vrany <jan.vrany@labware.com>
Thu, 21 Nov 2024 12:31:20 +0000 (12:31 +0000)
committerJan Vrany <jan.vrany@labware.com>
Thu, 21 Nov 2024 13:49:11 +0000 (13:49 +0000)
Like previous patch, but for gdb.Symtab.

gdb/python/py-symtab.c
gdb/testsuite/gdb.python/py-symtab.exp

index 99a5094ba6075d913dd90861014164434adbf980..5330b15ef8dedbe4425936a5ceab41bd30ca0950 100644 (file)
@@ -579,7 +579,8 @@ PyTypeObject symtab_object_type = {
   "GDB symtab object",           /*tp_doc */
   0,                             /*tp_traverse */
   0,                             /*tp_clear */
-  0,                             /*tp_richcompare */
+  gdbpy_richcompare<symtab_object, symtab, &symtab_object::symtab>,
+                                   /*tp_richcompare */
   0,                             /*tp_weaklistoffset */
   0,                             /*tp_iter */
   0,                             /*tp_iternext */
index 4765ef5cb2fd52ec969d7fbcfb846012375e1e0d..9caa5f1ebad51a27c6a8a5d65cb15db9285a27bf 100644 (file)
@@ -89,6 +89,27 @@ gdb_test_multiple "python print (\"simple_struct\" in static_symbols)" \
            }
        }
     }
+# Test comparison for equality and non-equality
+gdb_test "python print (symtab == symtab)"\
+    "True" \
+    "test symtab equality with itself"
+gdb_test "python print (symtab == sal.symtab)"\
+    "True" \
+    "test symtab equality with other symtab object referring to the same symtab"
+gdb_test "python print (symtab == 123 )"\
+    "False" \
+    "test symtab equality with non-symtab"
+
+gdb_test "python print (symtab != symtab)"\
+    "False" \
+    "test symtab non-equality with itself"
+gdb_test "python print (symtab != sal.symtab)"\
+    "False" \
+    "test symtab non-equality with other symtab object referring to the same symtab"
+gdb_test "python print (symtab != 123 )"\
+    "True" \
+    "test symtab non-equality with non-symtab"
+
 
 # Test is_valid when the objfile is unloaded.  This must be the last
 # test as it unloads the object file in GDB.