emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 e1cc203: Handle hash tables and vectors when read


From: Eric Abrahamsen
Subject: [Emacs-diffs] emacs-26 e1cc203: Handle hash tables and vectors when reading/writing EIEIO objects
Date: Sat, 9 Dec 2017 11:57:58 -0500 (EST)

branch: emacs-26
commit e1cc2037a9183bab9440b7b981a233c95d896aac
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Handle hash tables and vectors when reading/writing EIEIO objects
    
    * lisp/emacs-lisp/eieio.el (eieio-override-prin1): EIEIO objects
      printed with `prin1' can no longer be read with `read'. Make sure
      they are printed with object-write instead, even when they're inside
      hash tables and vectors.
    * lisp/emacs-lisp/eieio-base.el (eieio-persistent-validate/fix-slot-value):
      Check for written representations of objects inside hash tables and
      vectors, and reconstruct them.
---
 lisp/emacs-lisp/eieio-base.el | 20 ++++++++++++++++++++
 lisp/emacs-lisp/eieio.el      | 19 +++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index f11056f..a07e1f1 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -354,6 +354,26 @@ Second, any text properties will be stripped from strings."
                   proposed-value))
                 (t
                  proposed-value))))
+        ;; For hash-tables and vectors, the top-level `read' will not
+        ;; "look inside" member values, so we need to do that
+        ;; explicitly.
+        ((hash-table-p proposed-value)
+         (maphash
+          (lambda (key value)
+            (when (class-p (car-safe value))
+              (setf (gethash key proposed-value)
+                    (eieio-persistent-convert-list-to-object
+                     value))))
+          proposed-value)
+         proposed-value)
+
+        ((vectorp proposed-value)
+         (dotimes (i (length proposed-value))
+           (when (class-p (car-safe (aref proposed-value i)))
+             (aset proposed-value i
+                   (eieio-persistent-convert-list-to-object
+                    (aref proposed-value i)))))
+         proposed-value)
 
         ((stringp proposed-value)
          ;; Else, check for strings, remove properties.
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 75f1097..c73b7a8 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -913,6 +913,25 @@ this object."
         (object-write thing))
        ((consp thing)
         (eieio-list-prin1 thing))
+       ((hash-table-p thing)
+         (let ((copy (copy-hash-table thing)))
+          (maphash
+           (lambda (key val)
+             (setf (gethash key copy)
+                   (read
+                    (with-output-to-string
+                      (eieio-override-prin1 val)))))
+           copy)
+          (prin1 copy)))
+       ((vectorp thing)
+         (let ((copy (copy-sequence thing)))
+         (dotimes (i (length copy))
+           (aset copy i
+                 (read
+                  (with-output-to-string
+                    (eieio-override-prin1
+                     (aref copy i))))))
+         (prin1 copy)))
        ((eieio--class-p thing)
         (princ (eieio--class-print-name thing)))
        (t (prin1 thing))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]