From d4c20918b97dbfc72ad238c308b3a72a69792212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Tue, 23 Apr 2024 09:42:54 +0200 Subject: [PATCH] core: register the finalizer immedietely after allocation Previously we've registered the finalizer when a symbol was dynamically bound for the first time; this commit changes that to remove a dependency on GC when binding special variables. --- src/c/alloc_2.d | 7 ++++--- src/c/stacks.d | 1 - src/c/symbol.d | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/c/alloc_2.d b/src/c/alloc_2.d index 08529ad42..e3c6497ab 100644 --- a/src/c/alloc_2.d +++ b/src/c/alloc_2.d @@ -889,9 +889,10 @@ standard_finalizer(cl_object o) break; } case t_symbol: { - ecl_atomic_push(&cl_core.reused_indices, - ecl_make_fixnum(o->symbol.binding)); - o->symbol.binding = ECL_MISSING_SPECIAL_BINDING; + if (o->symbol.binding != ECL_MISSING_SPECIAL_BINDING) { + ecl_atomic_push(&cl_core.reused_indices, ecl_make_fixnum(o->symbol.binding)); + o->symbol.binding = ECL_MISSING_SPECIAL_BINDING; + } } #endif /* ECL_THREADS */ default:; diff --git a/src/c/stacks.d b/src/c/stacks.d index 71bf88c5d..a7d2c0a39 100644 --- a/src/c/stacks.d +++ b/src/c/stacks.d @@ -435,7 +435,6 @@ ecl_new_binding_index(cl_env_ptr env, cl_object symbol) } symbol->symbol.binding = new_index; } - ecl_set_finalizer_unprotected(symbol, ECL_T); return new_index; } diff --git a/src/c/symbol.d b/src/c/symbol.d index 1215891fe..0cc4e6a21 100644 --- a/src/c/symbol.d +++ b/src/c/symbol.d @@ -112,6 +112,7 @@ cl_make_symbol(cl_object str) x->symbol.plist = ECL_NIL; x->symbol.hpack = ECL_NIL; x->symbol.stype = ecl_stp_ordinary; + ecl_set_finalizer_unprotected(x, ECL_T); @(return x); }