changeset 4633:9de853d23279 HEAD

Added p_free_and_null() and did some cleanups.
author Timo Sirainen <tss@iki.fi>
date Sun, 08 Oct 2006 16:28:56 +0300
parents 35ecfba4ab39
children 5e94f1332189
files src/lib/imem.c src/lib/imem.h src/lib/lib.c src/lib/mempool.h
diffstat 4 files changed, 13 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/imem.c	Mon Sep 25 15:14:50 2006 +0300
+++ b/src/lib/imem.c	Sun Oct 08 16:28:56 2006 +0300
@@ -78,7 +78,3 @@
 {
 	default_pool = system_pool;
 }
-
-void imem_deinit(void)
-{
-}
--- a/src/lib/imem.h	Mon Sep 25 15:14:50 2006 +0300
+++ b/src/lib/imem.h	Sun Oct 08 16:28:56 2006 +0300
@@ -1,27 +1,17 @@
 #ifndef __IMEM_H
 #define __IMEM_H
 
+/* For easy allocation of memory from default memory pool. */
+
 extern pool_t default_pool;
 
-/* For easy allocation of memory from default memory pool. */
-#define i_new(type, count) \
-        ((type *) i_malloc(sizeof(type) * (count)))
+#define i_new(type, count) p_new(default_pool, type, count)
 
 void *i_malloc(size_t size);
 void *i_realloc(void *mem, size_t old_size, size_t new_size);
 
-/* Free the memory. Currently it also sets memory to NULL, but that shouldn't
-   be relied on as it's only extra safety check. It might as well be later
-   changed to some invalid pointer causing segfault, or removed completely
-   in some "optimization".. */
-#define i_free(mem) \
-	STMT_START { \
-          p_free(default_pool, mem); \
-          (mem) = NULL; \
-	} STMT_END
-
-/* A macro that's guaranteed to set mem = NULL. */
-#define i_free_and_null(mem) i_free(mem)
+#define i_free(mem) p_free(default_pool, mem)
+#define i_free_and_null(mem) p_free_and_null(default_pool, mem)
 
 /* string functions */
 char *i_strdup(const char *str);
@@ -34,6 +24,5 @@
 char *i_strconcat(const char *str1, ...); /* NULL terminated */
 
 void imem_init(void);
-void imem_deinit(void);
 
 #endif
--- a/src/lib/lib.c	Mon Sep 25 15:14:50 2006 +0300
+++ b/src/lib/lib.c	Sun Oct 08 16:28:56 2006 +0300
@@ -28,7 +28,6 @@
 
 void lib_deinit(void)
 {
-        imem_deinit();
 	data_stack_deinit();
         failures_deinit();
 }
--- a/src/lib/mempool.h	Mon Sep 25 15:14:50 2006 +0300
+++ b/src/lib/mempool.h	Sun Oct 08 16:28:56 2006 +0300
@@ -66,12 +66,20 @@
 #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)
+
+/* 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
+   changed to some invalid pointer causing a segfault, or removed completely
+   in some "optimization".. */
 #define p_free(pool, mem) \
 	STMT_START { \
           (pool)->free(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)->clear(pool)
 
 #define p_get_max_easy_alloc_size(pool) (pool)->get_max_easy_alloc_size(pool)