From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#27214: truncate_undo_list in undo.c: exclusions, warnings, documentation. Date: Wed, 19 Jul 2017 15:41:27 -0700 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1500504137 2148 195.159.176.226 (19 Jul 2017 22:42:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Jul 2017 22:42:17 +0000 (UTC) To: 27214@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 20 00:42:12 2017 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 1dXxfV-0008Uh-Su for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Jul 2017 00:42:10 +0200 Original-Received: from localhost ([::1]:35256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXxfb-0004NT-7Y for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Jul 2017 18:42:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXxfU-0004MS-7q for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 18:42:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXxfP-0004c4-CZ for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 18:42:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dXxfP-0004bd-35 for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 18:42:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dXxfN-0007Cm-ML for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 18:42:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Jul 2017 22:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27214 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27214-submit@debbugs.gnu.org id=B27214.150050409427660 (code B ref 27214); Wed, 19 Jul 2017 22:42:01 +0000 Original-Received: (at 27214) by debbugs.gnu.org; 19 Jul 2017 22:41:34 +0000 Original-Received: from localhost ([127.0.0.1]:48284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXxew-0007C3-5r for submit@debbugs.gnu.org; Wed, 19 Jul 2017 18:41:34 -0400 Original-Received: from gateway33.websitewelcome.com ([192.185.146.68]:25099) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXxeu-0007Bv-0M for 27214@debbugs.gnu.org; Wed, 19 Jul 2017 18:41:32 -0400 Original-Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 9890086688 for <27214@debbugs.gnu.org>; Wed, 19 Jul 2017 17:41:29 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id XxfQdyU5mnlKZXxfQd7812; Wed, 19 Jul 2017 17:42:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:To:From:Message-ID:Date: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=mwvUdaP825xrFNLyHohpZkYk7qj1FxqkCR320XTWRG8=; b=k5iR8KHy0/V8beZDwCBShIFER0 oqw/wr+m+uyLogMnmYLifodr+lIw6+1VjbFWTC1lR/fwiBBH5TtFDi8lXLERAtb8X8oqAtjEe3uC6 yU7pQ6oGy+00R4bRw9VtUthCjKGQGvdQ60KJtDbWykGRX0Vc9Xjv+f5leskc7IADV+Owhx5Xs04OW 0SGqyJvr3um2Jcuw0jw8vNWFH/uy6if9XDKbwqQ2bUqF3C2PdFS3RZ25/95Ej54Qz29rQwOxBcCzs 5SZQD5FvTwAkVvUY0e3WsNv02ioLiVfA9HoY7/nRppcrgXq+WCP2IALJar45/Cxp9R2n4b07VWFPi FwScvO9g==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:50045 helo=server.local) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1dXxeq-0036xZ-S2 for 27214@debbugs.gnu.org; Wed, 19 Jul 2017 17:41:29 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Exim-ID: 1dXxeq-0036xZ-S2 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.local) [45.48.239.195]:50045 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes 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:134769 Archived-At: I opted to prevent truncate_undo_list from truncating the buffer-undo-list when undo-tree-canary is present, except if the undo-outer-limit is exceeded. Here is the revision: /* At garbage collection time, make an undo list shorter at the end, returning the truncated list. How this is done depends on the variables undo-limit, undo-strong-limit and undo-outer-limit. In some cases this works by calling undo-outer-limit-function. */ void truncate_undo_list (struct buffer *b) { Lisp_Object list; Lisp_Object prev, next, last_boundary; EMACS_INT size_so_far = 0; /* Make sure that calling undo-outer-limit-function won't cause another GC. */ ptrdiff_t count = inhibit_garbage_collection (); /* Make the buffer current to get its local values of variables such as undo_limit. Also so that Vundo_outer_limit_function can tell which buffer to operate on. */ record_unwind_current_buffer (); set_buffer_internal (b); list = BVAR (b, undo_list); prev = Qnil; next = list; last_boundary = Qnil; /* If the first element is an undo boundary, skip past it. */ if (CONSP (next) && NILP (XCAR (next))) { /* Add in the space occupied by this element and its chain link. */ size_so_far += sizeof (struct Lisp_Cons); /* Advance to next element. */ prev = next; next = XCDR (next); } /* Always preserve at least the most recent undo record unless it is really horribly big. Skip, skip, skip the undo, skip, skip, skip the undo, Skip, skip, skip the undo, skip to the undo bound'ry. */ while (CONSP (next) && ! NILP (XCAR (next))) { Lisp_Object elt; elt = XCAR (next); /* Add in the space occupied by this element and its chain link. */ size_so_far += sizeof (struct Lisp_Cons); if (CONSP (elt)) { size_so_far += sizeof (struct Lisp_Cons); if (STRINGP (XCAR (elt))) size_so_far += (sizeof (struct Lisp_String) - 1 + SCHARS (XCAR (elt))); } /* Advance to next element. */ prev = next; next = XCDR (next); } /* If by the first boundary we have already passed undo_outer_limit, we're heading for memory full, so offer to clear out the list. */ if (INTEGERP (Vundo_outer_limit) && size_so_far > XINT (Vundo_outer_limit) && !NILP (Vundo_outer_limit_function)) { Lisp_Object tem; /* Normally the function this calls is undo-outer-limit-truncate. */ tem = call1 (Vundo_outer_limit_function, make_number (size_so_far)); if (! NILP (tem)) { /* The function is responsible for making any desired changes in buffer-undo-list. */ unbind_to (count, Qnil); return; } } /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ /* undo-tree */ if (CONSP (list) && ! NILP (Fmemq (Qundo_tree_canary, list))) { unbind_to (count, Qnil); return; } /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ if (CONSP (next)) last_boundary = prev; /* Keep additional undo data, if it fits in the limits. */ while (CONSP (next)) { Lisp_Object elt; elt = XCAR (next); /* When we get to a boundary, decide whether to truncate either before or after it. The lower threshold, undo_limit, tells us to truncate after it. If its size pushes past the higher threshold undo_strong_limit, we truncate before it. */ if (NILP (elt)) { if (size_so_far > undo_strong_limit) break; last_boundary = prev; if (size_so_far > undo_limit) break; } /* Add in the space occupied by this element and its chain link. */ size_so_far += sizeof (struct Lisp_Cons); if (CONSP (elt)) { size_so_far += sizeof (struct Lisp_Cons); if (STRINGP (XCAR (elt))) size_so_far += (sizeof (struct Lisp_String) - 1 + SCHARS (XCAR (elt))); } /* Advance to next element. */ prev = next; next = XCDR (next); } /* If we scanned the whole list, it is short enough; don't change it. */ if (NILP (next)) ; /* Truncate at the boundary where we decided to truncate. */ else if (!NILP (last_boundary)) XSETCDR (last_boundary, Qnil); /* There's nothing we decided to keep, so clear it out. */ else bset_undo_list (b, Qnil); unbind_to (count, Qnil); } void syms_of_undo (void) { /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ /* undo-tree */ DEFSYM (Qundo_tree_canary, "undo-tree-canary"); /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ * * *