A def's properties buffer: CBM_SZ_2K for every other field plus the whole * serialized docstring, variants and variant_key fields, which have no length * cap (a field that does not fit is dropped whole). Returns `stack` for a def * with none of them, or when the larger buffer cannot be allocated. Twin of * pass_parallel.c -- keep both in sync. */
| 359 | * with none of them, or when the larger buffer cannot be allocated. Twin of |
| 360 | * pass_parallel.c -- keep both in sync. */ |
| 361 | static char *pd_props_buf(const CBMDefinition *def, char *stack, size_t *size) { |
| 362 | size_t need = *size; |
| 363 | if (def->docstring && def->docstring[0]) { |
| 364 | need += strlen("docstring") + def_json_escaped_len(def->docstring) + PD_JSON_FIELD_OVERHEAD; |
| 365 | } |
| 366 | if (def->variants && def->variants[0]) { |
| 367 | need += strlen("variants") + strlen(def->variants) + PD_JSON_FIELD_OVERHEAD; |
| 368 | } |
| 369 | if (def->variant_key && def->variant_key[0]) { |
| 370 | need += |
| 371 | strlen("variant_key") + def_json_escaped_len(def->variant_key) + PD_JSON_FIELD_OVERHEAD; |
| 372 | } |
| 373 | if (need == *size) { |
| 374 | return stack; |
| 375 | } |
| 376 | char *buf = cbm_alloc(CBM_MEM_CLASS_GBUF_STRING, need); |
| 377 | if (!buf) { |
| 378 | return stack; |
| 379 | } |
| 380 | *size = need; |
| 381 | return buf; |
| 382 | } |
| 383 | |
| 384 | /* Add a file's own doc (Go package comment, Rust inner docs) to its File |
| 385 | * node as "docstring". Twin of pass_parallel.c -- keep both in sync. */ |
no test coverage detected