From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/3] Implement tp_richcompare for gdb.Block
Date: Thu, 25 Apr 2024 12:09:58 -0600 [thread overview]
Message-ID: <20240425181032.80275-3-tromey@adacore.com> (raw)
In-Reply-To: <20240425181032.80275-1-tromey@adacore.com>
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.
---
gdb/python/py-block.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index 3e30faf0856..3de6200e7c2 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 */
--
2.44.0
next prev parent reply other threads:[~2024-04-25 18:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 18:09 [PATCH 0/3] Add more info to DAP disassemble response Tom Tromey
2024-04-25 18:09 ` [PATCH 1/3] Simplify DAP make_source callers Tom Tromey
2024-04-25 18:09 ` Tom Tromey [this message]
2024-04-25 18:09 ` [PATCH 3/3] Add symbol, line, and location to DAP disassemble result Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240425181032.80275-3-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).