Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Matthieu Longo <matthieu.longo@arm.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 2/9] gdb: introduce rgb_color type to simplify existing code
Date: Wed, 4 Mar 2026 16:30:54 +0000	[thread overview]
Message-ID: <8a9cd094-eb92-4b92-a0a8-5e556e412e67@arm.com> (raw)
In-Reply-To: <87342gsrrh.fsf@tromey.com>

On 03/03/2026 18:16, 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.
> 
> Nice, thanks.
> 
>>     else if (m_color_space == color_space::ANSI_8COLOR
>>   	   && 0 <= m_value && m_value <= 7)
>> -    memcpy (rgb, palette_8colors[m_value], 3 * sizeof (uint8_t));
>> +    memcpy (rgb, palette_8colors[m_value], rgb.size_bytes ());
>>     else if (m_color_space == color_space::AIXTERM_16COLOR
>>   	   && 0 <= m_value && m_value <= 15)
>> -    memcpy (rgb, palette_16colors[m_value], 3 * sizeof (uint8_t));
>> +    memcpy (rgb, palette_16colors[m_value], rgb.size_bytes ());
>>     else if (m_color_space != color_space::XTERM_256COLOR)
>>       gdb_assert_not_reached ("get_rgb called on invalid color");
>>     else if (0 <= m_value && m_value <= 15)
>> -    memcpy (rgb, palette_16colors[m_value], 3 * sizeof (uint8_t));
>> +    memcpy (rgb, palette_16colors[m_value], rgb.size_bytes ());
> 
> I wonder if the types of palette_8colors and palette_16colors should
> change as well.  Then it seems the memcpy could be an assignment.
> 

Yes, it makes sense. I hadn't looked too much at the code using it.
Ok, I will fix this in the new revision.

>> diff --git a/gdb/ui-style.h b/gdb/ui-style.h
>> index fca9150889b..72349256034 100644
>> --- a/gdb/ui-style.h
>> +++ b/gdb/ui-style.h
>> @@ -54,6 +54,34 @@ extern bool color_space_safe_cast (color_space *result, long c);
>>   /* Get the number of colors supported by the terminal where GDB is running.  */
>>   extern int gdb_get_ncolors ();
>   
>> +struct rgb_color
>> +{
> 
> Usually in gdb we add a comment before a struct definition that explains
> what it is about.
> 

/* Convenient wrapper for RGB color values.  */ ?

>> +  constexpr const uint8_t& operator[](std::size_t idx) const noexcept
>> +  { return m_data[idx]; }
> 
> The "&" should come after the space here.
> Also a space between "[]" and "()".
> 

Fixed.

>> +    color (const rgb_color &rgb)
>> +      : m_color_space (color_space::RGB_24BIT),
>> +	m_red (rgb.r ()),
>> +	m_green (rgb.g ()),
>> +	m_blue (rgb.b ())
>> +    {
>> +    }
> 
> Probably this constructor should be 'explicit'.  That's the norm in gdb
> unless there's a real need for an implicit conversion.

Fixed.

> 
> thanks,
> Tom

Matthieu

  reply	other threads:[~2026-03-04 16:36 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 16:16 [PATCH v2 0/9] gdb: more fixes for Python limited C API support Matthieu Longo
2026-03-03 16:16 ` [PATCH v2 1/9] gdb: switch tuple object helpers to Python limited API equivalents Matthieu Longo
2026-03-03 18:09   ` Tom Tromey
2026-03-03 16:16 ` [PATCH v2 2/9] gdb: introduce rgb_color type to simplify existing code Matthieu Longo
2026-03-03 18:16   ` Tom Tromey
2026-03-04 16:30     ` Matthieu Longo [this message]
2026-03-03 16:16 ` [PATCH v2 3/9] gdb: switch bytes object helpers to Python limited API equivalents Matthieu Longo
2026-03-03 18:03   ` Tom Tromey
2026-03-03 16:16 ` [PATCH v2 4/9] gdb: add new helpers for retrieving a type's fully qualified name Matthieu Longo
2026-03-03 18:59   ` Tom Tromey
2026-03-06 17:49     ` Matthieu Longo
2026-03-06 19:45       ` Tom Tromey
2026-03-03 16:16 ` [PATCH v2 5/9] gdb/python: allow ref_ptr<T, Policy>::new_reference to accept subclasses of T Matthieu Longo
2026-03-03 18:18   ` Tom Tromey
2026-03-04 16:56     ` Matthieu Longo
2026-03-04 18:55       ` Tom Tromey
2026-03-06 11:37     ` Matthieu Longo
2026-03-06 11:43       ` Matthieu Longo
2026-03-06 16:47       ` Tom Tromey
2026-03-09 11:38         ` Matthieu Longo
2026-03-03 16:16 ` [PATCH v2 6/9] gdb/python: flatten functions calling PyObject_New and use gdbpy_ref Matthieu Longo
2026-03-03 18:22   ` Tom Tromey
2026-03-09 11:41     ` Matthieu Longo
2026-03-03 18:22   ` Tom Tromey
2026-03-03 16:16 ` [PATCH v2 7/9] gdb/python: accept gdbpy_ref in init helpers and return bool Matthieu Longo
2026-03-03 18:24   ` Tom Tromey
2026-03-09 13:25     ` Matthieu Longo
2026-03-03 16:16 ` [PATCH v2 8/9] gdb/python: add gdbpy_dict_wrapper:allocate_dict helper Matthieu Longo
2026-03-03 18:30   ` Tom Tromey
2026-03-06 12:03     ` Matthieu Longo
2026-03-03 16:16 ` [PATCH v2 9/9] gdb/python: add accessor helpers for __dict__ in Python extension objects Matthieu Longo
2026-03-03 19:02   ` Tom Tromey
2026-03-06 14:33     ` Matthieu Longo
2026-03-06 16:04       ` 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=8a9cd094-eb92-4b92-a0a8-5e556e412e67@arm.com \
    --to=matthieu.longo@arm.com \
    --cc=gdb-patches@sourceware.org \
    --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