| 238 | } |
| 239 | |
| 240 | cbm_test_declarations_t *cbm_test_declarations_parse(const char *bytes, size_t len, bool absent) { |
| 241 | if (len > TD_MAX_BYTES || (absent && len) || (!absent && (!bytes || !len)) || |
| 242 | (len && memchr(bytes, '\0', len))) |
| 243 | return NULL; |
| 244 | CBMArena arena; |
| 245 | cbm_arena_init_lazy(&arena, 4096); |
| 246 | cbm_test_declarations_t *declarations = cbm_arena_calloc(&arena, sizeof(*declarations)); |
| 247 | if (!declarations) { |
| 248 | cbm_arena_destroy(&arena); |
| 249 | return NULL; |
| 250 | } |
| 251 | declarations->arena = arena; |
| 252 | for (int preset = 0; preset < CBM_TEST_PRESET_COUNT; preset++) |
| 253 | declarations->presets[preset] = preset != CBM_TEST_PRESET_C_CBM; |
| 254 | bool valid = true; |
| 255 | if (!absent) { |
| 256 | yyjson_doc *doc = yyjson_read(bytes, len, 0); |
| 257 | if (!doc) { |
| 258 | valid = false; |
| 259 | } else { |
| 260 | valid = td_project(declarations, yyjson_doc_get_root(doc)); |
| 261 | yyjson_doc_free(doc); |
| 262 | } |
| 263 | } |
| 264 | if (!valid) { |
| 265 | cbm_test_declarations_free(declarations); |
| 266 | return NULL; |
| 267 | } |
| 268 | td_digest(declarations, bytes, len, absent); |
| 269 | return declarations; |
| 270 | } |
| 271 | |
| 272 | void cbm_test_declarations_free(cbm_test_declarations_t *declarations) { |
| 273 | if (!declarations) |
no test coverage detected