Skip to content

Commit 55d7c9b

Browse files
committed
Merge fu/argparse-memcore into fu/integration
Retain CBM_MEM_CLASS_OPERATION_ARG ownership across operation parsing and project normalization, with cbm_operation_arg_free releases and lowered allocator baseline. No textual conflicts. Auto-merged src/operations/snippet.c; checked both-side edits and all conditional blocks for duplicate definitions, declarations, TEST bodies and RUN_TEST entries; none added.
2 parents 656f59a + f9344bf commit 55d7c9b

23 files changed

Lines changed: 325 additions & 347 deletions

‎scripts/memory-core-baseline.txt‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,29 @@ src/foundation/workspace.c 5
5050
src/foundation/yaml.c 10
5151
src/git/git_context.c 18
5252
src/main.c 35
53-
src/operations/adr.c 50
54-
src/operations/architecture.c 88
55-
src/operations/changes.c 56
53+
src/operations/adr.c 18
54+
src/operations/architecture.c 77
55+
src/operations/changes.c 46
5656
src/operations/command_runner.c 1
5757
src/operations/compact_out.c 39
58-
src/operations/compare.c 18
59-
src/operations/coverage.c 7
60-
src/operations/cross_repo.c 24
58+
src/operations/compare.c 3
59+
src/operations/cross_repo.c 22
6160
src/operations/execute.c 2
62-
src/operations/file_outline.c 15
63-
src/operations/index.c 78
61+
src/operations/file_outline.c 1
62+
src/operations/index.c 56
6463
src/operations/index_supervisor.c 8
65-
src/operations/json_args.c 1
66-
src/operations/mutation.c 5
67-
src/operations/project_arg.c 5
68-
src/operations/query.c 35
69-
src/operations/read.c 13
64+
src/operations/project_arg.c 3
65+
src/operations/query.c 4
66+
src/operations/read.c 7
7067
src/operations/reliability_events.c 4
7168
src/operations/result_wire.c 1
72-
src/operations/schema.c 10
73-
src/operations/search.c 13
69+
src/operations/schema.c 3
70+
src/operations/search.c 5
7471
src/operations/session_state.c 12
75-
src/operations/snippet.c 26
76-
src/operations/source_search.c 96
72+
src/operations/snippet.c 12
73+
src/operations/source_search.c 64
7774
src/operations/store_host.c 11
78-
src/operations/trace.c 12
75+
src/operations/trace.c 5
7976
src/pipeline/artifact.c 38
8077
src/pipeline/fqn.c 23
8178
src/pipeline/lsp_resolve.h 4

‎src/foundation/mem_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static mem_class_stats_t g_classes[CBM_MEM_CLASS_COUNT];
6767

6868
static const char *const g_class_names[CBM_MEM_CLASS_COUNT] = {
6969
"other", "gbuf_node", "gbuf_edge", "gbuf_string", "gbuf_index", "extract", "arena",
70-
"ts_tree", "semantic", "dump", "store", "hash_table", "dyn_array",
70+
"ts_tree", "semantic", "dump", "store", "hash_table", "dyn_array", "operation_arg",
7171
};
7272

