VecInitT
Description
Typed-cast variant of VecInit for assigning into a typed Vec variable. The cast makes the macro usable both as an in-place initializer (Vec(int) v = VecInitT(v, alloc);) and as an assignment target. The allocator argument is optional inside a Scope block.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Graph.c:162:
deinit_vec(GENERIC_VEC(&slot->out_neighbors), sizeof(GraphNodeId));
slot->out_neighbors = VecInitT(slot->out_neighbors, graph->allocator);
deinit_vec(GENERIC_VEC(&slot->in_neighbors), sizeof(GraphNodeId));
slot->in_neighbors = VecInitT(slot->in_neighbors, graph->allocator);- In
Graph.c:164:
slot->out_neighbors = VecInitT(slot->out_neighbors, graph->allocator);
deinit_vec(GENERIC_VEC(&slot->in_neighbors), sizeof(GraphNodeId));
slot->in_neighbors = VecInitT(slot->in_neighbors, graph->allocator);
slot->visit_count = 0;- In
Graph.c:479:
} else {
deinit_vec(GENERIC_VEC(&slot->out_neighbors), sizeof(GraphNodeId));
slot->out_neighbors = VecInitT(slot->out_neighbors, graph->allocator);
deinit_vec(GENERIC_VEC(&slot->in_neighbors), sizeof(GraphNodeId));
slot->in_neighbors = VecInitT(slot->in_neighbors, graph->allocator);- In
Graph.c:481:
slot->out_neighbors = VecInitT(slot->out_neighbors, graph->allocator);
deinit_vec(GENERIC_VEC(&slot->in_neighbors), sizeof(GraphNodeId));
slot->in_neighbors = VecInitT(slot->in_neighbors, graph->allocator);
slot->visit_count = 0;
slot->flags = 0;- In
Graph.c:541:
}
slot_ptr->out_neighbors = VecInitT(slot_ptr->out_neighbors, graph->allocator);
slot_ptr->in_neighbors = VecInitT(slot_ptr->in_neighbors, graph->allocator);
slot_ptr->data = graph_alloc_node_data(graph, item_size);- In
Graph.c:542:
slot_ptr->out_neighbors = VecInitT(slot_ptr->out_neighbors, graph->allocator);
slot_ptr->in_neighbors = VecInitT(slot_ptr->in_neighbors, graph->allocator);
slot_ptr->data = graph_alloc_node_data(graph, item_size);
if (!slot_ptr->data) {- In
Graph.c:554:
slot_ptr->data = NULL;
deinit_vec(GENERIC_VEC(&slot_ptr->out_neighbors), sizeof(GraphNodeId));
slot_ptr->out_neighbors = VecInitT(slot_ptr->out_neighbors, graph->allocator);
deinit_vec(GENERIC_VEC(&slot_ptr->in_neighbors), sizeof(GraphNodeId));
slot_ptr->in_neighbors = VecInitT(slot_ptr->in_neighbors, graph->allocator);- In
Graph.c:556:
slot_ptr->out_neighbors = VecInitT(slot_ptr->out_neighbors, graph->allocator);
deinit_vec(GENERIC_VEC(&slot_ptr->in_neighbors), sizeof(GraphNodeId));
slot_ptr->in_neighbors = VecInitT(slot_ptr->in_neighbors, graph->allocator);
slot_ptr->visit_count = 0;
slot_ptr->flags = 0;- In
Graph.c:573:
}
slot.out_neighbors = VecInitT(slot.out_neighbors, graph->allocator);
slot.in_neighbors = VecInitT(slot.in_neighbors, graph->allocator);
slot.data = graph_alloc_node_data(graph, item_size);- In
Graph.c:574:
slot.out_neighbors = VecInitT(slot.out_neighbors, graph->allocator);
slot.in_neighbors = VecInitT(slot.in_neighbors, graph->allocator);
slot.data = graph_alloc_node_data(graph, item_size);
if (!slot.data) { MemSet(out, 0, sizeof(*out));
out->allocator = alloc;
out->cache = VecInitT(out->cache, alloc);
if (!ProcMapsLoad(&out->maps, alloc)) {
VecDeinit(&out->cache);- In
ProcMaps.c:175:
MemSet(out, 0, sizeof(*out));
out->raw = StrInit(alloc);
out->entries = VecInitT(out->entries, alloc);
// `/proc/self/maps` reports stat-size 0 because it's generated by
- In
Dns.c:316:
MemSet(out, 0, sizeof(*out));
out->allocator = alloc;
out->hosts = VecInitT(out->hosts, alloc);
out->nameservers = VecInitT(out->nameservers, alloc);
out->timeout_ms = 5000;- In
Dns.c:317:
out->allocator = alloc;
out->hosts = VecInitT(out->hosts, alloc);
out->nameservers = VecInitT(out->nameservers, alloc);
out->timeout_ms = 5000;
out->retries = 2;- In
Dns.c:440:
ArenaAllocator scratch = ArenaAllocatorInit();
DnsWireBuf query = VecInitT(query, &scratch);
u16 id = random_query_id();
if (!DnsBuildQuery(&query, id, hostname, qtype)) {- In
Dns.c:627:
return false;
}
DnsAddrs addrs = VecInitT(addrs, self->allocator);
bool ok = dns_resolve_4_vec_zstr(self, spec, kind, &addrs);
bool have_one = ok && VecLen(&addrs) > 0;- In
MachO.c:428:
MemSet(out, 0, sizeof(*out));
out->data = taken;
out->segments = VecInitT(out->segments, BufAllocator(&taken));
out->sections = VecInitT(out->sections, BufAllocator(&taken));
out->symbols = VecInitT(out->symbols, BufAllocator(&taken));- In
MachO.c:429:
out->data = taken;
out->segments = VecInitT(out->segments, BufAllocator(&taken));
out->sections = VecInitT(out->sections, BufAllocator(&taken));
out->symbols = VecInitT(out->symbols, BufAllocator(&taken));- In
MachO.c:430:
out->segments = VecInitT(out->segments, BufAllocator(&taken));
out->sections = VecInitT(out->sections, BufAllocator(&taken));
out->symbols = VecInitT(out->symbols, BufAllocator(&taken));
MachoContext ctx = {.out = out};- In
Elf.c:442:
MemSet(out, 0, sizeof(*out));
out->data = taken;
out->sections = VecInitT(out->sections, BufAllocator(&taken));
out->symbols = VecInitT(out->symbols, BufAllocator(&taken));
out->dynamic_symbols = VecInitT(out->dynamic_symbols, BufAllocator(&taken));- In
Elf.c:443:
out->data = taken;
out->sections = VecInitT(out->sections, BufAllocator(&taken));
out->symbols = VecInitT(out->symbols, BufAllocator(&taken));
out->dynamic_symbols = VecInitT(out->dynamic_symbols, BufAllocator(&taken));- In
Elf.c:444:
out->sections = VecInitT(out->sections, BufAllocator(&taken));
out->symbols = VecInitT(out->symbols, BufAllocator(&taken));
out->dynamic_symbols = VecInitT(out->dynamic_symbols, BufAllocator(&taken));
if (!elf_decode_header(out))- In
Dwarf.c:212:
static void cu_strings_init(CuStrings *cs, Allocator *alloc) {
cs->dir_offsets = VecInitT(cs->dir_offsets, alloc);
cs->file_dir_idx = VecInitT(cs->file_dir_idx, alloc);
cs->file_offsets = VecInitT(cs->file_offsets, alloc);- In
Dwarf.c:213:
static void cu_strings_init(CuStrings *cs, Allocator *alloc) {
cs->dir_offsets = VecInitT(cs->dir_offsets, alloc);
cs->file_dir_idx = VecInitT(cs->file_dir_idx, alloc);
cs->file_offsets = VecInitT(cs->file_offsets, alloc);
}- In
Dwarf.c:214:
cs->dir_offsets = VecInitT(cs->dir_offsets, alloc);
cs->file_dir_idx = VecInitT(cs->file_dir_idx, alloc);
cs->file_offsets = VecInitT(cs->file_offsets, alloc);
}- In
Dwarf.c:546:
MemSet(out, 0, sizeof(*out));
out->allocator = alloc;
out->entries = VecInitT(out->entries, alloc);
out->string_pool = StrInit(alloc);- In
Dwarf.c:557:
// Parallel arrays of file / dir offsets, one per emitted row. We
// resolve them to pointers at the end after string_pool is final.
U64Vec pending_file_offsets = VecInitT(pending_file_offsets, alloc);
U64Vec pending_dir_offsets = VecInitT(pending_dir_offsets, alloc);- In
Dwarf.c:558:
// resolve them to pointers at the end after string_pool is final.
U64Vec pending_file_offsets = VecInitT(pending_file_offsets, alloc);
U64Vec pending_dir_offsets = VecInitT(pending_dir_offsets, alloc);
BufIter section_cur = BufIterFromMemory(BufData(ElfBuf(elf)) + line_section->offset, line_section->size);- In
DwarfInfo.c:107:
// by an entry with code 0. Returns false on malformed input.
static bool parse_abbrev_table(BufIter cur, AbbrevTable *out, Allocator *alloc) {
*out = VecInitT(*out, alloc);
while (IterRemainingLength(&cur) > 0) {
u64 code;- In
DwarfInfo.c:128:
e.tag = (u32)tag;
e.has_children = has_children != 0;
e.attrs = VecInitT(e.attrs, alloc);
for (;;) {- In
DwarfInfo.c:525:
MemSet(out, 0, sizeof(*out));
out->allocator = alloc;
out->entries = VecInitT(out->entries, alloc);
out->string_pool = StrInit(alloc);- In
DwarfInfo.c:538:
BufIter info_cur = BufIterFromMemory(info_bytes, info_size);
PendingFns pending = VecInitT(pending, alloc);
bool ok = true;- In
Pdb.c:644:
// the pool may grow during the walk -- StrBegin() can move under
// us each time pool_append_cstr() grows the backing storage.
PendingPubs pending = VecInitT(pending, BufAllocator(&self->data));
bool ok = walk_publics(self, dbi.symrec_stream, sections, num_sections, &self->name_pool, &pending);
AllocatorFree(BufAllocator(&self->data), sections);- In
Pdb.c:706:
MemSet(out, 0, sizeof(*out));
out->data = taken;
out->functions = VecInitT(out->functions, BufAllocator(&taken));
out->name_pool = StrInit(BufAllocator(&taken)); MemSet(out, 0, sizeof(*out));
out->allocator = alloc;
out->cies = VecInitT(out->cies, alloc);
out->fdes = VecInitT(out->fdes, alloc); out->allocator = alloc;
out->cies = VecInitT(out->cies, alloc);
out->fdes = VecInitT(out->fdes, alloc);
const ElfSection *eh = ElfFindSection(elf, ".eh_frame");- In
Dns.c:179:
rec->name = StrInit(alloc);
rec->target = StrInit(alloc);
rec->rdata = VecInitT(rec->rdata, alloc);
MemSet(rec->ipv4, 0, sizeof(rec->ipv4));
MemSet(rec->ipv6, 0, sizeof(rec->ipv6));- In
Dns.c:275:
}
MemSet(out, 0, sizeof(*out));
out->answers = VecInitT(out->answers, alloc);
out->authority = VecInitT(out->authority, alloc);
out->additional = VecInitT(out->additional, alloc);- In
Dns.c:276:
MemSet(out, 0, sizeof(*out));
out->answers = VecInitT(out->answers, alloc);
out->authority = VecInitT(out->authority, alloc);
out->additional = VecInitT(out->additional, alloc);- In
Dns.c:277:
out->answers = VecInitT(out->answers, alloc);
out->authority = VecInitT(out->authority, alloc);
out->additional = VecInitT(out->additional, alloc);
if (len < 12) {- In
Pe.c:517:
// Initialize the sections vec up-front so PeDeinit on a
// failed-parse path doesn't trip ValidateVec.
out->sections = VecInitT(out->sections, BufAllocator(&taken));
PeContext ctx = {- In
Resolve.c:38:
}
DnsAddrs addrs = VecInitT(addrs, alloc);
if (!DnsResolve(&r, hostname, 0, SOCKET_KIND_TCP, &addrs)) {
DnsResolverDeinit(&r);- In
VecInt.c:20:
void init_int_vec(IntVec *vec, DefaultAllocator *alloc) {
*vec = VecInitT(*vec, alloc);
}- In
VecInt.c:334:
case VEC_INT_MERGE : {
IntVec temp = VecInitT(temp, alloc);
uint8_t count = extract_u8(data, offset, data_size);
count = count % 4;- In
VecInt.c:388:
case VEC_INT_INIT_CLONE : {
IntVec temp = VecInitT(temp, alloc);
uint8_t count = extract_u8(data, offset, data_size);
count = count % 4;- In
RoundTrip.c:548:
VecPushBack(&original.config.features, feature2);
original.numbers = VecInitT(original.numbers, &alloc);
i32 vals[3] = {10, 20, -5};
for (size i = 0; i < 3; i++) {- In
RoundTrip.c:554:
}
original.flags = VecInitT(original.flags, &alloc);
bool bools[3] = {true, false, true};
for (size i = 0; i < 3; i++) {- In
RoundTrip.c:589:
parsed.config.log_level = StrInit(&alloc);
parsed.config.features = VecInitWithDeepCopyT(parsed.config.features, NULL, StrDeinit, &alloc);
parsed.numbers = VecInitT(parsed.numbers, &alloc);
parsed.flags = VecInitT(parsed.flags, &alloc);- In
RoundTrip.c:590:
parsed.config.features = VecInitWithDeepCopyT(parsed.config.features, NULL, StrDeinit, &alloc);
parsed.numbers = VecInitT(parsed.numbers, &alloc);
parsed.flags = VecInitT(parsed.flags, &alloc);
StrIter si = StrIterFromStr(json);- In
Backtrace.c:73:
Allocator *alloc_base = ALLOCATOR_OF(&alloc);
StackFrames frames = VecInitT(frames, alloc_base);
bool ok = bt_vec_capture_outer(&frames);
ok = ok && VecLen(&frames) >= 2;- In
SysDns.c:23:
}
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "localhost", 8080, SOCKET_KIND_TCP, &out);- In
SysDns.c:51:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "LocalHost", 0, SOCKET_KIND_TCP, &out);- In
SysDns.c:69:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "localhost.", 0, SOCKET_KIND_TCP, &out);- In
SysDns.c:88:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "203.0.113.7:9999", SOCKET_KIND_TCP, &out);- In
SysDns.c:112:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "[::1]:443", SOCKET_KIND_TCP, &out);- In
SysDns.c:137:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "localhost:53", SOCKET_KIND_TCP, &out);- In
SysDns.c:191:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "localhost", SOCKET_KIND_TCP, &out);- In
SysDns.c:210:
DnsResolverInit(&r, a);
DnsAddrs out = VecInitT(out, a);
bool got = DnsResolve(&r, "localhost:abc", SOCKET_KIND_TCP, &out); BitVecPush(&pattern, true);
BitVecMatchIndices matches = VecInitT(matches, base);
result = result && BitVecFindAllPattern(&source, &pattern, &matches);
result = result && VecLen(&matches) == 5;- In
Vec.Init.c:175:
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);- In
Vec.Init.c:179:
TestVec vec_d = VecInitWithDeepCopyT(vec_d, TestItemCopyInit, TestItemDeinit, &h_default);
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); BitVecPush(&bv, true);
BitVecRuns runs = VecInitT(runs, base);
bool result = BitVecRunLengths(&bv, &runs);
result = result && VecLen(&runs) == 5;
// Create a new vector for testing fast delete operations
vec = VecInitT(vec, &alloc);
// Add elements again
// Test with an L-value index
vec = VecInitT(vec, &alloc);
// Add elements again
// Test with large number of elements
VecDeinit(&vec);
vec = VecInitT(vec, &alloc);
// Push a large number of elements
// Test with zero-capacity vector
VecDeinit(&vec);
vec = VecInitT(vec, &alloc);
// Reserve zero capacity
- In
Dns.c:15:
Allocator *a = ALLOCATOR_OF(&alloc);
DnsWireBuf buf = VecInitT(buf, a);
bool ok = DnsBuildQuery(&buf, 0x1234, "example.com", DNS_TYPE_A);- In
Dns.c:42:
Allocator *a = ALLOCATOR_OF(&alloc);
DnsWireBuf no_dot = VecInitT(no_dot, a);
DnsWireBuf w_dot = VecInitT(w_dot, a);
bool ok = DnsBuildQuery(&no_dot, 1, "a.b.c", DNS_TYPE_AAAA) && DnsBuildQuery(&w_dot, 1, "a.b.c.", DNS_TYPE_AAAA);- In
Dns.c:43:
DnsWireBuf no_dot = VecInitT(no_dot, a);
DnsWireBuf w_dot = VecInitT(w_dot, a);
bool ok = DnsBuildQuery(&no_dot, 1, "a.b.c", DNS_TYPE_AAAA) && DnsBuildQuery(&w_dot, 1, "a.b.c.", DNS_TYPE_AAAA);
Last updated on