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_definitions.c -- keep both in sync. */
| 737 | * with none of them, or when the larger buffer cannot be allocated. Twin of |
| 738 | * pass_definitions.c -- keep both in sync. */ |
| 739 | static char *pp_props_buf(const CBMDefinition *def, char *stack, size_t *size) { |
| 740 | size_t need = *size; |
| 741 | if (def->docstring && def->docstring[0]) { |
| 742 | need += strlen("docstring") + pp_json_escaped_len(def->docstring) + PP_JSON_FIELD_OVERHEAD; |
| 743 | } |
| 744 | if (def->variants && def->variants[0]) { |
| 745 | need += strlen("variants") + strlen(def->variants) + PP_JSON_FIELD_OVERHEAD; |
| 746 | } |
| 747 | if (def->variant_key && def->variant_key[0]) { |
| 748 | need += |
| 749 | strlen("variant_key") + pp_json_escaped_len(def->variant_key) + PP_JSON_FIELD_OVERHEAD; |
| 750 | } |
| 751 | if (need == *size) { |
| 752 | return stack; |
| 753 | } |
| 754 | char *buf = cbm_alloc(CBM_MEM_CLASS_GBUF_STRING, need); |
| 755 | if (!buf) { |
| 756 | return stack; |
| 757 | } |
| 758 | *size = need; |
| 759 | return buf; |
| 760 | } |
| 761 | |
| 762 | /* Insert one definition node (and its route if present) into the local gbuf. */ |
| 763 | static void insert_def_into_gbuf(extract_worker_state_t *ws, const cbm_stem_marks_t *marks, |
no test coverage detected