7373
const char *cbm_mem_class_name(cbm_mem_class_t cls) {

‎src/foundation/mem_core.h‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@
5353
* semantic plateau does not. Attribution that cannot separate those two cannot
5454
* choose between "park workers" and "stream the vectors". */
5555
typedef enum {
56-
CBM_MEM_CLASS_OTHER = 0, /* unclassified; the residual to drive down */
57-
CBM_MEM_CLASS_GBUF_NODE, /* node records (~64 B each) */
58-
CBM_MEM_CLASS_GBUF_EDGE, /* edge records (~48 B each) */
59-
CBM_MEM_CLASS_GBUF_STRING, /* name / qualified_name / properties_json */
60-
CBM_MEM_CLASS_GBUF_INDEX, /* the 8 lookup indexes (383 MB peak on the Go corpus) */
61-
CBM_MEM_CLASS_EXTRACT, /* per-file working set: source text, extraction scratch */
62-
CBM_MEM_CLASS_ARENA, /* CBMArena blocks -- every arena, whoever owns it */
63-
CBM_MEM_CLASS_TS_TREE, /* tree-sitter: parse trees + parser state (bound allocator) */
64-
CBM_MEM_CLASS_SEMANTIC, /* semantic pass: vectors, token pools, LSH (87 MB on Go) */
65-
CBM_MEM_CLASS_DUMP, /* dump-time transients */
66-
CBM_MEM_CLASS_STORE, /* SQLite (bound mem methods) + store batches and row buffers */
67-
CBM_MEM_CLASS_HASH_TABLE, /* CBMHashTable buckets/entries not claimed by an owner class */
68-
CBM_MEM_CLASS_DYN_ARRAY, /* CBM_DYN_ARRAY item storage (every cbm_da_* user) */
56+
CBM_MEM_CLASS_OTHER = 0, /* unclassified; the residual to drive down */
57+
CBM_MEM_CLASS_GBUF_NODE, /* node records (~64 B each) */
58+
CBM_MEM_CLASS_GBUF_EDGE, /* edge records (~48 B each) */
59+
CBM_MEM_CLASS_GBUF_STRING, /* name / qualified_name / properties_json */
60+
CBM_MEM_CLASS_GBUF_INDEX, /* the 8 lookup indexes (383 MB peak on the Go corpus) */
61+
CBM_MEM_CLASS_EXTRACT, /* per-file working set: source text, extraction scratch */
62+
CBM_MEM_CLASS_ARENA, /* CBMArena blocks -- every arena, whoever owns it */
63+
CBM_MEM_CLASS_TS_TREE, /* tree-sitter: parse trees + parser state (bound allocator) */
64+
CBM_MEM_CLASS_SEMANTIC, /* semantic pass: vectors, token pools, LSH (87 MB on Go) */
65+
CBM_MEM_CLASS_DUMP, /* dump-time transients */
66+
CBM_MEM_CLASS_STORE, /* SQLite (bound mem methods) + store batches and row buffers */
67+
CBM_MEM_CLASS_HASH_TABLE, /* CBMHashTable buckets/entries not claimed by an owner class */
68+
CBM_MEM_CLASS_DYN_ARRAY, /* CBM_DYN_ARRAY item storage (every cbm_da_* user) */
69+
CBM_MEM_CLASS_OPERATION_ARG, /* transient strings parsed from operation arguments */
6970
CBM_MEM_CLASS_COUNT
7071
} cbm_mem_class_t;
7172

‎src/operations/adr.c‎

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "foundation/compat_fs.h"
66
#include "foundation/constants.h"
7+
#include "foundation/mem_core.h"
78
#include "store/store.h"
89
#include "yyjson/yyjson.h"
910

@@ -44,7 +45,7 @@ static char *adr_string_arg(const char *args, const char *key) {
4445
yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
4546
yyjson_val *value = yyjson_is_obj(root) ? yyjson_obj_get(root, key) : NULL;
4647
const char *text = yyjson_is_str(value) ? yyjson_get_str(value) : NULL;
47-
char *copy = text ? adr_strdup(text) : NULL;
48+
char *copy = text ? cbm_mem_strdup(CBM_MEM_CLASS_OPERATION_ARG, text) : NULL;
4849
if (doc)
4950
yyjson_doc_free(doc);
5051
return copy;
@@ -394,28 +395,28 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
394395
char *mode = adr_string_arg(args, "mode");
395396
char *content = adr_string_arg(args, "content");
396397
if (!mode)
397-
mode = adr_strdup("outline");
398+
mode = cbm_mem_strdup(CBM_MEM_CLASS_OPERATION_ARG, "outline");
398399

399400
bool valid_mode = mode && (strcmp(mode, "outline") == 0 || strcmp(mode, "get") == 0 ||
400401
strcmp(mode, "sections") == 0 || strcmp(mode, "update") == 0 ||
401402
strcmp(mode, "set_sections") == 0 || strcmp(mode, "store") == 0);
402403
if (!valid_mode) {
403-
free(project);
404-
free(mode);
405-
free(content);
404+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
405+
cbm_operation_arg_free(mode);
406+
cbm_operation_arg_free(content);
406407
return adr_error("invalid_arguments",
407408
"invalid mode: use outline, get, sections, set_sections, or update");
408409
}
409410
if ((strcmp(mode, "update") == 0 || strcmp(mode, "store") == 0) && !content) {
410-
free(project);
411-
free(mode);
411+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
412+
cbm_operation_arg_free(mode);
412413
return adr_error("invalid_arguments", "content is required for update");
413414
}
414415

415416
if (adr_has_removed_sections_arg(args)) {
416-
free(project);
417-
free(mode);
418-
free(content);
417+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
418+
cbm_operation_arg_free(mode);
419+
cbm_operation_arg_free(content);
419420
return adr_error("invalid_arguments", "The sections argument is not an update primitive "
420421
"and has been removed. No ADR write was performed.");
421422
}
@@ -435,9 +436,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
435436
if (updates.status) {
436437
cbm_operation_result_t result = adr_error(updates.status, updates.error);
437438
adr_updates_free(&updates);
438-
free(project);
439-
free(mode);
440-
free(content);
439+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
440+
cbm_operation_arg_free(mode);
441+
cbm_operation_arg_free(content);
441442
return result;
442443
}
443444
}
@@ -447,9 +448,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
447448
set_sections;
448449
if (!runtime || !runtime->store_resolve) {
449450
adr_updates_free(&updates);
450-
free(project);
451-
free(mode);
452-
free(content);
451+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
452+
cbm_operation_arg_free(mode);
453+
cbm_operation_arg_free(content);
453454
return adr_error("store_unavailable",
454455
"project store resolution is unavailable for this execution path");
455456
}
@@ -459,18 +460,18 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
459460
if (!runtime->mutation_begin || !runtime->mutation_end ||
460461
!runtime->mutation_begin(runtime->mutation_context, project)) {
461462
adr_updates_free(&updates);
462-
free(project);
463-
free(mode);
464-
free(content);
463+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
464+
cbm_operation_arg_free(mode);
465+
cbm_operation_arg_free(content);
465466
return adr_error("busy", "project operation cancelled or blocked by an active index");
466467
}
467468
mutation_held = true;
468469
if (runtime->cancelled && runtime->cancelled(runtime->cancelled_context)) {
469470
runtime->mutation_end(runtime->mutation_context, project);
470471
adr_updates_free(&updates);
471-
free(project);
472-
free(mode);
473-
free(content);
472+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
473+
cbm_operation_arg_free(mode);
474+
cbm_operation_arg_free(content);
474475
return adr_error("cancelled", "project operation cancelled for this request");
475476
}
476477
}
@@ -497,9 +498,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
497498
if (mutation_held)
498499
runtime->mutation_end(runtime->mutation_context, project);
499500
adr_updates_free(&updates);
500-
free(project);
501-
free(mode);
502-
free(content);
501+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
502+
cbm_operation_arg_free(mode);
503+
cbm_operation_arg_free(content);
503504
return result;
504505
}
505506

