From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#23917: Please consider making Bug #23917 a blocker for 25.1 (was Re: org-capture: Capture template =?UTF-8?Q?=E2=80=98g=E2=80=99:?= Match data clobbered by buffer modification hooks) Date: Tue, 19 Jul 2016 19:18:36 -0400 Message-ID: <87k2ghcj3n.fsf@users.sourceforge.net> References: <87vb066ejv.fsf@linaro.org> <8360s67qcp.fsf@gnu.org> <87bn1yyaui.fsf@linaro.org> <87mvlhmv0x.fsf_-_@moondust.awandering> <837fcl5zs9.fsf@gnu.org> <87a8hgkwcb.fsf@linaro.org> <8360s42mcb.fsf@gnu.org> <87eg6rgmlg.fsf@gmail.com> <83lh0y24y6.fsf@gnu.org> <83eg6q1hbo.fsf@gnu.org> <83a8hd1vzi.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1468970364 21818 80.91.229.3 (19 Jul 2016 23:19:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Jul 2016 23:19:24 +0000 (UTC) Cc: nljlistbox2@gmail.com, jwiegley@gmail.com, rpluim@gmail.com, 23917@debbugs.gnu.org, Stefan Monnier , alex.bennee@linaro.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 20 01:19:13 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bPeIC-0004nn-N6 for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Jul 2016 01:19:12 +0200 Original-Received: from localhost ([::1]:59503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPeIC-00079H-1f for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Jul 2016 19:19:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPeI6-0006w4-9G for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2016 19:19:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPeI2-0006Lv-1A for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2016 19:19:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPeI1-0006Lr-TH; Tue, 19 Jul 2016 19:19:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bPeI1-00081A-Mu; Tue, 19 Jul 2016 19:19:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, emacs-orgmode@gnu.org Resent-Date: Tue, 19 Jul 2016 23:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23917 X-GNU-PR-Package: emacs,org-mode X-GNU-PR-Keywords: Original-Received: via spool by 23917-submit@debbugs.gnu.org id=B23917.146897032630795 (code B ref 23917); Tue, 19 Jul 2016 23:19:01 +0000 Original-Received: (at 23917) by debbugs.gnu.org; 19 Jul 2016 23:18:46 +0000 Original-Received: from localhost ([127.0.0.1]:57700 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPeHm-00080d-1k for submit@debbugs.gnu.org; Tue, 19 Jul 2016 19:18:46 -0400 Original-Received: from mail-it0-f43.google.com ([209.85.214.43]:37481) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPeHi-00080M-Ub for 23917@debbugs.gnu.org; Tue, 19 Jul 2016 19:18:44 -0400 Original-Received: by mail-it0-f43.google.com with SMTP id f6so34347330ith.0 for <23917@debbugs.gnu.org>; Tue, 19 Jul 2016 16:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=MXE6IzwjCXlD30feJVo3yGvf3hvQaN399e+9ojqxuyk=; b=eZ8k9uGmF+6j5aS4eKLJpMS8MqEgUcweTuMNuJjStqlJZOCS7blQnSub33gmNp9ooi CI8//sVSenTm6beYun4BLKTASLI7xNSikRGzMZmcbEel72WjkaAhkdElTjnzwslut0DL +BIxGiJiFZfyY2cJzipU7TyISxSpS9BmTvID0JWgbJ8hGRdQk4efPygL9RmoaPHS31Kj I2jqf07c+5vDLybAj6eRjOCgQExgxwt1SKHBtIOdEJHlDUnl0FrhSCoowwnWJjw/Km7b wgXBRW0DSPL1O5xD6EZBufifpfchSZGY5lxYOIIXZTMHxP1BWNVTgM+5HNVUw7pNcYhI nsaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=MXE6IzwjCXlD30feJVo3yGvf3hvQaN399e+9ojqxuyk=; b=OJPBy9dGqsl6bFjTeloPriN5Up/2xGQGyQmQu+9Ykl0GyIESVLFFJZDI/87Ngdg9/t F7QRl75qpEYIZtH+YkTzigw2uOurvj+XGJKet79OQl2SmxCTZ91DPL1n5ZzIShJZbg8W x+LfaVWUjVOykP2l57yN4AGfNne4bz0oMRy+UbLGw64E0wuBbgRPwZh9o3X9QlN11X9f vzt654g3ApU9JhHcN57UYxn7EzuVNowZgvaHC8EDvd35HJrtAYU+iY4B3Yc/X2EU8Jmx VEfoJM3dVnBfA5y/8v7hHdq9ymglKt0+ZsT5e/wVLbMJWW+tnLg5QSbFtAC978dbrBMn k0eQ== X-Gm-Message-State: ALyK8tKVPyCNOkf7KXU9GXu4HHo9gtBhmMLe5mkeDLNNfcoqeU54gaRec3ihSced5yhTTA== X-Received: by 10.36.20.75 with SMTP id 72mr32451981itg.83.1468970317481; Tue, 19 Jul 2016 16:18:37 -0700 (PDT) Original-Received: from zony (206-188-64-44.cpe.distributel.net. [206.188.64.44]) by smtp.googlemail.com with ESMTPSA id o15sm10022998ith.2.2016.07.19.16.18.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 16:18:36 -0700 (PDT) In-Reply-To: <83a8hd1vzi.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 19 Jul 2016 18:35:45 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.93 (gnu/linux) 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:121279 Archived-At: Eli Zaretskii writes: >> From: Stefan Monnier >> Cc: rpluim@gmail.com, 23917@debbugs.gnu.org, alex.bennee@linaro.org, jwiegley@gmail.com, nljlistbox2@gmail.com >> Date: Tue, 19 Jul 2016 00:48:19 -0400 >> >> > The more general problem is when there's at least one more >> > sub-expression, whose start and/or end are after the new EOB. >> > Those sub-expression's data will be completely bogus after the >> > adjustment, >> >> If they were after the EOB, they were already bogus to start with. > > I think we are mis-communicating. I mean the following scenario: > > Before call to replace_range in replace-match: > > |---------------------------|---|------|----| > s1 e1 s2 e2 EOB > > (s1, e1, etc. are the start and end of the corresponding > sub-expressions.) > > After the call to replace_range in replace-match: > > |---------|---|------|----| > s1 e1 s2 e2 EOB > > IOW, the 1st sub-expression got replaced with a much shorter text, > which made EOB be smaller than the original beginning and end of the > 2nd sub-expression. There's nothing bogus with this, is there? The > user will expect to get match-data adjusted as shown in the second > diagram, and that's what she will really get -- unless there are > buffer-modification hooks that use save-match-data. In the latter > case, what the user will get instead is this: > > |---------|---|------|----| > s1 EOB > e1 > s2 > e2 > > and that is even before the adjustment code kicks in and makes > "adjustments" with an incorrect adjustment value, which is computed as > > newpoint = search_regs.start[sub] + SCHARS (newtext); > [...] > ptrdiff_t change = newpoint - search_regs.end[sub]; > > and so will use the new EOB as search_regs.end[sub], instead of the > correct original value of e1 from the first diagram above. > > IOW, the call to save-match-data in a buffer-modification hook > _disrupts_ the normal operation of replace-match in this case, by > indirectly sabotaging the adjustment of match data after the > replacement. Is it not possible to adjust the match data *before* calling buffer modification hooks? Seems to me the root of the problem is that buffer modification hooks get to see this invalid intermediate state where the match data is out of sync with the buffer.