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

Function php_read_binding_snapshot

src/pipeline/pass_pkgmap.c:2890–2986  ·  view source on GitHub ↗

Validate the entire snapshot, including bindings that coalesced into one * (source, target, local_name) edge. A positive insertion ID alone is not * evidence that all properties and secondary indexes were stored. */

Source from the content-addressed store, hash-verified

2888 * (source, target, local_name) edge. A positive insertion ID alone is not
2889 * evidence that all properties and secondary indexes were stored. */
2890static bool php_read_binding_snapshot(const cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *file,
2891 const CBMFileResult *result, const char *json,
2892 cbm_php_vendor_names_t *out) {
2893 if (!json || strncmp(json, php_import_complete, sizeof(php_import_complete) - 1) != 0)
2894 return false;
2895 yyjson_doc *doc = yyjson_read(json, strlen(json), 0);
2896 if (!doc)
2897 return false;
2898 yyjson_val *root = yyjson_doc_get_root(doc);
2899 yyjson_val *manifest = yyjson_obj_get(root, "php_import_bindings");
2900 int count = result->imports.count;
2901 const cbm_gbuf_edge_t **edges = NULL;
2902 int edge_count = 0;
2903 const char **targets = NULL;
2904 int *seen = NULL;
2905 bool ok =
2906 count >= 0 && (count == 0 || result->imports.items) &&
2907 php_json_key_count(root, "php_imports_complete") == 1 &&
2908 php_json_key_count(root, "php_import_bindings") == 1 && yyjson_is_arr(manifest) &&
2909 yyjson_arr_size(manifest) == (size_t)count &&
2910 cbm_gbuf_find_edges_by_source_type(gbuf, file->id, "IMPORTS", &edges, &edge_count) == 0 &&
2911 edge_count >= 0 && (edge_count == 0 || edges);
2912 if (!ok)
2913 goto done;
2914 size_t slots = count > 0 ? (size_t)count : 1;
2915 if (slots > SIZE_MAX / sizeof(*targets) || slots > SIZE_MAX / sizeof(*seen)) {
2916 ok = false;
2917 goto done;
2918 }
2919 targets = cbm_calloc(CBM_MEM_CLASS_OTHER, slots * sizeof(*targets));
2920 seen = cbm_calloc(CBM_MEM_CLASS_OTHER, slots * sizeof(*seen));
2921 if (!targets || !seen) {
2922 ok = false;
2923 goto done;
2924 }
2925 for (int i = 0; ok && i < count; i++) {
2926 yyjson_val *entry = yyjson_arr_get(manifest, (size_t)i);
2927 yyjson_val *target = yyjson_obj_get(entry, "target");
2928 ok = php_binding_identity(entry, &result->imports.items[i]);
2929 if (yyjson_is_str(target)) {
2930 const cbm_gbuf_node_t *node = cbm_gbuf_find_by_qn(gbuf, yyjson_get_str(target));
2931 ok = ok && node && node->id != file->id && node->qualified_name &&
2932 php_json_string_eq(target, node->qualified_name);
2933 if (ok)
2934 targets[i] = node->qualified_name;
2935 } else if (!yyjson_is_null(target)) {
2936 ok = false;
2937 }
2938 }
2939 for (int e = 0; ok && e < edge_count; e++) {
2940 const cbm_gbuf_edge_t *edge = edges[e];
2941 if (!edge) {
2942 ok = false;
2943 break;
2944 }
2945 const cbm_gbuf_node_t *target = cbm_gbuf_find_by_id(gbuf, edge->target_id);
2946 yyjson_doc *edoc = edge->properties_json ? yyjson_read(edge->properties_json,
2947 strlen(edge->properties_json), 0)

Calls 8

php_json_key_countFunction · 0.85
cbm_callocFunction · 0.85
php_binding_identityFunction · 0.85
cbm_gbuf_find_by_qnFunction · 0.85
php_json_string_eqFunction · 0.85
cbm_gbuf_find_by_idFunction · 0.85
cbm_freeFunction · 0.85

Tested by

no test coverage detected