change kv-list destructor strategy to only use the list destructors default tip

Wed, 10 Sep 2025 19:15:58 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 10 Sep 2025 19:15:58 +0200
changeset 1368
19025ca34caa
parent 1367
6b3d52dd176e

change kv-list destructor strategy to only use the list destructors

relates to #461

src/kv_list.c file | annotate | diff | comparison | revisions
--- a/src/kv_list.c	Tue Sep 09 22:30:18 2025 +0200
+++ b/src/kv_list.c	Wed Sep 10 19:15:58 2025 +0200
@@ -107,11 +107,11 @@
         list->map_destr = list->map->map_base.base.collection.simple_destructor;
         list->map->map_base.base.collection.simple_destructor = NULL;
     }
-    if (list->map->map_base.base.collection.advanced_destructor != cx_kv_list_destructor_wrapper_map) {
+    if (list->map->map_base.base.collection.advanced_destructor != NULL) {
         list->map_destr2 = list->map->map_base.base.collection.advanced_destructor;
         list->map_destr_data = list->map->map_base.base.collection.destructor_data;
-        list->map->map_base.base.collection.advanced_destructor = cx_kv_list_destructor_wrapper_map;
-        list->map->map_base.base.collection.destructor_data = list;
+        list->map->map_base.base.collection.advanced_destructor = NULL;
+        list->map->map_base.base.collection.destructor_data = NULL;
     }
 }
 
@@ -119,8 +119,6 @@
     cx_kv_list *kv_list = (cx_kv_list*)list;
     // patch the destructors
     cx_kv_list_update_destructors(kv_list);
-    // free the map first, but skip the destructors of the map
-    cxDefineAdvancedDestructor(&kv_list->map->map_base.base, NULL, NULL);
     kv_list->map_methods->deallocate(&kv_list->map->map_base.base);
     // then free the list, now the destructors may be called
     kv_list->list_methods->deallocate(list);
@@ -185,9 +183,7 @@
 static void cx_kvl_clear(struct cx_list_s *list) {
     cx_kv_list *kv_list = (cx_kv_list*)list;
     // patch the destructors
-    // but remove the wrapper from the map to avoid calling it twice
     cx_kv_list_update_destructors(kv_list);
-    cxDefineAdvancedDestructor(&kv_list->map->map_base.base, NULL, NULL);
     // clear the list
     kv_list->list_methods->clear(list);
     // then clear the map
@@ -251,7 +247,7 @@
 static void cx_kvl_map_clear(struct cx_map_s *map) {
     cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list;
     cx_kv_list_update_destructors(kv_list);
-    // TODO: iterate through the map elements, unlink them from the list, and free them
+    kv_list->list_methods->clear(&kv_list->list.base);
     kv_list->map_methods->clear(map);
 }
 

mercurial