diff options
| author | Tom Tromey <tromey@adacore.com> | 2026-02-20 12:38:31 -0700 |
|---|---|---|
| committer | Tom Tromey <tromey@adacore.com> | 2026-02-23 05:29:11 -0700 |
| commit | 800d967797a86e02119509cdc4be06946f41ccdd (patch) | |
| tree | 0eba7c1f1576f419831ac4dfb6c0616de7279586 /gdb/python | |
| parent | 6aaa64b8ef4bf06ad786403dbc0c4ffaee2f6d80 (diff) | |
| download | binutils-800d967797a86e02119509cdc4be06946f41ccdd.tar.gz binutils-800d967797a86e02119509cdc4be06946f41ccdd.tar.bz2 binutils-800d967797a86e02119509cdc4be06946f41ccdd.zip | |
Return gdbpy_ref<> from symtab_and_line_to_sal_object
This changes symtab_and_line_to_sal_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>
Diffstat (limited to 'gdb/python')
| -rw-r--r-- | gdb/python/py-frame.c | 5 | ||||
| -rw-r--r-- | gdb/python/py-progspace.c | 5 | ||||
| -rw-r--r-- | gdb/python/py-record-btrace.c | 4 | ||||
| -rw-r--r-- | gdb/python/py-symtab.c | 4 | ||||
| -rw-r--r-- | gdb/python/py-unwind.c | 6 | ||||
| -rw-r--r-- | gdb/python/python-internal.h | 2 | ||||
| -rw-r--r-- | gdb/python/python.c | 8 |
7 files changed, 12 insertions, 22 deletions
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index ab7883b4e73..65a6ec669dd 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -466,21 +466,18 @@ static PyObject * frapy_find_sal (PyObject *self, PyObject *args) { frame_info_ptr frame; - PyObject *sal_obj = NULL; /* Initialize to appease gcc warning. */ try { FRAPY_REQUIRE_VALID (self, frame); symtab_and_line sal = find_frame_sal (frame); - sal_obj = symtab_and_line_to_sal_object (sal); + return symtab_and_line_to_sal_object (sal).release (); } catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception (nullptr, except); } - - return sal_obj; } /* Implementation of gdb.Frame.read_var_value (self, variable, diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 19f5e533b0a..943bc04ef81 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -534,7 +534,6 @@ static PyObject * pspy_find_pc_line (PyObject *o, PyObject *args) { CORE_ADDR pc; - PyObject *result = NULL; /* init for gcc -Wall */ PyObject *pc_obj; pspace_object *self = (pspace_object *) o; @@ -553,14 +552,12 @@ pspy_find_pc_line (PyObject *o, PyObject *args) set_current_program_space (self->pspace); sal = find_sal_for_pc (pc, 0); - result = symtab_and_line_to_sal_object (sal); + return symtab_and_line_to_sal_object (sal).release (); } catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception (nullptr, except); } - - return result; } /* Implementation of is_valid (self) -> Boolean. diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c index 3fcf653f4ba..90d9ecd95a8 100644 --- a/gdb/python/py-record-btrace.c +++ b/gdb/python/py-record-btrace.c @@ -205,7 +205,7 @@ PyObject * recpy_bt_insn_sal (PyObject *self, void *closure) { const btrace_insn * const insn = btrace_insn_from_recpy_insn (self); - PyObject *result = NULL; + gdbpy_ref<> result; if (insn == NULL) return NULL; @@ -219,7 +219,7 @@ recpy_bt_insn_sal (PyObject *self, void *closure) return gdbpy_handle_gdb_exception (nullptr, except); } - return result; + return result.release (); } /* Implementation of RecordInstruction.pc [int] for btrace. diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 2dca0083277..820542932ba 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -390,7 +390,7 @@ symtab_to_symtab_object (struct symtab *symtab) /* Create a new symtab and line (gdb.Symtab_and_line) object that encapsulates the symtab_and_line structure from GDB. */ -PyObject * +gdbpy_ref<> symtab_and_line_to_sal_object (struct symtab_and_line sal) { sal_object *sal_obj; @@ -399,7 +399,7 @@ symtab_and_line_to_sal_object (struct symtab_and_line sal) if (sal_obj != nullptr) set_sal (sal_obj, sal); - return (PyObject *) sal_obj; + return gdbpy_ref<> (sal_obj); } /* Return struct symtab_and_line reference that is wrapped by this diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index d4c35e17f14..c50df8377f9 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -613,21 +613,17 @@ pending_framepy_find_sal (PyObject *self, PyObject *args) PENDING_FRAMEPY_REQUIRE_VALID (pending_frame); - PyObject *sal_obj = nullptr; - try { frame_info_ptr frame = pending_frame->frame_info; symtab_and_line sal = find_frame_sal (frame); - sal_obj = symtab_and_line_to_sal_object (sal); + return symtab_and_line_to_sal_object (sal).release (); } catch (const gdb_exception &except) { return gdbpy_handle_gdb_exception (nullptr, except); } - - return sal_obj; } /* Implement PendingFrame.block(). Return a gdb.Block for the pending diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 8925714f3c1..feabf270464 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -495,7 +495,7 @@ gdb::unique_xmalloc_ptr<char> gdbpy_parse_command_name PyObject *gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *kw); -PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal); +gdbpy_ref<> symtab_and_line_to_sal_object (struct symtab_and_line sal); PyObject *symtab_to_symtab_object (struct symtab *symtab); PyObject *symbol_to_symbol_object (struct symbol *sym); PyObject *block_to_block_object (const struct block *block, diff --git a/gdb/python/python.c b/gdb/python/python.c index 79b5d24d1cf..d2a77890072 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1020,11 +1020,11 @@ gdbpy_decode_line (PyObject *self, PyObject *args) return NULL; for (size_t i = 0; i < sals.size (); ++i) { - PyObject *obj = symtab_and_line_to_sal_object (sals[i]); - if (obj == NULL) - return NULL; + gdbpy_ref<> obj = symtab_and_line_to_sal_object (sals[i]); + if (obj == nullptr) + return nullptr; - PyTuple_SetItem (result.get (), i, obj); + PyTuple_SetItem (result.get (), i, obj.release ()); } } else |
