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

Function cni_alloc

src/mcp/test_impact_inventory.c:91–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91void *cni_alloc(cni_context *c, CBMArena *arena, size_t count, size_t width) {
92 if (!count || !width) {
93 return NULL;
94 }
95 if (count > SIZE_MAX / width) {
96 cni_fail(c, CBM_INVENTORY_LIMIT);
97 return NULL;
98 }
99 size_t size = count * width;
100 size_t available = c->owner->limits.max_arena_bytes - c->owner->limits.max_ignore_arena_bytes;
101 size_t *charged = &c->owner->usage.attachment_arena_requested_bytes;
102 if (*charged > available || size > available - *charged) {
103 cni_fail(c, CBM_INVENTORY_LIMIT);
104 return NULL;
105 }
106 if (!cni_poll(c) || !cni_arena_room(c, arena, size)) {
107 return NULL;
108 }
109 *charged += size;
110 void *result = cbm_arena_alloc(arena, size);
111 if (!result) {
112 cni_fail(c, CBM_INVENTORY_OOM);
113 return NULL;
114 }
115 return cni_poll(c) && cni_copy(c, result, NULL, size) ? result : NULL;
116}
117
118static bool cni_delegate(cni_context *c, cbm_pinned_tree_t *tree, cbm_inventory_source_t *source) {
119 cbm_test_impact_inventory_t *owner = c->owner;

Callers 4

cni_rootFunction · 0.85
cni_fileFunction · 0.85
cni_snapshotFunction · 0.85

Calls 5

cni_failFunction · 0.85
cni_pollFunction · 0.85
cni_arena_roomFunction · 0.85
cni_copyFunction · 0.85
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected