diff options
author | Tom Tromey <tromey@adacore.com> | 2024-04-24 11:58:38 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-05-10 12:09:32 -0600 |
commit | 400d4e3290b2012f9c44dff21cf6af9bb557e8de (patch) | |
tree | 1b51213e1e7f463dffeb0388706ccbc534caa71d /gdb | |
parent | 4b09134a09ea6663850091c6a8da614cf3902fe1 (diff) | |
download | gdb-400d4e3290b2012f9c44dff21cf6af9bb557e8de.zip gdb-400d4e3290b2012f9c44dff21cf6af9bb557e8de.tar.gz gdb-400d4e3290b2012f9c44dff21cf6af9bb557e8de.tar.bz2 |
Implement tp_richcompare for gdb.Block
I noticed that two gdb.Block objects will never compare as equal with
'=='. This patch fixes the problem by implementing tp_richcompare, as
was done for gdb.Frame.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/python/py-block.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 3e30faf..3de6200 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -452,6 +452,28 @@ blpy_repr (PyObject *self) name, str.c_str ()); } +/* Implements the equality comparison for Block objects. All other + comparison operators will throw NotImplemented, as they aren't + valid for blocks. */ + +static PyObject * +blpy_richcompare (PyObject *self, PyObject *other, int op) +{ + if (!PyObject_TypeCheck (other, &block_object_type) + || (op != Py_EQ && op != Py_NE)) + { + Py_INCREF (Py_NotImplemented); + return Py_NotImplemented; + } + + block_object *self_block = (block_object *) self; + block_object *other_block = (block_object *) other; + + bool expected = self_block->block == other_block->block; + bool equal = op == Py_EQ; + return PyBool_FromLong (equal == expected); +} + static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_blocks (void) { @@ -530,7 +552,7 @@ PyTypeObject block_object_type = { "GDB block object", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ - 0, /* tp_richcompare */ + blpy_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ blpy_iter, /* tp_iter */ 0, /* tp_iternext */ |