From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Vivek Dasmohapatra Newsgroups: gmane.emacs.bugs Subject: bug#26932: Found the triggering behaviour Date: Wed, 10 Jan 2018 13:58:43 +0000 (GMT) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1515592643 716 195.159.176.226 (10 Jan 2018 13:57:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 10 Jan 2018 13:57:23 +0000 (UTC) User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) To: 26932@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 10 14:57:19 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZGsP-0007iz-BQ for geb-bug-gnu-emacs@m.gmane.org; Wed, 10 Jan 2018 14:57:09 +0100 Original-Received: from localhost ([::1]:43442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZGuO-0007vE-Td for geb-bug-gnu-emacs@m.gmane.org; Wed, 10 Jan 2018 08:59:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZGuI-0007uZ-Eq for bug-gnu-emacs@gnu.org; Wed, 10 Jan 2018 08:59:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZGuE-0005Ma-7W for bug-gnu-emacs@gnu.org; Wed, 10 Jan 2018 08:59:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42469) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZGuE-0005MP-3E for bug-gnu-emacs@gnu.org; Wed, 10 Jan 2018 08:59:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eZGuD-0007AP-Ri for bug-gnu-emacs@gnu.org; Wed, 10 Jan 2018 08:59:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Vivek Dasmohapatra Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Jan 2018 13:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26932 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26932-submit@debbugs.gnu.org id=B26932.151559273127530 (code B ref 26932); Wed, 10 Jan 2018 13:59:01 +0000 Original-Received: (at 26932) by debbugs.gnu.org; 10 Jan 2018 13:58:51 +0000 Original-Received: from localhost ([127.0.0.1]:50366 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZGu3-00079y-Bl for submit@debbugs.gnu.org; Wed, 10 Jan 2018 08:58:51 -0500 Original-Received: from ceres.etla.org ([85.119.82.193]:53067) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZGu0-00079n-TW for 26932@debbugs.gnu.org; Wed, 10 Jan 2018 08:58:49 -0500 Original-Received: from yaffle.pepperfish.net ([88.99.213.221] helo=[10.112.101.20]) by ceres.etla.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eZGtz-00048T-3s for 26932@debbugs.gnu.org; Wed, 10 Jan 2018 13:58:47 +0000 X-X-Sender: vivek@platypus.pepperfish.net X-Spam_score: -3.0 X-Spam_score_int: -29 X-Spam_bar: --- X-Spam_report: Spam detection software, running on the system "ceres.etla.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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. [...] Content analysis details: (-3.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 AWL A X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:141976 Archived-At: 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: ( 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)))