GCC Code Coverage Report


Directory: src/
File: src/core/memory.h
Date: 2026-09-30 11:11:31
Exec Total Coverage
Lines: 4 4 100.0%
Functions: 1 1 100.0%
Branches: 1 2 50.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2026 Tiger Data, Inc.
3 * Licensed under the PostgreSQL License. See LICENSE for details.
4 *
5 * memory.h - Memory abstraction interface
6 *
7 * Provides a unified interface for memory allocation that works in both
8 * standalone mode (arena allocator) and PostgreSQL mode (palloc/pfree).
9 *
10 * Build configuration:
11 * - Standalone: define VS_STANDALONE, compile memory_standalone.c
12 * - PostgreSQL: no define needed, header-only (macros map to palloc)
13 */
14
15 #ifndef VS_MEMORY_H
16 #define VS_MEMORY_H
17
18 #ifdef VS_STANDALONE
19 #include "standalone/memory_sa.h"
20 #else
21 #include "pg/memory_pg.h"
22 #endif
23
24 /* Helper for cleanup attribute (works in both modes) */
25 static inline void
26 2608 vs_memctx_delete_ptr(VsMemCtx *ctx)
27 {
28
1/2
✓ Branch 0 taken 2608 times.
✗ Branch 1 not taken.
2608 if (*ctx)
29 2608 vs_memctx_delete(*ctx);
30 1096 }
31
32 /*
33 * Scoped context (RAII-style via cleanup attribute)
34 *
35 * Usage:
36 * void some_function(void) {
37 * VS_MEMCTX_SCOPE(work_ctx);
38 * VsMemCtx old = vs_memctx_switch(work_ctx);
39 * // allocations happen in work_ctx
40 * // ...
41 * vs_memctx_switch(old);
42 * } // work_ctx automatically deleted here
43 */
44 #ifdef VS_STANDALONE
45 #define VS_MEMCTX_SCOPE(name) \
46 VsMemCtx name __attribute__((cleanup(vs_memctx_delete_ptr))) = \
47 vs_memctx_create(vs_current_memctx, #name)
48 #else
49 #define VS_MEMCTX_SCOPE(name) \
50 VsMemCtx name __attribute__((cleanup(vs_memctx_delete_ptr))) = \
51 vs_memctx_create(CurrentMemoryContext, #name)
52 #endif
53
54 #endif /* VS_MEMORY_H */
55