From df3789cfece5eaa149d76b07eda310c607288fbb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 28 Feb 2018 18:48:44 -0800 Subject: bugfix: missing actions in reset-struct. * struct.c (reset_struct): Perform the post-init actions are performed, not only the init actions. Also, catch exceptions and call finalizers, just like in a new structure instantiation. * txr.1: Document the requirements for finalizers being called by reset-struct, and clarify the issue of possible duplicate finalization registration. Add compat notes. --- struct.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'struct.c') diff --git a/struct.c b/struct.c index 6178340b..0e8b1080 100644 --- a/struct.c +++ b/struct.c @@ -726,14 +726,30 @@ val reset_struct(val strct) struct struct_inst *si = struct_handle(strct, self); struct struct_type *st = si->type; cnum i; + volatile val inited = nil; + int compat_190 = opt_compat && opt_compat <= 190; check_init_lazy_struct(strct, si); + uw_simple_catch_begin; + for (i = 0; i < st->nslots; i++) si->slot[i] = nil; call_initfun_chain(st, strct); + if (!compat_190) + call_postinitfun_chain(st, strct); + + inited = t; + + uw_unwind { + if (!inited && !compat_190) + gc_call_finalizers(strct); + } + + uw_catch_end; + return strct; } -- cgit v1.2.3