From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Lisp primitives and their calling of the change hooks Date: Wed, 10 Jan 2018 18:29:09 +0000 Message-ID: <20180110182909.GA6175@ACM> References: <83bmi58sao.fsf@gnu.org> <20180107194845.GE22254@ACM> <838td98mqe.fsf@gnu.org> <20180107211055.GF22254@ACM> <837est81bl.fsf@gnu.org> <20180108192415.GA5531@ACM> <83h8rw6oio.fsf@gnu.org> <20180109195357.GA3869@ACM> <83r2qy6bmp.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1515609157 21863 195.159.176.226 (10 Jan 2018 18:32:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 10 Jan 2018 18:32:37 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 10 19:32:33 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZLAt-0005GB-Um for ged-emacs-devel@m.gmane.org; Wed, 10 Jan 2018 19:32:32 +0100 Original-Received: from localhost ([::1]:59141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLCt-0004M0-FK for ged-emacs-devel@m.gmane.org; Wed, 10 Jan 2018 13:34:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZLCg-0004Kg-Ig for emacs-devel@gnu.org; Wed, 10 Jan 2018 13:34:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZLCb-0008HC-Q2 for emacs-devel@gnu.org; Wed, 10 Jan 2018 13:34:22 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:53264 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1eZLCb-0008GC-GQ for emacs-devel@gnu.org; Wed, 10 Jan 2018 13:34:17 -0500 Original-Received: (qmail 39361 invoked by uid 3782); 10 Jan 2018 18:34:16 -0000 Original-Received: from acm.muc.de (p548C7214.dip0.t-ipconnect.de [84.140.114.20]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 10 Jan 2018 19:34:15 +0100 Original-Received: (qmail 6244 invoked by uid 1000); 10 Jan 2018 18:29:09 -0000 Content-Disposition: inline In-Reply-To: <83r2qy6bmp.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221802 Archived-At: Hello, Eli. On Tue, Jan 09, 2018 at 22:05:50 +0200, Eli Zaretskii wrote: > > Date: Tue, 9 Jan 2018 19:53:57 +0000 > > Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org > > From: Alan Mackenzie > > However, I think we'll agree that we've already spent enough time > > debating this issue. If you still say one b/a-c-f pair for a > > (successful) zlib-decompress-region call, I will accept it, and fix the > > b/a-c-f call of the unsuccessful case. > Yes, I still think that zlib-decompress-region is a replacement > primitive (and base64-decode-region is in error not behaving the > same). You want me to fix it? (Half joking.) > Thanks. OK, a patch, perhaps for the last time. In a call to z-d-r, successful or not, there will be exactly one b-c-f call and exactly one a-c-f call. I think, for the failing case, this is neater than having a bare b-c-f with nothing following it. diff --git a/src/decompress.c b/src/decompress.c index 41de6da1dd..6f75f821c4 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -24,6 +24,7 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "buffer.h" +#include "composite.h" #include @@ -66,7 +67,7 @@ init_zlib_functions (void) struct decompress_unwind_data { - ptrdiff_t old_point, start, nbytes; + ptrdiff_t old_point, orig, start, nbytes; z_stream *stream; }; @@ -76,10 +77,19 @@ unwind_decompress (void *ddata) struct decompress_unwind_data *data = ddata; inflateEnd (data->stream); - /* Delete any uncompressed data already inserted on error. */ + /* Delete any uncompressed data already inserted on error, but + without calling the change hooks. */ if (data->start) - del_range (data->start, data->start + data->nbytes); - + { + del_range_2 (data->start, data->start, /* byte, char offsets the same */ + data->start + data->nbytes, data->start + data->nbytes, + 0); + update_compositions (data->start, data->start, CHECK_HEAD); + /* "Balance" the before-change-functions call, which would + otherwise be left "hanging". */ + signal_after_change (data->orig, data->start - data->orig, + data->start - data->orig); + } /* Put point where it was, or if the buffer has shrunk because the compressed data is bigger than the uncompressed, at point-max. */ @@ -141,6 +151,10 @@ This function can be called only in unibyte buffers. */) the same. */ istart = XINT (start); iend = XINT (end); + + /* Do the following before manipulating the gap. */ + modify_text (istart, iend); + move_gap_both (iend, iend); stream.zalloc = Z_NULL; @@ -154,6 +168,7 @@ This function can be called only in unibyte buffers. */) if (inflateInit2 (&stream, MAX_WBITS + 32) != Z_OK) return Qnil; + unwind_data.orig = istart; unwind_data.start = iend; unwind_data.stream = &stream; unwind_data.old_point = PT; @@ -196,7 +211,11 @@ This function can be called only in unibyte buffers. */) unwind_data.start = 0; /* Delete the compressed data. */ - del_range (istart, iend); + del_range_2 (istart, istart, /* byte and char offsets are the same. */ + iend, iend, 0); + + signal_after_change (istart, iend - istart, unwind_data.nbytes); + update_compositions (istart, istart, CHECK_HEAD); return unbind_to (count, Qt); } -- Alan Mackenzie (Nuremberg, Germany).