git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Make remaining usage strings and string tables const

From
Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Date
Apr 21, 2025, 20:53 UTC
Message-ID
<zvqoyyyfgyjd3chrxaitn7rqbpmosoxd2qfz6hkumkkjzdwxnl@tarta.nabijaczleweli.xyz>
In-Reply-To
<xmqqv7qx5kb7.fsf@gitster.g>
On Mon, Apr 21, 2025 at 01:30:36PM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> writes:
> > -static const char *blame_opt_usage[] = {
> > +static const char *const blame_opt_usage[] = {
> >  	blame_usage,
> >  	"",
> >  	N_("<rev-opts> are documented in git-rev-list(1)"),
> >  	NULL
> >  };
> much looser to allow swapping the pointers in the array is *not* a
> problem per-se, but as long as the compiler would not barf after
> this patch, we know these callers that use these arrays are not
> doing such mutations to these arrays themselves, so it is good.
This built for me on Debian and the resulting binary worked so there's
no obvious sneaky const-incorrectness; it only resulted in one error,
where one of these variables was assigned to a
  const char *      *opt_usage;
instead of a
  const char *const *opt_usage;
this has been obviously fixed and is part of this submission.
I came across this as I was debugging some other issue
(that ended up as me holding it wrong),
static const char *s in library functions appeared quite pervasive,
but those aren't really possible to identify and close semi-automatically
(and it's unclear to me if a tighter analysis scope allows the compiler
 to actually put the static in .rodata or eliminate it outright).
Best,
Previous: Junio C Hamano
Message 3 of 3 in “Make remaining usage strings and string tables const”
  1. Make remaining usage strings and string tables constAhelenia Ziemiańska, Apr 21, 2025
  2. Junio C HamanoApr 21, 2025
  3. Ahelenia ZiemiańskaApr 21, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.