Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCHv2] gdb/tui: use init_extended_color where possible
Date: Wed, 12 Aug 2026 15:26:58 -0400	[thread overview]
Message-ID: <e5a28b2f-289a-4aac-ba0d-24d2c23fca3f@simark.ca> (raw)
In-Reply-To: <5da7a3fea6997922a87508807efc3cadd119ff7c.1785930494.git.aburgess@redhat.com>

On 8/5/26 7:50 AM, Andrew Burgess wrote:
> In v2:
> 
>   - Split the scaling of GDB's RGB value out from the init_color and
>     init_extended_color calls.  This removes some code duplication and
>     allows the comment to sit closer to the code in question.
> 
>   - Rebase to current HEAD and retest.
> 
> ---
> 
> After commit:
> 
>   commit fbe7f20a0f098ca03913452b29f50f0dc8568f77
>   Date:   Sat May 9 23:27:43 2026 +0200
> 
>     gdb/tui: fix unexpected reuse of color pairs
> 
> which converted GDB to use init_extended_pair where possible, I
> realised we could also make use of init_extended_color.
> 
> The motivation for using init_extended_color is slightly less than
> init_extended_pair.  Assuming the terminal supports it the standard
> init_color API supports up to SHRT_MAX (32767) different colors,
> switching to init_extended_color removes the SHRT_MAX limit on color
> indices, allowing us to support the full range of COLORS.
> 
> But the cost of making this change is minimal, we already track the
> color indices as an `int` within the global COLOR_MAP, so it's mostly
> just a case of calling init_extended_color where needed.
> 
> We only use init_extended_color when both that function and
> init_extended_pair is available.  The fallback to init_extended_pair
> is init_pair, which expects the color indices to be shorts.  If we are
> using the init_pair fallback then using init_extended_color is
> pointless.
> 
> In reality init_extended_pair and init_extended_color were both added
> in ncurses 6.1, so should both be available together.
> 
> There is one additional change in here.  Assuming that a terminal does
> support more than SHRT_MAX colours, but for some reason GDB is
> compiled with a version of the curses library that doesn't support
> init_extended_color, then it is possible that in `get_color` the value
> of NEXT could end up above SHRT_MAX, in which case the `init_color`
> call will truncate the value of NEXT to a short and we will end up
> redefining an earlier color index.  To avoid this unlikely case I've
> added a compare against SHRT_MAX.
> 
> The init_extended_color path doesn't have this risk as COLORS is an
> `int` and NEXT is passed as an `int` on this path so there is no risk
> of truncation.

Seems fine to me, thanks.  Hopefully one day we can just assume that the
extended functions are present.

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

Simon

  reply	other threads:[~2026-08-12 19:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 14:24 [PATCH] " Andrew Burgess
2026-08-05 11:50 ` [PATCHv2] " Andrew Burgess
2026-08-12 19:26   ` Simon Marchi [this message]
2026-08-12 19:44   ` Tom Tromey
2026-08-13  9:53     ` Andrew Burgess

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=e5a28b2f-289a-4aac-ba0d-24d2c23fca3f@simark.ca \
    --to=simark@simark.ca \
    --cc=aburgess@redhat.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