MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tir_alloc

Function tir_alloc

src/mcp/test_impact_result_util.c:65–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65void *tir_alloc(tir_context *c, size_t count, size_t size) {
66 if (!count || !size || c->status != CBM_TEST_RESULT_OK)
67 return NULL;
68 if (count > (SIZE_MAX - 7 - sizeof(tir_allocation)) / size) {
69 tir_fail(c, CBM_TEST_RESULT_LIMIT);
70 return NULL;
71 }
72 size_t payload = count * size;
73 size_t bytes = payload + sizeof(tir_allocation);
74 size_t aligned = (bytes + 7) & ~(size_t)7;
75 if (aligned > SIZE_MAX - c->arena.used || aligned > SIZE_MAX - c->arena.total_alloc ||
76 !tir_reserve(c, bytes) || !tir_poll(c)) {
77 tir_fail(c, CBM_TEST_RESULT_LIMIT);
78 return NULL;
79 }
80 void *out = cbm_arena_alloc(&c->arena, bytes);
81 if (!out) {
82 tir_fail(c, CBM_TEST_RESULT_OOM);
83 return NULL;
84 }
85 for (size_t pos = 0; pos < bytes;) {
86 size_t step = bytes - pos < 4096 ? bytes - pos : 4096;
87 if (!tir_step(c, step, 0))
88 return NULL;
89 memset((unsigned char *)out + pos, 0, step);
90 pos += step;
91 }
92 tir_allocation *entry = out;
93 entry->next = c->owned;
94 entry->size = payload;
95 entry->data = entry + 1;
96 c->owned = entry;
97 return entry->data;
98}
99
100bool tir_forget_borrowed(tir_context *c, const cbm_test_result_t *result) {
101 tir_allocation *entry = c->owned;

Callers 15

tir_case_idFunction · 0.85
tir_filter_jsonFunction · 0.85
tir_nodeFunction · 0.85
tir_addFunction · 0.85
tir_hexFunction · 0.85
tir_renderFunction · 0.85
tir_check_extensionsFunction · 0.85
cbm_test_result_buildFunction · 0.85
tir_sortFunction · 0.85
tir_string_arrayFunction · 0.85
tir_read_rulesFunction · 0.85
tir_read_lanesFunction · 0.85

Calls 5

tir_failFunction · 0.85
tir_reserveFunction · 0.85
tir_pollFunction · 0.85
tir_stepFunction · 0.85
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected