new function list_deep_free
authorMatthias Kramm <kramm@quiss.org>
Sat, 7 Feb 2009 19:53:38 +0000 (20:53 +0100)
committerMatthias Kramm <kramm@quiss.org>
Sat, 7 Feb 2009 19:53:38 +0000 (20:53 +0100)
lib/q.c
lib/q.h

diff --git a/lib/q.c b/lib/q.c
index def25ba..9438033 100644 (file)
--- a/lib/q.c
+++ b/lib/q.c
@@ -604,7 +604,7 @@ char ptr_equals(const void*o1, const void*o2)
 }
 unsigned int ptr_hash(const void*o) 
 {
-    return string_hash3(&o, sizeof(o));
+    return string_hash3((const char*)&o, sizeof(o));
 }
 void* ptr_dup(const void*o) 
 {
@@ -1214,6 +1214,20 @@ void list_free_(void*_list)
     }
     *list = 0;
 }
+void list_deep_free_(void*_list)
+{
+    commonlist_t**list = (commonlist_t**)_list;
+    commonlist_t*l = *list;
+    while(l) {
+        commonlist_t*next = l->next;
+        if(l->entry) {
+            free(l->entry);l->entry=0;
+        }
+        free(l);
+        l = next;
+    }
+    *list = 0;
+}
 void*list_clone_(void*_list) 
 {
     commonlist_t*l = *(commonlist_t**)_list;
diff --git a/lib/q.h b/lib/q.h
index cc965b0..942bf28 100644 (file)
--- a/lib/q.h
+++ b/lib/q.h
@@ -226,12 +226,14 @@ void*list_clone_(void*_list);
 void list_append_(void*_list, void*entry);
 void list_prepend_(void*_list, void*entry);
 void list_free_(void*_list);
+void list_deep_free_(void*_list);
 void list_concat_(void*l1, void*l2);
 #define list_new() ((void*)0)
 #define list_append(list, e) {sizeof((list)->next);list_append_(&(list),(e));}
 #define list_concat(l1, l2) {sizeof((l1)->next);sizeof((l2)->next);list_concat_(&(l1),&(l2));}
 #define list_prepend(list, e) {sizeof((list)->next);list_prepend_(&(list),(e));}
 #define list_free(list) {sizeof((list)->next);list_free_(&(list));}
+#define list_deep_free(list) {sizeof((list)->next);list_deep_free_(&(list));}
 #define list_clone(list) (sizeof((list)->next),list_clone_(&(list)))
 #define list_length(list) (sizeof((list)->next),list_length_(list))