summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-22 17:47:51 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-22 17:47:51 +0200
commitad4999488eadac3a10de99caf50b732af8b771b9 (patch)
treed3ffbbc2830b4bf2b520ae6b734d1c188d465be9 /src
parent35a18b1dea21f006b38694dcf5c99f817411ad4d (diff)
downloadfastd-ad4999488eadac3a10de99caf50b732af8b771b9.tar
fastd-ad4999488eadac3a10de99caf50b732af8b771b9.zip
Remove VECTOR_ALLOC
It is done automatically now if the VECTOR is zeroed before.
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c4
-rw-r--r--src/peer.c2
-rw-r--r--src/peer_hashtable.c6
-rw-r--r--src/poll.c2
-rw-r--r--src/shell.c5
-rw-r--r--src/vector.c21
-rw-r--r--src/vector.h11
7 files changed, 8 insertions, 43 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 9be4290..589a293 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -533,10 +533,6 @@ static inline void init(int argc, char *argv[]) {
ctx.next_maintenance = fastd_in_seconds(MAINTENANCE_INTERVAL);
ctx.unknown_handshakes[0].timeout = ctx.now;
- VECTOR_ALLOC(ctx.eth_addrs, 0);
- VECTOR_ALLOC(ctx.peers, 0);
- VECTOR_ALLOC(ctx.async_pids, 0);
-
#ifdef WITH_DYNAMIC_PEERS
fastd_sem_init(&ctx.verify_limit, VERIFY_LIMIT);
#endif
diff --git a/src/peer.c b/src/peer.c
index 19b10d8..1ae7b3c 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -729,8 +729,6 @@ fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf) {
if (peer_conf) {
peer->config = peer_conf;
- VECTOR_ALLOC(peer->remotes, 0);
-
fastd_remote_config_t *remote_config;
for (remote_config = peer_conf->remotes; remote_config; remote_config = remote_config->next) {
fastd_remote_t remote = {.config = remote_config};
diff --git a/src/peer_hashtable.c b/src/peer_hashtable.c
index b835ea9..321b0d5 100644
--- a/src/peer_hashtable.c
+++ b/src/peer_hashtable.c
@@ -44,11 +44,7 @@
void fastd_peer_hashtable_init(void) {
fastd_random_bytes(&ctx.peer_addr_ht_seed, sizeof(ctx.peer_addr_ht_seed), false);
- ctx.peer_addr_ht = fastd_new_array(PEER_ADDR_HT_SIZE, __typeof__(*ctx.peer_addr_ht));
-
- size_t i;
- for (i = 0; i < PEER_ADDR_HT_SIZE; i++)
- VECTOR_ALLOC(ctx.peer_addr_ht[i], 0);
+ ctx.peer_addr_ht = fastd_new0_array(PEER_ADDR_HT_SIZE, __typeof__(*ctx.peer_addr_ht));
}
/** Frees the resources used by the hashtable */
diff --git a/src/poll.c b/src/poll.c
index a0b41ba..3f94379 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -180,7 +180,7 @@ void fastd_poll_handle(void) {
#else
void fastd_poll_init(void) {
- VECTOR_ALLOC(ctx.pollfds, 2 + ctx.n_socks);
+ VECTOR_RESIZE(ctx.pollfds, 2 + ctx.n_socks);
VECTOR_INDEX(ctx.pollfds, 0) = (struct pollfd) {
.fd = -1,
diff --git a/src/shell.c b/src/shell.c
index 87aa320..19dc6e5 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -54,10 +54,7 @@ struct fastd_shell_env {
/** Allocated a new shell environment */
fastd_shell_env_t * fastd_shell_env_alloc(void) {
- fastd_shell_env_t *env = fastd_new(fastd_shell_env_t);
- VECTOR_ALLOC(env->entries, 0);
-
- return env;
+ return fastd_new0(fastd_shell_env_t);
}
/** Sets a variable in a shell environment */
diff --git a/src/vector.c b/src/vector.c
index 04dd934..054470e 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -41,22 +41,6 @@
/**
- Allocates a new vector
-
- Internal function, use VECTOR_ALLOC() instead.
-*/
-void _fastd_vector_alloc(fastd_vector_desc_t *desc, void **data, size_t n, size_t elemsize) {
- desc->allocated = MIN_VECTOR_ALLOC;
-
- while (desc->allocated < n*3/2)
- desc->allocated <<= 1;
-
- desc->length = n;
-
- *data = fastd_alloc(desc->allocated * elemsize);
-}
-
-/**
Resizes a vector
Vector allocations are always powers of 2.
@@ -68,6 +52,11 @@ void _fastd_vector_resize(fastd_vector_desc_t *desc, void **data, size_t n, size
size_t alloc = desc->allocated;
+ if (!alloc) {
+ alloc = MIN_VECTOR_ALLOC;
+ n = n*3/2;
+ }
+
while (alloc < n)
alloc <<= 1;
while (alloc > n*3 && alloc > MIN_VECTOR_ALLOC)
diff --git a/src/vector.h b/src/vector.h
index 0571d4d..8b60f4a 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -55,23 +55,12 @@ typedef struct fastd_vector_desc {
-void _fastd_vector_alloc(fastd_vector_desc_t *desc, void **data, size_t n, size_t elemsize);
void _fastd_vector_resize(fastd_vector_desc_t *desc, void **data, size_t n, size_t elemsize);
void _fastd_vector_insert(fastd_vector_desc_t *desc, void **data, void *element, size_t pos, size_t elemsize);
void _fastd_vector_delete(fastd_vector_desc_t *desc, void **data, size_t pos, size_t elemsize);
/**
- Allocates resources for the vector \e a, starting with \e n elements
-
- \hideinitializer
-*/
-#define VECTOR_ALLOC(v, n) ({ \
- __typeof__(v) *_v = &(v); \
- _fastd_vector_alloc(&_v->desc, (void**)&_v->data, (n), sizeof(*_v->data)); \
- })
-
-/**
Resizes the vector \e a to \e n elements
\hideinitializer