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 14:09:25 -0700 Message-ID: <878qz5oquy.fsf@ushin.org> References: <87o785pq6j.fsf@ushin.org> <87bk42mjb0.fsf@posteo.net> <87r0cynjr5.fsf@ushin.org> <87cyoikosb.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29735"; 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 Sun Jun 16 07:11:43 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 1sIiB4-0007XK-0e for ged-emacs-devel@m.gmane-mx.org; Sun, 16 Jun 2024 07:11:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sIiAO-0007SO-TF; Sun, 16 Jun 2024 01:11:00 -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 1sIaeU-0004bk-A8 for emacs-devel@gnu.org; Sat, 15 Jun 2024 17:09:34 -0400 Original-Received: from out-187.mta1.migadu.com ([95.215.58.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sIaeS-0005WK-48 for emacs-devel@gnu.org; Sat, 15 Jun 2024 17:09:34 -0400 X-Envelope-To: philipk@posteo.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ushin.org; s=key1; t=1718485769; 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=pmkqQu4m/u35J0np8QgXvkWhX85z7lkaKwrShe0t3Cg=; b=Ne5e3Z0IwxRa0ADHl3qthEk0HRVzjjf7iyXCxANXhUhp3f6U0hORN2D0TnbhnjpmsL195e XjcsgoYBtk2iWkcP3zQOQTEZHg/npZ/3vhfZ+Mrsebo0rXpHH4rbny6r857+sZEBqZ27/A snqIIs7OgzonEJBJJSsUpaiU5pIysg3xQ2aW9SV7AdWniMM3YNFdcqi6mpjp8eye+kRTVO UUKetlDwBeXg9kZC7xDFEkJsBqr5dKXc6dZaW3asX/eoIGanY8xD7ilbunxPD6X+S+2aqh eyDig73H/CWuWdSFWmmhDuzP6vtapceQge9ilmJVb/cAFIl1iSogG3jmt3wQYQ== 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: <87cyoikosb.fsf@posteo.net> (Philip Kaludercic's message of "Sat, 15 Jun 2024 19:07:48 +0000") X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.187; envelope-from=joseph@ushin.org; helo=out-187.mta1.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, RCVD_IN_DNSWL_NONE=-0.0001, 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: Sun, 16 Jun 2024 01:10:58 -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:320173 Archived-At: Philip Kaludercic writes: > 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! I agree, I don't think a new release is necessary. >>>> 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))))))