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

Function cif_alloc

src/discover/inventory_guard.c:91–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91void *cif_alloc(cif_context *c, size_t count, size_t width) {
92 if (!count || !width) {
93 return NULL;
94 }
95 if (count > SIZE_MAX / width) {
96 cif_fail(c, CBM_INVENTORY_LIMIT);
97 return NULL;
98 }
99 size_t n = count * width;
100 cbm_inventory_filter_t *o = c->owner;
101 size_t available = o->limits.max_arena_bytes - o->limits.max_ignore_arena_bytes;
102 if (n > available - o->usage.non_ignore_arena_requested_bytes) {
103 cif_fail(c, CBM_INVENTORY_LIMIT);
104 return NULL;
105 }
106 if (!cif_poll(c) || !cif_arena_room(c, n)) {
107 return NULL;
108 }
109 o->usage.non_ignore_arena_requested_bytes += n;
110 void *result = cbm_arena_alloc(&o->arena, n);
111 if (!result) {
112 cif_fail(c, CBM_INVENTORY_OOM);
113 return NULL;
114 }
115 if (!cif_poll(c) || !cif_copy(c, result, NULL, n)) {
116 return NULL;
117 }
118 return result;
119}
120
121unsigned char *cif_string(cif_context *c, const unsigned char *source, size_t length) {
122 if (length == SIZE_MAX) {

Callers 6

cif_read_controlFunction · 0.85
cif_sort_directoriesFunction · 0.85
cif_directoriesFunction · 0.85
cif_stringFunction · 0.85
cif_metadataFunction · 0.85

Calls 5

cif_failFunction · 0.85
cif_pollFunction · 0.85
cif_arena_roomFunction · 0.85
cif_copyFunction · 0.85
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected