unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 75188@debbugs.gnu.org
Cc: Adam Porter <adam@alphapapa.net>
Subject: bug#75188: persist.el should recursively copy hash tables
Date: Mon, 30 Dec 2024 01:05:30 -0800	[thread overview]
Message-ID: <87wmfhk0bp.fsf@breatheoutbreathe.in> (raw)

[-- Attachment #1: Type: text/plain, Size: 356 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Test-that-persist-copy-recursively-copies-hash-table.patch --]
[-- Type: text/x-diff, Size: 1142 bytes --]

From c28644c957d9fabf883990ff145cec19ed12ff10 Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@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


[-- Attachment #3: Type: text/plain, Size: 459 bytes --]


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@localhost/

Thank you!

Joseph

             reply	other threads:[~2024-12-30  9:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-30  9:05 Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-12-31 22:12 ` bug#75188: persist.el should recursively copy hash tables Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wmfhk0bp.fsf@breatheoutbreathe.in \
    --to=bug-gnu-emacs@gnu.org \
    --cc=75188@debbugs.gnu.org \
    --cc=adam@alphapapa.net \
    --cc=joseph@breatheoutbreathe.in \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).