Skip to content

BufAllocator

Description

Allocator backing b’s storage. Read-only; rebinding the allocator after init is not supported.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        self->stream_sizes        = AllocatorAlloc(BufAllocator(&self->data), (size)sizes_bytes, 0);
        self->stream_blocks       = AllocatorAlloc(BufAllocator(&self->data), (size)ptrs_bytes, 0);
        self->stream_block_counts = AllocatorAlloc(BufAllocator(&self->data), (size)counts_bytes, 0);
    
        self->stream_sizes        = AllocatorAlloc(BufAllocator(&self->data), (size)sizes_bytes, 0);
        self->stream_blocks       = AllocatorAlloc(BufAllocator(&self->data), (size)ptrs_bytes, 0);
        self->stream_block_counts = AllocatorAlloc(BufAllocator(&self->data), (size)counts_bytes, 0);
        if (!self->stream_sizes || !self->stream_blocks || !self->stream_block_counts)
        self->stream_sizes        = AllocatorAlloc(BufAllocator(&self->data), (size)sizes_bytes, 0);
        self->stream_blocks       = AllocatorAlloc(BufAllocator(&self->data), (size)ptrs_bytes, 0);
        self->stream_block_counts = AllocatorAlloc(BufAllocator(&self->data), (size)counts_bytes, 0);
        if (!self->stream_sizes || !self->stream_blocks || !self->stream_block_counts)
            return false;
        }
        u32         n   = sz / 40;
        SectionRva *out = AllocatorAlloc(BufAllocator(&self->data), n * sizeof(SectionRva), 0);
        if (!out)
            return NULL;
            return NULL;
    
        u8 *buf = AllocatorAlloc(BufAllocator(&self->data), sz, 0);
        if (!buf) {
            AllocatorFree(BufAllocator(&self->data), out);
        u8 *buf = AllocatorAlloc(BufAllocator(&self->data), sz, 0);
        if (!buf) {
            AllocatorFree(BufAllocator(&self->data), out);
            return NULL;
        }
        bool read_ok = stream_read(self, section_hdr_stream, 0, buf, sz);
        if (!read_ok) {
            AllocatorFree(BufAllocator(&self->data), buf);
            AllocatorFree(BufAllocator(&self->data), out);
            return NULL;
        if (!read_ok) {
            AllocatorFree(BufAllocator(&self->data), buf);
            AllocatorFree(BufAllocator(&self->data), out);
            return NULL;
        }
            (void)BufReadU32LE(&rec, &out[i].virtual_address);
        }
        AllocatorFree(BufAllocator(&self->data), buf);
        *out_count = n;
        return out;
        // Stream into a flat buffer; the record stream is typically large
        // but not unbounded.
        u8 *buf = AllocatorAlloc(BufAllocator(&self->data), sz, 0);
        if (!buf)
            return false;
            return false;
        if (!stream_read(self, symrec_stream, 0, buf, sz)) {
            AllocatorFree(BufAllocator(&self->data), buf);
            return false;
        }
                        pp.rva = rva;
                        if (!pool_append_cstr(pool, name, &pp.name_offset_in_pool)) {
                            AllocatorFree(BufAllocator(&self->data), buf);
                            return false;
                        }
                        }
                        if (!VecPushBackR(pending, pp)) {
                            AllocatorFree(BufAllocator(&self->data), buf);
                            return false;
                        }
        }
    
        AllocatorFree(BufAllocator(&self->data), buf);
        return true;
    }
        if (!sections || num_sections == 0) {
            if (sections)
                AllocatorFree(BufAllocator(&self->data), sections);
            return true; // can't compute RVAs without section table
        }
        // Per-function names need an offset-into-pool indirection because
        // the pool may grow during the walk.
        Str         name_pool = StrInit(BufAllocator(&self->data));
        PendingPubs pending   = VecInitT(pending, BufAllocator(&self->data));
        bool        ok        = walk_publics(self, dbi.symrec_stream, sections, num_sections, &name_pool, &pending);
        // the pool may grow during the walk.
        Str         name_pool = StrInit(BufAllocator(&self->data));
        PendingPubs pending   = VecInitT(pending, BufAllocator(&self->data));
        bool        ok        = walk_publics(self, dbi.symrec_stream, sections, num_sections, &name_pool, &pending);
        AllocatorFree(BufAllocator(&self->data), sections);
        PendingPubs pending   = VecInitT(pending, BufAllocator(&self->data));
        bool        ok        = walk_publics(self, dbi.symrec_stream, sections, num_sections, &name_pool, &pending);
        AllocatorFree(BufAllocator(&self->data), sections);
    
        if (!ok) {
        if (!self)
            return;
        Allocator *alloc = BufAllocator(&self->data);
        BufDeinit(&self->data);
        if (alloc) {
Last updated on