From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Calling Lisp from undo.c's record_* functions Date: Tue, 17 Nov 2015 20:00:56 +0200 Message-ID: <8337w4bj53.fsf@gnu.org> References: <83r3jpc2of.fsf@gnu.org> <87h9kkbz6k.fsf@russet.org.uk> <87d1v8bsbf.fsf@russet.org.uk> <83bnasbnlq.fsf@gnu.org> <836110blpb.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1447783341 11768 80.91.229.3 (17 Nov 2015 18:02:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Nov 2015 18:02:21 +0000 (UTC) Cc: emacs-devel@gnu.org, phillip.lord@russet.org.uk To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 17 19:02:10 2015 Return-path: Envelope-to: ged-emacs-devel@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 1ZykZm-0005QL-HG for ged-emacs-devel@m.gmane.org; Tue, 17 Nov 2015 19:01:54 +0100 Original-Received: from localhost ([::1]:60083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZykZm-0006oo-5q for ged-emacs-devel@m.gmane.org; Tue, 17 Nov 2015 13:01:54 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZykYy-0005da-Jz for emacs-devel@gnu.org; Tue, 17 Nov 2015 13:01:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZykYu-0002v0-Ju for emacs-devel@gnu.org; Tue, 17 Nov 2015 13:01:04 -0500 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:37275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZykYu-0002uX-CT for emacs-devel@gnu.org; Tue, 17 Nov 2015 13:01:00 -0500 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0NXZ003000CFC800@a-mtaout22.012.net.il> for emacs-devel@gnu.org; Tue, 17 Nov 2015 20:00:57 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([84.94.185.246]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NXZ003R90PL4R50@a-mtaout22.012.net.il>; Tue, 17 Nov 2015 20:00:57 +0200 (IST) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-Received-From: 80.179.55.172 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:194661 Archived-At: > From: Stefan Monnier > Cc: phillip.lord@russet.org.uk, emacs-devel@gnu.org > Date: Tue, 17 Nov 2015 12:34:08 -0500 > > >> When would it not be called? > > E.g., in insert_from_gap. Also, in many insdel.c functions when they > > are called with the PREPARE argument false. > > AFAIK these are cases where prepare_to_modify_buffer has already been > called earlier. That's what the comments say, yes. How deep do we believe them? > >> You mean there are cases where we'd add stuff to the undo list but > >> we don't run before-change-functions? > > I don't know. I don't think we have such bugs, but thinking is one > > thing and convincing yourself it's true by looking at the callers is > > something entirely different... > > That's OK, then: I believe that failing to call run_undoable_change is > not more serious than failing to run before-change-functions. > > So I think moving the call to run_undoable_change into > prepare_to_modify_buffer is n attractive solution to this problem, since > it preserves the use of Elisp, and it probably also simplifies the code > (since we can remove most/all other calls to run_undoable_change). Did you take a look at subst-char-in-region? It calls prepare_to_modify_buffer from within a loop which seems to assume that (a) gap position doesn't move, and (b) that pointer into buffer text is valid across the call to prepare_to_modify_buffer. GC could invalidate both assumptions, no? transpose-regions also does something funky, but it looks safe. zlib-decompress-region, OTOH, seems to call insert_from_gap, and doesn't call prepare_to_modify_buffer at all, except at its very end, when it deletes the uncompressed data. Bottom line: I think all the functions that manipulate the gap should be carefully audited to identify any potential problem with this approach.