From: Lars Ingebrigtsen <larsi@gnus.org>
To: Oleh Krehel <ohwoeowho@gmail.com>
Cc: 20153@debbugs.gnu.org
Subject: bug#20153: 24.4.91; destructive add-face-text-property and string deep copying
Date: Wed, 09 Oct 2019 05:04:03 +0200 [thread overview]
Message-ID: <874l0iwrfg.fsf@gnus.org> (raw)
In-Reply-To: <87bnjnyhtb.fsf@gmail.com> (Oleh Krehel's message of "Fri, 20 Mar 2015 13:28:00 +0100")
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
next prev parent reply other threads:[~2019-10-09 3:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 12:28 bug#20153: 24.4.91; destructive add-face-text-property and string deep copying Oleh Krehel
2019-10-09 2:25 ` Lars Ingebrigtsen
2019-10-09 3:04 ` Lars Ingebrigtsen [this message]
2019-10-09 8:24 ` Oleh Krehel
2019-10-09 17:10 ` Eli Zaretskii
2019-10-09 17:45 ` Lars Ingebrigtsen
2019-10-09 18:06 ` Eli Zaretskii
2019-10-09 18:09 ` Lars Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874l0iwrfg.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=20153@debbugs.gnu.org \
--cc=ohwoeowho@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).