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

Re: [PATCH 2/2] string-list API users: manually use string_list_init_*()

From
Elijah Newren <newren@gmail.com>
Date
Jul 21, 2022, 07:48 UTC
Message-ID
<CABPp-BFiNXM_2kfOQ+BnC5bWVEVZTk2kiFNuPSPPsz+5owM9kA@mail.gmail.com>
In-Reply-To
<patch-2.2-5d8baa9cbc4-20220721T063543Z-avarab@gmail.com>

On Wed, Jul 20, 2022 at 11:39 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 7 quoted lines
>
> Convert various code that didn't use string_list_init_*() to do so, in
> cases where the only thing being allocated was the string list we can
> change from CALLOC_ARRAY() to ALLOC_ARRAY(), the string_list_init_*()
> function will zero out the memory.
>
> This covers cases that weren't matched by tho coccinelle rule in the
s/tho/the/ ?
Show 21 quoted lines
> preceding commit, which is conservative enough to care about the type
> of what we're modifying.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  notes-utils.c | 4 ++--
>  reflog-walk.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/notes-utils.c b/notes-utils.c
> index d7d18e30f5a..73559d24ec8 100644
> --- a/notes-utils.c
> +++ b/notes-utils.c
> @@ -129,8 +129,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
>         c->cmd = cmd;
>         c->enabled = 1;
>         c->combine = combine_notes_concatenate;
> -       CALLOC_ARRAY(c->refs, 1);
> -       c->refs->strdup_strings = 1;
> +       ALLOC_ARRAY(c->refs, 1);
> +       string_list_init_dup(c->refs);

But c->refs is a struct string_list *; why doesn't cocci recognize this one and convert it?

Show 13 quoted lines
>         c->refs_from_env = 0;
>         c->mode_from_env = 0;
>         if (rewrite_mode_env) {
> diff --git a/reflog-walk.c b/reflog-walk.c
> index 7aa6595a51f..2b17408f9a4 100644
> --- a/reflog-walk.c
> +++ b/reflog-walk.c
> @@ -120,7 +120,7 @@ struct reflog_walk_info {
>  void init_reflog_walk(struct reflog_walk_info **info)
>  {
>         CALLOC_ARRAY(*info, 1);
> -       (*info)->complete_reflogs.strdup_strings = 1;
> +       string_list_init_dup(&((*info)->complete_reflogs));
Makes sense.
Show 6 quoted lines
>  }
>
>  void reflog_walk_info_release(struct reflog_walk_info *info)
> --
> 2.37.1.1095.g64a1e8362fd
>
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 4 of 11 in “string_list API users: use alloc + init, not calloc + strdup_strings”
  1. 0/2 string_list API users: use alloc + init, not calloc + strdup_stringsÆvar Arnfjörð Bjarmason, Jul 21, 2022
  2. 1/2 string_list API users + cocci: use string_list_init_dup()Ævar Arnfjörð Bjarmason, Jul 21, 2022
  3. 2/2 string-list API users: manually use string_list_init_*()Ævar Arnfjörð Bjarmason, Jul 21, 2022
  4. Elijah NewrenJul 21, 2022
  5. 0/6 string-list API user: fix API use, some with coccinelleÆvar Arnfjörð Bjarmason, Jul 21, 2022
  6. 1/6 string_list API users + cocci: use string_list_init_dup()Ævar Arnfjörð Bjarmason, Jul 21, 2022
  7. 2/6 cocci: apply string_list.cocci with --disable-worth-trying-optÆvar Arnfjörð Bjarmason, Jul 21, 2022
  8. 3/6 reflog-walk.c: use string_list_init_dup()Ævar Arnfjörð Bjarmason, Jul 21, 2022
  9. 5/6 string-list API users: don't tweak "strdup_strings" to free dupesÆvar Arnfjörð Bjarmason, Jul 21, 2022
  10. 4/6 cocci: add "string_list" rule to swap "DUP" <-> "NODUP"Ævar Arnfjörð Bjarmason, Jul 21, 2022
  11. 6/6 notes.c: make "struct string_list display_notes_refs" non-staticÆvar Arnfjörð Bjarmason, Jul 21, 2022

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.