Browse Source

hashmap_put takes "struct hashmap_entry *"

This is less error-prone than "void *" as the compiler now
detects invalid types being passed.

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Eric Wong 5 years ago committed by Junio C Hamano
parent
commit
26b455f21e
  1. 2
      builtin/fast-export.c
  2. 2
      hashmap.c
  3. 2
      hashmap.h
  4. 4
      merge-recursive.c
  5. 2
      oidmap.c
  6. 5
      refs.c
  7. 2
      remote.c
  8. 2
      revision.c
  9. 2
      sequencer.c
  10. 2
      submodule-config.c
  11. 2
      t/helper/test-hashmap.c

2
builtin/fast-export.c

@ -160,7 +160,7 @@ static const void *anonymize_mem(struct hashmap *map, @@ -160,7 +160,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;

2
hashmap.c

@ -241,7 +241,7 @@ void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key, @@ -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);

2
hashmap.h

@ -340,7 +340,7 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry); @@ -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

4
merge-recursive.c

@ -2229,7 +2229,7 @@ static struct hashmap *get_directory_renames(struct diff_queue_struct *pairs) @@ -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, @@ -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);

2
oidmap.c

@ -51,5 +51,5 @@ void *oidmap_put(struct oidmap *map, void *entry) @@ -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);
}

5
refs.c

@ -1863,10 +1863,13 @@ static void register_ref_store_map(struct hashmap *map, @@ -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);
}


2
remote.c

@ -159,7 +159,7 @@ static struct remote *make_remote(const char *name, int len) @@ -159,7 +159,7 @@ static struct remote *make_remote(const char *name, int len)
remotes[remotes_nr++] = ret;

hashmap_entry_init(&ret->ent, lookup_entry.hash);
replaced = hashmap_put(&remotes_hash, ret);
replaced = hashmap_put(&remotes_hash, &ret->ent);
assert(replaced == NULL); /* no previous entry overwritten */
return ret;
}

2
revision.c

@ -153,7 +153,7 @@ static void paths_and_oids_insert(struct hashmap *map, @@ -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);

2
sequencer.c

@ -5254,7 +5254,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) @@ -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);
}
}


2
submodule-config.c

@ -125,7 +125,7 @@ static void cache_put_path(struct submodule_cache *cache, @@ -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,

2
t/helper/test-hashmap.c

@ -187,7 +187,7 @@ int cmd__hashmap(int argc, const char **argv) @@ -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");

Loading…
Cancel
Save