From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#20153: 24.4.91; destructive add-face-text-property and string deep copying Date: Wed, 09 Oct 2019 05:04:03 +0200 Message-ID: <874l0iwrfg.fsf@gnus.org> References: <87bnjnyhtb.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="265652"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 20153@debbugs.gnu.org To: Oleh Krehel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 09 18:10:27 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iIEXi-0016yZ-5P for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Oct 2019 18:10:26 +0200 Original-Received: from localhost ([::1]:52016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIEXg-0001Pp-NF for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Oct 2019 12:10:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47923) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iI2Hg-0005Gv-5s for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 23:05:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iI2Hf-0008QX-19 for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 23:05:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iI2He-0008QO-U0 for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 23:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iI2He-0001KG-Nt for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 23:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Oct 2019 03:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20153 X-GNU-PR-Package: emacs Original-Received: via spool by 20153-submit@debbugs.gnu.org id=B20153.15705902505001 (code B ref 20153); Wed, 09 Oct 2019 03:05:02 +0000 Original-Received: (at 20153) by debbugs.gnu.org; 9 Oct 2019 03:04:10 +0000 Original-Received: from localhost ([127.0.0.1]:51761 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iI2Gn-0001Ia-T1 for submit@debbugs.gnu.org; Tue, 08 Oct 2019 23:04:10 -0400 Original-Received: from quimby.gnus.org ([80.91.231.51]:51404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iI2Gl-0001IK-Mf for 20153@debbugs.gnu.org; Tue, 08 Oct 2019 23:04:08 -0400 Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iI2Gh-0001lj-JA; Wed, 09 Oct 2019 05:04:05 +0200 In-Reply-To: <87bnjnyhtb.fsf@gmail.com> (Oleh Krehel's message of "Fri, 20 Mar 2015 13:28:00 +0100") 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: 209.51.188.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:168696 Archived-At: 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