@@ -511,9 +512,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
511512
if (mutation_held)
512513
runtime->mutation_end(runtime->mutation_context, project);
513514
adr_updates_free(&updates);
514-
free(project);
515-
free(mode);
516-
free(content);
515+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
516+
cbm_operation_arg_free(mode);
517+
cbm_operation_arg_free(content);
517518
return adr_error("open_failed", "failed to open writable ADR store");
518519
}
519520
}
@@ -571,9 +572,9 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
571572
adr_updates_free(&updates);
572573
free(legacy_seed);
573574
free(legacy);
574-
free(project);
575-
free(mode);
576-
free(content);
575+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
576+
cbm_operation_arg_free(mode);
577+
cbm_operation_arg_free(content);
577578
return cbm_operation_result_copy("{\"error\":\"result allocation failed\"}", true);
578579
}
579580
yyjson_mut_doc_set_root(doc, root);
@@ -656,8 +657,8 @@ cbm_operation_result_t cbm_adr_operation_execute(const char *args_json,
656657
adr_updates_free(&updates);
657658
free(legacy_seed);
658659
free(legacy);
659-
free(project);
660-
free(mode);
661-
free(content);
660+
cbm_free(CBM_MEM_CLASS_OPERATION_ARG, project);
661+
cbm_operation_arg_free(mode);
662+
cbm_operation_arg_free(content);
662663
return result;
663664
}

