Skip to content

Commit 008137f

Browse files
committed
fix(grammar): isolate properties scanner state
Signed-off-by: ngallodev <[email protected]>
1 parent 7a388ed commit 008137f

4 files changed

Lines changed: 65 additions & 11 deletions

File tree

‎internal/cbm/vendored/grammars/MANIFEST.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Re-vendoring from upstream must re-apply these.
8585
| rescript | `rescript/scanner.c`, deserialize | guard `memcpy(state, buffer, n_bytes)` with `if (n_bytes > 0)` | UBSan: zero-length `memcpy` with a NULL `buffer` / `n_bytes == 0` on empty-state deserialize (formal UB, harmless). The sibling serialize copies a fixed `sizeof(ScannerState)` (always > 0, non-NULL src) and needs no guard. |
8686
| purescript | `purescript/scanner.c`, serialize | guard `memcpy(buffer, indents->data, to_copy)` with `if (to_copy > 0)` | UBSan: zero-length `memcpy` with a NULL/0-size source when the indent vector is empty (formal UB, harmless) |
8787
| plsql | `plsql/parser.c`, include | `#include <tree_sitter/parser.h>` → `#include "tree_sitter/parser.h"` | The older ABI-14 generator emits angle brackets; every other vendored grammar uses the quoted form, which resolves the per-grammar `tree_sitter/` header from the including file's directory |
88+
| properties | `properties/scanner.c`, whole file | move the `reached_eof` flag out of a file-scope `static bool` and into a per-parser payload allocated by `..._external_scanner_create()` | Data race: upstream's process-wide flag can suppress the `FAKE_EOL` needed by another concurrent parser, leaving `.properties` indexing stuck at EOF. The serialize/deserialize wire format remains the returned length. Re-apply this patch when re-vendoring pinned upstream `6310671b24d4` |
8889

8990
## Vendored from verified upstream
9091

‎internal/cbm/vendored/grammars/properties/scanner.c‎

Lines changed: 21 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/vendored-checksums.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ c5cfb43042b6b72045f4ba997834d0a7786d2793d91680868b5815b39f14fc78 internal/cbm/v
55
b29c1c9fb7cc82f58c84b376df1297d6e2737a1d655fd356db0859e3c29c2fea internal/cbm/vendored/common/tree_sitter/alloc.h
66
31e60a1bff6f715afacce03b5b70efe42b58371b4f9595dd4af52a577ff9608c internal/cbm/vendored/common/tree_sitter/array.h
77
180b893c8734778fd32f372dfbc27bd6ad1cd2221f26150b31256ff6716320d2 internal/cbm/vendored/common/tree_sitter/parser.h
8-
e1233d81f21d868b8f2d9e8fca10e15f2ec3ae4db4a7ba0301161cc011deef65 internal/cbm/vendored/grammars/MANIFEST.md
8+
56939310af6656e7e51b939d09068401b0235eb4c20f436c416f1886b97e3efd internal/cbm/vendored/grammars/MANIFEST.md
99
ad8425038de519f8c4e3e9339feebf99dfad8a6002dcf79227d91402780a32cc internal/cbm/vendored/grammars/ada/LICENSE
1010
02805ec13939b749c891567be36bf024b09034e04c80683a1ae667272458d549 internal/cbm/vendored/grammars/ada/parser.c
1111
115a75d000bef9c70c4de7dfbb7f2a80b90cbb14ba265056dc7abb1ef3b9b6db internal/cbm/vendored/grammars/ada/tree_sitter/alloc.h
@@ -610,7 +610,7 @@ fbce36bb615a015ea545373da62c178fe9e7e3a7b7de656455738e6f671aa652 internal/cbm/v
610610
c4b9482069f61a2a26a590181baa34f08eb6dcc57a138def578e6f9720c35ea5 internal/cbm/vendored/grammars/prisma/tree_sitter/parser.h
611611
3297073719030b7261afd78b7267931ccc03a27f7a65ca6fc644316180f71bf6 internal/cbm/vendored/grammars/properties/LICENSE
612612
98e06c3a7b3043d7641ec0b2c28c9f66e54341e343e1f553f994ae5a6f0c0452 internal/cbm/vendored/grammars/properties/parser.c
613-
3c00e7a8ec38662b05cb00858d2959b123b2b5c783eb3dc25c80b7577b4c27ac internal/cbm/vendored/grammars/properties/scanner.c
613+
e13d4f10cf7e39eb306e82f5e1584d2c6dccab27da7c5ac014116e41234de380 internal/cbm/vendored/grammars/properties/scanner.c
614614
115a75d000bef9c70c4de7dfbb7f2a80b90cbb14ba265056dc7abb1ef3b9b6db internal/cbm/vendored/grammars/properties/tree_sitter/alloc.h
615615
02d139d44303b0b0b85a899839dbc1346c478e7318d1f2971fad2b38fd57cb73 internal/cbm/vendored/grammars/properties/tree_sitter/array.h
616616
c4b9482069f61a2a26a590181baa34f08eb6dcc57a138def578e6f9720c35ea5 internal/cbm/vendored/grammars/properties/tree_sitter/parser.h

‎tests/test_grammar_regression.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "cbm.h"
1818
#include "grammar_cases.h"
1919

20+
#include <pthread.h>
21+
#include <sched.h>
22+
#include <stdatomic.h>
23+
2024
static int reg_has_def_any(CBMFileResult *r, const char *name) {
2125
for (int i = 0; i < r->defs.count; i++) {
2226
if (strcmp(r->defs.items[i].name, name) == 0)
@@ -401,6 +405,43 @@ TEST(grammar_regression_all) {
401405
PASS();
402406
}
403407

408+
typedef struct {
409+
atomic_int *ready;
410+
atomic_int *failures;
411+
} PropertiesParallelArgs;
412+
413+
static void *properties_parallel_worker(void *arg) {
414+
PropertiesParallelArgs *args = arg;
415+
atomic_fetch_add(args->ready, 1);
416+
while (atomic_load(args->ready) != 8)
417+
sched_yield();
418+
for (int i = 0; i < 8; i++) {
419+
CBMFileResult *r = extract("# generated probe\nalpha=one\nbeta=two\ngamma=three\n",
420+
CBM_LANG_PROPERTIES, "parallel", "probe.properties");
421+
if (!r)
422+
atomic_fetch_add(args->failures, 1);
423+
cbm_free_result(r);
424+
}
425+
return NULL;
426+
}
427+
428+
TEST(properties_scanner_parallel_extract) {
429+
enum { WORKERS = 8 };
430+
pthread_t threads[WORKERS];
431+
atomic_int ready = 0;
432+
atomic_int failures = 0;
433+
PropertiesParallelArgs args = {.ready = &ready, .failures = &failures};
434+
for (int i = 0; i < WORKERS; i++)
435+
ASSERT_EQ(pthread_create(&threads[i], NULL, properties_parallel_worker, &args), 0);
436+
while (atomic_load(&ready) != WORKERS)
437+
sched_yield();
438+
for (int i = 0; i < WORKERS; i++)
439+
ASSERT_EQ(pthread_join(threads[i], NULL), 0);
440+
ASSERT_EQ(atomic_load(&failures), 0);
441+
PASS();
442+
}
443+
404444
void suite_grammar_regression(void) {
405445
RUN_TEST(grammar_regression_all);
446+
RUN_TEST(properties_scanner_parallel_extract);
406447
}

0 commit comments

Comments
 (0)