]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Return gdbpy_ref<> from gdbarch_to_arch_object
authorTom Tromey <tromey@adacore.com>
Fri, 20 Feb 2026 20:20:56 +0000 (13:20 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 23 Feb 2026 12:29:12 +0000 (05:29 -0700)
This changes gdbarch_to_arch_object to return a gdbpy_ref<>,
using the type system to convey that a new reference is always
returned.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/python/py-arch.c
gdb/python/py-disasm.c
gdb/python/py-frame.c
gdb/python/py-inferior.c
gdb/python/py-unwind.c
gdb/python/python-internal.h
gdb/python/python.c

index cf740821dfadcde146188f3911a7063547de9062..f40d7da17636e3bfc6539ca9e0e24e403dd22c8d 100644 (file)
@@ -84,7 +84,7 @@ gdbpy_is_architecture (PyObject *obj)
    Returns a new reference to the arch_object associated as data with
    GDBARCH.  */
 
-PyObject *
+gdbpy_ref<>
 gdbarch_to_arch_object (struct gdbarch *gdbarch)
 {
   PyObject *new_ref = arch_object_data.get (gdbarch);
@@ -97,7 +97,7 @@ gdbarch_to_arch_object (struct gdbarch *gdbarch)
   /* new_ref could be NULL if creation failed.  */
   Py_XINCREF (new_ref);
 
-  return new_ref;
+  return gdbpy_ref<> (new_ref);
 }
 
 /* Implementation of gdb.Architecture.name (self) -> String.
index 9f5d0e2fdcbfbaa48cfc6678f7829d4dd43601ba..748ffd5e6a3a0977d3d3e56c22cb0184b62f1f69 100644 (file)
@@ -699,7 +699,7 @@ disasmpy_info_architecture (PyObject *self, void *closure)
 {
   disasm_info_object *obj = (disasm_info_object *) self;
   DISASMPY_DISASM_INFO_REQUIRE_VALID (obj);
-  return gdbarch_to_arch_object (obj->gdbarch);
+  return gdbarch_to_arch_object (obj->gdbarch).release ();
 }
 
 /* Implement DisassembleInfo.progspace attribute.  Return the
index bba0b2991ab7c6b9395b772de4e7d80902a30a18..9d122f1a221e90129d741ae6b3c7e8d46243362e 100644 (file)
@@ -201,7 +201,7 @@ frapy_arch (PyObject *self, PyObject *args)
       return gdbpy_handle_gdb_exception (nullptr, except);
     }
 
-  return gdbarch_to_arch_object (obj->gdbarch);
+  return gdbarch_to_arch_object (obj->gdbarch).release ();
 }
 
 /* Implementation of gdb.Frame.unwind_stop_reason (self) -> Integer.
index 53f3344429d226c271353500d8c1da4c16f3c88b..fd9da27b92e4f959f81a7ffeed13480684381b2d 100644 (file)
@@ -778,7 +778,7 @@ infpy_architecture (PyObject *self, PyObject *args)
 
   INFPY_REQUIRE_VALID (inf);
 
-  return gdbarch_to_arch_object (inf->inferior->arch ());
+  return gdbarch_to_arch_object (inf->inferior->arch ()).release ();
 }
 
 /* Implement repr() for gdb.Inferior.  */
index 277e8d2be6fb14c882b26f7531fe32a04a3bbee2..d160db1f0ae6b55f04f21356567eea1d9acc61df 100644 (file)
@@ -762,7 +762,7 @@ pending_framepy_architecture (PyObject *self, PyObject *args)
 
   PENDING_FRAMEPY_REQUIRE_VALID (pending_frame);
 
-  return gdbarch_to_arch_object (pending_frame->gdbarch);
+  return gdbarch_to_arch_object (pending_frame->gdbarch).release ();
 }
 
 /* Implementation of PendingFrame.level (self) -> Integer.  */
index 85f7f1f4dd1effa1bf2c1cea3526565b2d10f766..1f0964f24d3b3f125938dab3150e39dd95ee3262 100644 (file)
@@ -517,7 +517,7 @@ PyObject *objfpy_get_frame_unwinders (PyObject *, void *);
 PyObject *objfpy_get_xmethods (PyObject *, void *);
 PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw);
 
-PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
+gdbpy_ref<> gdbarch_to_arch_object (struct gdbarch *gdbarch);
 PyObject *gdbpy_all_architecture_names (PyObject *self, PyObject *args);
 
 PyObject *gdbpy_new_register_descriptor_iterator (struct gdbarch *gdbarch,
index 9862d1a726fb99ea58e0e481ff14aa230b4ae824..8739864a8613c5ec176643f20e77d26bd1d25fe6 100644 (file)
@@ -1421,7 +1421,7 @@ gdbpy_colorize_disasm (const std::string &content, gdbarch *gdbarch)
       return {};
     }
 
-  gdbpy_ref<> gdbarch_arg (gdbarch_to_arch_object (gdbarch));
+  gdbpy_ref<> gdbarch_arg = gdbarch_to_arch_object (gdbarch);
   if (gdbarch_arg == nullptr)
     {
       gdbpy_print_stack ();