VecInitWithDeepCopy
Description
Initialize a Vec with deep-copy callbacks. The allocator argument is optional in the same way as VecInit - inside a Scope block you may omit it and MisraScope is used automatically.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Complex.c:183:
// Create a vector of ComplexItem with deep copy functions
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
// Check initial state
- In
Complex.c:226:
// Create a vector of ComplexItem with deep copy functions
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
// Create test items
- In
Complex.c:270:
// Create a vector of ComplexItem with deep copy functions
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
// Create test items
- In
Complex.c:313:
// Create two vectors of ComplexItem with deep copy functions
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec1 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
ComplexVec vec2 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);- In
Complex.c:314:
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec1 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
ComplexVec vec2 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
// Create test items
- In
Complex.c:343:
// Now test VecMergeL which transfers ownership
ComplexVec vec3 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
ComplexVec vec4 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);- In
Complex.c:344:
// Now test VecMergeL which transfers ownership
ComplexVec vec3 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
ComplexVec vec4 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// Create more test items
- In
Complex.c:673:
// Create a temporary vector with no copy_init but with copy_deinit for proper cleanup
typedef Vec(ComplexItem) ComplexVec;
ComplexVec temp_vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// Insert with L-value semantics (vector takes ownership)
- In
Complex.c:699:
// Create a vector with no copy_init but with copy_deinit for proper cleanup
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// First, create a dummy item and add it to the vector
- In
Complex.c:731:
// Create a vector with no copy_init but with copy_deinit for proper cleanup
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// Make sure we have enough capacity to avoid reallocation issues
- In
Complex.c:800:
// Create a vector with no copy_init but with copy_deinit for proper cleanup
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// Add a dummy item first
- In
Complex.c:827:
// Create a vector with no copy_init but with copy_deinit for proper cleanup
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec1 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
ComplexVec vec2 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);- In
Complex.c:828:
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec1 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
ComplexVec vec2 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// Create test items for vec2
- In
Complex.c:865:
// Create a vector with no copy_init but with copy_deinit for proper cleanup
typedef Vec(ComplexItem) ComplexVec;
ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
// Create an array of complex items
- In
Memory.c:289:
typedef Vec(int) IntVec;
IntVec vec = VecInitWithDeepCopy(NULL, counting_deinit, &alloc);
int values[] = {10, 20, 30, 40};- In
Init.c:124:
// Test vector initialization with deep copy functions
bool test_vec_init_with_deep_copy(void) {
WriteFmt("Testing VecInitWithDeepCopy\n");
// Test with struct type and custom copy/deinit functions
- In
Init.c:128:
// Test with struct type and custom copy/deinit functions
typedef Vec(TestItem) TestVec;
TestVec vec = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit, &alloc);
// Check initial state
- In
Init.c:150:
// Test with struct type, custom copy/deinit functions, and 8-byte alignment
typedef Vec(TestItem) TestVec;
TestVec vec = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit, &aligned8);
// Check initial state
- In
Init.c:188:
TestVec vec_a = VecInit(&h_default);
TestVec vec_b = VecInitT(vec_b, &h_default);
TestVec vec_c = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit, &h_default);
TestVec vec_d = VecInitWithDeepCopyT(vec_d, TestItemCopyInit, TestItemDeinit, &h_default);
TestVec vec_e = VecInit(&h8);- In
Init.c:192:
TestVec vec_e = VecInit(&h8);
TestVec vec_f = VecInitT(vec_f, &h16);
TestVec vec_g = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit, &h32);
TestVec vec_h = VecInitWithDeepCopyT(vec_h, TestItemCopyInit, TestItemDeinit, &h64);- In
Insert.c:694:
// values seed, seed+1, ... All copy_init calls during prefill succeed.
static ElemVec make_filled_elem_vec(int seed, size count) {
ElemVec vec = VecInitWithDeepCopy(elem_copy_init, elem_copy_deinit, &alloc);
g_fail_at = 0;
g_init_calls = 0;- In
Insert.c:1403:
// fails during this phase).
static TrackVec make_track_vec(const int *tags, size n) {
TrackVec v = VecInitWithDeepCopy(track_copy_init, track_copy_deinit, &alloc);
reset_tracking((size)-1);
for (size i = 0; i < n; i++) {- In
Insert.c:1692:
// a single element and restores every original.
const size N = 100000;
TrackVec vec = VecInitWithDeepCopy(track_copy_init, track_copy_deinit, &alloc);
reset_tracking((size)-1);
for (size i = 0; i < N; i++) {- In
Insert.c:1842:
DebugAllocator dbg = DebugAllocatorInit();
MutElemVec vec = VecInitWithDeepCopy(mut_copy_init, mut_copy_deinit, &dbg);
// Arm copy_init to fail, then attempt a fast L-insert into the empty vec.
- In
Insert.c:1872:
WriteFmt("Testing VecInsertL reports copy_init failure (584:10)\n");
MutElemVec vec = VecInitWithDeepCopy(mut_copy_init, mut_copy_deinit, &alloc);
g_fail = true;- In
Insert.c:1902:
WriteFmt("Testing insert failure zeroes vacated tail slots\n");
ElemVec vec = VecInitWithDeepCopy(elem_copy_init, elem_copy_deinit, &alloc);
// Fill 4 live originals (10..13). copy_init must not fail during prefill.
- In
Insert.c:1948:
WriteFmt("Testing fast-insert failure zeroes parked tail slots\n");
ElemVec vec = VecInitWithDeepCopy(elem_copy_init, elem_copy_deinit, &alloc);
g_fail_at = 0;- In
Remove.c:989:
typedef Vec(int) IntVec;
IntVec vec = VecInitWithDeepCopy(NULL, counting_deinit, &alloc);
int values[] = {10, 20, 30};- In
Remove.c:1012:
typedef Vec(int) IntVec;
IntVec vec = VecInitWithDeepCopy(NULL, counting_deinit, &alloc);
int values[] = {10, 20, 30};- In
Remove.c:1035:
typedef Vec(int) IntVec;
IntVec vec = VecInitWithDeepCopy(NULL, counting_deinit, &alloc);
int values[] = {10, 20, 30, 40};- In
Remove.c:1057:
typedef Vec(int) IntVec;
IntVec vec = VecInitWithDeepCopy(NULL, counting_deinit, &alloc);
int values[] = {10, 20, 30};- In
Remove.c:1081:
typedef Vec(int) IntVec;
IntVec vec = VecInitWithDeepCopy(NULL, counting_deinit, &alloc);
int values[] = {10, 20, 30}; DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecPrefixMatch(NULL, patterns, 1) - should fatal\n");
BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
BitVecPush(VecPtrAt(&vp, 0), true);
BitVecPrefixMatch(NULL, &vp); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecSuffixMatch(NULL, patterns, 1) - should fatal\n");
BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
BitVecPush(VecPtrAt(&vp, 0), true);
BitVecSuffixMatch(NULL, &vp); WriteFmt("Testing BitVecPrefixMatch(NULL, empty) - should fatal\n");
BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
// Empty patterns: with validation present this aborts on the NULL bv;
WriteFmt("Testing BitVecSuffixMatch(NULL, empty) - should fatal\n");
BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
// Empty patterns: with validation present this aborts on the NULL bv;
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
bool result = true;
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
bool result = true;- In
Type.c:50:
// Create a Strs object (vector of strings)
Strs sv = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
// Add some strings
- In
Http.c:297:
Allocator *adbg = ALLOCATOR_OF(&dbg);
HttpHeaders headers = VecInitWithDeepCopy(http_header_init_copy, http_header_deinit, adbg);
HttpHeader hh = HttpHeaderInit(adbg); StrIter si = StrIterFromStr(json);
Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
JR_OBJ(si, {
Vec(i32) empty_numbers = VecInit(&alloc);
Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
JW_OBJ(json, { true,
StrInitFromZstr("Success", &alloc),
VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)
}; Str json = StrInit(&alloc);
Vec(FunctionInfo) functions = VecInitWithDeepCopy(NULL, FunctionInfoDeinit, &alloc);
FunctionInfo func1 = {12345, StrInitFromZstr("test_func", &alloc), 1024, 4096}; Str json = StrInit(&alloc);
Vec(AnnSymbol) symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc);
AnnSymbol sym1 = {0}; VecPushBack(&numbers, num3);
Vec(Str) strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
// Create strings and push them properly
typedef Vec(AnnSymbol) Symbols;
Symbols symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc);
JR_OBJ(si, { StrIter si = StrIterFromStr(json);
ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};
JR_OBJ(si, { StrIter si = StrIterFromStr(json);
ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};
WriteFmt("[DEBUG] About to parse JSON...\n"); StrIter si = StrIterFromStr(json);
ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};
WriteFmt("[DEBUG] About to parse JSON...\n"); Str json = StrInit(&alloc);
Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
// Create strings and push them properly
StrIter si2 = StrIterFromStr(json2);
Vec(Str) data = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
JR_OBJ(si2, {- In
RoundTrip.c:370:
// Original data
Vec(i32) original_numbers = VecInit(&alloc);
Vec(Str) original_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
// Populate arrays
- In
RoundTrip.c:398:
// Read back from JSON
Vec(i32) parsed_numbers = VecInit(&alloc);
Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
StrIter si = StrIterFromStr(json);- In
RoundTrip.c:675:
// Original empty data
Vec(i32) empty_numbers = VecInit(&alloc);
Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
Str empty_str = StrInit(&alloc);- In
RoundTrip.c:695:
// Read back from JSON
Vec(i32) parsed_numbers = VecInit(&alloc);
Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
Str parsed_str = StrInit(&alloc);
bool found_empty_object = false;
Last updated on