GNU bug report logs - #75188
persist.el should recursively copy hash tables

Previous Next

Package: emacs;

Reported by: Joseph Turner <joseph <at> breatheoutbreathe.in>

Date: Mon, 30 Dec 2024 09:06:02 UTC

Severity: normal

Tags: patch

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Joseph Turner <joseph <at> breatheoutbreathe.in>
To: bug-gnu-emacs <at> gnu.org
Subject: persist.el should recursively copy hash tables
Date: Mon, 30 Dec 2024 01:05:30 -0800
[Message part 1 (text/plain, inline)]
Hello!

This patch demonstrates a bug in persist.el, which may be the cause of
https://github.com/alphapapa/activities.el/issues/109 and a similar bug
in hyperdrive.el which causes the `persist' variable file to be deleted.
We have not yet found a way to reproduce the bug in either activities.el
or hyperdrive.el, so this `persist' bug may be unrelated.

[0001-Test-that-persist-copy-recursively-copies-hash-table.patch (text/x-diff, inline)]
From c28644c957d9fabf883990ff145cec19ed12ff10 Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph <at> breatheoutbreathe.in>
Date: Mon, 30 Dec 2024 00:40:33 -0800
Subject: [PATCH] Test that persist-copy recursively copies hash tables

---
 test/persist-tests.el | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/test/persist-tests.el b/test/persist-tests.el
index 6bf2ed3708..adf37a5bf0 100644
--- a/test/persist-tests.el
+++ b/test/persist-tests.el
@@ -151,3 +151,14 @@ (ert-deftest test-persist-reset ()
      (should-not (eq persist--test-reset-variable initial-value))
      (should-not (eq initial-value
                      (persist-default 'persist--test-reset-variable))))))
+
+(ert-deftest test-persist-copy-hash-table ()
+  "`persist-copy' should copy hash keys and values."
+  (let* ((hash (make-hash-table))
+         (rec (record 'a))
+         (_ (puthash 'foo rec hash))
+         (copy-hash (persist-copy hash)))
+    (setf (aref (gethash 'foo copy-hash) 0) 'b)
+    (should-not (persist-equal hash copy-hash))
+    (should-not (eq (gethash 'foo hash)
+                    (gethash 'foo copy-hash)))))
-- 
2.46.0

[Message part 3 (text/plain, inline)]
IIUC, the solution requires rewriting `persist-copy-tree' (which is
copied from Emacs 30's `copy-tree') so that it handles hash tables.  If
you all agree, I can do this in `persist.el`.

However, would it make sense for `copy-tree' to handle hash tables?

Forgive me if this has been discussed and settled before.  I did find
this thread about comparing hash tables with `equal':

https://yhetil.org/emacs-devel/871qvz4kdw.fsf <at> localhost/

Thank you!

Joseph

This bug report was last modified 177 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.