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

Re: [PATCH 1/4] config: factor out config file stack management

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Feb 27, 2013, 07:51 UTC
Message-ID
<20130227075100.GA3268@sandbox-ub>
In-Reply-To
<7vobf6loas.fsf@alter.siamese.dyndns.org>
On Tue, Feb 26, 2013 at 02:10:03PM -0800, Junio C Hamano wrote:
Show 31 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > I wonder if it would be more obvious with the more usual OO-struct
> > functions, like:
> >
> >   struct config_source {
> >           ...
> >   };
> >   void config_source_init_file(struct config_source *, const char *fn);
> >   void config_source_init_strbuf(struct config_source *,
> >                                  const struct strbuf *buf);
> >   void config_source_clear(struct config_source *);
> >
> >   int config_source_parse(struct config_source *);
> >
> > and then the use would be something like:
> >
> >   struct config_source top;
> >   int ret;
> >
> >   config_source_init_file(&top, "foo");
> >   ret = config_source_parse(&top);
> >   config_source_clear(&top);
> >
> >   return ret;
> >
> > I.e., "init" constructors, a "clear" destructor, and any methods like
> > "parse" that you need.
> 
> Yup, that cocincides with my first impression I sent out for the
> previous RFC/PATCH round.

I agree that your suggestions would make the design more OO and provide us with more flexibility. However at the following costs:

Currently the push and pop are combined into one function. This design makes it impossible to forget the cleanup if someone else uses this function. The same applies to the private data handling around do_config_from().

All memory is currently handled on the stack. If we have an init/clear design at least the private data for strbuf needs to be put on the heap. We could pass in the config_strbuf but IMO that would violate the encapsulation.

Thus we also require a specialized clear which frees that private data (we need that to close the file anyway). Because of that I would probably call it destroy or free.

That means there will be six additional functions instead of one: We need init and clear for both, a common init and a common clear for the push/pop part. IMO that will make the code harder to read for the first time.

Then we would have a hybrid stack/heap solution still involving side effects (setting the global cf).

Do not get me wrong. I am not against changing it but I would like to spell out the consequences first before doing so.

Do you still think that is nicer approach?
Cheers Heiko
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 25 in “fetch moved submodules on-demand”
  1. 0/3 fetch moved submodules on-demandHeiko Voigt, Feb 25, 2013
  2. 1/3 teach config parsing to read from strbufHeiko Voigt, Feb 25, 2013
  3. Junio C HamanoFeb 25, 2013
  4. Heiko VoigtFeb 25, 2013
  5. 0/4 allow more sources for config valuesHeiko Voigt, Feb 26, 2013
  6. 1/4 config: factor out config file stack managementHeiko Voigt, Feb 26, 2013
  7. Jeff KingFeb 26, 2013
  8. Heiko VoigtFeb 26, 2013
  9. Jeff KingFeb 26, 2013
  10. Junio C HamanoFeb 26, 2013
  11. Heiko VoigtFeb 27, 2013
  12. Junio C HamanoFeb 26, 2013
  13. Heiko VoigtFeb 27, 2013
  14. 2/4 config: drop file pointer validity check in get_next_char()Heiko Voigt, Feb 26, 2013
  15. Jeff KingFeb 26, 2013
  16. Heiko VoigtFeb 27, 2013
  17. Heiko VoigtFeb 28, 2013
  18. Heiko VoigtFeb 28, 2013
  19. 3/4 config: make parsing stack struct independent from actual data sourceHeiko Voigt, Feb 26, 2013
  20. 4/4 teach config parsing to read from strbufHeiko Voigt, Feb 26, 2013
  21. Ramsay JonesMar 7, 2013
  22. Heiko VoigtMar 10, 2013
  23. Jeff KingFeb 26, 2013
  24. 2/3 implement fetching of moved submodulesHeiko Voigt, Feb 25, 2013
  25. 3/3 submodule: simplify decision tree whether to or not to fetchHeiko Voigt, Feb 25, 2013

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.