diff options
| author | Noam Postavsky | 2019-05-27 19:05:56 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2019-05-30 18:46:07 -0400 |
| commit | 5f01af6c8e0f7355f7a99a80ff32369071f65eda (patch) | |
| tree | f65280a7140425f0db5ad19782c699a0def2bed5 /lisp | |
| parent | 4b24b0185d910d756e85ecdc30f49c414577050e (diff) | |
| download | emacs-5f01af6c8e0f7355f7a99a80ff32369071f65eda.tar.gz emacs-5f01af6c8e0f7355f7a99a80ff32369071f65eda.zip | |
Use plain symbols for eieio type descriptors (Bug#29220)
Since Emacs 26, eieio objects use a class record (with circular
references) as the type descriptor of the object record. This causes
problems when reading back an object from a string, because the class
record is not `eq' to the canonical one (which means that read objects
don't satisfy the foo-p predicate).
* lisp/emacs-lisp/eieio.el (make-instance): As a (partial) fix, set
the record's type descriptor to a plain symbol for the type descriptor
when eieio-backward-compatibility is non-nil (the default).
* lisp/emacs-lisp/eieio-core.el (eieio--object-class): Call
eieio--class-object on the type tag when eieio-backward-compatibility
is non-nil.
(eieio-object-p): Use eieio--object-class instead of
eieio--object-class-tag.
* test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
(eieio-test-persist-hash-and-vector)
(eieio-test-persist-interior-lists): Make into functions.
(eieio-persist-hash-and-vector-backward-compatibility)
(eieio-persist-hash-and-vector-no-backward-compatibility)
(eieio-test-persist-interior-lists-backward-compatibility)
(eieio-test-persist-interior-lists-no-backward-compatibility): New
tests which call them, eieio-backward-compatibility let-bound.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/eieio-core.el | 11 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 3 |
2 files changed, 10 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index f879a3999fb..4d55ed6e1d1 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el | |||
| @@ -117,9 +117,6 @@ Currently under control of this var: | |||
| 117 | (defsubst eieio--object-class-tag (obj) | 117 | (defsubst eieio--object-class-tag (obj) |
| 118 | (aref obj 0)) | 118 | (aref obj 0)) |
| 119 | 119 | ||
| 120 | (defsubst eieio--object-class (obj) | ||
| 121 | (eieio--object-class-tag obj)) | ||
| 122 | |||
| 123 | 120 | ||
| 124 | ;;; Important macros used internally in eieio. | 121 | ;;; Important macros used internally in eieio. |
| 125 | 122 | ||
| @@ -132,6 +129,12 @@ Currently under control of this var: | |||
| 132 | (or (cl--find-class class) class) | 129 | (or (cl--find-class class) class) |
| 133 | class)) | 130 | class)) |
| 134 | 131 | ||
| 132 | (defsubst eieio--object-class (obj) | ||
| 133 | (let ((tag (eieio--object-class-tag obj))) | ||
| 134 | (if eieio-backward-compatibility | ||
| 135 | (eieio--class-object tag) | ||
| 136 | tag))) | ||
| 137 | |||
| 135 | (defun class-p (x) | 138 | (defun class-p (x) |
| 136 | "Return non-nil if X is a valid class vector. | 139 | "Return non-nil if X is a valid class vector. |
| 137 | X can also be is a symbol." | 140 | X can also be is a symbol." |
| @@ -163,7 +166,7 @@ Return nil if that option doesn't exist." | |||
| 163 | (defun eieio-object-p (obj) | 166 | (defun eieio-object-p (obj) |
| 164 | "Return non-nil if OBJ is an EIEIO object." | 167 | "Return non-nil if OBJ is an EIEIO object." |
| 165 | (and (recordp obj) | 168 | (and (recordp obj) |
| 166 | (eieio--class-p (eieio--object-class-tag obj)))) | 169 | (eieio--class-p (eieio--object-class obj)))) |
| 167 | 170 | ||
| 168 | (define-obsolete-function-alias 'object-p 'eieio-object-p "25.1") | 171 | (define-obsolete-function-alias 'object-p 'eieio-object-p "25.1") |
| 169 | 172 | ||
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 38436d1f944..864ac2616b9 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -710,6 +710,9 @@ calls `initialize-instance' on that object." | |||
| 710 | ;; Call the initialize method on the new object with the slots | 710 | ;; Call the initialize method on the new object with the slots |
| 711 | ;; that were passed down to us. | 711 | ;; that were passed down to us. |
| 712 | (initialize-instance new-object slots) | 712 | (initialize-instance new-object slots) |
| 713 | (when eieio-backward-compatibility | ||
| 714 | ;; Use symbol as type descriptor, for backwards compatibility. | ||
| 715 | (aset new-object 0 class)) | ||
| 713 | ;; Return the created object. | 716 | ;; Return the created object. |
| 714 | new-object)) | 717 | new-object)) |
| 715 | 718 | ||