From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id A210A1F461 for ; Mon, 26 Aug 2019 02:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729206AbfHZCoA (ORCPT ); Sun, 25 Aug 2019 22:44:00 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:36444 "EHLO dcvr.yhbt.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729202AbfHZCn7 (ORCPT ); Sun, 25 Aug 2019 22:43:59 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2CC8B1F4C0; Mon, 26 Aug 2019 02:43:34 +0000 (UTC) From: Eric Wong To: Junio C Hamano Cc: git@vger.kernel.org Subject: [PATCH 09/11] hashmap_put takes "struct hashmap_entry *" Date: Mon, 26 Aug 2019 02:43:30 +0000 Message-Id: <20190826024332.3403-10-e@80x24.org> In-Reply-To: <20190826024332.3403-1-e@80x24.org> References: <20190826024332.3403-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This is less error-prone than "void *" as the compiler now detects invalid types being passed. Signed-off-by: Eric Wong --- builtin/fast-export.c | 2 +- hashmap.c | 2 +- hashmap.h | 2 +- merge-recursive.c | 4 ++-- oidmap.c | 2 +- refs.c | 5 ++++- remote.c | 2 +- revision.c | 2 +- sequencer.c | 2 +- submodule-config.c | 2 +- t/helper/test-hashmap.c | 2 +- 11 files changed, 15 insertions(+), 12 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 081cdd70c9..654bfce8d5 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -161,7 +161,7 @@ static const void *anonymize_mem(struct hashmap *map, ret->orig_len = *len; ret->anon = generate(orig, len); ret->anon_len = *len; - hashmap_put(map, ret); + hashmap_put(map, &ret->hash); } *len = ret->anon_len; diff --git a/hashmap.c b/hashmap.c index efcb6420fc..2dd9912e13 100644 --- a/hashmap.c +++ b/hashmap.c @@ -241,7 +241,7 @@ void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key, return old; } -void *hashmap_put(struct hashmap *map, void *entry) +void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry) { struct hashmap_entry *old = hashmap_remove(map, entry, NULL); hashmap_add(map, entry); diff --git a/hashmap.h b/hashmap.h index c8d5314667..b62ee2e7b9 100644 --- a/hashmap.h +++ b/hashmap.h @@ -340,7 +340,7 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry); * `entry` is the entry to add or replace. * Returns the replaced entry, or NULL if not found (i.e. the entry was added). */ -void *hashmap_put(struct hashmap *map, void *entry); +void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry); /* * Removes a hashmap entry matching the specified key. If the hashmap contains diff --git a/merge-recursive.c b/merge-recursive.c index f60451d396..a685b4fb69 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -2229,7 +2229,7 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs) if (!entry) { entry = xmalloc(sizeof(*entry)); dir_rename_entry_init(entry, old_dir); - hashmap_put(dir_renames, entry); + hashmap_put(dir_renames, &entry->ent); } else { free(old_dir); } @@ -2360,7 +2360,7 @@ static void compute_collisions(struct hashmap *collisions, sizeof(struct collision_entry)); hashmap_entry_init(&collision_ent->ent, strhash(new_path)); - hashmap_put(collisions, collision_ent); + hashmap_put(collisions, &collision_ent->ent); collision_ent->target_file = new_path; } else { free(new_path); diff --git a/oidmap.c b/oidmap.c index 6d6e840d03..cd22b3a8bf 100644 --- a/oidmap.c +++ b/oidmap.c @@ -51,5 +51,5 @@ void *oidmap_put(struct oidmap *map, void *entry) oidmap_init(map, 0); hashmap_entry_init(&to_put->internal_entry, oidhash(&to_put->oid)); - return hashmap_put(&map->map, to_put); + return hashmap_put(&map->map, &to_put->internal_entry); } diff --git a/refs.c b/refs.c index c43ec59c6e..3e55031256 100644 --- a/refs.c +++ b/refs.c @@ -1863,10 +1863,13 @@ static void register_ref_store_map(struct hashmap *map, struct ref_store *refs, const char *name) { + struct ref_store_hash_entry *entry; + if (!map->tablesize) hashmap_init(map, ref_store_hash_cmp, NULL, 0); - if (hashmap_put(map, alloc_ref_store_hash_entry(name, refs))) + entry = alloc_ref_store_hash_entry(name, refs); + if (hashmap_put(map, &entry->ent)) BUG("%s ref_store '%s' initialized twice", type, name); } diff --git a/remote.c b/remote.c index dc09172e9d..248d60e0ad 100644 --- a/remote.c +++ b/remote.c @@ -161,7 +161,7 @@ static struct remote *make_remote(const char *name, int len) remotes[remotes_nr++] = ret; hashmap_entry_init(&ret->ent, hash); - replaced = hashmap_put(&remotes_hash, ret); + replaced = hashmap_put(&remotes_hash, &ret->ent); assert(replaced == NULL); /* no previous entry overwritten */ return ret; } diff --git a/revision.c b/revision.c index 4336281286..a7e2339064 100644 --- a/revision.c +++ b/revision.c @@ -153,7 +153,7 @@ static void paths_and_oids_insert(struct hashmap *map, hashmap_entry_init(&entry->ent, hash); entry->path = xstrdup(key.path); oidset_init(&entry->trees, 16); - hashmap_put(map, entry); + hashmap_put(map, &entry->ent); } oidset_insert(&entry->trees, oid); diff --git a/sequencer.c b/sequencer.c index ee11cda7e7..b4ef70e260 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5254,7 +5254,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) entry->i = i; hashmap_entry_init(&entry->entry, strhash(entry->subject)); - hashmap_put(&subject2item, entry); + hashmap_put(&subject2item, &entry->entry); } } diff --git a/submodule-config.c b/submodule-config.c index 7486745a6a..9248c5ea5b 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -125,7 +125,7 @@ static void cache_put_path(struct submodule_cache *cache, struct submodule_entry *e = xmalloc(sizeof(*e)); hashmap_entry_init(&e->ent, hash); e->config = submodule; - hashmap_put(&cache->for_path, e); + hashmap_put(&cache->for_path, &e->ent); } static void cache_remove_path(struct submodule_cache *cache, diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index 49e715f1cd..de2bd083b9 100644 --- a/t/helper/test-hashmap.c +++ b/t/helper/test-hashmap.c @@ -187,7 +187,7 @@ int cmd__hashmap(int argc, const char **argv) entry = alloc_test_entry(hash, p1, p2); /* add / replace entry */ - entry = hashmap_put(&map, entry); + entry = hashmap_put(&map, &entry->ent); /* print and free replaced entry, if any */ puts(entry ? get_value(entry) : "NULL"); -- EW