From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#39585: after-change-functions called with invalid positions in call-process Date: Thu, 13 Feb 2020 19:15:19 +0000 Message-ID: <20200213191519.GA5215@ACM> References: <0a3d3423-965f-4681-b6e2-04b8c1a36a6a@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="113774"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 39585@debbugs.gnu.org To: =?UTF-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 13 20:31:46 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j2KDB-000TT2-Sx for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Feb 2020 20:31:45 +0100 Original-Received: from localhost ([::1]:58366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2KDA-0007vD-UJ for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Feb 2020 14:31:44 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43581) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2JyF-0003IX-Uk for bug-gnu-emacs@gnu.org; Thu, 13 Feb 2020 14:16:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2Jy1-0001Sn-Eu for bug-gnu-emacs@gnu.org; Thu, 13 Feb 2020 14:16:18 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54494) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2Jxy-0001PT-QQ for bug-gnu-emacs@gnu.org; Thu, 13 Feb 2020 14:16:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j2Jxy-0007EM-Ls for bug-gnu-emacs@gnu.org; Thu, 13 Feb 2020 14:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Feb 2020 19:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39585 X-GNU-PR-Package: emacs Original-Received: via spool by 39585-submit@debbugs.gnu.org id=B39585.158162132527738 (code B ref 39585); Thu, 13 Feb 2020 19:16:02 +0000 Original-Received: (at 39585) by debbugs.gnu.org; 13 Feb 2020 19:15:25 +0000 Original-Received: from localhost ([127.0.0.1]:60466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j2JxM-0007DK-Pd for submit@debbugs.gnu.org; Thu, 13 Feb 2020 14:15:25 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:13056 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1j2JxK-0007DA-LM for 39585@debbugs.gnu.org; Thu, 13 Feb 2020 14:15:23 -0500 Original-Received: (qmail 81497 invoked by uid 3782); 13 Feb 2020 19:15:20 -0000 Original-Received: from acm.muc.de (p4FE15C42.dip0.t-ipconnect.de [79.225.92.66]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 13 Feb 2020 20:15:19 +0100 Original-Received: (qmail 5220 invoked by uid 1000); 13 Feb 2020 19:15:19 -0000 Content-Disposition: inline In-Reply-To: <0a3d3423-965f-4681-b6e2-04b8c1a36a6a@gmail.com> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:176012 Archived-At: Hello, Clément. On Wed, Feb 12, 2020 at 22:56:49 -0500, Clément Pit-Claudel wrote: > Hi all, > Recent changes in call-process have introduced surprising behavior in > after-change-functions (and caused bugs in flycheck, e.g. > https://github.com/flycheck/flycheck/issues/1677). From the > documentation, I expected that functions added to the > after-change-functions hook would be called only with valid positions. > However, the following snippets shows that it's not the case: > (defun ~/after-change (beg end len) > (message "(after-change %S %S %S); (buffer %S %S %S)" > beg end len (point-min) (point-max) (buffer-size))) > (with-current-buffer (get-buffer-create "*tmp*") > (make-variable-buffer-local 'after-change-functions) > (add-hook 'after-change-functions #'~/after-change) > (call-process "echo" nil t t "Hello")) > Running it repeatedly, this is what I observe: > (after-change 7 13 0); (buffer 1 7 6) > (after-change 13 19 0); (buffer 1 13 12) > (after-change 19 25 0); (buffer 1 19 18) > (after-change 25 31 0); (buffer 1 25 24) > Note how each time the after-change-functions hook is called with a > region past the end of the buffer. It's as if after-change-functions > was in fact call right before the insertion, instead of after. Well, something like that. Sorry about it, and thanks for drawing my attention to it. > Previous versions of Emacs didn't call after-change-functions in this > case; it seems that the new behavior was introduced by this commit: > commit 224e8d146485ce178086549d41fa8359dcc0e03e > Author: Alan Mackenzie > Date: Wed Jan 22 19:50:30 2020 +0000 > Make call_process call signal_after_change. This fixes bug #38691. > Now, functions such as call-proess-region invoke after-change-functions > correctly. > * src/callproc.c (call_process): Call prepare_to_modify_buffer in a single > place, no longer delegating the task to insert_1_both, etc. Call > signal_after_change in each of two code branches, such that > before-change-functions and after-change-functions are always called in > balanced pairs. > Alan, is this behavior expected? No, it is not. I've applied this corrective patch to the emacs-27 branch: commit d1e8ce8bb6fadf3d034ae437ff1c1b81be7d5209 Author: Alan Mackenzie Date: Thu Feb 13 19:00:36 2020 +0000 Make after-change-functions called from call-process get the correct BEG This fixes bug #39585. * src/callproc.c (call_process): Supply the correct CHARPOS to signal_after_change (twice). diff --git a/src/callproc.c b/src/callproc.c index 07dcc4c3ae..8883415f3f 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -811,7 +811,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, && ! CODING_MAY_REQUIRE_DECODING (&process_coding)) { insert_1_both (buf, nread, nread, 0, 0, 0); - signal_after_change (PT, 0, nread); + signal_after_change (PT - nread, 0, nread); } else { /* We have to decode the input. */ @@ -854,7 +854,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, TEMP_SET_PT_BOTH (PT + process_coding.produced_char, PT_BYTE + process_coding.produced); - signal_after_change (PT, 0, process_coding.produced_char); + signal_after_change (PT - process_coding.produced_char, + 0, process_coding.produced_char); carryover = process_coding.carryover_bytes; if (carryover > 0) memcpy (buf, process_coding.carryover, . It should find its way into the master branch in the usual way. Please let me know whether you agree with me that this bug can now be closed. Thanks! > Thanks, > Clément. -- Alan Mackenzie (Nuremberg, Germany).