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

Re: [PATCH v2 2/4] t-reftable-readwrite: use free_names() instead of a for loop

From
CPChandra Pratap <chandrapratap3519@gmail.com>
Date
Aug 10, 2024, 05:50 UTC
Message-ID
<CA+J6zkSHX892NoNOyTDc-38_giBR=Q-Hf7+7nymU9GnPu1V-5Q@mail.gmail.com>
In-Reply-To
<xmqqjzgpcymq.fsf@gitster.g>
On Sat, 10 Aug 2024 at 00:27, Junio C Hamano <gitster@pobox.com> wrote:
Show 36 quoted lines
>
> Chandra Pratap <chandrapratap3519@gmail.com> writes:
>
> > free_names() as defined by reftable/basics.{c,h} frees a NULL
> > terminated array of malloced strings along with the array itself.
> > Use this function instead of a for loop to free such an array.
>
> Going back to [1/4], the headers included in this test looked like this:
>
>     -#include "system.h"
>     -
>     -#include "basics.h"
>     -#include "block.h"
>     -#include "blocksource.h"
>     -#include "reader.h"
>     -#include "record.h"
>     -#include "test_framework.h"
>     -#include "reftable-tests.h"
>     -#include "reftable-writer.h"
>     +#include "test-lib.h"
>     +#include "reftable/reader.h"
>     +#include "reftable/blocksource.h"
>     +#include "reftable/reftable-error.h"
>     +#include "reftable/reftable-writer.h"
>
> I found this part a bit curious, perhaps because I was not involved
> in either reftable/ or unit-tests/ development.  So I may be asking
> a stupid question, but is it intended that some headers like
> "block.h" and "record.h" are no longer included?
>
> It is understandable that inclusion of "test-lib.h" is new (and
> needs to be there to work as part of t/unit-tests/), and the leading
> directory name "reftable/" added to header files are also justified,
> of course.  But if you depend on "basics.h" and do not include it,
> that does not sound like the most hygenic thing to do, at least to
> me.

I think 'basics.{c,h}' in reftable/ is equivalent to 'stdio.h' in a generic C program, it holds fundamental functionalities to be used by other reftable structures and hence, is always (implicitly or explicitly) #included in almost all of the files in reftable/.

This test is supposed to focus on reftable's read-write functionalities so it makes sense to explicitly #include only those headers that are directly responsible for those functionalities, namely 'reader.h', 'blocksource.h' and 'reftable-writer.h'. 'reftable-error.h' is thrown in there as well because some tests need to explicitly mention the various error codes and it doesn't make sense to rely on it being #included by others.

Show 8 quoted lines
> The code changes themselves look good; I can see that the
> implementation of free_names() in reftable/basics.c safely replaces
> these loops.  There is a slight behaviour difference that names[]
> that was fed to reftable_iterator_seek_ref() earlier goes away
> before the iterator is destroyed, but _seek_ref() does not retain
> the names[0] argument in the iterator object, so that is OK.
>
> Thanks.
Previous: Junio C HamanoNext: Junio C Hamano
Message 17 of 30 in “t: port reftable/readwrite_test.c to the unit testing framework”
  1. Chandra PratapAug 7, 2024
  2. 1/5 t: move reftable/readwrite_test.c to the unit testing frameworkChandra Pratap, Aug 7, 2024
  3. 2/5 t-reftable-readwrite: use free_names() instead of a for loopChandra Pratap, Aug 7, 2024
  4. 3/5 t-reftable-readwrite: use 'for' in place of infinite 'while' loopsChandra Pratap, Aug 7, 2024
  5. 4/5 t-reftable-readwrite: add test for known errorChandra Pratap, Aug 7, 2024
  6. 5/5 t-reftable-readwrite: add tests for print functionsChandra Pratap, Aug 7, 2024
  7. Patrick SteinhardtAug 8, 2024
  8. Patrick SteinhardtAug 8, 2024
  9. Chandra PratapAug 8, 2024
  10. Junio C HamanoAug 9, 2024
  11. [GSoC][PATCH v2 0/4] t: port reftable/readwrite_test.c to the unit testing frameworkChandra Pratap, Aug 9, 2024
  12. 1/4 t: move reftable/readwrite_test.c to the unit testing frameworkChandra Pratap, Aug 9, 2024
  13. Junio C HamanoAug 9, 2024
  14. Chandra PratapAug 12, 2024
  15. 2/4 t-reftable-readwrite: use free_names() instead of a for loopChandra Pratap, Aug 9, 2024
  16. Junio C HamanoAug 9, 2024
  17. Chandra PratapAug 10, 2024
  18. Junio C HamanoAug 10, 2024
  19. 3/4 t-reftable-readwrite: use 'for' in place of infinite 'while' loopsChandra Pratap, Aug 9, 2024
  20. Junio C HamanoAug 9, 2024
  21. 4/4 t-reftable-readwrite: add test for known errorChandra Pratap, Aug 9, 2024
  22. [GSoC][PATCH v3 0/4] t: port reftable/readwrite_test.c to the unit testing frameworkChandra Pratap, Aug 13, 2024
  23. 1/4 t: move reftable/readwrite_test.c to the unit testing frameworkChandra Pratap, Aug 13, 2024
  24. Josh SteadmonAug 13, 2024
  25. Chandra PratapAug 14, 2024
  26. Patrick SteinhardtAug 14, 2024
  27. 2/4 t-reftable-readwrite: use free_names() instead of a for loopChandra Pratap, Aug 13, 2024
  28. 3/4 t-reftable-readwrite: use 'for' in place of infinite 'while' loopsChandra Pratap, Aug 13, 2024
  29. 4/4 t-reftable-readwrite: add test for known errorChandra Pratap, Aug 13, 2024
  30. Junio C HamanoAug 13, 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.