From 40ad1ff327616721ce060ea774631b54e3ba26ca Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Tue, 19 Dec 2017 14:56:13 -0800 Subject: Handle possible classtype values in eieio-persistent-read * lisp/emacs-lisp/eieio-base.el (eieio-persistent-validate/fix-slot-value): The function `eieio-persistent-slot-type-is-class-p' could return either a single class, or a list of classes. --- lisp/emacs-lisp/eieio-base.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index f0fed17b7da..af240794e38 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el @@ -349,7 +349,7 @@ Second, any text properties will be stripped from strings." (seq-some (lambda (elt) (child-of-class-p (car proposed-value) elt)) - classtype)) + (if (listp classtype) classtype (list classtype)))) (eieio-persistent-convert-list-to-object proposed-value)) (t -- cgit v1.2.3 From f0cf4dc62918a5acd2c6bbade78909cfa73ca9c8 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Thu, 28 Dec 2017 18:14:47 -0800 Subject: Let eieio-persistent-read read what object-write has written * lisp/emacs-lisp/eieio-base.el (eieio-persistent-validate/fix-slot-value): `object-write' may quote lists inside hash tables and vectors, so unquote those lists here. This patch allows the eieio-persistent write/restore process to perform a clean round trip. It only handles a very specific and limited range of object structures, but at least the write and read procedures match. --- lisp/emacs-lisp/eieio-base.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index af240794e38..5ff8574d9a9 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el @@ -360,19 +360,28 @@ Second, any text properties will be stripped from strings." ((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)))) + (cond ((class-p (car-safe value)) + (setf (gethash key proposed-value) + (eieio-persistent-convert-list-to-object + value))) + ((and (consp value) + (eq (car value) 'quote)) + (setf (gethash key proposed-value) + (cadr 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))))) + (let ((val (aref proposed-value i))) + (cond ((class-p (car-safe val)) + (aset proposed-value i + (eieio-persistent-convert-list-to-object + (aref proposed-value i)))) + ((and (consp val) + (eq (car val) 'quote)) + (aset proposed-value i + (cadr val)))))) proposed-value) ((stringp proposed-value) -- cgit v1.2.3 From daa9e853bd6de90e0fc0b13e30eb261c5a45774e Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sat, 10 Mar 2018 16:26:38 +0800 Subject: Improve warning and error messages * lisp/emacs-lisp/eieio-base.el (eieio-persistent-read, (eieio-persistent-validate/fix-slot-value): Indicate exactly what went wrong. --- lisp/emacs-lisp/eieio-base.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index 5ff8574d9a9..cba6cab1d4f 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el @@ -219,7 +219,7 @@ for CLASS. Optional ALLOW-SUBCLASS says that it is ok for `eieio-persistent-read' to load in subclasses of class instead of being pedantic." (unless class - (message "Unsafe call to `eieio-persistent-read'.")) + (warn "`eieio-persistent-read' called without specifying a class")) (when class (cl-check-type class class)) (let ((ret nil) (buffstr nil)) @@ -234,13 +234,16 @@ being pedantic." ;; the current buffer will work. (setq ret (read buffstr)) (when (not (child-of-class-p (car ret) 'eieio-persistent)) - (error "Corrupt object on disk: Unknown saved object")) + (error + "Invalid object: %s is not a subclass of `eieio-persistent'" + (car ret))) (when (and class - (not (or (eq (car ret) class ) ; same class - (and allow-subclass - (child-of-class-p (car ret) class)) ; subclasses - ))) - (error "Corrupt object on disk: Invalid saved class")) + (not (or (eq (car ret) class) ; same class + (and allow-subclass ; subclass + (child-of-class-p (car ret) class))))) + (error + "Invalid object: %s is not an object of class %s nor a subclass" + (car ret) class)) (setq ret (eieio-persistent-convert-list-to-object ret)) (oset ret file filename)) (kill-buffer " *tmp eieio read*")) @@ -332,7 +335,8 @@ Second, any text properties will be stripped from strings." ;; We have a predicate, but it doesn't satisfy the predicate? (dolist (PV (cdr proposed-value)) (unless (child-of-class-p (car PV) (car classtype)) - (error "Corrupt object on disk"))) + (error "Invalid object: slot member %s does not match class %s" + (car PV) (car classtype)))) ;; We have a list of objects here. Lets load them ;; in. -- cgit v1.2.3