Skip to content

Commit b372112

Browse files
committed
doc-links(cs): a doc-line map that cannot grow fails the layer (R5)
cbm_doclink_note_doc_line returned silently when the map (or its first block) could not be allocated. The doc it was noting then keeps its definition's line, and a doc shared by the declarators of one field declaration is no longer marked as taken, so its references are parsed once per declarator -- while the layer reports ok. Both allocation failures now set the file's doc_links.failed, as every other lost piece of doc-link data does; the layer then says error. A test seam, CBM_DOCLINK_ALLOC_DOC_LINE, fails the map's growth. Test: alloc_failure_status gets the doc-line map as one more point (one error row). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent aba240b commit b372112

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

‎internal/cbm/doclink.c‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ static CBMArena *doclink_scratch(CBMExtractCtx *ctx) {
195195
return ctx->scratch ? ctx->scratch : ctx->arena;
196196
}
197197

198+
/* The map could not hold a doc: its references then take their definition's
199+
* line, and a doc shared by several declarators is taken once per declarator.
200+
* The layer must not say ok over that (CBMDocLinkArray.failed). */
201+
static void doc_line_lost(CBMExtractCtx *ctx) {
202+
if (ctx->result) {
203+
ctx->result->doc_links.failed = true;
204+
}
205+
}
206+
198207
void cbm_doclink_note_doc_line(CBMExtractCtx *ctx, const char *doc, uint32_t line) {
199208
if (!ctx || !doc || !cbm_doclink_lang_supported(ctx->language)) {
200209
return;
@@ -204,16 +213,26 @@ void cbm_doclink_note_doc_line(CBMExtractCtx *ctx, const char *doc, uint32_t lin
204213
if (!m) {
205214
m = (doc_line_map_t *)cbm_arena_alloc(a, sizeof(*m));
206215
if (!m) {
216+
doc_line_lost(ctx);
207217
return;
208218
}
209219
memset(m, 0, sizeof(*m));
210220
ctx->doc_lines = m;
211221
}
212222
if (m->count >= m->cap) {
213223
int ncap = m->cap ? m->cap * PAIR_LEN : DOC_LINE_MAP_INIT;
214-
doc_line_ent_t *grown = (doc_line_ent_t *)cbm_arena_alloc(a, (size_t)ncap * sizeof(*grown));
224+
doc_line_ent_t *grown;
225+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
226+
if (cbm_doclink_test_fail_alloc(CBM_DOCLINK_ALLOC_DOC_LINE)) {
227+
grown = NULL;
228+
} else
229+
#endif
230+
{
231+
grown = (doc_line_ent_t *)cbm_arena_alloc(a, (size_t)ncap * sizeof(*grown));
232+
}
215233
if (!grown) {
216-
return; /* the reference keeps its definition's line instead */
234+
doc_line_lost(ctx);
235+
return;
217236
}
218237
if (m->count > 0) {
219238
memcpy(grown, m->items, (size_t)m->count * sizeof(*grown));

‎internal/cbm/doclink.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ enum {
149149
CBM_DOCLINK_ALLOC_TEXT,
150150
CBM_DOCLINK_ALLOC_VALUE,
151151
CBM_DOCLINK_ALLOC_TOKENS,
152-
CBM_DOCLINK_ALLOC_SCOPE, /* the C# scope scan, as if its builder ran out */
153-
CBM_DOCLINK_ALLOC_PROJECT, /* the project-file scan, likewise */
152+
CBM_DOCLINK_ALLOC_SCOPE, /* the C# scope scan, as if its builder ran out */
153+
CBM_DOCLINK_ALLOC_PROJECT, /* the project-file scan, likewise */
154+
CBM_DOCLINK_ALLOC_DOC_LINE, /* the doc-line map's growth */
154155
CBM_DOCLINK_ALLOC_KINDS,
155156
};
156157
void cbm_doclink_test_fail_alloc_after(int kind, int nth);

‎tests/test_doc_mentions.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9775,7 +9775,8 @@ TEST(doc_mentions_incremental_non_ascii_name) {
97759775
* loses references, a scope or an edge -- the layer then says error, never
97769776
* ok over a silently thinner graph. One allocation fails at each point in
97779777
* turn (a doc span, a doc text, a reference value, a token, the scope scan,
9778-
* a MENTIONS edge); the run without a failure has no error row. */
9778+
* the project scan, the doc-line map, a MENTIONS edge); the run without a
9779+
* failure has no error row. */
97799780
enum { DM_FAIL_EDGE = CBM_DOCLINK_ALLOC_KINDS };
97809781

97819782
static int dm_alloc_failure_errors(int point) {
@@ -10103,10 +10104,10 @@ TEST(doc_mentions_alloc_failure_status) {
1010310104
int point;
1010410105
const char *what;
1010510106
} points[] = {
10106-
{CBM_DOCLINK_ALLOC_SPAN, "doc span"}, {CBM_DOCLINK_ALLOC_TEXT, "doc text"},
10107-
{CBM_DOCLINK_ALLOC_VALUE, "value"}, {CBM_DOCLINK_ALLOC_TOKENS, "token"},
10108-
{CBM_DOCLINK_ALLOC_SCOPE, "scope scan"}, {CBM_DOCLINK_ALLOC_PROJECT, "project scan"},
10109-
{DM_FAIL_EDGE, "MENTIONS edge"},
10107+
{CBM_DOCLINK_ALLOC_SPAN, "doc span"}, {CBM_DOCLINK_ALLOC_TEXT, "doc text"},
10108+
{CBM_DOCLINK_ALLOC_VALUE, "value"}, {CBM_DOCLINK_ALLOC_TOKENS, "token"},
10109+
{CBM_DOCLINK_ALLOC_SCOPE, "scope scan"}, {CBM_DOCLINK_ALLOC_PROJECT, "project scan"},
10110+
{CBM_DOCLINK_ALLOC_DOC_LINE, "doc-line map"}, {DM_FAIL_EDGE, "MENTIONS edge"},
1011010111
};
1011110112
int baseline = dm_alloc_failure_errors(-1);
1011210113
bool ok = baseline == 0;

0 commit comments

Comments
 (0)