From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#56682: locked narrowing Date: Sat, 26 Nov 2022 18:51:37 +0200 Message-ID: <83a64dslpi.fsf@gnu.org> References: <831qtgff78.fsf@gnu.org> <83zgg4dw4y.fsf@gnu.org> <83r11gdrr4.fsf@gnu.org> <83edxfds7s.fsf@gnu.org> <83r11fc80o.fsf@gnu.org> <83o7wjc6o2.fsf@gnu.org> <83lernc5gu.fsf@gnu.org> <83k076dd7d.fsf@gnu.org> <83czcyd8jf.fsf@gnu.org> <83a682d66r.fsf@gnu.org> <837d36ceno.fsf@gnu.org> <37dd2827f54f8bbda5e3@heytings.org> <83fse6t4d5.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32778"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca, dgutov@yandex.ru To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 26 17:52:15 2022 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 1oyyPX-0008JX-LM for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 26 Nov 2022 17:52:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyyPM-0005UO-8D; Sat, 26 Nov 2022 11:52:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyyPK-0005UG-Mn for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:52:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oyyPK-0005mY-EK for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:52:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyyPK-0002d0-BJ for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Nov 2022 16:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56682 X-GNU-PR-Package: emacs Original-Received: via spool by 56682-submit@debbugs.gnu.org id=B56682.166948148310094 (code B ref 56682); Sat, 26 Nov 2022 16:52:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 26 Nov 2022 16:51:23 +0000 Original-Received: from localhost ([127.0.0.1]:41315 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyyOg-0002ck-N7 for submit@debbugs.gnu.org; Sat, 26 Nov 2022 11:51:23 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42780) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyyOe-0002ce-Ud for 56682@debbugs.gnu.org; Sat, 26 Nov 2022 11:51:21 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyyOZ-0005Xk-6B; Sat, 26 Nov 2022 11:51:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=2UgYiOdegH/Zj5K3N5JYHZTCm4bzBSWxseH12NmpWkA=; b=Ur5HwqnTkryQ zxsxvQOLgOOZ6cJiXPQOdA9mVu6Zzo6OjBNCzrF003JRrgdPfhll8L8hQMmeAu4ABgUUzZXslom1F c5XfX+XKqks79EkUXGMALIG4t0Rds0sX1bjP6vAj0onk/0/F9quwK0B7VYjyz9pBVRPbeA8RptahN th54M+xxUfXB2UlPHvnBGLOd3HQUvoLL1PYjL9ENU3OC0k5rtnW0YwBWp0zQLRjxrMQQIvsEIesKu Qw+pz+IqJb8eNboNA6Jym/JGeqoWKFMTQ8neiuxUWueKa3du3BT887bxVeCWFmt0hxFI/ke4V0xrS Mi0EBcOgr2QC3FvMlmxn0w==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyyOW-0005CG-FB; Sat, 26 Nov 2022 11:51:12 -0500 In-Reply-To: (message from Gregory Heytings on Sat, 26 Nov 2022 16:15:34 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:249114 Archived-At: > Date: Sat, 26 Nov 2022 16:15:34 +0000 > From: Gregory Heytings > cc: monnier@iro.umontreal.ca, 56682@debbugs.gnu.org, dgutov@yandex.ru > > >> +(defun with-narrowing-1 (start end tag body) > >> +(defun with-narrowing-2 (start end body) > > > > Should these two helpers be internal functions? > > > > You mean, they should be called with-narrowing--{1,2} (or perhaps > with--narrowing-{1,2})? I actually think these should not be called with-SOMETHING, since they aren't macros. And yes, the function names should include "--". > >> +/* Remove the innermost lock in BUF from the narrowing_lock alist. */ > >> static void > >> -unwind_locked_zv (Lisp_Object point_max) > >> +narrowing_lock_pop (Lisp_Object buf) > >> { > >> - SET_BUF_ZV (current_buffer, XFIXNUM (point_max)); > >> + Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); > >> + eassert (! NILP (buffer_locks)); > > > > Why this assertion? There's no similar assertions in other functions > > that deal with narrowing_locks. > > > > Because 'pop' on an empty stack is an error You don't need to pop, just return without doing anything. > and (more importantly) it would mean that the narrowing_locks alist is > corrupted. The cdr's in that alist should never be nil. A comment to that effect should be in order, then. > >> +static void > >> +narrowing_locks_restore (Lisp_Object buf_and_saved_locks) > >> +{ > >> + if (NILP (buf_and_saved_locks)) > >> + return; > >> + Lisp_Object buf = Fcar (buf_and_saved_locks); > >> + eassert (BUFFERP (buf)); > >> + Lisp_Object saved_locks = Fcdr (buf_and_saved_locks); > >> + eassert (! NILP (saved_locks)); > > > > Again, I don't understand the need for an assertion here. Just return > > if saved_locks is nil. > > > > Strictly speaking there is no need for an assertion, but again it would > mean that something that isn't supposed to happen happened. In this case > it would mean that narrowing_locks_restore is called with a list of length > 1, containing only a buffer, whereas it is supposed to be called with the > return value of narrowing_locks_save, which is either nil or a list of > length >= 2. I don't think I understand (you avoid the assertion in other cases which look similar to me), but if there are good reasons, please add comments there explaining the rationale. > > What about some tests? > > I'd have to add some tests, indeed. Not sure I'll have time to do that > today. We can add the tests after the branch is cut, I just wanted to be sure we will have them eventually. Thanks.