Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org,  Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCHv8 1/3] gdb/python: add gdb.Style class
Date: Tue, 16 Sep 2025 10:47:45 -0600	[thread overview]
Message-ID: <87qzw6l4y6.fsf@tromey.com> (raw)
In-Reply-To: <cb3f3a0a16a9d3a990e559bc28cc08ca0fc80f9d.1756294307.git.aburgess@redhat.com> (Andrew Burgess's message of "Wed, 27 Aug 2025 12:34:10 +0100")

>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> +static std::optional<ui_file_style>
Andrew> +stylepy_style_from_name (const char *name, bool *has_intensity_ptr = nullptr,
Andrew> +			 const cmd_list_element **found_cmd_ptr = nullptr)
Andrew> +{
Andrew> +  std::string cmd_str = std::string ("show style ") + name;
Andrew> +
Andrew> +  struct cmd_list_element *cmd = nullptr;
Andrew> +  struct cmd_list_element *alias = nullptr;
Andrew> +  int found;
Andrew> +  try
Andrew> +    {
Andrew> +      struct cmd_list_element *prefix;
Andrew> +      found = lookup_cmd_composition (cmd_str.c_str (), &alias, &prefix, &cmd);
Andrew> +    }
Andrew> +  catch (const gdb_exception &ex)
Andrew> +    {
Andrew> +      PyErr_Format (PyExc_RuntimeError,
Andrew> +		    _("style '%s' cannot be found."), name);
Andrew> +      return {};

Noting this for a later comment...

Andrew> +static PyObject *
Andrew> +stylepy_apply (PyObject *self, PyObject *args, PyObject *kw)
Andrew> +{
Andrew> +  style_object *style_obj = (style_object *) self;
Andrew> +
Andrew> +  static const char *keywords[] = { "string", nullptr };
Andrew> +  PyObject *input_obj;
Andrew> +
Andrew> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O!", keywords,
Andrew> +					&PyUnicode_Type, &input_obj))
Andrew> +    return nullptr;

Why "O!" and not "s" here?

Andrew> +      gdb::unique_xmalloc_ptr<char>
Andrew> +	input (python_string_to_target_string (input_obj));

target string seems like an unusual choice here.

Andrew> +      std::string output
Andrew> +	= string_printf ("%s%s%s", style->to_ansi ().c_str (), input.get (),
Andrew> +			 ui_file_style ().to_ansi ().c_str ());

This can just using "+" which seems a little cleaner.

Andrew> +  /* Handle named styles.  This is harder, we need to write to the actual
Andrew> +     parameter.  First though, look up the named style to see if it has an
Andrew> +     intensity.  HAS_INTENSITY will be set true only if the style exists,
Andrew> +     and has an 'intensity' setting.  */
Andrew> +
Andrew> +  bool has_intensity = false;
Andrew> +  (void) stylepy_style_from_name (style_obj->style_name, &has_intensity);
Andrew> +  if (!has_intensity)
Andrew> +    {
Andrew> +      PyErr_Format
Andrew> +	(PyExc_ValueError, "the intensity of style '%s' is not writable.",
Andrew> +	 style_obj->style_name);
Andrew> +      return -1;

I guess I don't know the Python rule here, but it seems like if
stylepy_style_from_name returns {}, then this can set an exception while
one is already set.  See the snippet above.

Instead of the (void) I think it would be a bit better to just check the
return result of stylepy_style_from_name, and if it returns an error,
just return -1 directly; and only then do the has_intensity check.

Tom

  reply	other threads:[~2025-09-16 16:48 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04  9:39 [PATCH 0/2] Python Style API Andrew Burgess
2025-06-04  9:39 ` [PATCH 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-04  9:39 ` [PATCH 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-06 13:38 ` [PATCHv2 0/2] Python Style API Andrew Burgess
2025-06-06 13:38   ` [PATCHv2 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-06 14:21     ` Eli Zaretskii
2025-06-06 13:38   ` [PATCHv2 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-07 10:44   ` [PATCHv3 0/2] Python Style API Andrew Burgess
2025-06-07 10:44     ` [PATCHv3 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-07 10:44     ` [PATCHv3 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-09 15:54     ` [PATCHv3 0/2] Python Style API Andrew Burgess
2025-06-18 19:30     ` [PATCHv4 0/4] " Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 4/4] gdb: extend gdb.write to support styled output Andrew Burgess
2025-06-25 14:42       ` [PATCHv5 0/4] Python Style API Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-07-07 14:43         ` [PATCHv6 0/4] Python Style API Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-08-13 10:25           ` [PATCHv7 0/4] Fix for gdb.Color + pagination AND new gdb.Style API Andrew Burgess
2025-08-13 10:25             ` [PATCHv7 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-08-24 16:13               ` Andrew Burgess
2025-08-25 10:21                 ` Tom de Vries
2025-08-26 14:35                   ` [PATCH] gdb/testsuite: work around empty substring bug in expect Andrew Burgess
2025-08-27  6:24                     ` Tom de Vries
2025-08-13 10:29             ` [PATCHv7 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-08-13 10:30             ` [PATCHv7 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-08-13 12:37               ` Eli Zaretskii
2025-08-13 10:34             ` [PATCHv7 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-08-13 13:05               ` Eli Zaretskii
2025-08-13 13:05               ` Eli Zaretskii
2025-08-27 11:34             ` [PATCHv8 0/3] new gdb.Style API Andrew Burgess
2025-08-27 11:34               ` [PATCHv8 1/3] gdb/python: add gdb.Style class Andrew Burgess
2025-09-16 16:47                 ` Tom Tromey [this message]
2025-09-23 16:59                   ` Andrew Burgess
2025-08-27 11:34               ` [PATCHv8 2/3] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-09-16 16:50                 ` Tom Tromey
2025-08-27 11:34               ` [PATCHv8 3/3] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-09-16 16:56                 ` Tom Tromey
2025-09-23 17:05                   ` Andrew Burgess
2025-09-23 18:38                     ` Tom Tromey
2025-09-23 16:54               ` [PATCHv9 0/3] new gdb.Style API Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 1/3] gdb/python: add gdb.Style class Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 2/3] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 3/3] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-10-03 19:27                 ` [PATCHv9 0/3] new gdb.Style API Tom Tromey
2025-10-05 12:51                   ` Andrew Burgess
2025-10-05 15:16                     ` Tom de Vries
2025-10-05 17:59                       ` Tom Tromey
2025-10-06  9:01                         ` Andrew Burgess
2025-10-05 18:03                       ` Andrew Burgess
2025-10-05 18:41                         ` Tom de Vries
2025-10-06  9:01                           ` Andrew Burgess
2025-10-06 12:29                             ` Tom de Vries

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=87qzw6l4y6.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=aburgess@redhat.com \
    --cc=eliz@gnu.org \
    --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