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

Re: [PATCH 5/6] do not discard const: keep signature

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 26, 2026, 17:18 UTC
Message-ID
<xmqqbjgaqzk3.fsf@gitster.g>
In-Reply-To
<9a90f93111ec54e5eb9675cb84ac1d70ad95e118.1774537954.git.git@grubix.eu>
Michael J Gruber <git@grubix.eu> writes:
> Here, while we do not mutate the struct itself, many other signatures
> expect a non-const argument - possibly unnecessarily - so we opt to keep
> the original signature by casting to non-const.
> ---

Sorry, but I do not understand the above description, or the code change. Doesn't bsearch() returns non-const "void *" pointer?

Ah, the constness of the return value in C23 depends on the constness of pm->commits[] array, which inherits its constness from the constness of parameter pm to the function, and you cast the value we are going to return explicitly to a non-const pointer.

OK. In the context of "C23 constness" patch series, that may be obvious to you, but I suspect a future reader who finds this single commit from the output of "git blame" or something would be puzzled unless we say this is about adjusting to C23 that makes bsearch() a qualifier-preserving function somewhere in the log message.

Show 15 quoted lines
>  pseudo-merge.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/pseudo-merge.c b/pseudo-merge.c
> index a2d5bd85f9..ac81792e65 100644
> --- a/pseudo-merge.c
> +++ b/pseudo-merge.c
> @@ -644,7 +644,7 @@ static struct pseudo_merge_commit *find_pseudo_merge(const struct pseudo_merge_m
>  	if (!pm->commits_nr)
>  		return NULL;
>  
> -	return bsearch(&pos, pm->commits, pm->commits_nr,
> +	return (struct pseudo_merge_commit *) bsearch(&pos, pm->commits, pm->commits_nr,
>  		       PSEUDO_MERGE_COMMIT_RAWSZ, pseudo_merge_commit_cmp);
>  }
Previous: Michael J GruberNext: Michael J Gruber
Message 3 of 24 in “ISOC23: quell warnings on discarding const”
  1. 0/6 ISOC23: quell warnings on discarding constMichael J Gruber, Mar 26, 2026
  2. 5/6 do not discard const: keep signatureMichael J Gruber, Mar 26, 2026
  3. Junio C HamanoMar 26, 2026
  4. 6/6 do not discard const: the ugly truthMichael J Gruber, Mar 26, 2026
  5. Junio C HamanoMar 26, 2026
  6. Jeff KingMar 26, 2026
  7. 0/4 fix const issues in revision parserJeff King, Mar 26, 2026
  8. 1/4 revision: make handle_dotdot() interface less confusingJeff King, Mar 26, 2026
  9. Junio C HamanoMar 26, 2026
  10. Jeff KingMar 26, 2026
  11. Junio C HamanoMar 27, 2026
  12. 2/4 rev-parse: simplify dotdot parsingJeff King, Mar 26, 2026
  13. 3/4 revision: avoid writing to const string for parent marksJeff King, Mar 26, 2026
  14. 4/4 rev-parse: avoid writing to const string for parent marksJeff King, Mar 26, 2026
  15. 1/6 do not discard const: the simple casesMichael J Gruber, Mar 26, 2026
  16. Jeff KingMar 26, 2026
  17. Junio C HamanoMar 26, 2026
  18. config: store allocated string in non-const pointerJeff King, Mar 26, 2026
  19. 4/6 do not discard const: declare const where we stay constMichael J Gruber, Mar 26, 2026
  20. 2/6 do not discard const: make git-compat-util ISOC23-likeMichael J Gruber, Mar 26, 2026
  21. 3/6 do not discard const: adjust to non-const data typesMichael J Gruber, Mar 26, 2026
  22. Junio C HamanoMar 26, 2026
  23. D. Ben KnobleMar 26, 2026
  24. Michael J GruberMar 27, 2026

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.