diff options
| author | Eric Abrahamsen | 2017-12-05 14:41:50 -0800 |
|---|---|---|
| committer | Eric Abrahamsen | 2017-12-09 08:55:58 -0800 |
| commit | e1cc2037a9183bab9440b7b981a233c95d896aac (patch) | |
| tree | b7b5345cdbfdaa1df6bfb6fbdd031cc8d278a4c2 | |
| parent | cda219c3df688cb54b20bf8d061dac56b8f754be (diff) | |
| download | emacs-e1cc2037a9183bab9440b7b981a233c95d896aac.tar.gz emacs-e1cc2037a9183bab9440b7b981a233c95d896aac.zip | |
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.
| -rw-r--r-- | lisp/emacs-lisp/eieio-base.el | 20 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 19 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index f11056faecc..a07e1f13acf 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." | |||
| 354 | proposed-value)) | 354 | proposed-value)) |
| 355 | (t | 355 | (t |
| 356 | proposed-value)))) | 356 | proposed-value)))) |
| 357 | ;; For hash-tables and vectors, the top-level `read' will not | ||
| 358 | ;; "look inside" member values, so we need to do that | ||
| 359 | ;; explicitly. | ||
| 360 | ((hash-table-p proposed-value) | ||
| 361 | (maphash | ||
| 362 | (lambda (key value) | ||
| 363 | (when (class-p (car-safe value)) | ||
| 364 | (setf (gethash key proposed-value) | ||
| 365 | (eieio-persistent-convert-list-to-object | ||
| 366 | value)))) | ||
| 367 | proposed-value) | ||
| 368 | proposed-value) | ||
| 369 | |||
| 370 | ((vectorp proposed-value) | ||
| 371 | (dotimes (i (length proposed-value)) | ||
| 372 | (when (class-p (car-safe (aref proposed-value i))) | ||
| 373 | (aset proposed-value i | ||
| 374 | (eieio-persistent-convert-list-to-object | ||
| 375 | (aref proposed-value i))))) | ||
| 376 | proposed-value) | ||
| 357 | 377 | ||
| 358 | ((stringp proposed-value) | 378 | ((stringp proposed-value) |
| 359 | ;; Else, check for strings, remove properties. | 379 | ;; Else, check for strings, remove properties. |
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 75f1097acf1..c73b7a8c3f1 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -913,6 +913,25 @@ this object." | |||
| 913 | (object-write thing)) | 913 | (object-write thing)) |
| 914 | ((consp thing) | 914 | ((consp thing) |
| 915 | (eieio-list-prin1 thing)) | 915 | (eieio-list-prin1 thing)) |
| 916 | ((hash-table-p thing) | ||
| 917 | (let ((copy (copy-hash-table thing))) | ||
| 918 | (maphash | ||
| 919 | (lambda (key val) | ||
| 920 | (setf (gethash key copy) | ||
| 921 | (read | ||
| 922 | (with-output-to-string | ||
| 923 | (eieio-override-prin1 val))))) | ||
| 924 | copy) | ||
| 925 | (prin1 copy))) | ||
| 926 | ((vectorp thing) | ||
| 927 | (let ((copy (copy-sequence thing))) | ||
| 928 | (dotimes (i (length copy)) | ||
| 929 | (aset copy i | ||
| 930 | (read | ||
| 931 | (with-output-to-string | ||
| 932 | (eieio-override-prin1 | ||
| 933 | (aref copy i)))))) | ||
| 934 | (prin1 copy))) | ||
| 916 | ((eieio--class-p thing) | 935 | ((eieio--class-p thing) |
| 917 | (princ (eieio--class-print-name thing))) | 936 | (princ (eieio--class-print-name thing))) |
| 918 | (t (prin1 thing)))) | 937 | (t (prin1 thing)))) |