Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Matthieu Longo <matthieu.longo@arm.com>, Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v3 1/7] gdb: introduce rgb_color type to simplify existing code
Date: Wed, 11 Mar 2026 14:04:34 -0400	[thread overview]
Message-ID: <b7a2226b-8690-472e-a0a9-5074bb0efd80@simark.ca> (raw)
In-Reply-To: <6709ef98-2ff2-47d7-b292-9c6b02f5fc05@arm.com>

On 3/11/26 1:55 PM, Matthieu Longo wrote:
> On 11/03/2026 15:03, Simon Marchi wrote:
>> On 3/9/26 3:22 PM, Tom Tromey wrote:
>>>>>>>> Matthieu Longo <matthieu.longo@arm.com> writes:
>>>
>>>> This patch replaces the raw uint8[3] buffer used to represent RGB values
>>>> with a more convenient wrapper, rgb_color, around std::array<uint8_t, 3>.
>>>> It also changes the return type of ui_file_style::color::get_rgb to
>>>> rgb_color instead of filling a caller-provided buffer, and updates all
>>>> callers accordingly.
>>>
>>> One tiny nit.
>>>
>>>>     if (target_space == color_space::RGB_24BIT)
>>>>       {
>>>> -      uint8_t rgb[3];
>>>> -      get_rgb (rgb);
>>>> -      return color (rgb[0], rgb[1], rgb[2]);
>>>> +      return color (get_rgb ());
>>>>       }
>>>   Since there's only one statement now, the braces should be removed.
>>>
>>> This is ok with this change.
>>> Approved-By: Tom Tromey <tom@tromey.com>
>>>
>>> Tom
>>
>> This appears to have caused a build failure on armhf:
>>
>> https://builder.sourceware.org/buildbot/#/builders/72/builds/7402/steps/4/logs/stdio
>>
>> Sample:
>>
>> ../../binutils-gdb/gdb/tui/tui-io.c: In function ‘bool get_color(const ui_file_style::color&, int*)’:
>> ../../binutils-gdb/gdb/tui/tui-io.c:260:38: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [-Werror]
>>    260 |           if (init_color (next, rgb[0] * 1000 / 255, rgb[1] * 1000 / 255,
>>        |                                      ^
>> In file included from ./../../binutils-gdb/gdb/ui-file.h:23,
>>                   from ./../../binutils-gdb/gdb/defs.h:60,
>>                   from <command-line>:
>> ./../../binutils-gdb/gdb/ui-style.h:78:22: note: candidate 1: ‘constexpr uint8_t& rgb_color::operator[](std::size_t)’
>>     78 |   constexpr uint8_t &operator[] (std::size_t idx) noexcept
>>        |                      ^~~~~~~~
>> ../../binutils-gdb/gdb/tui/tui-io.c:260:38: note: candidate 2: ‘operator[](uint8_t* {aka unsigned char*}, int)’ (built-in)
>>    260 |           if (init_color (next, rgb[0] * 1000 / 255, rgb[1] * 1000 / 255,
>>        |                                      ^
>>
>> It seems to be because an rgb_color can be implicitly converted to a
>> `uint8_t *`, which can be subscripted, but also has an operator[].
>>
>> Not sure why the uint8_t* operator is needed,
> 
> It was originally required for this line when passing rgb to memcpy().
>  
>   memcpy (rgb, palette_8colors[m_value], rgb.bytes_size ());
> 
> But was later replaced by this assignment:
> 
>   rgb = palette_8colors[m_value];
> 
>> but it compiles fine here if I remove it.  If really needed, I think that an explicit method
>> (`.data()`) would be preferable, to avoid unwanted conversions.
>>
>> Simon
> 
> I locally tested the removal of this uint8_t* operator, and the code compiles fine.
> 
> diff --git a/gdb/ui-style.h b/gdb/ui-style.h
> index a1d656cd39c..fc40b93709d 100644
> --- a/gdb/ui-style.h
> +++ b/gdb/ui-style.h
> @@ -72,7 +72,6 @@ struct rgb_color
>    constexpr uint8_t g () const noexcept { return m_data[1]; }
>    constexpr uint8_t b () const noexcept { return m_data[2]; }
> 
> -  constexpr operator uint8_t *() noexcept { return m_data.data (); }
>    constexpr size_t size () const noexcept { return m_data.size (); }
> 
>    constexpr uint8_t &operator[] (std::size_t idx) noexcept
> 
> Do you want me to publish a patch for this ? Or will you fix it ?

Please push a patch that does exactly that.  You can put my:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

  reply	other threads:[~2026-03-11 18:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-09 17:56 [PATCH v3 0/7] gdb: more fixes for Python limited C API support Matthieu Longo
2026-03-09 17:56 ` [PATCH v3 1/7] gdb: introduce rgb_color type to simplify existing code Matthieu Longo
2026-03-09 19:22   ` Tom Tromey
2026-03-11 15:03     ` Simon Marchi
2026-03-11 17:55       ` Matthieu Longo
2026-03-11 18:04         ` Simon Marchi [this message]
2026-03-11 18:16         ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 2/7] gdb: fail configure if Python version is too old for limited API Matthieu Longo
2026-03-24 18:53   ` Tom Tromey
2026-03-31 10:16     ` Matthieu Longo
2026-04-07 13:36       ` Matthieu Longo
2026-04-07 20:39       ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 3/7] gdb: add new helpers for retrieving a type's fully qualified name Matthieu Longo
2026-03-24 18:44   ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 4/7] gdb/python: allow ref_ptr<T, Policy>::new_reference to accept subclasses of T Matthieu Longo
2026-03-09 19:40   ` Tom Tromey
2026-03-10 12:26     ` Matthieu Longo
2026-03-09 17:56 ` [PATCH v3 5/7] gdb/python: flatten functions calling PyObject_New and use gdbpy_ref Matthieu Longo
2026-03-09 20:07   ` Tom Tromey
2026-03-09 17:56 ` [PATCH v3 6/7] gdb/python: add gdbpy_dict_wrapper:allocate_dict helper Matthieu Longo
2026-03-09 20:09   ` Tom Tromey
2026-03-10 12:26     ` Matthieu Longo
2026-03-09 17:56 ` [PATCH v3 7/7] gdb/python: add accessor helpers for __dict__ in Python extension objects Matthieu Longo
2026-03-13 18:09   ` Tom Tromey
2026-03-23 10:28 ` [PATCH v3 0/7] gdb: more fixes for Python limited C API support Matthieu Longo

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=b7a2226b-8690-472e-a0a9-5074bb0efd80@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=matthieu.longo@arm.com \
    --cc=tom@tromey.com \
    /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