‎src/operations/architecture.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "operations/result_wire.h"
2+
#include "operations/json_args.h"
23
#include "operations/architecture.h"
34
#include "operations/store_host.h"
45

@@ -28,8 +29,9 @@ static char *architecture_string_arg(const char *args_json, const char *name) {
2829
yyjson_doc *doc = yyjson_read(json, strlen(json), 0);
2930
yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
3031
yyjson_val *value = yyjson_is_obj(root) ? yyjson_obj_get(root, name) : NULL;
31-
char *result =
32-
value && yyjson_is_str(value) ? architecture_copy_string(yyjson_get_str(value)) : NULL;
32+
char *result = value && yyjson_is_str(value)
33+
? cbm_mem_strdup(CBM_MEM_CLASS_OPERATION_ARG, yyjson_get_str(value))
34+
: NULL;
3335
if (doc)
3436
yyjson_doc_free(doc);
3537
return result;
@@ -522,13 +524,13 @@ static char *arch_node_qn(cbm_store_t *store, int64_t id) {
522524
cbm_operation_result_t cbm_architecture_operation_execute(const char *args) {
523525
char *project = architecture_project_arg(args);
524526
if (!project || !project[0]) {
525-
free(project);
527+
cbm_operation_arg_free(project);
526528
return architecture_error("project is required");
527529
}
528530
cbm_store_open_status_t open_status = CBM_STORE_OPEN_OK;
529531
cbm_store_t *store = cbm_store_host_open_query(project, &open_status);
530532
if (!store) {
531-
free(project);
533+
cbm_operation_arg_free(project);
532534
return architecture_error(open_status == CBM_STORE_OPEN_CORRUPT
533535
? CBM_STORE_CORRUPT_ERROR
534536
: "project not found or not indexed");
@@ -537,8 +539,8 @@ cbm_operation_result_t cbm_architecture_operation_execute(const char *args) {
537539

538540
if (cbm_store_count_nodes(store, project) <= 0) {
539541
cbm_store_close(store);
540-
free(project);
541-
free(scope_path);
542+
cbm_operation_arg_free(project);
543+
cbm_operation_arg_free(scope_path);
542544
return architecture_error("project not indexed or index is empty");
543545
}
544546

@@ -594,8 +596,8 @@ cbm_operation_result_t cbm_architecture_operation_execute(const char *args) {
594596
snprintf(msg, sizeof(msg), "Unknown aspect '%s'. Valid: %s.", aspects_strs[i],
595597
valid_list);
596598
cbm_operation_result_t err = architecture_error(msg);
597-
free(project);
598-
free(scope_path);
599+
cbm_operation_arg_free(project);
600+
cbm_operation_arg_free(scope_path);
599601
if (aspects_doc) {
600602
yyjson_doc_free(aspects_doc);
601603
}
@@ -637,7 +639,7 @@ cbm_operation_result_t cbm_architecture_operation_execute(const char *args) {
637639
* same model as structured JSON ({cols, rows} per section). */
638640
char *arch_format = architecture_string_arg(args, "format");
639641
bool arch_legacy_json = arch_format && strcmp(arch_format, "json") == 0;
640-
free(arch_format);
642+
cbm_operation_arg_free(arch_format);
641643

642644
if (!arch_legacy_json) {
643645
cbm_sb_t sb;
@@ -897,8 +899,8 @@ cbm_operation_result_t cbm_architecture_operation_execute(const char *args) {
897899
if (aspects_doc) {
898900
yyjson_doc_free(aspects_doc);
899901
}
900-
free(project);
901-
free(scope_path);
902+
cbm_operation_arg_free(project);
903+
cbm_operation_arg_free(scope_path);
902904
free(norm_path);
903905
char *text = cbm_sb_finish(&sb);
904906
if (!text) {
@@ -1157,8 +1159,8 @@ cbm_operation_result_t cbm_architecture_operation_execute(const char *args) {
11571159
if (aspects_doc) {
11581160
yyjson_doc_free(aspects_doc);
11591161
}
1160-
free(project);
1161-
free(scope_path);
1162+
cbm_operation_arg_free(project);
1163+
cbm_operation_arg_free(scope_path);
11621164
free(norm_path);
11631165

11641166
cbm_store_close(store);

0 commit comments

Comments
 (0)