From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#56682: locked narrowing Date: Sat, 26 Nov 2022 16:15:34 +0000 Message-ID: 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> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20511"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 26 17:16:19 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 1oyxqk-00058s-V0 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 26 Nov 2022 17:16:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyxqa-0006s7-1Q; Sat, 26 Nov 2022 11:16:08 -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 1oyxqV-0006rq-Gn for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:16:05 -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 1oyxqV-0007R8-7C for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:16:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyxqU-0002J3-2N for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 11:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Nov 2022 16:16: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.16694793398857 (code B ref 56682); Sat, 26 Nov 2022 16:16:02 +0000 Original-Received: (at 56682) by debbugs.gnu.org; 26 Nov 2022 16:15:39 +0000 Original-Received: from localhost ([127.0.0.1]:41279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyxq6-0002In-Rl for submit@debbugs.gnu.org; Sat, 26 Nov 2022 11:15:39 -0500 Original-Received: from heytings.org ([95.142.160.155]:60386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyxq3-0002Ih-VD for 56682@debbugs.gnu.org; Sat, 26 Nov 2022 11:15:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20220101; t=1669479334; bh=vjr75GCdwTXZIpAdGWCwVGbtpmSpVLTho+jA4OFn5z0=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=VJuK2dOfNvT6sNXoklro+ygEf/9Z5I/Jz0/lafZmu0ByPDCOkpUs9+L4hDxliKTe8 XT8jsWAc7Kia9t0zgOmtS2pFgNwLVcNog8y8vvWzJXPZu4J8KvJhdFfo+oDMWdf9vL gjO7J1liGxs+xAHy6rBymKurAjdUE4zmFEip4LuNV3+mbt2uEouJk6alcbe1Rd/+Qp 5Zvx85FGKR+Ahvf4gmu5OIuW/j85qkufJIbmZkn5WDDWwkq380eMU7sWpyOvpLMfx0 7XSLjaEwktCC9DIREmAfgt46QQq5dFlbL7PzhroT9LzUlTXHFE9J0ylHdtfg7rSyFb tnV0ONr+g+fIQ== In-Reply-To: <83fse6t4d5.fsf@gnu.org> 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:249112 Archived-At: Thanks for your detailed review, and for the useful suggestions! A few comments/questions below: >> +(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})? >> +/* 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, and (more importantly) it would mean that the narrowing_locks alist is corrupted. The cdr's in that alist should never be nil. >> +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. > > The values you keep in narrowing_locks are markers, so they include the > byte position. By returning only the character position, you've lost > that useful information, and thus SET_BUF_BEGV/SET_BUF_ZV will have to > recompute it. I think it's better to return the marker there, and then > you can use the byte positions here and call SET_BUF_BEGV_BOTH and > SET_BUF_ZV_BOTH. > Thanks, I didn't think of that possibility, it seems better indeed. > > What about some tests? > I'd have to add some tests, indeed. Not sure I'll have time to do that today.