git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Abhishek Kumar <abhishekkumar8222@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] oidmap: make oidmap_free independent of struct layout
Date: Tue, 07 Apr 2020 23:02:32 -0700	[thread overview]
Message-ID: <xmqqr1wyplaf.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200408040659.14511-1-abhishekkumar8222@gmail.com> (Abhishek Kumar's message of "Wed, 8 Apr 2020 09:36:58 +0530")

Abhishek Kumar <abhishekkumar8222@gmail.com> writes:

> c8e424c introduced hashmap_free_entries, which can free any struct
> pointer, regardless of the hashmap_entry field offset.

    c8e424c9 (hashmap: introduce hashmap_free_entries, 2019-10-06)
    introduced hashmap_free_entries(), which ...

is how we refer to existing commits and functions.

> oidmap does not make use of this flexibilty, hardcoding the offset to
> zero instead. Let's fix this by passing struct type and member to
> hashmap_free_entries.

Makes sense.

> Additionally, removes an erroneous semi-colon at the end of
> hashmap_free_entries macro.

s/removes/remove/

Good eyes.  Of course, your if/else would have broken without this
fix ;-)

Looking good.  Thanks.

> Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com>
> ---
>  hashmap.h | 2 +-
>  oidmap.c  | 6 ++++--
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/hashmap.h b/hashmap.h
> index 79ae9f80de..6d0a65a39f 100644
> --- a/hashmap.h
> +++ b/hashmap.h
> @@ -245,7 +245,7 @@ void hashmap_free_(struct hashmap *map, ssize_t offset);
>   * where @member is the hashmap_entry struct used to associate with @map
>   */
>  #define hashmap_free_entries(map, type, member) \
> -	hashmap_free_(map, offsetof(type, member));
> +	hashmap_free_(map, offsetof(type, member))
>  
>  /* hashmap_entry functions */
>  
> diff --git a/oidmap.c b/oidmap.c
> index 423aa014a3..65d63787a8 100644
> --- a/oidmap.c
> +++ b/oidmap.c
> @@ -26,8 +26,10 @@ void oidmap_free(struct oidmap *map, int free_entries)
>  	if (!map)
>  		return;
>  
> -	/* TODO: make oidmap itself not depend on struct layouts */
> -	hashmap_free_(&map->map, free_entries ? 0 : -1);
> +	if (free_entries)
> +		hashmap_free_entries(&map->map, struct oidmap_entry, internal_entry);
> +	else
> +		hashmap_free(&map->map);
>  }
>  
>  void *oidmap_get(const struct oidmap *map, const struct object_id *key)

  parent reply	other threads:[~2020-04-08  6:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08  4:06 [PATCH 1/2] oidmap: make oidmap_free independent of struct layout Abhishek Kumar
2020-04-08  4:06 ` [PATCH 2/2] oidmap: rework iterators to return typed pointer Abhishek Kumar
2020-04-08  6:02 ` Junio C Hamano [this message]
2020-04-08  7:03 ` [PATCH v2 1/2] oidmap: make oidmap_free independent of struct layout Abhishek Kumar
2020-04-08  7:03   ` [PATCH v2 2/2] oidmap: rework iterators to return typed pointer Abhishek Kumar
2020-04-08 22:08     ` Jeff King
2020-04-08 21:54 ` [PATCH 1/2] oidmap: make oidmap_free independent of struct layout Jeff King
2020-04-25  2:59 ` [PATCH v3 1/3] " Abhishek Kumar
2020-04-25  2:59   ` [PATCH v3 2/3] oidmap: rework iterators to return typed pointer Abhishek Kumar
2020-04-25  2:59   ` [PATCH v3 3/3] oidmap: return oidmap_entry pointers Abhishek Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqr1wyplaf.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=abhishekkumar8222@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).