feat: add sel_alloc_thread_id ownership check in eval_select and gc_sweep (6-10)

This commit is contained in:
Rongsong Shen 2026-04-30 06:04:21 +00:00
parent 742d79ee55
commit b722e5cb3d
4 changed files with 59 additions and 0 deletions

View file

@ -2226,6 +2226,32 @@ test_gc_clear_marks_exported(void)
sel_optimize_test_reset();
}
/* ── Task 8: sel_alloc_thread_id ownership check ─────────────────────────*/
static void
test_sel_register_alloc_thread(void)
{
sel_optimize_test_reset(); /* resets sel_alloc_thread_id to 0 */
sel_optimize_set(1);
sel_node_table_init();
/* Should not crash when unregistered (id=0 means skip check) */
xce_select_node_t* n = makeSelectNode(SEL_TRUE, 0, 0);
TEST_ASSERT_NOT_NULL(n);
/* Register current thread */
sel_register_alloc_thread();
/* makeSelectNode from same thread must still work */
xce_select_node_t* n2 = makeSelectNode(SEL_FALSE, 0, 0);
TEST_ASSERT_NOT_NULL(n2);
gc_clear_marks();
gc_sweep_select_nodes(NULL, 0);
sel_node_table_fini();
sel_optimize_test_reset();
}
/* ── Top-level runner ─────────────────────────────────────────────────────*/
void
@ -2337,5 +2363,8 @@ test_select(void)
/* ── Phase 6 prep: exported GC mark primitives ───────────────────── */
RUN_TEST(test_gc_clear_marks_exported);
/* ── Task 8: sel_alloc_thread_id ownership check ─────────────────── */
RUN_TEST(test_sel_register_alloc_thread);
xstring_table_fini();
}