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 19:07:48 +0000 Message-ID: <87cyoikosb.fsf@posteo.net> References: <87o785pq6j.fsf@ushin.org> <87bk42mjb0.fsf@posteo.net> <87r0cynjr5.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="35829"; 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 21:08:41 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 1sIYlV-000983-E2 for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jun 2024 21:08:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sIYkn-0007lZ-3a; Sat, 15 Jun 2024 15:07:57 -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 1sIYkl-0007lF-VL for emacs-devel@gnu.org; Sat, 15 Jun 2024 15:07:56 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sIYkj-0000l4-Eo for emacs-devel@gnu.org; Sat, 15 Jun 2024 15:07:55 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 32E78240101 for ; Sat, 15 Jun 2024 21:07:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1718478470; bh=Fr30T82SDfHc3bLquLu7H1+qk5CES2HMCElDjR2Zz6Y=; h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=ZlGACc6D/Wh0hU/old2BfwjvEEwjqmO6jGphrma40pEtIq7Yhs+SzsbsJZu5uiH8X 1TBx4crKE4V1Vp62MMnD/dlNDicpqghUCqjePLWiAqmHhz7HT7CnAVBnVJxylHolBP wTP7dWTFcqXaA08zbrbwlb1x8hAGFUa6y7/FgiS12VQ94YTnkesUVsUSEz6Yz14HB2 royFtHhAdfE0vnJXPpqhXu1DLvXHj1Qobr9t/qzN3giUpkTYGBnKWeoyBHxMAmBCXD DPvWoSXWXKvddbSsQJVDSrbFD+PKbdEEPdwWGlGnEM+Jkzz9YNaitnB8mnyqABpxcD 7ZIy6sxZL/Tkg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4W1lyr6nFzz6tvb; Sat, 15 Jun 2024 21:07:48 +0200 (CEST) In-Reply-To: <87r0cynjr5.fsf@ushin.org> (Joseph Turner's message of "Sat, 15 Jun 2024 11:28:14 -0700") OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.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:320167 Archived-At: Joseph Turner writes: > Philip Kaludercic writes: > >> 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! Would you please apply the second patchset with the improved > tests? I have rebased and created new patches, attached. OK done, but this doesn't warrant a new release, right? I bumped the version tag earlier, as my understanding was that the bug you fixed was functional. >>> 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))))) > > From 4b5c7687bf72af7f253f8b38a175f8e2c5f18cd3 Mon Sep 17 00:00:00 2001 > From: Joseph Turner > Date: Sat, 15 Jun 2024 11:26:49 -0700 > Subject: [PATCH] Also test that persist-reset does not reset to initial value > > --- > test/persist-tests.el | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/test/persist-tests.el b/test/persist-tests.el > index d571325fae..4439fa3e07 100644 > --- a/test/persist-tests.el > +++ b/test/persist-tests.el > @@ -137,10 +137,17 @@ (ert-deftest test-persist-location () > > (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))))) > + (let ((initial-value (make-hash-table))) > + (with-local-temp-persist > + (persist-defvar persist--test-reset-variable initial-value "docstring") > + (should-not (eq persist--test-reset-variable > + (persist-default 'persist--test-reset-variable))) > + (should-not (eq persist--test-reset-variable initial-value)) > + (should-not (eq initial-value > + (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))) > + (should-not (eq persist--test-reset-variable initial-value)) > + (should-not (eq initial-value > + (persist-default 'persist--test-reset-variable)))))) -- Philip Kaludercic on peregrine