|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
From 270eaf14c4905a9635bd1d009cb1565cd4f3626f Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
From: Lennart Poettering <lennart@poettering.net>
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
Date: Mon, 22 Feb 2016 18:40:28 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
Subject: [PATCH] hashmap: use void* and uint8_t* for generic pointers
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
As suggested by CODING_STYLE we should use "void*" as type for generic memory,
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
and uint8_t* for generic bytes. Hence use that instead of "char*", which should
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
really be used only for strings these days.
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
(cherry picked from commit 1a39bc8c650802630696c38e510a4a2a4c6bda92)
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
src/basic/hashmap.c | 14 +++++++-------
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
1 file changed, 7 insertions(+), 7 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
index 6f1a049d47..85b8d812b3 100644
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
--- a/src/basic/hashmap.c
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+++ b/src/basic/hashmap.c
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -176,7 +176,7 @@ enum HashmapType {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
};
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
struct _packed_ indirect_storage {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
- char *storage; /* where buckets and DIBs are stored */
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+ void *storage; /* where buckets and DIBs are stored */
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
uint8_t hash_key[HASH_KEY_SIZE]; /* hash key; changes during resize */
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
unsigned n_entries; /* number of stored entries */
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -193,7 +193,7 @@ struct direct_storage {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
/* This gives us 39 bytes on 64bit, or 35 bytes on 32bit.
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
* That's room for 4 set_entries + 4 DIB bytes + 3 unused bytes on 64bit,
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
* or 7 set_entries + 7 DIB bytes + 0 unused bytes on 32bit. */
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
- char storage[sizeof(struct indirect_storage)];
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+ uint8_t storage[sizeof(struct indirect_storage)];
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
};
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
#define DIRECT_BUCKETS(entry_t) \
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -302,7 +302,7 @@ static void n_entries_dec(HashmapBase *h) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
h->n_direct_entries--;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
-static char *storage_ptr(HashmapBase *h) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+static void *storage_ptr(HashmapBase *h) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
return h->has_indirect ? h->indirect.storage
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
: h->direct.storage;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -347,7 +347,7 @@ static void get_hash_key(uint8_t hash_key[HASH_KEY_SIZE], bool reuse_is_ok) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
static struct hashmap_base_entry *bucket_at(HashmapBase *h, unsigned idx) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
return (struct hashmap_base_entry*)
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
- (storage_ptr(h) + idx * hashmap_type_info[h->type].entry_size);
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+ ((uint8_t*) storage_ptr(h) + idx * hashmap_type_info[h->type].entry_size);
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
static struct plain_hashmap_entry *plain_bucket_at(Hashmap *h, unsigned idx) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -381,7 +381,7 @@ static struct hashmap_base_entry *bucket_at_virtual(HashmapBase *h, struct swap_
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
static dib_raw_t *dib_raw_ptr(HashmapBase *h) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
return (dib_raw_t*)
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
- (storage_ptr(h) + hashmap_type_info[h->type].entry_size * n_buckets(h));
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+ ((uint8_t*) storage_ptr(h) + hashmap_type_info[h->type].entry_size * n_buckets(h));
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
static unsigned bucket_distance(HashmapBase *h, unsigned idx, unsigned from) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -1028,7 +1028,7 @@ static int hashmap_base_put_boldly(HashmapBase *h, unsigned idx,
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
*/
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
static int resize_buckets(HashmapBase *h, unsigned entries_add) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
struct swap_entries swap;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
- char *new_storage;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+ void *new_storage;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
dib_raw_t *old_dibs, *new_dibs;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
const struct hashmap_type_info *hi;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
unsigned idx, optimal_idx;
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
@@ -1095,7 +1095,7 @@ static int resize_buckets(HashmapBase *h, unsigned entries_add) {
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
h->indirect.n_buckets = (1U << new_shift) /
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
(hi->entry_size + sizeof(dib_raw_t));
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
- old_dibs = (dib_raw_t*)(new_storage + hi->entry_size * old_n_buckets);
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
+ old_dibs = (dib_raw_t*)((uint8_t*) new_storage + hi->entry_size * old_n_buckets);
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
new_dibs = dib_raw_ptr(h);
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
|
|
Zbigniew Jędrzejewski-Szmek |
2b6823 |
/*
|