From 5613a3b0d42a89d061df18cd9ae4e1008696572c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 20 Jul 2021 23:26:38 -0700 Subject: parse/eval: use weak-both hash tables. This addresses the problem that a4c376979d15323ad729e92e41ba43768e8dc163 tried to fix. * eval.c (eval_init): Make all the top-level binding tables, top_fb, top_vb, top_mb, top_smb, special and builtin, weak-both tables: keys and values are weak. This way, the entries disappear if both key and value are unreachable, even if they refer to each other. (eval_compat_fixup): In 266 or earlier compat mode, weak-both tables don't have the right semantics, so we tweak the tables to weak-key tables. * parser.c (parse_init): Same treatment for stream_parser_hash. We want an entry to disappear from the hash if neither the parser nor the stream are reachable. (parse_compat_fixup): New function. * parser.h (parse_compat_function): Declared. * hash.c, hash.h (tweak_hash): New function. * lib.c (compat_fixup): Call parse_compat_fixup. --- parser.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index 0deb3867..169b58b0 100644 --- a/parser.c +++ b/parser.c @@ -1878,7 +1878,7 @@ void parse_init(void) parser_cls = cobj_register(parser_s); protect(&stream_parser_hash, &unique_s, &catch_all, convert(val *, 0)); - stream_parser_hash = make_hash(t, nil, nil); + stream_parser_hash = make_hash(t, t, nil); catch_all = cons(t, nil); parser_l_init(); @@ -1897,3 +1897,9 @@ void parse_init(void) reg_fun(intern(lit("repl"), system_package), func_n4(repl)); reg_mac(json_s, func_n2(me_json)); } + +void parse_compat_fixup(int compat_ver) +{ + if (compat_ver <= 266) + tweak_hash(stream_parser_hash, t, nil); +} -- cgit v1.2.3