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: Tue, 16 Apr 2019 15:31:08 +0200 Message-ID: References: <20190415083338.9906.18508@vcs0.savannah.gnu.org> <20190415083339.64FE620536@vcs0.savannah.gnu.org> <871s2277mv.fsf@gmx.de> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_47038F3F-750D-4BBF-9AC4-FD5DA7BA4BAB" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="145357"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 16 15:35:02 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 1hGOEm-000bdZ-UY for ged-emacs-devel@m.gmane.org; Tue, 16 Apr 2019 15:35:01 +0200 Original-Received: from localhost ([127.0.0.1]:37020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGOEl-0007XH-Q7 for ged-emacs-devel@m.gmane.org; Tue, 16 Apr 2019 09:34:59 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:43547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGOBD-0005ts-Mh for emacs-devel@gnu.org; Tue, 16 Apr 2019 09:31:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGOBC-0002No-CK for emacs-devel@gnu.org; Tue, 16 Apr 2019 09:31:19 -0400 Original-Received: from mail152c50.megamailservers.eu ([91.136.10.162]:52578 helo=mail50c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGOB9-0002Hp-MR for emacs-devel@gnu.org; Tue, 16 Apr 2019 09:31:17 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1555421471; bh=zpGOqFAAncBzylFp6GxANKU54r6Cw3ESb/iFbEUt08w=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=OcetK1niathY0XsgZ/1NvS0dmIHANpNztTZ26nkliOyIUjdAFaes4qzwla4VTgMF8 y4YaKbStAifqLMVWgHrk7pql6AxJWRg+oeaNb2enbE6jd7S0rvSgMZw3oYku5v/qTP gHvKmUVwNl3XqAZA7JsYoPUAPinNEyXQJdDgF/KE= 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 mail50c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x3GDV9TK005303; Tue, 16 Apr 2019 13:31:10 +0000 In-Reply-To: <871s2277mv.fsf@gmx.de> X-Mailer: Apple Mail (2.3445.104.8) X-CTCH-RefID: str=0001.0A0B0206.5CB5D91F.0001, 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=ILEs9DnG c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=Vi_lrhURuRz-pUnfQ_IA:9 a=czJRLEc12jeYgO9c:21 a=GO2QsrLlsmberSMT:21 a=CjuIK1q_8ugA:10 a=upQsEGSO-laeOn_Who0A: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.162 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:235517 Archived-At: --Apple-Mail=_47038F3F-750D-4BBF-9AC4-FD5DA7BA4BAB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 16 apr. 2019 kl. 09.04 skrev Michael Albinus : > I haven't tested thoroughly yet, but wouldn't it suffice if in > auto-revert-notify-rm-watch there is just the test >=20 > (when (file-notify-valid-p auto-revert-notify-watch-descriptor) >=20 > instead of >=20 > (when auto-revert-notify-watch-descriptor Thanks for reading my change. It is a fair question! First of all, the descriptor wouldn't then be removed from = `auto-revert-notify-watch-descriptor-hash-list' since that part is also = guarded by the condition, but that's just a matter of rearranging code. (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'?) I'm not necessarily enamoured with `file-notify-valid-p'. It just tells = whether there is, right now, a descriptor that looks like the argument, = in use by someone, somewhere. These descriptors are reused, making the = predicate dangerous to rely on, or requires brittle code that just knows = that no reuse has occurred. 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. Now that you `mentioned auto-revert-notify-rm-watch', does it strike you = as odd the way it does (maphash (lambda (key value) (when (equal key some-key) do-something)) some-hashtable) instead of using the hash table directly? Suggested patch to fix this = attached. (For that matter, the documentation doesn't say what mutation is = permitted inside `maphash'. I can guess from the source.) 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. --Apple-Mail=_47038F3F-750D-4BBF-9AC4-FD5DA7BA4BAB Content-Disposition: attachment; filename=0001-autorevert.el-auto-revert-notify-rm-watch-Simplify.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-autorevert.el-auto-revert-notify-rm-watch-Simplify.patch" Content-Transfer-Encoding: quoted-printable =46rom=2000733fac960526e25e5f7e5d68be48d042d28315=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Tue,=2016=20Apr=202019=2015:13:57=20+0200=0A= Subject:=20[PATCH]=20*=20autorevert.el=20(auto-revert-notify-rm-watch):=20= Simplify.=0A=0A---=0A=20lisp/autorevert.el=20|=2024=20= +++++++++++-------------=0A=201=20file=20changed,=2011=20insertions(+),=20= 13=20deletions(-)=0A=0Adiff=20--git=20a/lisp/autorevert.el=20= b/lisp/autorevert.el=0Aindex=201dc2f0eafd..cf9dc53f85=20100644=0A---=20= a/lisp/autorevert.el=0A+++=20b/lisp/autorevert.el=0A@@=20-501,19=20= +501,17=20@@=20will=20use=20an=20up-to-date=20value=20of=20= `auto-revert-interval'"=0A=20=20=20"Disable=20file=20notification=20for=20= current=20buffer's=20associated=20file.=0A=20If=20REMOVE-DESCRIPTOR=20is=20= non-nil,=20remove=20the=20corresponding=20notification=0A=20descriptor;=20= otherwise=20assume=20that=20it=20has=20already=20been=20removed."=0A-=20=20= (when=20auto-revert-notify-watch-descriptor=0A-=20=20=20=20(maphash=0A-=20= =20=20=20=20(lambda=20(key=20value)=0A-=20=20=20=20=20=20=20(when=20= (equal=20key=20auto-revert-notify-watch-descriptor)=0A-=09=20(setq=20= value=20(delete=20(current-buffer)=20value))=0A-=09=20(if=20value=0A-=09=20= =20=20=20=20(puthash=20key=20value=20= auto-revert-notify-watch-descriptor-hash-list)=0A-=09=20=20=20(remhash=20= key=20auto-revert-notify-watch-descriptor-hash-list)=0A-=20=20=20=20=20=20= =20=20=20=20=20(when=20remove-descriptor=0A-=09=20=20=20=20=20= (ignore-errors=0A-=09=20=20=20=20=20=20=20(file-notify-rm-watch=20= auto-revert-notify-watch-descriptor))))))=0A-=20=20=20=20=20= auto-revert-notify-watch-descriptor-hash-list)=0A-=20=20=20=20= (remove-hook=20'kill-buffer-hook=20= #'auto-revert-notify-rm-watch-callback=20t))=0A+=20=20(let=20((desc=20= auto-revert-notify-watch-descriptor)=0A+=20=20=20=20=20=20=20=20(table=20= auto-revert-notify-watch-descriptor-hash-list))=0A+=20=20=20=20(when=20= desc=0A+=20=20=20=20=20=20(let=20((buffers=20(delq=20(current-buffer)=20= (gethash=20desc=20table))))=0A+=20=20=20=20=20=20=20=20(if=20buffers=0A+=20= =20=20=20=20=20=20=20=20=20=20=20(puthash=20desc=20buffers=20table)=0A+=20= =20=20=20=20=20=20=20=20=20(remhash=20desc=20table)))=0A+=20=20=20=20=20=20= (when=20remove-descriptor=0A+=09(ignore-errors=0A+=09=20=20= (file-notify-rm-watch=20desc)))=0A+=20=20=20=20=20=20(remove-hook=20= 'kill-buffer-hook=20#'auto-revert-notify-rm-watch-callback=20t)))=0A=20=20= =20(setq=20auto-revert-notify-watch-descriptor=20nil=0A=20=09= auto-revert-notify-modified-p=20nil))=0A=20=0A--=20=0A2.20.1=20(Apple=20= Git-117)=0A=0A= --Apple-Mail=_47038F3F-750D-4BBF-9AC4-FD5DA7BA4BAB--