From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63513: [PATCH] Make persist-defvar work with records and hash tables Date: Sun, 14 May 2023 22:56:20 -0700 Message-ID: <87wn1axgh6.fsf@breatheoutbreathe.in> Reply-To: Joseph Turner 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="24955"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Adam Porter To: 63513@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 15 08:22:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1pyRbD-0006H0-Pr for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 May 2023 08:22:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyRb3-0002bf-SX; Mon, 15 May 2023 02:22:14 -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 1pyRas-0002aY-R9 for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 02:22:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pyRas-0001b3-Jj for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 02:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pyRas-00017Z-Ei for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 02:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 May 2023 06:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63513 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16841316814247 (code B ref -1); Mon, 15 May 2023 06:22:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 May 2023 06:21:21 +0000 Original-Received: from localhost ([127.0.0.1]:42580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pyRaC-00016Q-UE for submit@debbugs.gnu.org; Mon, 15 May 2023 02:21:21 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:47924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pyRaB-00016I-Bz for submit@debbugs.gnu.org; Mon, 15 May 2023 02:21:19 -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 1pyRaB-0002Wt-4l for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 02:21:19 -0400 Original-Received: from out-61.mta0.migadu.com ([2001:41d0:1004:224b::3d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyRa8-0001T7-AP for bug-gnu-emacs@gnu.org; Mon, 15 May 2023 02:21:18 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1684131673; 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; bh=/J+Wuhx9Z07WLBqIvRsD91bExLO9ACZRI2vfr7W7GA4=; b=MUqWPHoNx8/jzosYXYwKG5P/tUNebiotXbp8+jF4surQVXmPMRyDE94NFLPlEZLhtXMow1 geLCx55M9fjQvTH65bTnL3evvLnSho2e2twUfrAzKgf0SHRYho65p3iPdPlc4SdOA5I5Yz o3/d8kR6bLIkyJ6Ymg+o2E78lp/o6xE= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:1004:224b::3d; envelope-from=joseph@breatheoutbreathe.in; helo=out-61.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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261730 Archived-At: --=-=-= Content-Type: text/plain Hello! persist-defvar does not persist records or hash tables correctly. Here's a minimal example with a hash table: (progn (persist-defvar foo (make-hash-table :test #'equal) "docstring") (puthash 'bar t foo) (persist-save 'foo) (gethash 'bar (persist-default 'foo))) ;; Expected nil, got t This patch fixes persisting records by using copy-tree. Currently, copy-tree does not work with records (see ). The following snippet will return the expected value only when both this patch and the above-linked patch are applied: (progn (cl-defstruct baz a) (persist-defvar quux (make-baz :a nil) "docstring") (setf (baz-a quux) t) (persist-save 'quux) (baz-a (persist-default 'quux))) ;; Expected nil, got t Before applying this patch, the updated values in both cases are not persisted to disk. With the patch, the updated values are persisted as expected. Best, Joseph --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-persist-defvar-work-with-records-and-hash-table.patch >From b1512983fb82b9800ab6d0d1c9ca359e1251e94a Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sun, 14 May 2023 22:32:16 -0700 Subject: [PATCH] Make persist-defvar work with records and hash tables Previously, when persist-defvar received a record or hash table for an initial value, updated values were not persisted. This was because the value and default value shared the same structure. --- persist.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/persist.el b/persist.el index d80943d19e..a40fc2b297 100644 --- a/persist.el +++ b/persist.el @@ -118,7 +118,9 @@ (defun persist-symbol (symbol &optional initvalue) (let ((initvalue (or initvalue (symbol-value symbol)))) (add-to-list 'persist--symbols symbol) (put symbol 'persist t) - (put symbol 'persist-default initvalue))) + (if (eq 'hash-table (type-of initvalue)) + (put symbol 'persist-default (copy-hash-table initvalue)) + (put symbol 'persist-default (copy-tree initvalue t))))) (defun persist--persistant-p (symbol) "Return non-nil if SYMBOL is a persistant variable." -- 2.40.1 --=-=-=--