From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: master e9e807e: Don't remove notify descriptor that is already gone Date: Sat, 20 Apr 2019 12:20:15 +0200 Message-ID: References: <20190415083338.9906.18508@vcs0.savannah.gnu.org> <20190415083339.64FE620536@vcs0.savannah.gnu.org> <871s2277mv.fsf@gmx.de> <87wojqhwlk.fsf@gmx.de> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_ED3F4ADB-FC0E-4F29-90CC-390FAC488B13" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="211953"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Emacs developers To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 20 12:20:40 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHn6r-000t0u-FB for ged-emacs-devel@m.gmane.org; Sat, 20 Apr 2019 12:20:37 +0200 Original-Received: from localhost ([127.0.0.1]:39583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHn6q-0007xW-Gc for ged-emacs-devel@m.gmane.org; Sat, 20 Apr 2019 06:20:36 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:37765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHn6k-0007xL-1x for emacs-devel@gnu.org; Sat, 20 Apr 2019 06:20:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hHn6i-0005Kv-2r for emacs-devel@gnu.org; Sat, 20 Apr 2019 06:20:30 -0400 Original-Received: from mail176c50.megamailservers.eu ([91.136.10.186]:51108 helo=mail37c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hHn6e-0005HH-L9 for emacs-devel@gnu.org; Sat, 20 Apr 2019 06:20:26 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1555755618; bh=Dw/3bVXokq0sHmcntD6qSziBrdjZI28GitLEU5TGJtU=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=JJBNdzOcxQE1y2MzVrDq7AT3OSWYdm3fkxrkgm0C5oaoZs3F9LSNfoNleq/yVEwcD u5NatWxAZU0wI4sux9sptr5sNpZEQg4Ku4uQ/TRQO1npBhVjoU2LPzFYeDyLjtPlua z1niZDWPwVMZtF9w+tVeqCZkHVhKuVa6baWgZNL0= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.1.64] (c-e636e253.032-75-73746f71.bbcust.telenor.se [83.226.54.230]) (authenticated bits=0) by mail37c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x3KAKGmr000448; Sat, 20 Apr 2019 10:20:17 +0000 In-Reply-To: <87wojqhwlk.fsf@gmx.de> X-Mailer: Apple Mail (2.3445.104.8) X-CTCH-RefID: str=0001.0A0B0209.5CBAF262.0020, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=Fr8rAVjq c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=6XTajijljjA4J9GdTd0A:9 a=PZaDtA_2swoH2df1:21 a=wkQGtDm1AnUB1FLm:21 a=CjuIK1q_8ugA:10 a=eHSmKPHdKwwcaknvi-IA:9 a=B2y7HmGcmWMA:10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 91.136.10.186 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:235692 Archived-At: --Apple-Mail=_ED3F4ADB-FC0E-4F29-90CC-390FAC488B13 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 19 apr. 2019 kl. 16.56 skrev Michael Albinus : >=20 >> (Not only is `auto-revert-notify-watch-descriptor-hash-list' a >> mouthful, it is a bit misleading. It maps descriptors to lists of >> buffers. How about `auto-revert--buffers-by-watch-descriptor'?) >=20 > No objection. Thanks, I'll do this separately. >> Slightly more robust would be to stop reusing descriptors: either = made >> mutable, so that they can be invalidated, or made unique by using a >> counter. However, the basic design is still somewhat dubious: it = tells >> us whether the descriptor is valid, but that just raises the = question: >> why do we even have to ask? Correct code should understand its own >> invariants. >=20 > In theory you are right. But I fear there could be situations where = such > assumptions do ne keep. A double-check is OK. What about using the checks in assertions to validate the assumptions, = instead of making the code bug-tolerant? Assertions both inform the = reader and check correctness. After all, bug-tolerant code just leads to more bugs, to code where the = just-in-case conditions cannot be distinguished from the essential ones, = and where nobody understands the invariants. >> Now that you `mentioned auto-revert-notify-rm-watch', does it strike >> you as odd the way it does >>=20 >> (maphash >> (lambda (key value) >> (when (equal key some-key) >> do-something)) >> some-hashtable) >>=20 >> instead of using the hash table directly? Suggested patch to fix this >> attached. >=20 > I'm still not convinced that we need REMOVE-DESCRIPTOR. We shall = always > remove the descriptor, and assure, that no superfluous events are = raised. Can I take it that you are happy with the patch attached to that = message, which just does away with the maphash? Regarding getting rid of remove-descriptor, that's fine with me -- I'm = attaching a new patch which does the work in file-notify instead, which = is how I interpret your wish. With that patch, e9e807e931 (addition of = the remove-descriptor parameter) can be reverted. >> By the way, why don't we give each buffer in auto-revert-mode a = unique >> descriptor, so that the table just maps descriptors to buffers, >> instead of to lists of buffers? It would simplify the code in many >> places, and it cannot be that common to have multiple buffers for the >> same file that it warrants the descriptor-sharing optimisation. >=20 > Well, the descriptor is the one we get from filenotify. I don't = believe > we shall do double housekeeping. Sounds to me error-prone. Agreed, and filenotify seems to ensure that each watch gets a distinct = descriptor even for the same file. I'll prepare a patch for simplifying = the table in autorevert.el, unless you can remember the reason for = introducing the buffer lists in ef3544f6a6. I have read bug#13540, which = is mentioned in the commit message, and am none the wiser. --Apple-Mail=_ED3F4ADB-FC0E-4F29-90CC-390FAC488B13 Content-Disposition: attachment; filename=0001-Make-file-notify-rm-watch-robust-against-reentry.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Make-file-notify-rm-watch-robust-against-reentry.patch" Content-Transfer-Encoding: quoted-printable =46rom=201105a7d356b1adfb2a39ae29f4970e997f37a2f6=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Sat,=2020=20Apr=202019=2010:19:52=20+0200=0A= Subject:=20[PATCH]=20Make=20file-notify-rm-watch=20robust=20against=20= reentry=0A=0AAllow=20file-notify=20callbacks=20to=20call=20= `file-notify-rm-watch',=20harmlessly,=0Aafter=20receiving=20a=20= `stopped'=20event=20without=20triggering=20recursion.=0A=0A*=20= lisp/filenotify.el=20(file-notify--watch):=20Note=20that=20`callback'=20= can=20be=20nil.=0A(file-notify--rm-descriptor):=20Set=20the=20`callback'=20= field=20to=20nil=20before=0Asending=20`stopped'.=0A= (file-notify-rm-watch):=20Don't=20do=20anything=20if=20the=20`callback'=20= field=20is=20nil.=0A---=0A=20lisp/filenotify.el=20|=2057=20= +++++++++++++++++++++++++---------------------=0A=201=20file=20changed,=20= 31=20insertions(+),=2026=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/filenotify.el=20b/lisp/filenotify.el=0Aindex=20= 3f9bb960a9..62dd1cd911=20100644=0A---=20a/lisp/filenotify.el=0A+++=20= b/lisp/filenotify.el=0A@@=20-49,7=20+49,7=20@@=20could=20use=20another=20= implementation.")=0A=20=20=20directory=0A=20=20=20;;=20Watched=20= relative=20filename,=20nil=20if=20watching=20the=20directory.=0A=20=20=20= filename=0A-=20=20;;=20Function=20to=20propagate=20events=20to.=0A+=20=20= ;;=20Function=20to=20propagate=20events=20to,=20or=20nil=20if=20watch=20= is=20being=20removed.=0A=20=20=20callback)=0A=20=0A=20(defun=20= file-notify--watch-absolute-filename=20(watch)=0A@@=20-72,12=20+72,15=20= @@=20struct.")=0A=20DESCRIPTOR=20should=20be=20an=20object=20returned=20= by=20`file-notify-add-watch'.=0A=20If=20it=20is=20registered=20in=20= `file-notify-descriptors',=20a=20stopped=20event=20is=20sent."=0A=20=20=20= (when-let*=20((watch=20(gethash=20descriptor=20= file-notify-descriptors)))=0A-=20=20=20=20;;=20Send=20`stopped'=20event.=0A= -=20=20=20=20(unwind-protect=0A-=20=20=20=20=20=20=20=20(funcall=0A-=20=20= =20=20=20=20=20=20=20(file-notify--watch-callback=20watch)=0A-=20=20=20=20= =20=20=20=20=20`(,descriptor=20stopped=20= ,(file-notify--watch-absolute-filename=20watch)))=0A-=20=20=20=20=20=20= (remhash=20descriptor=20file-notify-descriptors))))=0A+=20=20=20=20(let=20= ((callback=20(file-notify--watch-callback=20watch)))=0A+=20=20=20=20=20=20= ;;=20Make=20sure=20this=20is=20the=20last=20time=20the=20callback=20is=20= invoked.=0A+=20=20=20=20=20=20(setf=20(file-notify--watch-callback=20= watch)=20nil)=0A+=20=20=20=20=20=20;;=20Send=20`stopped'=20event.=0A+=20=20= =20=20=20=20(unwind-protect=0A+=20=20=20=20=20=20=20=20=20=20(funcall=0A= +=20=20=20=20=20=20=20=20=20=20=20callback=0A+=20=20=20=20=20=20=20=20=20= =20=20`(,descriptor=20stopped=20,(file-notify--watch-absolute-filename=20= watch)))=0A+=20=20=20=20=20=20=20=20(remhash=20descriptor=20= file-notify-descriptors)))))=0A=20=0A=20;;=20This=20function=20is=20used=20= by=20`inotify',=20`kqueue',=20`gfilenotify'=20and=0A=20;;=20`w32notify'=20= events.=0A@@=20-381,25=20+384,27=20@@=20FILE=20is=20the=20name=20of=20= the=20file=20whose=20event=20is=20being=20reported."=0A=20=20=20"Remove=20= an=20existing=20watch=20specified=20by=20its=20DESCRIPTOR.=0A=20= DESCRIPTOR=20should=20be=20an=20object=20returned=20by=20= `file-notify-add-watch'."=0A=20=20=20(when-let*=20((watch=20(gethash=20= descriptor=20file-notify-descriptors)))=0A-=20=20=20=20(let=20((handler=20= (find-file-name-handler=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(file-notify--watch-directory=20watch)=0A-=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20'file-notify-rm-watch)))=0A-=20=20= =20=20=20=20(condition-case=20nil=0A-=20=20=20=20=20=20=20=20=20=20(if=20= handler=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20;;=20A=20file=20= name=20handler=20could=20exist=20even=20if=20there=20is=20no=0A-=20=20=20= =20=20=20=20=20=20=20=20=20=20=20;;=20local=20file=20notification=20= support.=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20(funcall=20handler=20= 'file-notify-rm-watch=20descriptor)=0A-=0A-=20=20=20=20=20=20=20=20=20=20= =20=20(funcall=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20(cond=0A-=20=20=20= =20=20=20=20=20=20=20=20=20=20=20((eq=20file-notify--library=20'inotify)=20= 'inotify-rm-watch)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20((eq=20= file-notify--library=20'kqueue)=20'kqueue-rm-watch)=0A-=20=20=20=20=20=20= =20=20=20=20=20=20=20=20((eq=20file-notify--library=20'gfilenotify)=20= 'gfile-rm-watch)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20((eq=20= file-notify--library=20'w32notify)=20'w32notify-rm-watch))=0A-=20=20=20=20= =20=20=20=20=20=20=20=20=20descriptor))=0A-=20=20=20=20=20=20=20=20= (file-notify-error=20nil)))=0A-=20=20=20=20;;=20Modify=20= `file-notify-descriptors'.=0A-=20=20=20=20(file-notify--rm-descriptor=20= descriptor)))=0A+=20=20=20=20;;=20If=20we=20are=20called=20from=20a=20= `stopped'=20event,=20do=20nothing.=0A+=20=20=20=20(when=20= (file-notify--watch-callback=20watch)=0A+=20=20=20=20=20=20(let=20= ((handler=20(find-file-name-handler=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(file-notify--watch-directory=20watch)=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= 'file-notify-rm-watch)))=0A+=20=20=20=20=20=20=20=20(condition-case=20= nil=0A+=20=20=20=20=20=20=20=20=20=20=20=20(if=20handler=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20;;=20A=20file=20name=20handler=20could=20= exist=20even=20if=20there=20is=20no=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20;;=20local=20file=20notification=20support.=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(funcall=20handler=20= 'file-notify-rm-watch=20descriptor)=0A+=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(funcall=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (cond=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20((eq=20= file-notify--library=20'inotify)=20'inotify-rm-watch)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20((eq=20file-notify--library=20'kqueue)=20= 'kqueue-rm-watch)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= ((eq=20file-notify--library=20'gfilenotify)=20'gfile-rm-watch)=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20((eq=20file-notify--library=20= 'w32notify)=20'w32notify-rm-watch))=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20descriptor))=0A+=20=20=20=20=20=20=20=20=20=20= (file-notify-error=20nil)))=0A+=20=20=20=20=20=20;;=20Modify=20= `file-notify-descriptors'=20and=20send=20a=20`stopped'=20event.=0A+=20=20= =20=20=20=20(file-notify--rm-descriptor=20descriptor))))=0A=20=0A=20= (defun=20file-notify-valid-p=20(descriptor)=0A=20=20=20"Check=20a=20= watch=20specified=20by=20its=20DESCRIPTOR.=0A--=20=0A2.20.1=20(Apple=20= Git-117)=0A=0A= --Apple-Mail=_ED3F4ADB-FC0E-4F29-90CC-390FAC488B13--