From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Fix persist-reset Date: Sat, 15 Jun 2024 11:28:14 -0700 Message-ID: <87r0cynjr5.fsf@ushin.org> References: <87o785pq6j.fsf@ushin.org> <87bk42mjb0.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13104"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs Devel Mailing List , Adam Porter To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jun 15 20:56:55 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 1sIYa6-0003Cj-GN for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jun 2024 20:56:55 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sIYZd-0001QE-UR; Sat, 15 Jun 2024 14:56:25 -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 1sIY8X-0008RZ-1X for emacs-devel@gnu.org; Sat, 15 Jun 2024 14:28:25 -0400 Original-Received: from out-178.mta0.migadu.com ([91.218.175.178]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sIY8U-00026Z-AV for emacs-devel@gnu.org; Sat, 15 Jun 2024 14:28:24 -0400 X-Envelope-To: philipk@posteo.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ushin.org; s=key1; t=1718476099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1S4mbvCKQHRu2Wz+v8u7opi92ppklnVVVKoKIaxha30=; b=V39f0T698IdjhvIE3DxQnj+SMY/mQpQEX1kyv8PDGvU1tllSt7ca3s2NrVp3KzbVKk6gun K/I6cLZOtwA+M1Rgk1vCNLfyd49/I30jEsjhBjhy6v+18UVnN62+DKR7dq3NP8AGL4cs0P xuD+KuxR+q/SdIVWLUnWTnc3rcsDbxAf5oc8LjWYv41Wb4u1mycB6Ao2AC6Ba+mHFGF1Qn Yjc+okDiPkiORcwuOlMppC4SYT75iU/e/QATsB4U3aIUbWg/m1VfpcSwJuDxqPHSOuoVUu 7NOzN0PP8eutKouLLWvNe/aqO2w31wYkRijessUHyvJgFWzstQzctA9tbPrZ1w== X-Envelope-To: emacs-devel@gnu.org X-Envelope-To: adam@alphapapa.net X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-Reply-To: <87bk42mjb0.fsf@posteo.net> (Philip Kaludercic's message of "Sat, 15 Jun 2024 13:23:15 +0000") X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.178; envelope-from=joseph@ushin.org; helo=out-178.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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-Mailman-Approved-At: Sat, 15 Jun 2024 14:56:24 -0400 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:320165 Archived-At: --=-=-= Content-Type: text/plain 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. >> 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))))) --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Also-test-that-persist-reset-does-not-reset-to-initi.patch >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)))))) -- 2.41.0 --=-=-=--