From 5f01af6c8e0f7355f7a99a80ff32369071f65eda Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Mon, 27 May 2019 19:05:56 -0400 Subject: 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. --- lisp/emacs-lisp/eieio-core.el | 11 +++++++---- lisp/emacs-lisp/eieio.el | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lisp/emacs-lisp') 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: (defsubst eieio--object-class-tag (obj) (aref obj 0)) -(defsubst eieio--object-class (obj) - (eieio--object-class-tag obj)) - ;;; Important macros used internally in eieio. @@ -132,6 +129,12 @@ Currently under control of this var: (or (cl--find-class class) class) class)) +(defsubst eieio--object-class (obj) + (let ((tag (eieio--object-class-tag obj))) + (if eieio-backward-compatibility + (eieio--class-object tag) + tag))) + (defun class-p (x) "Return non-nil if X is a valid class vector. X can also be is a symbol." @@ -163,7 +166,7 @@ Return nil if that option doesn't exist." (defun eieio-object-p (obj) "Return non-nil if OBJ is an EIEIO object." (and (recordp obj) - (eieio--class-p (eieio--object-class-tag obj)))) + (eieio--class-p (eieio--object-class obj)))) (define-obsolete-function-alias 'object-p 'eieio-object-p "25.1") 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." ;; Call the initialize method on the new object with the slots ;; that were passed down to us. (initialize-instance new-object slots) + (when eieio-backward-compatibility + ;; Use symbol as type descriptor, for backwards compatibility. + (aset new-object 0 class)) ;; Return the created object. new-object)) -- cgit v1.2.3 From 134edc10367a8434167656e631865c85b5f10c42 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Mon, 27 May 2019 20:36:41 -0400 Subject: Warn about wrong number of args for subrs (Bug#35767) * lisp/emacs-lisp/bytecomp.el (byte-compile-callargs-warn): Don't assume byte-compile-fdefinition will return non-nil. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-warn-wrong-args) (bytecomp-warn-wrong-args-subr): New tests. --- lisp/emacs-lisp/bytecomp.el | 2 +- test/lisp/emacs-lisp/bytecomp-tests.el | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 9ea4179b68d..72e81a653c7 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1379,7 +1379,7 @@ when printing the error message." (defun byte-compile-callargs-warn (form) (let* ((def (or (byte-compile-fdefinition (car form) nil) (byte-compile-fdefinition (car form) t))) - (sig (byte-compile--function-signature def)) + (sig (byte-compile--function-signature (or def (car form)))) (ncall (length (cdr form)))) ;; Check many or unevalled from subr-arity. (if (and (cdr-safe sig) diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index bc28c5a6a00..c399f65b402 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -438,6 +438,20 @@ Subtests signal errors if something goes wrong." ;; Should not warn that mt--test2 is not known to be defined. (should-not (re-search-forward "my--test2" nil t)))) +(ert-deftest bytecomp-warn-wrong-args () + (with-current-buffer (get-buffer-create "*Compile-Log*") + (let ((inhibit-read-only t)) (erase-buffer)) + (byte-compile '(remq 1 2 3)) + (ert-info ((buffer-string) :prefix "buffer: ") + (should (re-search-forward "remq.*3.*2"))))) + +(ert-deftest bytecomp-warn-wrong-args-subr () + (with-current-buffer (get-buffer-create "*Compile-Log*") + (let ((inhibit-read-only t)) (erase-buffer)) + (byte-compile '(safe-length 1 2 3)) + (ert-info ((buffer-string) :prefix "buffer: ") + (should (re-search-forward "safe-length.*3.*1"))))) + (ert-deftest test-eager-load-macro-expansion () (test-byte-comp-compile-and-load nil '(progn (defmacro abc (arg) 1) (defun def () (abc 2)))) -- cgit v1.2.3