From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Armstrong Newsgroups: gmane.emacs.bugs Subject: bug#58639: 29.0.50; [noverlay] Nested overlay iteration in GC Date: Wed, 19 Oct 2022 15:16:53 -0700 Message-ID: <87bkq7o3vu.fsf@rfc20.org> References: <87r0z3py0n.fsf@rfc20.org> <87k04vo55c.fsf@rfc20.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39060"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58639@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 20 00:18:33 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olHOR-0009lv-3n for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Oct 2022 00:18:31 +0200 Original-Received: from localhost ([::1]:45098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olHOP-0007nX-Bu for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Oct 2022 18:18:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olHO8-0007n8-Ve for bug-gnu-emacs@gnu.org; Wed, 19 Oct 2022 18:18:13 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33066) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olHNy-0006jc-Nx for bug-gnu-emacs@gnu.org; Wed, 19 Oct 2022 18:18:12 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1olHNy-00070I-It for bug-gnu-emacs@gnu.org; Wed, 19 Oct 2022 18:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matt Armstrong Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Oct 2022 22:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58639 X-GNU-PR-Package: emacs Original-Received: via spool by 58639-submit@debbugs.gnu.org id=B58639.166621783126861 (code B ref 58639); Wed, 19 Oct 2022 22:18:02 +0000 Original-Received: (at 58639) by debbugs.gnu.org; 19 Oct 2022 22:17:11 +0000 Original-Received: from localhost ([127.0.0.1]:60377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1olHN9-0006zB-EI for submit@debbugs.gnu.org; Wed, 19 Oct 2022 18:17:11 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:42145) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1olHN5-0006yc-LA for 58639@debbugs.gnu.org; Wed, 19 Oct 2022 18:17:10 -0400 Original-Received: (Authenticated sender: matt@rfc20.org) by mail.gandi.net (Postfix) with ESMTPSA id 6D0171BF204; Wed, 19 Oct 2022 22:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rfc20.org; s=gm1; t=1666217821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hbxIGdIa6jKW5n4LlnsOhbEW/7oGy0JmDG0J5TTG2Vw=; b=NvIqmaCl/o4/uyf8VPHizp0foeO69KtroroopYnkvK1UENSoQ+W4e1DdZrMX5opWfdr6Xy CI1inclFaO6CDQC+xhbzqdeEbBLU3FoZge1fTtiY83d8jLDN8mPQHmBHX2aW9VAp6BXNxs yyWm+xfdkBcOknlFqso9ypE96FhPc3BTKIrdSZ+6bloMDsQw+tTwv+iRzaJRLTPH81DkwO zIMsspA8LopSEchuTDMFfC+/jOWCENUJNorAYMLttR85vW/2k8lSjb6Z0p4jSW9tMCvyiD jYVs+9fCxJ4wZT64kpXDG7mVlkOUo1YG/Y4L0LIPAnvuI6e1dIFYCIQF4tcn3w== Original-Received: from matt by naz with local (Exim 4.96) (envelope-from ) id 1olHMr-004Oqk-13; Wed, 19 Oct 2022 15:16:53 -0700 In-Reply-To: <87k04vo55c.fsf@rfc20.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:245905 Archived-At: --=-=-= Content-Type: text/plain Sorry Stefan, that last patch won't build against the current feature/noverlay. I sent it from a tree that was not fully merged. This one renames the itree_busy_p call to itree_iterator_busy_p. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Revert-mark_overlays-Use-the-normal-ITREE_FOREACH.patch >From 7bd90841b07a58b16c08b8bc07b94b0946aca1f3 Mon Sep 17 00:00:00 2001 From: Matt Armstrong Date: Wed, 19 Oct 2022 13:42:35 -0700 Subject: [PATCH] Revert "mark_overlays: Use the normal ITREE_FOREACH" This reverts commit b8fbd42f0a7caa4cd9e2d50dd4e4b2101ac78acd, with edits. * src/alloc.c (mark_overlays): restore function. (mark_buffer): Call it, not ITREE_FOREACH. (garbage_collect): eassert (!itree_busy_p ()). * src/itree.h: Comment tweak: explain why GC is considered risky. It isn't that GC itself is risky, it is that GC can call ELisp by way of a hook, and running ELisp during iteration is risks nested iteration. --- src/alloc.c | 22 +++++++++++++++++++--- src/itree.h | 3 ++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 00f2991f250..d7e0a99ffe7 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6279,6 +6279,11 @@ 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 (); @@ -6510,6 +6515,18 @@ mark_overlay (struct Lisp_Overlay *ov) mark_object (ov->plist); } +/* Mark the overlay subtree rooted at NODE. */ + +static void +mark_overlays (struct interval_node *node) +{ + if (node == NULL) + return; + mark_object (node->data); + mark_overlays (node->left); + mark_overlays (node->right); +} + /* Mark Lisp_Objects and special pointers in BUFFER. */ static void @@ -6531,9 +6548,8 @@ mark_buffer (struct buffer *buffer) if (!BUFFER_LIVE_P (buffer)) mark_object (BVAR (buffer, undo_list)); - struct interval_node *node; - ITREE_FOREACH (node, buffer->overlays, PTRDIFF_MIN, PTRDIFF_MAX, ASCENDING) - mark_object (node->data); + if (buffer->overlays) + mark_overlays (buffer->overlays->root); /* If this is an indirect buffer, mark its base buffer. */ if (buffer->base_buffer && diff --git a/src/itree.h b/src/itree.h index f98f028ea52..8647168c935 100644 --- a/src/itree.h +++ b/src/itree.h @@ -152,7 +152,8 @@ itree_iterator_start (struct interval_tree *tree, ptrdiff_t begin, it is cheap a pure. - Only a single iteration can happen at a time, so make sure none of the code within the loop can start another tree iteration, i.e. it shouldn't - be able to run ELisp code (or GC for that matter). + be able to run ELisp code, nor GC since GC can run ELisp by way + of `post-gc-hook`. - If you need to exit the loop early, you *have* to call `ITREE_ABORT` just before exiting (e.g. with `break` or `return`). - Non-local exits are not supported within the body of the loop. -- 2.35.1 --=-=-=--