Re: [PATCH 06/21] convert manual allocations to argv_array
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Feb 20, 2016, 08:39 UTC
- Message-ID
- <CAPig+cQK15OoNdG0zyCC0eZJ1XeidD7sOU8BggnNN7k=Zi9zdw@mail.gmail.com>
- In-Reply-To
- <20160220083426.GA17171@sigill.intra.peff.net>
On Sat, Feb 20, 2016 at 3:34 AM, Jeff King <peff@peff.net> wrote:
Show 26 quoted lines
> On Sat, Feb 20, 2016 at 03:29:29AM -0500, Eric Sunshine wrote: >> On Sat, Feb 20, 2016 at 3:10 AM, Jeff King <peff@peff.net> wrote: >> > On Sat, Feb 20, 2016 at 03:07:00AM -0500, Eric Sunshine wrote: >> >> > + /* argv strings are now owned by pathspec */ >> >> > + paths.argc = 0; >> >> > + argv_array_clear(&paths); >> >> >> >> This overly intimate knowledge of the internal implementation of >> >> argv_array_clear() is rather ugly. >> > >> > Yep, I agree. Suggestions? >> > [...] >> > >> > I guess we can make an argv_array_detach_strings() function. Or maybe >> > even just argv_array_detach() would be less gross, and then this >> > function could manually free the array but not the strings themselves. >> >> [...] >> I wonder if a simple "dup'ing" string_list would be more suitable for >> this case. You'd have to append the NULL item manually with >> string_list_append_nodup(), and string_list_clear() would then be the >> correct way to dispose of the list without intimate knowledge of its >> implementation and no need for an API extension. > > A string_list doesn't just store pointers; it's a struct with a util > field. So you can't pass it to things expecting a "const char **".
Yep, I knew that but wasn't thinking straight.
> I think argv_array_detach() is the least-bad thing here. It matches > strbuf_detach() to say "you now own the storage" (as opposed to just > peeking at argv.argv, which we should do only in a read-only way).
I also had made the strbuf_detach() analogy in my response but deleted it before sending; I do think it's a reasonable API template to mirror via new argv_array_detach().