[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree 8842bb5 176/195: More undo-tree GC corruption
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree 8842bb5 176/195: More undo-tree GC corruption mitigations. |
Date: |
Sat, 28 Nov 2020 13:41:47 -0500 (EST) |
branch: externals/undo-tree
commit 8842bb53396384aeb0d7d04601964c661eb5e15a
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
More undo-tree GC corruption mitigations.
Repeatedly try to copy buffer-undo-list until we succeed without GC
occurring,
in an attempt to avoid truncating undo history if some buffer-undo-list cdr
is
temporarily null whilst copying due to GC.
---
undo-tree.el | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index 6ae4f69..989b76a 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -1754,6 +1754,12 @@ Comparison is done with `eq'."
copy)))
+(defvar undo-tree-gc-flag nil)
+
+(defun undo-tree-post-gc ()
+ (setq undo-tree-gc-flag t))
+
+
(defun undo-list-transfer-to-tree ()
;; Transfer entries accumulated in `undo-list' to `buffer-undo-tree'.
@@ -1764,13 +1770,19 @@ Comparison is done with `eq'."
;; if `buffer-undo-tree' is empty, create initial undo-tree
(when (null buffer-undo-tree) (setq buffer-undo-tree (make-undo-tree)))
- ;; garbage-collect then deep-copy `buffer-undo-list', in an attempt to
- ;; mitigate race conditions with garbage collector corrupting undo history
- ;; -- is this even a thing?
- (garbage-collect)
- (let ((undo-list (copy-tree buffer-undo-list))
- changeset)
+ ;; garbage-collect then repeatedly try to deep-copy `buffer-undo-list' until
+ ;; we succeed without GC running, in an attempt to mitigate race conditions
+ ;; with garbage collector corrupting undo history (is this even a thing?!)
+ (unless (or (null buffer-undo-list)
+ (undo-list-found-canary-p buffer-undo-list))
+ (garbage-collect))
+ (let (undo-list changeset)
+ (setq undo-tree-gc-flag t)
+ (while undo-tree-gc-flag
+ (setq undo-tree-gc-flag nil
+ undo-list (copy-tree buffer-undo-list)))
(setq buffer-undo-list '(nil undo-tree-canary))
+
(when (setq changeset (undo-list-pop-changeset undo-list))
;; create new node from first changeset in `undo-list', save old
;; `buffer-undo-tree' current node, and make new node the current node
@@ -2673,9 +2685,11 @@ Within the undo-tree visualizer, the following keys are
available:
;; if disabling `undo-tree-mode', rebuild `buffer-undo-list' from tree so
;; Emacs undo can work
- (when (not undo-tree-mode)
+ (if undo-tree-mode
+ (add-hook 'post-gc-hook #'undo-tree-post-gc nil )
(undo-list-rebuild-from-tree)
- (setq buffer-undo-tree nil)))
+ (setq buffer-undo-tree nil)
+ (remove-hook 'post-gc-hook #'undo-tree-post-gc 'local)))
(defun turn-on-undo-tree-mode (&optional print-message)
- [elpa] externals/undo-tree 43663f6 159/195: Fix bug in menu entries that triggered error on null buffer-undo-tree., (continued)
- [elpa] externals/undo-tree 43663f6 159/195: Fix bug in menu entries that triggered error on null buffer-undo-tree., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 133b439 148/195: Set protected-local property on various visualizer variables., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bc9d095 156/195: Clear undo-tree-visualizer-needs-extending-[up|down] before drawing tree., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b35a6af 160/195: Bump copyright year and version number., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree a3e81b6 161/195: Fix bug that caused undo-tree to hang when undoing in region (bug#16377)., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 2947d7c 169/195: Add hooks to transform/discard undo elements on saving/loading., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree c3d04ea 165/195: Change obsolete subtract-time -> time-subtract., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree af99ee3 166/195: Uncoditionally clear visualizer data before writing to file., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f6471ef 173/195: Simplify undo-list-byte-size., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree ea165ed 174/195: Refactor undo-list-transfer-to-tree to not act directly on buffer-undo-list., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8842bb5 176/195: More undo-tree GC corruption mitigations.,
Stefan Monnier <=
- [elpa] externals/undo-tree f6f557c 178/195: Fix various bugs in undo history loading/saving., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b8652b4 180/195: Null undo-tree-limit attemps to preserve all undo history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f0a6192 184/195: Proper fix to copy-undo-tree by writing bespoke copier., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 3090c4f 185/195: Temporarily increase max-lisp-eval-depth and max-specpdl-size when copying undo-trees., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8cf384f 187/195: Redraw visualizer when history-discarding invalidates it., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree d79fab9 193/195: Switch from cl to cl-lib., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bd65bb0 192/195: Fix hook function issue in Emacs 27., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e01a3e7 191/195: Fix some byte-compilation warnings., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 17454bd 084/195: Improved undo-tree-switch-branch behaviour., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f16ab5f 067/195: Trivial fix in Commentary., Stefan Monnier, 2020/11/28