Skip to content

ListDeinit

Description

Release a list’s nodes and zero its handle. Calls any configured copy_deinit hook on each live element before freeing storage.

Parameters

Name Direction Description
l in,out Pointer to a List(T) handle.

Success

Returns to the caller. The handle is zeroed; all node storage reclaimed through the configured allocator.

Failure

ValidateList aborts via LOG_FATAL when l is NULL or uninitialised.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    void deinit_int_list(IntList *list) {
        ListDeinit(list);
    }
    
                ListMergeR(list, &temp);
                ListDeinit(&temp); // Clean up temp to prevent memory leak
                break;
            }
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {60, 80, 40, 10, 30, 20, 50, 90, 70}, 9);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && (arr[0] == 0) && (arr[1] == 0) && (arr[2] == 0);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && (arr[0] == 4) && (arr[1] == 5) && (arr[2] == 6);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && list_matches(GENERIC_LIST(&list), (const int[]) {1007, 1007, 1008, 1009}, 4);
    
        ListDeinit(&list);
        result = result && (g_copy_deinit_count == 4);
        DefaultAllocatorDeinit(&alloc);
        result = result && list_matches(GENERIC_LIST(&src), (const int[]) {1005}, 1);
    
        ListDeinit(&dest);
        ListDeinit(&src);
        result = result && (g_copy_deinit_count == 1);
    
        ListDeinit(&dest);
        ListDeinit(&src);
        result = result && (g_copy_deinit_count == 1);
        DefaultAllocatorDeinit(&alloc);
        result      = result && (ListLen(&src_a) == 0) && (ListHead(&src_a) == NULL) && (ListTail(&src_a) == NULL);
    
        ListDeinit(&dest_l);
        ListDeinit(&src_l);
        ListDeinit(&dest_r);
    
        ListDeinit(&dest_l);
        ListDeinit(&src_l);
        ListDeinit(&dest_r);
        ListDeinit(&src_r);
        ListDeinit(&dest_l);
        ListDeinit(&src_l);
        ListDeinit(&dest_r);
        ListDeinit(&src_r);
        ListDeinit(&dest_a);
        ListDeinit(&src_l);
        ListDeinit(&dest_r);
        ListDeinit(&src_r);
        ListDeinit(&dest_a);
        ListDeinit(&src_a);
        ListDeinit(&dest_r);
        ListDeinit(&src_r);
        ListDeinit(&dest_a);
        ListDeinit(&src_a);
        DefaultAllocatorDeinit(&alloc);
        ListDeinit(&src_r);
        ListDeinit(&dest_a);
        ListDeinit(&src_a);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && (ListLen(&empty_dest) == 0) && (ListLen(&empty_src) == 0);
    
        ListDeinit(&deep_dest);
        ListDeinit(&shallow_src);
        ListDeinit(&empty_dest);
    
        ListDeinit(&deep_dest);
        ListDeinit(&shallow_src);
        ListDeinit(&empty_dest);
        ListDeinit(&empty_src);
        ListDeinit(&deep_dest);
        ListDeinit(&shallow_src);
        ListDeinit(&empty_dest);
        ListDeinit(&empty_src);
        result = result && (g_copy_deinit_count == 2);
        ListDeinit(&shallow_src);
        ListDeinit(&empty_dest);
        ListDeinit(&empty_src);
        result = result && (g_copy_deinit_count == 2);
        DefaultAllocatorDeinit(&alloc);
        result      = result && (ListAt(&list, 2) == 9);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
    
        s_copy_fail_at = UINT64_MAX;
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && ListTail(&list) && ListNodeData(ListTail(&list)) && (*ListNodeData(ListTail(&list)) == 30);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && ListTail(&list) && ListNodeData(ListTail(&list)) && (*ListNodeData(ListTail(&list)) == 4);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && (ListLen(&list) == 0) && (ListHead(&list) == NULL) && (ListTail(&list) == NULL);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && list_matches(GENERIC_LIST(&list), (const int[]) {4}, 1);
    
        ListDeinit(&list);
        result = result && (g_copy_deinit_count == 1);
        DefaultAllocatorDeinit(&alloc);
        bool result = got && (node_value(got) == 80);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool result = true;
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        // Unreachable on real code (LOG_FATAL longjmps out). If the mutant
        // swallows the guard we fall through here; clean up and return.
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return true;
        result = result && (ListCopyInit(&list_d) == tracked_copy_init) && (ListCopyDeinit(&list_d) == tracked_copy_deinit);
    
        ListDeinit(&list_a);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
    
        ListDeinit(&list_a);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
        ListDeinit(&list_d);
        ListDeinit(&list_a);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
        ListDeinit(&list_d);
        DefaultAllocatorDeinit(&alloc);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
        ListDeinit(&list_d);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && (ListCopyInit(&list_c) == tracked_copy_init) && (ListCopyDeinit(&list_d) == tracked_copy_deinit);
    
        ListDeinit(&list_a);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
    
        ListDeinit(&list_a);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
        ListDeinit(&list_d);
        ListDeinit(&list_a);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
        ListDeinit(&list_d);
        DefaultAllocatorDeinit(&alloc);
        ListDeinit(&list_b);
        ListDeinit(&list_c);
        ListDeinit(&list_d);
        DefaultAllocatorDeinit(&alloc);
        return result;
    
    static bool test_list_deinit_with_deep_copy(void) {
        WriteFmt("Testing ListDeinit with deep copy\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        result      = result && (ListAt(&list, 1) == 1009);
    
        ListDeinit(&list);
    
        result = result && (g_copy_deinit_count == 2);
                      (ListCopyDeinit(&list) == NULL) && (ListLen(&list) == 0) && MAGIC_MATCHES(list.__magic, LIST_MAGIC);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {9}, 1);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {4, 3, 2, 2, 1}, 5);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && list_matches(GENERIC_LIST(&singleton), (const int[]) {42}, 1);
    
        ListDeinit(&empty);
        ListDeinit(&singleton);
        DefaultAllocatorDeinit(&alloc);
    
        ListDeinit(&empty);
        ListDeinit(&singleton);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {9}, 1);
    
        ListDeinit(&list);
        result = result && (g_copy_deinit_count == 3);
        DefaultAllocatorDeinit(&alloc);
        result      = result && (ListAt(&list, 1) == 2);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
    
        s_copy_fail_at = UINT64_MAX;
        ListDeinit(&dst);
        ListDeinit(&src);
        DefaultAllocatorDeinit(&alloc);
        s_copy_fail_at = UINT64_MAX;
        ListDeinit(&dst);
        ListDeinit(&src);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 20, 30, 40, 50}, 5);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 20, 30, 40, 50}, 5);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 20, 30, 40, 50}, 5);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 20, 30, 40, 50}, 5);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result      = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 20, 30, 40, 50}, 5);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        }
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return count == 0;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {30}, 1);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 40, 30, 20}, 4);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && (ListNodePrev(null_node) == NULL);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && (ListFind(&list, &missing, compare_ints) == SIZE_MAX);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool result = (jumped_idx == 95) && (jumped_value == 95);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool result = got && (node_value(got) == 50);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool result = got && (node_value(got) == 30);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool result = got && (node_value(got) == 50);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool result = got && got->data && (*(int *)got->data == 30);
    
        ListDeinit(&list);
        return result;
    }
        bool result = got && got->data && (*(int *)got->data == 40);
    
        ListDeinit(&list);
        return result;
    }
        }
    
        ListDeinit(&list);
        return result;
    }
        bool             result = node && node->data && (*(int *)node->data == 30);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        bool             result = node && node->data && (*(int *)node->data == 40);
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
        result = result && (head_via_back == GENERIC_LIST_NODE(ListNodeBegin(&list)));
    
        ListDeinit(&list);
        DefaultAllocatorDeinit(&alloc);
        return result;
            (void)i;
        }
        ListDeinit(&li);
        DefaultAllocatorDeinit(&alloc);
Last updated on