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

Re: [PATCH v2 3/4] grep: copy struct in one fell swoop

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Nov 26, 2020, 20:25 UTC
Message-ID
<CAN0heSp2L4Q0pcn8V5hAKzXF6szZgpGqncLNYZOq5tmM7EucOQ@mail.gmail.com>
In-Reply-To
<xmqqlfepg9dq.fsf@gitster.c.googlers.com>
On Wed, 25 Nov 2020 at 08:53, Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
>
> Martin Ågren <martin.agren@gmail.com> writes:
>
> >   /*
> >    * The instance of grep_opt that we set up here is copied by
> >    * grep_init() to be used by each individual invocation.
> >    * When populating a new field of this structure here,
> >    * be sure to think about ownership (i.e. a shallow copy in
> >    * grep_init() may not be what you want).
> >    */
>
> I find the text near the end of both my version and yours a bit
> unsatisfying.  One thing I care about is not to mislead readers to
> think that the way grep_init() copies the singleton template is
> correct and sacred and they need to design their data structure to
> be compatible with the shallow copying.  We'd want it to be clear
> that it is expected that they will deep copy the field, and release
> it once individual invocation is done, when they need a new field
> that won't work well with shallow copying.  Perhaps "may not be wnat
> you want" is explicit enough, but I dunno.
I understand your concern. Here's what I'm considering using:
  /*
   * The instance of grep_opt that we set up here is copied by
   * grep_init() to be used by each individual invocation.
   * When populating a new field of this structure here, be
   * sure to think about ownership -- e.g., you might need to
   * override the shallow copy in grep_init() with a deep copy.
   */

I'm not going into the releasing of those resources, but hopefully that part can be left to the reader.

Other suggestions welcome, of course. I hope to get around to rerolling this on the weekend.

Martin
Previous: Junio C HamanoNext: Martin Ågren
Message 18 of 26 in “grep: retire `init_grep_defaults()`”
  1. 0/4 grep: retire `init_grep_defaults()`Martin Ågren, Nov 21, 2020
  2. 1/4 grep: don't set up a "default" repo for grepMartin Ågren, Nov 21, 2020
  3. 2/4 grep: use designated initializers for `grep_defaults`Martin Ågren, Nov 21, 2020
  4. 3/4 grep: simplify color setupMartin Ågren, Nov 21, 2020
  5. Jeff KingNov 21, 2020
  6. Martin ÅgrenNov 21, 2020
  7. Junio C HamanoNov 21, 2020
  8. Jeff KingNov 24, 2020
  9. 4/4 MyFirstObjectWalk: drop `init_walken_defaults()`Martin Ågren, Nov 21, 2020
  10. Johannes SchindelinNov 23, 2020
  11. 0/4 grep: simplify "grep defaults" handlingMartin Ågren, Nov 24, 2020
  12. 1/4 grep: don't set up a "default" repo for grepMartin Ågren, Nov 24, 2020
  13. 2/4 grep: use designated initializers for `grep_defaults`Martin Ågren, Nov 24, 2020
  14. 3/4 grep: copy struct in one fell swoopMartin Ågren, Nov 24, 2020
  15. Junio C HamanoNov 24, 2020
  16. Martin ÅgrenNov 25, 2020
  17. Junio C HamanoNov 25, 2020
  18. Martin ÅgrenNov 26, 2020
  19. 4/4 MyFirstObjectWalk: drop `init_walken_defaults()`Martin Ågren, Nov 24, 2020
  20. Ævar Arnfjörð BjarmasonNov 25, 2020
  21. 0/4 grep: simplify "grep defaults" handlingMartin Ågren, Nov 29, 2020
  22. 1/4 grep: don't set up a "default" repo for grepMartin Ågren, Nov 29, 2020
  23. 2/4 grep: use designated initializers for `grep_defaults`Martin Ågren, Nov 29, 2020
  24. 3/4 grep: copy struct in one fell swoopMartin Ågren, Nov 29, 2020
  25. 4/4 MyFirstObjectWalk: drop `init_walken_defaults()`Martin Ågren, Nov 29, 2020
  26. Junio C HamanoDec 1, 2020

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.