unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#75188: persist.el should recursively copy hash tables
@ 2024-12-30  9:05 Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-12-31 22:12 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-30  9:05 UTC (permalink / raw)
  To: 75188; +Cc: Adam Porter

[-- 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#75188: persist.el should recursively copy hash tables
  2024-12-30  9:05 bug#75188: persist.el should recursively copy hash tables Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-12-31 22:12 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-31 22:12 UTC (permalink / raw)
  To: 75188
  Cc: Ihor Radchenko, Daniel Mendler, Stefan Monnier, Adam Porter,
	Eli Zaretskii, phillip.lord

> Hello!
>
> This patch demonstrates a bug in persist.el

[...]

This issue also relates to the bug#63513, in which the suggestion was
made to replace persist-copy-tree with (compat-call copy-tree) now that
Compat 30 is available:

https://yhetil.org/emacs-bugs/80479897-500e-fe60-6586-0a44ccb5993b@daniel-mendler.de/





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-31 22:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-30  9:05 bug#75188: persist.el should recursively copy hash tables Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-31 22:12 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors

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).