Skip to content

ListPushArrL

Description

Append a contiguous range of elements to the end of the list. L-value form: takes ownership of the source range on success when the list has no copy_init handler.

Parameters

Name Direction Description
l in,out List handle.
arr in Pointer to source array. Must be non-NULL when count > 0.
count in Number of elements to append.

Success

Returns true. count new nodes are linked at the tail of the list; list length grows by count. When the list has no copy_init handler, the count * sizeof(element) source bytes have been zeroed. If a node allocation fails partway through, the already-inserted nodes stay linked (caller may treat the operation as partially complete).

Failure

Returns false on allocation failure during the first node allocation. The list and source are unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
                        values[i] = (i32)extract_u32(data, offset, data_size);
                    }
                    ListPushArrL(list, values, count);
                }
                break;
    
    static bool test_list_push_arr_l_zeroes_all_items(void) {
        WriteFmt("Testing ListPushArrL zeroes all transferred items\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        int     arr[] = {1, 2, 3};
    
        ListPushArrL(&list, arr, 3);
    
        bool result = list_matches(GENERIC_LIST(&list), (const int[]) {1, 2, 3}, 3);
    
    static bool test_list_push_arr_zero_count_is_noop(void) {
        WriteFmt("Testing ListPushArrL zero-count contract\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        ListPushBackR(&list, 1);
        ListPushArrL(&list, arr, 0);
    
        bool result = list_matches(GENERIC_LIST(&list), (const int[]) {1}, 1);
        ListPushBackR(&list, x);
        ListInsertL(&list, x, 1);
        ListPushArrL(&list, arr, 2);
    
        bool result = (g_copy_init_count == 4);
    /// TAGS: List, PushBack, Range, Insert
    ///
    #define ListPushArr(l, arr, count) ListPushArrL((l), (arr), (count))
    
    ///
    #define ListMustPushArrL(l, arr, count)                                                                                \
        do {                                                                                                               \
            if (!ListPushArrL((l), (arr), (count))) {                                                                      \
                LOG_FATAL("ListMustPushArrL failed");                                                                      \
            }                                                                                                              \
Last updated on