GNU bug report logs - #20153
24.4.91; destructive add-face-text-property and string deep copying

Previous Next

Package: emacs;

Reported by: Oleh Krehel <ohwoeowho <at> gmail.com>

Date: Fri, 20 Mar 2015 12:33:02 UTC

Severity: minor

Tags: fixed

Merged with 27433

Found in versions 24.4.91, 25.2

Fixed in version 27.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #13 received at 20153 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Oleh Krehel <ohwoeowho <at> gmail.com>
Cc: 20153 <at> debbugs.gnu.org
Subject: Re: bug#20153: 24.4.91; destructive add-face-text-property and
 string deep copying
Date: Wed, 09 Oct 2019 05:04:03 +0200
I've never really worked with the interval internals before, so I
thought this was going to be easy to fix.  :-/  But the problem is that
copy_intervals doesn't do a "deep" copy of the text properties, so this
has no effect, really.

(Patch included for reference.)

Instead I've now changed add_properties (and add_text_properties_1) to
take a bool parameter to say whether they're allowed to be destructive
or not, and make the add-face-text-property call that with false as the
parameter if the object is a string.  This fixes the test case for me
and should hopefully have no measurable performance impact.

diff --git a/src/textprop.c b/src/textprop.c
index d36b9e14a6..dcd3284209 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -1334,6 +1334,18 @@ face(s) are retained.  This is done by setting the `face' property to
    Lisp_Object append, Lisp_Object object)
 {
   AUTO_LIST2 (properties, Qface, face);
+
+  /* If we're adding face properties to a string, and the face
+     property is already a list, then copy the list first to avoid
+     destructively altering it. */
+  if (STRINGP (object))
+    {
+      INTERVAL copy = copy_intervals (string_intervals (object),
+				      0, SCHARS (object));
+      set_interval_object (copy, object);
+      set_string_intervals (object, copy);
+    }
+
   add_text_properties_1 (start, end, properties, object,
 			 (NILP (append)
 			  ? TEXT_PROPERTY_PREPEND

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





This bug report was last modified 5 years and 230 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.