unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Vivek Dasmohapatra <vivek@etla.org>
To: 26932@debbugs.gnu.org
Subject: bug#26932: Found the triggering behaviour
Date: Wed, 10 Jan 2018 13:58:43 +0000 (GMT)	[thread overview]
Message-ID: <alpine.DEB.2.02.1801101352580.6625@platypus.pepperfish.net> (raw)
In-Reply-To: <alpine.DEB.2.02.1705142142260.3637@platypus.pepperfish.net>

The old code in lui.el used to (effectively) do this:

   (setq buffer-undo-list (mapcar a-lambda-here buffer-undo-list))

This seemed to cause some strings in the undo list structure to get
freed to early, then freed again later.

The altered code uses the approach of setf'ing the relevant elements of
the undo-list, which doesn't trick the GC code into a premature free.

Since there's a workaround it's not particularly urgent, but it seems
to me that there's a hole in the GC logic somewhere.

--- /home/vivek/elisp/lui.el	2017-07-23 19:42:11.047162827 +0100
+++ /home/vivek/elisp/lui.el	2017-07-28 14:03:00.306977730 +0100
@@ -358,10 +358,8 @@
           (setq val (progn ,@body)))
         (when (consp buffer-undo-list)
           ;; Not t :-)
-         (setq buffer-undo-list (lui-adjust-undo-list buffer-undo-list
-                                                      ,old-marker-sym
-                                                      (- lui-input-marker
-                                                         ,old-marker-sym))))
+         (lui-adjust-undo-list  ,old-marker-sym (- lui-input-marker
+                                                   ,old-marker-sym)))
         val)))


@@ -776,66 +774,47 @@
                                    faces)))))))
    )

