dovecot-2.2: lib: Changed mempool.h to use inline functions inst...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jun 16 14:43:57 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/5de6a5f241db
changeset: 17501:5de6a5f241db
user: Timo Sirainen <tss at iki.fi>
date: Mon Jun 16 17:40:51 2014 +0300
description:
lib: Changed mempool.h to use inline functions instead of macros.
This way we can also mark p_malloc() with ATTR_MALLOC.
diffstat:
src/lib/mempool.h | 51 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 39 insertions(+), 12 deletions(-)
diffs (78 lines):
diff -r 24659b98b271 -r 5de6a5f241db src/lib/mempool.h
--- a/src/lib/mempool.h Mon Jun 16 16:27:12 2014 +0300
+++ b/src/lib/mempool.h Mon Jun 16 17:40:51 2014 +0300
@@ -68,17 +68,19 @@
old_size + 1. */
size_t pool_get_exp_grown_size(pool_t pool, size_t old_size, size_t min_size);
-/* Pools should be used through these macros: */
-#define pool_get_name(pool) (pool)->v->get_name(pool)
-#define pool_ref(pool) (pool)->v->ref(pool)
-#define pool_unref(pool) ((*pool))->v->unref(pool)
-
#define p_new(pool, type, count) \
((type *) p_malloc(pool, sizeof(type) * (count)))
+static inline void * ATTR_MALLOC
+p_malloc(pool_t pool, size_t size)
+{
+ return pool->v->malloc(pool, size);
+}
-#define p_malloc(pool, size) (pool)->v->malloc(pool, size)
-#define p_realloc(pool, mem, old_size, new_size) \
- (pool)->v->realloc(pool, mem, old_size, new_size)
+static inline void * ATTR_WARN_UNUSED_RESULT
+p_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size)
+{
+ return pool->v->realloc(pool, mem, old_size, new_size);
+}
/* Free the memory. Currently it also sets memory to NULL, but that shouldn't
be relied on as it's only an extra safety check. It might as well be later
@@ -86,17 +88,42 @@
in some "optimization".. */
#define p_free(pool, mem) \
STMT_START { \
- (pool)->v->free(pool, mem); \
+ p_free_internal(pool, mem); \
(mem) = NULL; \
} STMT_END
/* A macro that's guaranteed to set mem = NULL. */
#define p_free_and_null(pool, mem) p_free(pool, mem)
-#define p_clear(pool) (pool)->v->clear(pool)
+static inline void p_free_internal(pool_t pool, void *mem)
+{
+ pool->v->free(pool, mem);
+}
-#define p_get_max_easy_alloc_size(pool) \
- (pool)->v->get_max_easy_alloc_size(pool)
+static inline void p_clear(pool_t pool)
+{
+ pool->v->clear(pool);
+}
+
+static inline size_t p_get_max_easy_alloc_size(pool_t pool)
+{
+ return pool->v->get_max_easy_alloc_size(pool);
+}
+
+static inline const char *pool_get_name(pool_t pool)
+{
+ return pool->v->get_name(pool);
+}
+
+static inline void pool_ref(pool_t pool)
+{
+ pool->v->ref(pool);
+}
+
+static inline void pool_unref(pool_t *pool)
+{
+ (*pool)->v->unref(pool);
+}
/* These functions are only for pools created with pool_alloconly_create(): */
More information about the dovecot-cvs
mailing list