From fb7f1864da4aa4c09756cfe47db6c56b4e87bd14 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 17 Nov 2022 17:00:22 -0500 Subject: itree.c: Make the iterator reentrant (bug#59183) Get rid of the global iterator object and instead allocate a separate iterator for every loop. This still uses the "duplicate iterator" code, including the old iterator which needs a stack, make ITREE_FOREACH a bit more expensive than we'd like. * src/itree.h (init_itree, forget_itree, itree_iterator_busy_p): Delete declarations. (itree_iterator_start): Add iterator arg and remove `line` and `file` args. (struct itree_iterator): Move from `itree.c`. Remove `line` and `file` fields. (ITREE_FOREACH): Stack allocate an iterator object and pass it to `itree_iterator_start`. * src/itree.c (struct itree_iterator): Move to itree.h. (iter): Delete global variable. (itree_iterator_create, init_itree, forget_itree, itree_iterator_busy_p): Delete functions. (itree_contains): Adjust assertion. (itree_iterator_finish): Deallocate the iterator's stack. (itree_iterator_start): Take the (uninitialized) iterator as argument. Allocate a fresh new stack. Remove `file` and `line` arguments. Don't check `running` any more since the iterator is not expected to be initialized at all. * src/eval.c (signal_or_quit): * src/alloc.c (garbage_collect): Don't check `itree_iterator_busy_p` any more. * src/emacs.c (main): No need to `init_itree` any more. (Fdump_emacs): No need to `forget_itree` any more. --- src/alloc.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 6862cf916fb..b9d12dff7e0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6279,11 +6279,6 @@ garbage_collect (void) image_prune_animation_caches (false); #endif - /* ELisp code run by `gc-post-hook' could result in itree iteration, - which must not happen while the itree is already busy. See - bug#58639. */ - eassert (!itree_iterator_busy_p ()); - if (!NILP (Vpost_gc_hook)) { specpdl_ref gc_count = inhibit_garbage_collection (); -- cgit v1.2.1