-(defun lui-adjust-undo-list (list old-begin shift)
-  "Adjust undo positions in LIST by SHIFT.
-LIST is in the format of `buffer-undo-list'.
-Only positions after OLD-BEGIN are affected."
-  ;; This is necessary because the undo-list keeps exact buffer
-  ;; positions.
-  ;; Thanks to ERC for the idea of the code.
-  ;; ERC's code doesn't take care of an OLD-BEGIN value, which is
-  ;; necessary if you allow modification of the buffer.
-  (let* ((adjust-position (lambda (pos)
-                            (if (and (numberp pos)
-                                     ;; After the boundary: Adjust
-                                     (>= (abs pos)
-                                         old-begin))
-                                (* (if (< pos 0)
-                                       -1
-                                     1)
-                                   (+ (abs pos)
-                                      shift))
-                              pos)))
-         (adjust (lambda (entry)
-                   (cond
-                    ;; POSITION
-                    ((numberp entry)
-                     (funcall adjust-position entry))
-                    ((not (consp entry))
-                     entry)
-                    ;; (BEG . END)
-                    ((numberp (car entry))
-                     (cons (funcall adjust-position (car entry))
-                           (funcall adjust-position (cdr entry))))
-                    ;; (TEXT . POSITION)
-                    ((stringp (car entry))
-                     (cons (car entry)
-                           (funcall adjust-position (cdr entry))))
-                    ;; (nil PROPERTY VALUE BEG . END)
-                    ((not (car entry))
-                     `(nil ,(nth 1 entry)
-                           ,(nth 2 entry)
-                           ,(funcall adjust-position (nth 3 entry))
-                           .
-                           ,(funcall adjust-position (nthcdr 4 entry))))
-                    ;; (apply DELTA BEG END FUN-NAME . ARGS)
-                    ((and (eq 'apply (car entry))
-                          (numberp (cadr entry)))
-                     `(apply ,(nth 1 entry)
-                             ,(funcall adjust-position (nth 2 entry))
-                             ,(funcall adjust-position (nth 3 entry))
-                             ,(nth 4 entry)
-                             .
-                             ,(nthcdr 5 entry)))
-                    ;; XEmacs: (<extent> start end)
-                    ((and (fboundp 'extentp)
-                          (extentp (car entry)))
-                     (list (nth 0 entry)
-                           (funcall adjust-position (nth 1 entry))
-                           (funcall adjust-position (nth 2 entry))))
-                    (t
-                     entry)))))
-    (mapcar adjust list)))
+;; ----------------------------------------------------------------------------
+
+(defun lui--adjust-p (pos old)
+  (and (numberp pos) (>= (abs pos) old)))
+
+(defun lui--new-pos (pos shift)
+  (* (if (< pos 0) -1 1) (+ (abs pos) shift)))
+
+(defun lui-adjust-undo-list (old-begin shift)
+  ;; Translate buffer positions in buffer-undo-list by SHIFT.
+  (unless (or (zerop shift) (atom buffer-undo-list))
+    (let ((list buffer-undo-list) elt)
+      (while list
+        (setq elt (car list))
+        (cond ((integerp elt)           ; POSITION
+               (if (lui--adjust-p elt old-begin)
+                   (setf (car list) (lui--new-pos elt shift))))
+              ((or (atom elt)           ; nil, EXTENT
+                   (markerp (car elt))) ; (MARKER . DISTANCE)
+               nil)
+              ((integerp (car elt))     ; (BEGIN . END)
+               (if (lui--adjust-p (car elt) old-begin)
+                   (setf (car elt) (lui--new-pos (car elt) shift)))
+               (if (lui--adjust-p (cdr elt) old-begin)
+                   (setf (cdr elt) (lui--new-pos (cdr elt) shift))))
+              ((stringp (car elt))      ; (TEXT . POSITION)
+               (if (lui--adjust-p (cdr elt) old-begin)
+                   (setf (cdr elt) (lui--new-pos (cdr elt) shift))))
+              ((null (car elt))         ; (nil PROPERTY VALUE BEG . END)
+               (let ((cons (nthcdr 3 elt)))
+                 (if (lui--adjust-p (car cons) old-begin)
+                     (setf (car cons) (lui--new-pos (car cons) shift)))
+                 (if (lui--adjust-p (cdr cons) old-begin)
+                     (setf (cdr cons) (lui--new-pos (cdr cons) shift)))))
+              ((and (featurep 'xemacs)
+                    (extentp (car elt))) ; (EXTENT START END)
+               (if (lui--adjust-p (nth 1 elt) old-begin)
+                     (setf (nth 1 elt) (lui--new-pos (nth 1 elt) shift)))
+                 (if (lui--adjust-p (nth 2 elt) old-begin)
+                     (setf (nth 2 elt) (lui--new-pos (nth 2 elt) shift)))))
+        (setq list (cdr list))))))

  (defvar lui-prompt-map
    (let ((map (make-sparse-keymap)))






  parent reply	other threads:[~2018-01-10 13:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-14 20:54 bug#26932: 25.1; Crash triggered a few times a day with network process Vivek Dasmohapatra
2017-05-15  3:04 ` Eli Zaretskii
2017-05-15 11:18   ` Vivek Dasmohapatra
2017-06-11 21:39     ` Vivek Dasmohapatra
2017-06-12 14:10       ` Eli Zaretskii
2017-06-12 15:21         ` Vivek Dasmohapatra
2017-06-12 15:51           ` Eli Zaretskii
2017-06-12 15:56             ` Vivek Dasmohapatra
2017-06-12 16:30               ` Eli Zaretskii
2017-06-13 15:41                 ` Vivek Dasmohapatra
2017-06-13 16:41                   ` Eli Zaretskii
2017-06-13 17:04                     ` Vivek Dasmohapatra
2017-06-13 19:46                       ` Eli Zaretskii
2017-06-13 21:23                         ` Vivek Dasmohapatra
2017-06-14  2:32                           ` Eli Zaretskii
2017-06-15 13:48                             ` Vivek Dasmohapatra
2017-06-15 14:47                               ` Eli Zaretskii
2017-06-19  0:57                                 ` Vivek Dasmohapatra
2017-06-19 14:59                                   ` Eli Zaretskii
2017-06-19 18:03                                     ` Vivek Dasmohapatra
2017-07-10 13:01 ` bug#26932: Subject: Re: bug#26932: 25.1; Vivek Dasmohapatra
2018-01-10 13:58 ` Vivek Dasmohapatra [this message]
2019-10-23 10:02   ` bug#26932: Found the triggering behaviour Lars Ingebrigtsen
2020-01-20 15:11     ` Vivek Dasmohapatra
2020-01-22 13:30       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1801101352580.6625@platypus.pepperfish.net \
    --to=vivek@etla.org \
    --cc=26932@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).