all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 13743@debbugs.gnu.org
Subject: bug#13743: 24.2.93; Segmentation fault when trying to [s]teal a file opened elsewhere
Date: Mon, 25 Feb 2013 18:25:26 +0200	[thread overview]
Message-ID: <831uc4jr7t.fsf@gnu.org> (raw)
In-Reply-To: <512AFC18.4090504@yandex.ru>

> Date: Mon, 25 Feb 2013 09:52:24 +0400
> From: Dmitry Gutov <dgutov@yandex.ru>
> CC: monnier@iro.umontreal.ca, 13743@debbugs.gnu.org
> 
> OTOH, the existing behavior in this area is rather messy anyway:
> 
> a) If START equals to the beginning of the region with the same 
> property, the buffer is marked modified anyway (even though nothing 
> changes from the observer's point of view).
> 
> So, the trivial example of repeating an `add-text-properties' call with 
> the same arguments in a previously unpropertized buffer will mark it as 
> modified every time.
> 
> b) This probably has something to do with internal representation, but 
> even having the same property span before START is not a safe bet:

That's a bug, actually, and a very old one at that (at least 17 years
old, IIUC).  The code didn't handle correctly all the situations where
there's nothing to change, before it announced a change by calling
modify_region (and later called signal_after_change).

I installed on the trunk revision 111875 to fix this.  Now all your
examples:

> 1. Create a new file with a line of text in it, preferably without 
> spaces, to see face changes easily
> 2. Save it, disable font-lock-mode.
> 3. Evaluate:
> 
> (add-text-properties 1 6 '(face font-lock-constant-face)) => modified
> save
> (add-text-properties 2 6 '(face font-lock-constant-face)) => unmodified
> (add-text-properties 2 7 '(face font-lock-constant-face)) => modified
> save
> (add-text-properties 2 6 '(face font-lock-constant-face)) => unmodified
> - optional step
> (add-text-properties 2 7 '(face font-lock-constant-face)) => modified(!)
> - even though 1 still has the same face
> - you can save and repeat this step indefinitely

work as expected.

Interestingly, this also fixes the original segfault which started
this discussion (not before I fixed similar bugs in
remove-text-properties and elsewhere in textprop.c, because making the
change only n add-text-properties still triggered a similar segfault
from remove-text-properties).  So perhaps the fact that buffer
modifications were announced unnecessarily is the root cause for the
segfault.

I couldn't convince myself that, even after revision 111875, we could
not end up in a situation where redisplay triggered by modify_region
changes the intervals when it fontifies the buffer.  So perhaps we
need a followup patch to plumb that potential hole, something along
the following:

=== modified file 'src/textprop.c'
--- src/textprop.c	2013-02-25 16:13:42 +0000
+++ src/textprop.c	2013-02-25 16:23:43 +0000
@@ -1134,6 +1134,7 @@ Return t if any property value actually 
   register int modified = 0;
   struct gcpro gcpro1;
   ptrdiff_t got;
+  int first_time = 1;
 
   properties = validate_plist (properties);
   if (NILP (properties))
@@ -1142,6 +1143,7 @@ Return t if any property value actually 
   if (NILP (object))
     XSETBUFFER (object, current_buffer);
 
+ retry:
   i = validate_interval_range (object, &start, &end, hard);
   if (!i)
     return Qnil;
@@ -1174,8 +1176,25 @@ Return t if any property value actually 
       copy_properties (unchanged, i);
     }
 
-  if (BUFFERP (object))
-    modify_region (object, start, end);
+  if (BUFFERP (object) && first_time)
+    {
+      ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
+      ptrdiff_t prev_pos = i->position;
+
+      modify_region (object, start, end);
+      /* If someone called us recursively as a side effect of
+	 modify_region, and changed the intervals behind our back
+	 (could happen if lock_file, called by prepare_to_modify_buffer,
+	 triggers redisplay, and that calls add-text-properties again
+	 in the same buffer), we cannot continue with I, because its
+	 data changed.  So we restart the interval analysis anew.  */
+      if (TOTAL_LENGTH (i) != prev_total_length
+	  || i->position != prev_pos)
+	{
+	  first_time = 0;
+	  goto retry;
+	}
+    }
 
   /* We are at the beginning of interval I, with LEN chars to scan.  */
   for (;;)






  parent reply	other threads:[~2013-02-25 16:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18  6:41 bug#13743: 24.2.93; Segmentation fault when trying to [s]teal a file opened elsewhere Dmitry Gutov
2013-02-18 16:11 ` Eli Zaretskii
2013-02-19  0:52   ` Dmitry Gutov
2013-02-20 19:31     ` Eli Zaretskii
2013-02-21  8:30       ` Dmitry Gutov
2013-02-18 19:35 ` Glenn Morris
2013-02-19  0:55   ` Dmitry Gutov
2013-02-21  5:16 ` Paul Eggert
2013-02-21  7:03   ` Dmitry Gutov
2013-02-23  3:37   ` Dmitry Gutov
2013-02-23 15:10     ` Eli Zaretskii
2013-02-23 16:59       ` Stefan Monnier
2013-02-23 18:44         ` Eli Zaretskii
2013-02-24 15:28           ` Dmitry Gutov
2013-02-24 15:50             ` Eli Zaretskii
2013-02-25  5:52               ` Dmitry Gutov
2013-02-25 15:25                 ` Stefan Monnier
2013-02-25 16:37                   ` Eli Zaretskii
2013-02-25 18:29                     ` Stefan Monnier
2013-02-25 18:56                       ` Eli Zaretskii
2013-02-25 20:28                         ` Stefan Monnier
2013-02-26  3:39                           ` Eli Zaretskii
2013-02-26  4:35                             ` Stefan Monnier
2013-03-02  9:30                               ` Eli Zaretskii
2013-02-25 16:25                 ` Eli Zaretskii [this message]
2013-02-25 18:27                   ` Dmitry Gutov
2013-02-25 16:27                 ` Eli Zaretskii
2013-02-25 19:08                   ` Dmitry Gutov
2013-02-25 19:31                     ` Eli Zaretskii
2013-02-25 23:23                       ` Dmitry Gutov
2013-02-26  3:51                         ` Eli Zaretskii
2013-02-26  3:59                           ` Dmitry Gutov
2013-02-26 18:42                             ` Eli Zaretskii
2013-02-27 17:46                               ` Dmitry Gutov

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

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

  git send-email \
    --in-reply-to=831uc4jr7t.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=13743@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.