return p_malloc(default_pool, size);
}
-void i_free(void *mem)
-{
- p_free(default_pool, mem);
-}
-
void *i_realloc(void *mem, size_t old_size, size_t new_size)
{
return p_realloc(default_pool, mem, old_size, new_size);
/* For easy allocation of memory from default memory pool. */
#define i_new(type, count) \
((type *) i_malloc(sizeof(type) * (count)))
+
void *i_malloc(size_t size);
-void i_free(void *mem);
void *i_realloc(void *mem, size_t old_size, size_t new_size);
+#define i_free(mem) \
+ STMT_START { \
+ p_free(default_pool, mem); \
+ (mem) = NULL; \
+ } STMT_END
+
/* string functions */
char *i_strdup(const char *str);
char *i_strdup_empty(const char *str); /* like i_strdup(), but if str == "", return NULL */
/* Pools should be used through these macros: */
#define pool_get_name(pool) (pool)->get_name(pool)
#define pool_ref(pool) (pool)->ref(pool)
-#define pool_unref(pool) (pool)->unref(pool)
+#define pool_unref(pool) \
+ STMT_START { \
+ (pool)->unref(pool); \
+ (pool) = NULL; \
+ } STMT_END
+
+#define p_new(pool, type, count) \
+ ((type *) p_malloc(pool, sizeof(type) * (count)))
#define p_malloc(pool, size) (pool)->malloc(pool, size)
#define p_realloc(pool, mem, old_size, new_size) \
(pool)->realloc(pool, mem, old_size, new_size)
-#define p_free(pool, mem) (pool)->free(pool, mem)
-
-#define p_clear(pool) (pool)->clear(pool)
-
-/* Extra macros to make life easier: */
-#define p_new(pool, type, count) \
- ((type *) p_malloc(pool, sizeof(type) * (count)))
-#define p_free_and_null(pool, rec) \
+#define p_free(pool, mem) \
STMT_START { \
- p_free(pool, rec); \
- (rec) = NULL; \
+ (pool)->free(pool, mem); \
+ (mem) = NULL; \
} STMT_END
+#define p_clear(pool) (pool)->clear(pool)
+
#endif