From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Fix persist-reset Date: Sat, 15 Jun 2024 13:23:15 +0000 Message-ID: <87bk42mjb0.fsf@posteo.net> References: <87o785pq6j.fsf@ushin.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2711"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs Devel Mailing List , Adam Porter To: Joseph Turner Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jun 15 15:23:34 2024 Return-path: Envelope-to: ged-emacs-devel@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 1sITNV-0000Pi-6D for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jun 2024 15:23:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sITNK-0004EC-4N; Sat, 15 Jun 2024 09:23:22 -0400 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 1sITNI-0004AR-TA for emacs-devel@gnu.org; Sat, 15 Jun 2024 09:23:20 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sITNG-00038O-SE for emacs-devel@gnu.org; Sat, 15 Jun 2024 09:23:20 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 4E607240027 for ; Sat, 15 Jun 2024 15:23:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1718457797; bh=i/BLV6KjOR6eYBBNxALaYIqJQs+/Vlsb+KhDSiOD1xs=; h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=GUJ+rmyhsQ9uAH+t7894uQ6+L+CynBXAVKlkBBDR4063zTLEQBYFYBoPALEYiV0T+ wuZBMJ1+Ax/h0cx/o8uOxxKKVyhDA/YJsViYI3ayDl+lOhesu8jZgPB0yiywfN2YFs l5+GMcTEtmgdGpBtx3uqU46fUWIzeRGzYDI8MH5EOQ+SZB3VBcuTYOT8nj16JrNfVO 8Buj0UYMr5wgX5TeGjZlpp0DG4f476zWG1qc4XHaPmZiZlc1dZssUnUPCbzdsaoIGP /IANa3M/s4ZZgfkiEvRYN/vORyOfKnGrXVWNx5aMboT5B7O2FKVA/LkIa9WkvbmLGn TlO/F6/bpp5/Q== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4W1cKJ3v1Bz6tvl; Sat, 15 Jun 2024 15:23:16 +0200 (CEST) In-Reply-To: <87o785pq6j.fsf@ushin.org> (Joseph Turner's message of "Wed, 12 Jun 2024 18:49:40 -0700") OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:320140 Archived-At: Joseph Turner writes: > Previously, persist-reset set the value of SYM to its default without > copying it, which caused subsequent modifications to the value of SYM > to erroneously modify the default value. LGTM, and seeing as you are the maintainer and there is nothing funny going on I'll apply the patches to elpa.git. > Thanks to Adam Porter for helping resolve this issue! > > Joseph > > From 39b1a0a1d1ae25130a270a115ae8241af4ed6d75 Mon Sep 17 00:00:00 2001 > From: Joseph Turner > Date: Wed, 12 Jun 2024 18:45:32 -0700 > Subject: [PATCH 1/2] Copy default when resetting with persist-reset > > Previously, persist-reset set the value of SYM to its default without > copying it, which caused subsequent modifications to the value of SYM > to erroneously modify the default value. > > Co-authored-by: Adam Porter > --- > persist.el | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/persist.el b/persist.el > index 6cc94b4db3..df7f3836c5 100644 > --- a/persist.el > +++ b/persist.el > @@ -122,9 +122,7 @@ (defun persist-symbol (symbol &optional initvalue) > (let ((initvalue (or initvalue (symbol-value symbol)))) > (add-to-list 'persist--symbols symbol) > (put symbol 'persist t) > - (if (hash-table-p initvalue) > - (put symbol 'persist-default (copy-hash-table initvalue)) > - (put symbol 'persist-default (persist-copy-tree initvalue t))))) > + (put symbol 'persist-default (persist-copy initvalue)))) > > (defun persist--persistant-p (symbol) > "Return non-nil if SYMBOL is a persistent variable." > @@ -164,8 +162,8 @@ (defun persist-default (symbol) > (get symbol 'persist-default)) > > (defun persist-reset (symbol) > - "Reset the value of SYMBOL to the default." > - (set symbol (persist-default symbol))) > + "Set the value of SYMBOL to a copy of the default." > + (set symbol (persist-copy (persist-default symbol)))) > > (defun persist-load (symbol) > "Load the saved value of SYMBOL." > @@ -241,5 +239,11 @@ (defun persist-copy-tree (tree &optional vectors-and-records) > tree) > tree))) > > +(defun persist-copy (obj) > + "Return copy of OBJ." > + (if (hash-table-p obj) > + (copy-hash-table obj) > + (persist-copy-tree obj t))) > + > (provide 'persist) > ;;; persist.el ends here > -- > 2.41.0 > > > From 9423ecd164e5eb94bb91fbacfa2e3c821bdb2972 Mon Sep 17 00:00:00 2001 > From: Joseph Turner > Date: Wed, 12 Jun 2024 18:45:36 -0700 > Subject: [PATCH 2/2] Test persist-reset > > --- > test/persist-tests.el | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/test/persist-tests.el b/test/persist-tests.el > index 62d8501493..d571325fae 100644 > --- a/test/persist-tests.el > +++ b/test/persist-tests.el > @@ -134,3 +134,13 @@ (ert-deftest test-persist-location () > (should-error > (persist-save 'fred))) > (delete-directory "./persist-defined-location" t))) > + > +(ert-deftest test-persist-reset () > + "Symbol should be reset to a copy of the default." > + (with-local-temp-persist > + (persist-defvar persist--test-reset-variable (make-hash-table) "docstring") > + (should-not (eq persist--test-reset-variable > + (persist-default 'persist--test-reset-variable))) > + (persist-reset 'persist--test-reset-variable) > + (should-not (eq persist--test-reset-variable > + (persist-default 'persist--test-reset-variable))))) -- Philip Kaludercic on peregrine