177 // perform reallocation |
177 // perform reallocation |
178 void *newmem = reallocator->realloc( |
178 void *newmem = reallocator->realloc( |
179 *array, newcap, elem_size, reallocator |
179 *array, newcap, elem_size, reallocator |
180 ); |
180 ); |
181 if (newmem == NULL) { |
181 if (newmem == NULL) { |
182 return 1; |
182 return 1; // LCOV_EXCL_LINE |
183 } |
183 } |
184 |
184 |
185 // store new pointer |
185 // store new pointer |
186 *array = newmem; |
186 *array = newmem; |
187 |
187 |
363 *target, new_capacity, elem_size, reallocator |
363 *target, new_capacity, elem_size, reallocator |
364 ); |
364 ); |
365 if (new_mem == NULL) { |
365 if (new_mem == NULL) { |
366 // give it up right away, there is no contract |
366 // give it up right away, there is no contract |
367 // that requires us to insert as much as we can |
367 // that requires us to insert as much as we can |
368 return 1; |
368 return 1; // LCOV_EXCL_LINE |
369 } |
369 } |
370 *target = new_mem; |
370 *target = new_mem; |
371 *capacity = new_capacity; |
371 *capacity = new_capacity; |
372 } |
372 } |
373 |
373 |
1017 cxListStorePointers((CxList *) list); |
1015 cxListStorePointers((CxList *) list); |
1018 } |
1016 } |
1019 |
1017 |
1020 // allocate the array after the real elem_size is known |
1018 // allocate the array after the real elem_size is known |
1021 list->data = cxCalloc(allocator, initial_capacity, elem_size); |
1019 list->data = cxCalloc(allocator, initial_capacity, elem_size); |
1022 if (list->data == NULL) { |
1020 if (list->data == NULL) { // LCOV_EXCL_START |
1023 cxFree(allocator, list); |
1021 cxFree(allocator, list); |
1024 return NULL; |
1022 return NULL; |
1025 } |
1023 } // LCOV_EXCL_STOP |
1026 |
1024 |
1027 // configure the reallocator |
1025 // configure the reallocator |
1028 list->reallocator = cx_array_reallocator(allocator, NULL); |
1026 list->reallocator = cx_array_reallocator(allocator, NULL); |
1029 |
1027 |
1030 return (CxList *) list; |
1028 return (CxList *) list; |