From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#32265: 26.1; yank-excluded-properties set to t triggers "Error in syntax_table logic for intervals <-" signal Date: Wed, 01 Aug 2018 13:15:28 +0300 Message-ID: <8336vyo0jj.fsf@gnu.org> References: <87lg9zgal6.fsf@priss.frightenedpiglet.com> <87lg9r1uil.fsf@gmail.com> <83va8vnzz2.fsf@gnu.org> <87a7q628vz.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1533118472 30919 195.159.176.226 (1 Aug 2018 10:14:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Aug 2018 10:14:32 +0000 (UTC) Cc: sand@blarg.net, 32265@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 01 12:14:28 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 1fko9D-0007wq-KS for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Aug 2018 12:14:27 +0200 Original-Received: from localhost ([::1]:38768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkoBK-0007FM-3W for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Aug 2018 06:16:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkoAn-00073F-Od for bug-gnu-emacs@gnu.org; Wed, 01 Aug 2018 06:16:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkoAk-000181-Io for bug-gnu-emacs@gnu.org; Wed, 01 Aug 2018 06:16:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60180) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fkoAk-00017r-Ej for bug-gnu-emacs@gnu.org; Wed, 01 Aug 2018 06:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fkoAk-0006gN-5x for bug-gnu-emacs@gnu.org; Wed, 01 Aug 2018 06:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Aug 2018 10:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32265 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 32265-submit@debbugs.gnu.org id=B32265.153311852925644 (code B ref 32265); Wed, 01 Aug 2018 10:16:02 +0000 Original-Received: (at 32265) by debbugs.gnu.org; 1 Aug 2018 10:15:29 +0000 Original-Received: from localhost ([127.0.0.1]:36965 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fkoAC-0006fY-KK for submit@debbugs.gnu.org; Wed, 01 Aug 2018 06:15:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58584) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fkoAB-0006fL-3u for 32265@debbugs.gnu.org; Wed, 01 Aug 2018 06:15:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkoA2-0000ru-Ml for 32265@debbugs.gnu.org; Wed, 01 Aug 2018 06:15:21 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45657) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkoA2-0000ri-IL; Wed, 01 Aug 2018 06:15:18 -0400 Original-Received: from [176.228.60.248] (port=4461 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fkoA1-0001rs-Em; Wed, 01 Aug 2018 06:15:18 -0400 In-reply-to: <87a7q628vz.fsf@gmail.com> (message from Noam Postavsky on Tue, 31 Jul 2018 21:06:08 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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:149156 Archived-At: > From: Noam Postavsky > Cc: sand@blarg.net, 32265@debbugs.gnu.org > Date: Tue, 31 Jul 2018 21:06:08 -0400 > > Eli Zaretskii writes: > > > I presume just calling set-text-properties with the same arguments > > there doesn't trigger the problem? If so, I think we need to > > understand how come we got offset=-1 in frame #4. > > Actually, it looks like it can be triggered with just > set-text-properties, but there is some interaction with > c-before-change. I've reduced the testcase to this: > > (defconst dir (file-name-directory > (or load-file-name buffer-file-name))) > > (pop-to-buffer-same-window (get-buffer-create "*test*")) > (erase-buffer) > (insert-file-contents (expand-file-name "U.java" dir)) > (java-mode) > (set-text-properties 10467 10542 nil) Thanks for an easy test case. This is bug #13743 striking again in a slightly different incarnation: removing the text properties calls before-change-functions, which modify the buffer's interval tree, but we continue using the interval calculated from the unmodified tree. So the solution should be similar to what we used in that bug. If the patch below fixes the original problem (Derek, can you confirm?), I will install it on the emacs-26 branch. > The backtrace no longer has a negative offset to blame: > > ../../src/intervals.c:371: Emacs fatal error: assertion failed: LENGTH (i) > 0 > > (gdb) bt 8 > #0 terminate_due_to_signal (sig=6, backtrace_limit=2147483647) at ../../src/emacs.c:364 > #1 0x00000000006161d3 in die (msg=0x7795cd "LENGTH (i) > 0", file=0x7794f0 "../../src/intervals.c", > line=371) at ../../src/alloc.c:7410 > #2 0x00000000006b51c4 in balance_an_interval (i=0x324b0b0) at ../../src/intervals.c:371 > #3 0x00000000006b5792 in split_interval_right (interval=0x181f380 , > offset=4048) at ../../src/intervals.c:504 But the offset is still bogus, because: #3 0x012d2f46 in split_interval_right (interval=0xfa9c10, offset=4048) at intervals.c:504 504 balance_an_interval (new); (gdb) p new_length $8 = -107 IOW, OFFSET is greater than LENGTH(interval) in split_interval_right, which must not happen. Here's the proposed patch: diff --git a/src/textprop.c b/src/textprop.c index 984f2e6..904e226 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -1350,6 +1350,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, { register INTERVAL i; Lisp_Object ostart, oend; + bool first_time = true; ostart = start; oend = end; @@ -1372,6 +1373,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, return Qt; } + retry: i = validate_interval_range (object, &start, &end, soft); if (!i) @@ -1391,8 +1393,22 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, return Qnil; } - if (BUFFERP (object) && !NILP (coherent_change_p)) - modify_text_properties (object, start, end); + if (BUFFERP (object) && !NILP (coherent_change_p) && first_time) + { + ptrdiff_t prev_length = LENGTH (i); + ptrdiff_t prev_pos = i->position; + + modify_text_properties (object, start, end); + /* If someone called us recursively as a side effect of + modify_text_properties, and changed the intervals behind our + back, we cannot continue with I, because its data changed. + So we restart the interval analysis anew. */ + if (LENGTH (i) != prev_length || i->position != prev_pos) + { + first_time = false; + goto retry; + } + } set_text_properties_1 (start, end, properties, object, i);