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

Re: [PATCH] strvec: `strvec_splice()` to a statically initialized vector

From
Rubén Justo <rjusto@gmail.com>
Date
Dec 2, 2024, 22:01 UTC
Message-ID
<b0bd6c5d-83eb-4545-9b38-ab4e69d3882c@gmail.com>
In-Reply-To
<xmqqiks2kg6o.fsf@gitster.g>
On Mon, Dec 02, 2024 at 10:49:03AM +0900, Junio C Hamano wrote:
Show 26 quoted lines
> > Let's avoid an invalid pointer error in case a client of
> > `strvec_splice()` ends up with something similar to:
> >
> >        struct strvec arr = STRVEC_INIT;
> >        const char *rep[] = { "foo" };
> >
> >        strvec_splice(&arr, 0, 0, rep, ARRAY_SIZE(rep));
> 
> Well spotted, but the explanation can be a bit more helpful to
> casual readers.  If there were a few paragraphs like below
> 
>     An empty strvec does not represent the array part of the
>     structure with a NULL pointer, but with a singleton empty array,
>     to help read-only applications.  This is similar to how an empty
>     strbuf uses a singleton empty string.
> 
>     This approach requires us to be careful when adding elements to
>     an empty instance.  The strvec_splice() API function we recently
>     introduced however forgot to special case an empty strvec, and
>     ended up applying realloc() to the singleton.
>     
> before your proposed commit log message, I wouldn't have needed to
> go read the implementation of STRVEC_INIT to understand what the fix
> is about.  From the fix by itself, it is a bit hard to see why
> empty_strvec needs to be special cased, until you re-read the
> implementation of STRVEC_INIT.

The explanation can certainly be improved. I'll send a v2 iteration soon. Thanks.

Previous: Junio C HamanoNext: Patrick Steinhardt
Message 3 of 21 in “strvec: `strvec_splice()` to a statically initialized vector”
  1. strvec: `strvec_splice()` to a statically initialized vectorRubén Justo, Nov 29, 2024
  2. Junio C HamanoDec 2, 2024
  3. Rubén JustoDec 2, 2024
  4. Patrick SteinhardtDec 2, 2024
  5. strvec: `strvec_splice()` to a statically initialized vectorRubén Justo, Dec 3, 2024
  6. Junio C HamanoDec 4, 2024
  7. Rubén JustoDec 4, 2024
  8. Junio C HamanoDec 4, 2024
  9. Rubén JustoDec 4, 2024
  10. Rubén JustoDec 4, 2024
  11. Junio C HamanoDec 4, 2024
  12. Junio C HamanoDec 9, 2024
  13. Junio C HamanoDec 9, 2024
  14. Junio C HamanoDec 9, 2024
  15. Jeff KingDec 9, 2024
  16. Junio C HamanoDec 9, 2024
  17. Rubén JustoDec 9, 2024
  18. karthik nayakDec 4, 2024
  19. Rubén JustoDec 4, 2024
  20. karthik nayakDec 6, 2024
  21. strvec: `strvec_splice()` to a statically initialized vectorRubén Justo, Dec 4, 2024

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.