Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 4/4] gdb/python: remove more useless casts
Date: Mon, 14 Sep 2026 15:19:04 -0400	[thread overview]
Message-ID: <20260914191908.557014-4-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260914191908.557014-1-simon.marchi@efficios.com>

Remove a few (more) casts made unnecessary now that the GDB Python
objects inherit from PyObject.  A bunch of them were removed already by
commit 45e21c702fb ("Remove unneeded casts to PyObject*").

In one spot, I remove some now unnecessary parentheses where a cast was
removed by that previous patch.

Change-Id: I04e09497560b484c82d2bf29bdde34d3ffc31aec
---
 gdb/python/py-disasm.c           | 5 ++---
 gdb/python/py-finishbreakpoint.c | 6 ++----
 gdb/python/py-inferior.c         | 2 +-
 gdb/python/py-objfile.c          | 2 +-
 gdb/python/python-internal.h     | 2 +-
 5 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 48a2a4f6f8b8..c9dfd1f4571a 100644
--- a/gdb/python/py-disasm.c
+++ b/gdb/python/py-disasm.c
@@ -608,7 +608,7 @@ disasmpy_builtin_disassemble (PyObject *self, PyObject *args, PyObject *kw)
     ((disasm_result_object *) type->tp_alloc (type, 0));
   auto content = disassembler.release ();
   disasmpy_init_disassembler_result (res.get (), length, std::move (content));
-  return reinterpret_cast<PyObject *> (res.release ());
+  return res.release ();
 }
 
 /* Implement gdb._set_enabled function.  Takes a boolean parameter, and
@@ -1215,8 +1215,7 @@ gdbpy_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
 
   /* Create the new DisassembleInfo object we will pass into Python.  */
   gdbpy_ref<disasm_info_object> disasm_info
-    ((disasm_info_object *) PyObject_New (disasm_info_object,
-					  &disasm_info_object_type));
+    (PyObject_New (disasm_info_object, &disasm_info_object_type));
   if (disasm_info == nullptr)
     {
       gdbpy_print_stack ();
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index ec7399af4842..e81a9156ae6d 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -363,14 +363,12 @@ bpfinishpy_detect_out_scope_cb (struct breakpoint *b,
 				struct breakpoint *bp_stopped,
 				bool delete_bp)
 {
-  PyObject *py_bp = b->py_bp_object;
-
   /* Trigger out_of_scope if this is a FinishBreakpoint and its frame is
      not anymore in the current callstack.  */
-  if (py_bp != NULL && b->py_bp_object->is_finish_bp)
+  if (b->py_bp_object != nullptr && b->py_bp_object->is_finish_bp)
     {
       struct finish_breakpoint_object *finish_bp =
-	  (struct finish_breakpoint_object *) py_bp;
+	  (struct finish_breakpoint_object *) b->py_bp_object;
 
       /* Check scope if not currently stopped at the FinishBreakpoint.  */
       if (b != bp_stopped)
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 4c32a99e3ce7..82c0717d68f5 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -984,7 +984,7 @@ infpy_dealloc (PyObject *obj)
 PyObject *
 gdbpy_selected_inferior (PyObject *self, PyObject *args)
 {
-  return (inferior_to_inferior_object (current_inferior ()).release ());
+  return inferior_to_inferior_object (current_inferior ()).release ();
 }
 
 /* Implement the selected_context event handler.  This is called when some
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index dcd326b696cf..414965c89aed 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -674,7 +674,7 @@ objfile_to_objfile_object (struct objfile *objfile)
   if (result == NULL)
     {
       gdbpy_ref<objfile_object> object
-	((objfile_object *) PyObject_New (objfile_object, &objfile_object_type));
+	(PyObject_New (objfile_object, &objfile_object_type));
       if (object == NULL)
 	return NULL;
       if (!objfpy_initialize (object))
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 2e8f35729cd6..acec6b346eff 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -1214,7 +1214,7 @@ class gdbpy_registry
   gdbpy_ref<> lookup (O *owner, val_type *val) const
   {
     obj_type *obj = get_storage (owner)->lookup (val);
-    Py_XINCREF (static_cast<PyObject *> (obj));
+    Py_XINCREF (obj);
     return gdbpy_ref<> (obj);
   }
 
-- 
2.55.0


  parent reply	other threads:[~2026-09-14 19:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 19:19 [PATCH 1/4] gdb/python: check for nullptr before calling evpy_add_attribute Simon Marchi
2026-09-14 19:19 ` [PATCH 2/4] gdb/python: collapse some nested ifs Simon Marchi
2026-09-14 19:35   ` Tom Tromey
2026-09-14 19:46     ` Simon Marchi
2026-09-14 19:19 ` [PATCH 3/4] gdb/python: rename evregpy_no_listeners_p to evregpy_has_listeners_p Simon Marchi
2026-09-14 19:38   ` Tom Tromey
2026-09-14 19:19 ` Simon Marchi [this message]
2026-09-14 19:39   ` [PATCH 4/4] gdb/python: remove more useless casts Tom Tromey
2026-09-14 19:47     ` Simon Marchi
2026-09-14 19:24 ` [PATCH 1/4] gdb/python: check for nullptr before calling evpy_add_attribute Tom Tromey
2026-09-14 19:43   ` Simon Marchi

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=20260914191908.557014-4-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.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