From 498d331b07117408c5c5d8a3889b49b275b9a654 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Wed, 28 Sep 2022 16:30:34 +0200 Subject: [PATCH] Add debugging help for nested iterators (nug#58144) When starting an iteration, store __FILE__ and __LINE__ where this happens in the interval_tree structure. * src/buffer.h (buffer_overlay_iter_start): New macro adding __FILE and __LINE__. (buffer_overlay_iter_start1): Renamed from ..._start. * src/itree.h (struct interval_tree): Add file and line info. * src/itree.c: (interval_tree_contains, interval_tree_nodes, interval_tree_insert_gap): Pass __FILE__ and __LINE__ to iter_start. (interval_tree_iter_start): Record file and line info in tree. --- src/buffer.h | 9 ++++++--- src/itree.c | 11 +++++++---- src/itree.h | 5 ++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/buffer.h b/src/buffer.h index 7d6c693b0f2..097283be671 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1457,13 +1457,16 @@ remove_buffer_overlay (struct buffer *b, struct Lisp_Overlay *ov) } INLINE void -buffer_overlay_iter_start (struct buffer *b, ptrdiff_t begin, ptrdiff_t end, - enum interval_tree_order order) +buffer_overlay_iter_start1 (struct buffer *b, ptrdiff_t begin, ptrdiff_t end, + enum interval_tree_order order, const char* file, int line) { if (b->overlays) - interval_tree_iter_start (b->overlays, begin, end, order); + interval_tree_iter_start (b->overlays, begin, end, order, file, line); } +#define buffer_overlay_iter_start(b, begin, end, order) \ + buffer_overlay_iter_start1 ((b), (begin), (end), (order), __FILE__, __LINE__) + INLINE struct interval_node* buffer_overlay_iter_next (struct buffer *b) { diff --git a/src/itree.c b/src/itree.c index a6439970626..e31ce39ba11 100644 --- a/src/itree.c +++ b/src/itree.c @@ -328,7 +328,7 @@ interval_tree_contains (struct interval_tree *tree, struct interval_node *node) { struct interval_node *other; - interval_tree_iter_start (tree, node->begin, PTRDIFF_MAX, ITREE_ASCENDING); + interval_tree_iter_start (tree, node->begin, PTRDIFF_MAX, ITREE_ASCENDING, __FILE__, __LINE__); while ((other = interval_tree_iter_next (tree))) if (other == node) break; @@ -417,7 +417,7 @@ interval_tree_nodes (struct interval_tree *tree, { struct interval_node *node; - interval_tree_iter_start (tree, PTRDIFF_MIN, PTRDIFF_MAX, order); + interval_tree_iter_start (tree, PTRDIFF_MIN, PTRDIFF_MAX, order, __FILE__, __LINE__); while ((node = interval_tree_iter_next (tree))) { *nodes = node; @@ -434,12 +434,15 @@ interval_tree_nodes (struct interval_tree *tree, void interval_tree_iter_start (struct interval_tree *tree, ptrdiff_t begin, ptrdiff_t end, - enum interval_tree_order order) + enum interval_tree_order order, + const char* file, int line) { if (tree->iter_running) emacs_abort (); interval_generator_reset (tree->iter, begin, end, order); tree->iter_running = 1; + tree->file = file; + tree->line = line; } /* Limit the search interval of the iterator to the given values. The @@ -511,7 +514,7 @@ interval_tree_insert_gap (struct interval_tree *tree, ptrdiff_t pos, ptrdiff_t l order, so we need to remove them first. */ struct interval_stack *saved = interval_stack_create (0); struct interval_node *node = NULL; - interval_tree_iter_start (tree, pos, pos + 1, ITREE_PRE_ORDER); + interval_tree_iter_start (tree, pos, pos + 1, ITREE_PRE_ORDER, __FILE__, __LINE__); while ((node = interval_tree_iter_next (tree))) { if (node->begin == pos && node->front_advance diff --git a/src/itree.h b/src/itree.h index 21d8b21a02f..e5d68fbfabb 100644 --- a/src/itree.h +++ b/src/itree.h @@ -59,6 +59,8 @@ struct interval_tree intmax_t size; /* Number of nodes in the tree. */ struct interval_generator *iter; bool_bf iter_running : 1; + const char* file; + int line; }; enum interval_tree_order { @@ -79,7 +81,8 @@ void interval_tree_clear (struct interval_tree *); void interval_tree_insert (struct interval_tree *, struct interval_node *); bool interval_tree_contains (struct interval_tree *, struct interval_node *); struct interval_node *interval_tree_remove (struct interval_tree *, struct interval_node *); -void interval_tree_iter_start (struct interval_tree *, ptrdiff_t, ptrdiff_t, enum interval_tree_order); +void interval_tree_iter_start (struct interval_tree *, ptrdiff_t, ptrdiff_t, enum interval_tree_order, + const char* file, int line); void interval_tree_iter_narrow (struct interval_tree *, ptrdiff_t, ptrdiff_t); void interval_tree_iter_finish (struct interval_tree *); struct interval_node *interval_tree_iter_next (struct interval_tree *); -- 2.39.2