From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 4/9] Return a const reference from gdbpy_get_print_options
Date: Sat, 04 Jul 2026 16:05:18 -0600 [thread overview]
Message-ID: <20260704-print-opts-cleanup-v1-4-fb54a5112a8d@tromey.com> (raw)
In-Reply-To: <20260704-print-opts-cleanup-v1-0-fb54a5112a8d@tromey.com>
This changes gdbpy_get_print_options to return a const reference to
the relevant value_print_options.
---
gdb/python/py-prettyprint.c | 11 +++++------
gdb/python/py-value.c | 7 ++-----
gdb/python/python-internal.h | 2 +-
3 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 1326aaae476..a89bf073215 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -718,8 +718,7 @@ gdbpy_print_options (PyObject *unused1, PyObject *unused2)
if (result == nullptr)
return nullptr;
- value_print_options opts;
- gdbpy_get_print_options (&opts);
+ const value_print_options &opts = gdbpy_get_print_options ();
if (set_boolean (result.get (), "raw",
opts.raw) < 0
@@ -770,13 +769,13 @@ gdbpy_print_options (PyObject *unused1, PyObject *unused2)
/* Helper function that either finds the prevailing print options, or
calls get_user_print_options. */
-void
-gdbpy_get_print_options (value_print_options *opts)
+const value_print_options &
+gdbpy_get_print_options ()
{
if (gdbpy_current_print_options != nullptr)
- *opts = *gdbpy_current_print_options;
+ return *gdbpy_current_print_options;
else
- *opts = get_user_print_options ();
+ return get_user_print_options ();
}
/* A ValuePrinter is just a "tag", so it has no state other than that
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 5b38110396e..a63af395e2c 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -690,8 +690,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- struct value_print_options opts;
- gdbpy_get_print_options (&opts);
+ value_print_options opts = gdbpy_get_print_options ();
opts.deref_ref = false;
/* We need objects for booleans as the "p" flag for bools is new in
@@ -1248,9 +1247,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
static PyObject *
valpy_str (PyObject *self)
{
- struct value_print_options opts;
-
- gdbpy_get_print_options (&opts);
+ value_print_options opts = gdbpy_get_print_options ();
opts.deref_ref = false;
string_file stb;
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 4ca28bb6957..f9899740a5f 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -974,7 +974,7 @@ gdb::unique_xmalloc_ptr<char> gdbpy_get_display_hint (PyObject *printer);
PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
PyObject *gdbpy_print_options (PyObject *self, PyObject *args);
-void gdbpy_get_print_options (value_print_options *opts);
+const value_print_options &gdbpy_get_print_options ();
extern const struct value_print_options *gdbpy_current_print_options;
void bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj);
--
2.49.0
next prev parent reply other threads:[~2026-07-04 22:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 22:05 [PATCH 0/9] Some cleanups and C++-ification of value_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 1/9] Return value_print_options from get_formatted_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 2/9] Return value_print_options from get_no_prettyformat_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 3/9] Convert get_user_print_options Tom Tromey
2026-07-04 22:05 ` Tom Tromey [this message]
2026-07-04 22:05 ` [PATCH 5/9] Return value_print_options from varobj_formatted_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 6/9] Use 'const' with some value_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 7/9] Don't use 'struct' keyword with value_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 8/9] Use std::forward in fortran_array_walker Tom Tromey
2026-07-04 22:05 ` [PATCH 9/9] Use references for value_print_options 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=20260704-print-opts-cleanup-v1-4-fb54a5112a8d@tromey.com \
--to=tom@tromey.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