diff options
| author | Stefan Monnier | 2014-12-22 22:05:46 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2014-12-22 22:05:46 -0500 |
| commit | ee93d7ad4291a0946efe3197481cfbeff92f29b8 (patch) | |
| tree | 4ff0ca7149c5bead965c4e3e49d104af1cf42e1c | |
| parent | d4a12e7a9a46bbff2f9c4d59ecc284621634a2e8 (diff) | |
| download | emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.tar.gz emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.zip | |
* lisp/emacs-lisp/eieio*.el: Remove "name" field of objects
* lisp/emacs-lisp/eieio-base.el (clone) <eieio-instance-inheritor>:
Use call-next-method.
(eieio-constructor): Rename from `constructor'.
(eieio-persistent-convert-list-to-object): Drop objname.
(eieio-persistent-validate/fix-slot-value): Don't hardcode
eieio--object-num-slots.
(eieio-named): Use a normal slot.
(slot-missing) <eieio-named>: Remove.
(eieio-object-name-string, eieio-object-set-name-string, clone)
<eieio-named>: New methods.
* lisp/emacs-lisp/eieio-core.el (eieio--defalias): Follow aliases.
(eieio--object): Remove `name' field.
(eieio-defclass): Adjust to new convention where constructors don't
take an "object name" any more.
(eieio--defgeneric-init-form, eieio--defmethod): Follow aliases.
(eieio-validate-slot-value, eieio-oset-default)
(eieio-slot-name-index): Don't hardcode eieio--object-num-slots.
(eieio-generic-call-primary-only): Simplify.
* lisp/emacs-lisp/eieio-custom.el (eieio-widget-test): Remove dummy arg.
(eieio-object-value-get): Use eieio-object-set-name-string.
* lisp/emacs-lisp/eieio.el (make-instance): Simplify by not adding an object
name argument.
(eieio-object-name): Use eieio-object-name-string.
(eieio--object-names): New const.
(eieio-object-name-string, eieio-object-set-name-string): Re-implement
using a hashtable rather than a built-in slot.
(eieio-constructor): Rename from `constructor'. Remove `newname' arg.
(clone): Don't mess with the object's "name".
* test/automated/eieio-test-persist.el (persistent-with-objs-slot-subs):
The type FOO-child is the same as FOO.
* test/automated/eieio-tests.el: Remove dummy object names.
| -rw-r--r-- | lisp/ChangeLog | 34 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-base.el | 80 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-core.el | 55 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-custom.el | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 60 | ||||
| -rw-r--r-- | test/automated/eieio-test-methodinvoke.el | 5 | ||||
| -rw-r--r-- | test/automated/eieio-test-persist.el | 2 | ||||
| -rw-r--r-- | test/automated/eieio-tests.el | 62 |
8 files changed, 167 insertions, 135 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 739d442c55b..1a0383814cd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,37 @@ | |||
| 1 | 2014-12-23 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/eieio.el (make-instance): Simplify by not adding an object | ||
| 4 | name argument. | ||
| 5 | (eieio-object-name): Use eieio-object-name-string. | ||
| 6 | (eieio--object-names): New const. | ||
| 7 | (eieio-object-name-string, eieio-object-set-name-string): Re-implement | ||
| 8 | using a hashtable rather than a built-in slot. | ||
| 9 | (eieio-constructor): Rename from `constructor'. Remove `newname' arg. | ||
| 10 | (clone): Don't mess with the object's "name". | ||
| 11 | |||
| 12 | * emacs-lisp/eieio-custom.el (eieio-widget-test): Remove dummy arg. | ||
| 13 | (eieio-object-value-get): Use eieio-object-set-name-string. | ||
| 14 | |||
| 15 | * emacs-lisp/eieio-core.el (eieio--defalias): Follow aliases. | ||
| 16 | (eieio--object): Remove `name' field. | ||
| 17 | (eieio-defclass): Adjust to new convention where constructors don't | ||
| 18 | take an "object name" any more. | ||
| 19 | (eieio--defgeneric-init-form, eieio--defmethod): Follow aliases. | ||
| 20 | (eieio-validate-slot-value, eieio-oset-default) | ||
| 21 | (eieio-slot-name-index): Don't hardcode eieio--object-num-slots. | ||
| 22 | (eieio-generic-call-primary-only): Simplify. | ||
| 23 | |||
| 24 | * emacs-lisp/eieio-base.el (clone) <eieio-instance-inheritor>: | ||
| 25 | Use call-next-method. | ||
| 26 | (eieio-constructor): Rename from `constructor'. | ||
| 27 | (eieio-persistent-convert-list-to-object): Drop objname. | ||
| 28 | (eieio-persistent-validate/fix-slot-value): Don't hardcode | ||
| 29 | eieio--object-num-slots. | ||
| 30 | (eieio-named): Use a normal slot. | ||
| 31 | (slot-missing) <eieio-named>: Remove. | ||
| 32 | (eieio-object-name-string, eieio-object-set-name-string, clone) | ||
| 33 | <eieio-named>: New methods. | ||
| 34 | |||
| 1 | 2014-12-22 Stefan Monnier <monnier@iro.umontreal.ca> | 35 | 2014-12-22 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 36 | ||
| 3 | * emacs-lisp/eieio-core.el (eieio--class-v): Rename from class-v. | 37 | * emacs-lisp/eieio-core.el (eieio--class-v): Rename from class-v. |
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index f2020dfa74d..8a09dac2dff 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el | |||
| @@ -63,25 +63,10 @@ SLOT-NAME is the offending slot. FN is the function signaling the error." | |||
| 63 | ;; Throw the regular signal. | 63 | ;; Throw the regular signal. |
| 64 | (call-next-method))) | 64 | (call-next-method))) |
| 65 | 65 | ||
| 66 | (defmethod clone ((obj eieio-instance-inheritor) &rest params) | 66 | (defmethod clone ((obj eieio-instance-inheritor) &rest _params) |
| 67 | "Clone OBJ, initializing `:parent' to OBJ. | 67 | "Clone OBJ, initializing `:parent' to OBJ. |
| 68 | All slots are unbound, except those initialized with PARAMS." | 68 | All slots are unbound, except those initialized with PARAMS." |
| 69 | (let ((nobj (make-vector (length obj) eieio-unbound)) | 69 | (let ((nobj (call-next-method))) |
| 70 | (nm (eieio--object-name obj)) | ||
| 71 | (passname (and params (stringp (car params)))) | ||
| 72 | (num 1)) | ||
| 73 | (aset nobj 0 'object) | ||
| 74 | (setf (eieio--object-class nobj) (eieio--object-class obj)) | ||
| 75 | ;; The following was copied from the default clone. | ||
| 76 | (if (not passname) | ||
| 77 | (save-match-data | ||
| 78 | (if (string-match "-\\([0-9]+\\)" nm) | ||
| 79 | (setq num (1+ (string-to-number (match-string 1 nm))) | ||
| 80 | nm (substring nm 0 (match-beginning 0)))) | ||
| 81 | (setf (eieio--object-name nobj) (concat nm "-" (int-to-string num)))) | ||
| 82 | (setf (eieio--object-name nobj) (car params))) | ||
| 83 | ;; Now initialize from params. | ||
| 84 | (if params (shared-initialize nobj (if passname (cdr params) params))) | ||
| 85 | (oset nobj parent-instance obj) | 70 | (oset nobj parent-instance obj) |
| 86 | nobj)) | 71 | nobj)) |
| 87 | 72 | ||
| @@ -155,7 +140,7 @@ Multiple calls to `make-instance' will return this object.")) | |||
| 155 | A singleton is a class which will only ever have one instance." | 140 | A singleton is a class which will only ever have one instance." |
| 156 | :abstract t) | 141 | :abstract t) |
| 157 | 142 | ||
| 158 | (defmethod constructor :STATIC ((class eieio-singleton) _name &rest _slots) | 143 | (defmethod eieio-constructor :STATIC ((class eieio-singleton) &rest _slots) |
| 159 | "Constructor for singleton CLASS. | 144 | "Constructor for singleton CLASS. |
| 160 | NAME and SLOTS initialize the new object. | 145 | NAME and SLOTS initialize the new object. |
| 161 | This constructor guarantees that no matter how many you request, | 146 | This constructor guarantees that no matter how many you request, |
| @@ -270,7 +255,7 @@ malicious code. | |||
| 270 | Note: This function recurses when a slot of :type of some object is | 255 | Note: This function recurses when a slot of :type of some object is |
| 271 | identified, and needing more object creation." | 256 | identified, and needing more object creation." |
| 272 | (let ((objclass (nth 0 inputlist)) | 257 | (let ((objclass (nth 0 inputlist)) |
| 273 | (objname (nth 1 inputlist)) | 258 | ;; (objname (nth 1 inputlist)) |
| 274 | (slots (nthcdr 2 inputlist)) | 259 | (slots (nthcdr 2 inputlist)) |
| 275 | (createslots nil)) | 260 | (createslots nil)) |
| 276 | 261 | ||
| @@ -293,7 +278,7 @@ identified, and needing more object creation." | |||
| 293 | 278 | ||
| 294 | (setq slots (cdr (cdr slots)))) | 279 | (setq slots (cdr (cdr slots)))) |
| 295 | 280 | ||
| 296 | (apply 'make-instance objclass objname (nreverse createslots)) | 281 | (apply #'make-instance objclass (nreverse createslots)) |
| 297 | 282 | ||
| 298 | ;;(eval inputlist) | 283 | ;;(eval inputlist) |
| 299 | )) | 284 | )) |
| @@ -308,7 +293,8 @@ Second, any text properties will be stripped from strings." | |||
| 308 | (let ((slot-idx (eieio-slot-name-index class nil slot)) | 293 | (let ((slot-idx (eieio-slot-name-index class nil slot)) |
| 309 | (type nil) | 294 | (type nil) |
| 310 | (classtype nil)) | 295 | (classtype nil)) |
| 311 | (setq slot-idx (- slot-idx 3)) | 296 | (setq slot-idx (- slot-idx |
| 297 | (eval-when-compile eieio--object-num-slots))) | ||
| 312 | (setq type (aref (eieio--class-public-type (eieio--class-v class)) | 298 | (setq type (aref (eieio--class-public-type (eieio--class-v class)) |
| 313 | slot-idx)) | 299 | slot-idx)) |
| 314 | 300 | ||
| @@ -463,34 +449,38 @@ instance." | |||
| 463 | 449 | ||
| 464 | 450 | ||
| 465 | ;;; Named object | 451 | ;;; Named object |
| 466 | ;; | ||
| 467 | ;; Named objects use the objects `name' as a slot, and that slot | ||
| 468 | ;; is accessed with the `object-name' symbol. | ||
| 469 | 452 | ||
| 470 | (defclass eieio-named () | 453 | (defclass eieio-named () |
| 471 | () | 454 | ((object-name :initarg :object-name :initform nil)) |
| 472 | "Object with a name. | 455 | "Object with a name." |
| 473 | Name storage already occurs in an object. This object provides get/set | ||
| 474 | access to it." | ||
| 475 | :abstract t) | 456 | :abstract t) |
| 476 | 457 | ||
| 477 | (defmethod slot-missing ((obj eieio-named) | 458 | (defmethod eieio-object-name-string ((obj eieio-named)) |
| 478 | slot-name operation &optional new-value) | 459 | "Return a string which is OBJ's name." |
| 479 | "Called when a non-existent slot is accessed. | 460 | (or (slot-value obj 'object-name) |
| 480 | For variable `eieio-named', provide an imaginary `object-name' slot. | 461 | (symbol-name (eieio-object-class obj)))) |
| 481 | Argument OBJ is the named object. | 462 | |
| 482 | Argument SLOT-NAME is the slot that was attempted to be accessed. | 463 | (defmethod eieio-object-set-name-string ((obj eieio-named) name) |
| 483 | OPERATION is the type of access, such as `oref' or `oset'. | 464 | "Set the string which is OBJ's NAME." |
| 484 | NEW-VALUE is the value that was being set into SLOT if OPERATION were | 465 | (eieio--check-type stringp name) |
| 485 | a set type." | 466 | (eieio-oset obj 'object-name name)) |
| 486 | (if (memq slot-name '(object-name :object-name)) | 467 | |
| 487 | (cond ((eq operation 'oset) | 468 | (defmethod clone ((obj eieio-named) &rest params) |
| 488 | (if (not (stringp new-value)) | 469 | "Clone OBJ, initializing `:parent' to OBJ. |
| 489 | (signal 'invalid-slot-type | 470 | All slots are unbound, except those initialized with PARAMS." |
| 490 | (list obj slot-name 'string new-value))) | 471 | (let* ((newname (and (stringp (car params)) (pop params))) |
| 491 | (eieio-object-set-name-string obj new-value)) | 472 | (nobj (apply #'call-next-method obj params)) |
| 492 | (t (eieio-object-name-string obj))) | 473 | (nm (slot-value obj 'object-name))) |
| 493 | (call-next-method))) | 474 | (eieio-oset obj 'object-name |
| 475 | (or newname | ||
| 476 | (save-match-data | ||
| 477 | (if (and nm (string-match "-\\([0-9]+\\)" nm)) | ||
| 478 | (let ((num (1+ (string-to-number | ||
| 479 | (match-string 1 nm))))) | ||
| 480 | (concat (substring nm 0 (match-beginning 0)) | ||
| 481 | "-" (int-to-string num))) | ||
| 482 | (concat nm "-1"))))) | ||
| 483 | nobj)) | ||
| 494 | 484 | ||
| 495 | (provide 'eieio-base) | 485 | (provide 'eieio-base) |
| 496 | 486 | ||
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index 1e8d17d2652..299df8db378 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el | |||
| @@ -39,6 +39,9 @@ | |||
| 39 | "Like `defalias', but with less side-effects. | 39 | "Like `defalias', but with less side-effects. |
| 40 | More specifically, it has no side-effects at all when the new function | 40 | More specifically, it has no side-effects at all when the new function |
| 41 | definition is the same (`eq') as the old one." | 41 | definition is the same (`eq') as the old one." |
| 42 | (while (and (fboundp name) (symbolp (symbol-function name))) | ||
| 43 | ;; Follow aliases, so methods applied to obsolete aliases still work. | ||
| 44 | (setq name (symbol-function name))) | ||
| 42 | (unless (and (fboundp name) | 45 | (unless (and (fboundp name) |
| 43 | (eq (symbol-function name) body)) | 46 | (eq (symbol-function name) body)) |
| 44 | (defalias name body))) | 47 | (defalias name body))) |
| @@ -167,8 +170,7 @@ Stored outright without modifications or stripping."))) | |||
| 167 | 170 | ||
| 168 | (eieio--define-field-accessors object | 171 | (eieio--define-field-accessors object |
| 169 | (-unused-0 ;;Constant slot, set to `object'. | 172 | (-unused-0 ;;Constant slot, set to `object'. |
| 170 | (class "class struct defining OBJ") | 173 | (class "class struct defining OBJ"))) |
| 171 | name)) ;FIXME: Get rid of this field! | ||
| 172 | 174 | ||
| 173 | ;; FIXME: The constants below should have an `eieio-' prefix added!! | 175 | ;; FIXME: The constants below should have an `eieio-' prefix added!! |
| 174 | (defconst eieio--method-static 0 "Index into :static tag on a method.") | 176 | (defconst eieio--method-static 0 "Index into :static tag on a method.") |
| @@ -480,10 +482,10 @@ See `defclass' for more information." | |||
| 480 | ;; Create the test function | 482 | ;; Create the test function |
| 481 | (let ((csym (intern (concat (symbol-name cname) "-p")))) | 483 | (let ((csym (intern (concat (symbol-name cname) "-p")))) |
| 482 | (fset csym | 484 | (fset csym |
| 483 | (list 'lambda (list 'obj) | 485 | `(lambda (obj) |
| 484 | (format "Test OBJ to see if it an object of type %s" cname) | 486 | ,(format "Test OBJ to see if it an object of type %s" cname) |
| 485 | (list 'and '(eieio-object-p obj) | 487 | (and (eieio-object-p obj) |
| 486 | (list 'same-class-p 'obj cname))))) | 488 | (same-class-p obj ',cname))))) |
| 487 | 489 | ||
| 488 | ;; Make sure the method invocation order is a valid value. | 490 | ;; Make sure the method invocation order is a valid value. |
| 489 | (let ((io (class-option-assoc options :method-invocation-order))) | 491 | (let ((io (class-option-assoc options :method-invocation-order))) |
| @@ -499,7 +501,7 @@ See `defclass' for more information." | |||
| 499 | "Test OBJ to see if it an object is a child of type %s" | 501 | "Test OBJ to see if it an object is a child of type %s" |
| 500 | cname) | 502 | cname) |
| 501 | (and (eieio-object-p obj) | 503 | (and (eieio-object-p obj) |
| 502 | (object-of-class-p obj ,cname)))) | 504 | (object-of-class-p obj ',cname)))) |
| 503 | 505 | ||
| 504 | ;; When using typep, (typep OBJ 'myclass) returns t for objects which | 506 | ;; When using typep, (typep OBJ 'myclass) returns t for objects which |
| 505 | ;; are subclasses of myclass. For our predicates, however, it is | 507 | ;; are subclasses of myclass. For our predicates, however, it is |
| @@ -722,9 +724,14 @@ See `defclass' for more information." | |||
| 722 | 724 | ||
| 723 | ;; Non-abstract classes need a constructor. | 725 | ;; Non-abstract classes need a constructor. |
| 724 | (fset cname | 726 | (fset cname |
| 725 | `(lambda (newname &rest slots) | 727 | `(lambda (&rest slots) |
| 726 | ,(format "Create a new object with name NAME of class type %s" cname) | 728 | ,(format "Create a new object with name NAME of class type %s" cname) |
| 727 | (apply #'constructor ,cname newname slots))) | 729 | (if (and slots |
| 730 | (let ((x (car slots))) | ||
| 731 | (or (stringp x) (null x)))) | ||
| 732 | (message "Obsolete name %S passed to %S constructor" | ||
| 733 | (pop slots) ',cname)) | ||
| 734 | (apply #'eieio-constructor ',cname slots))) | ||
| 728 | ) | 735 | ) |
| 729 | 736 | ||
| 730 | ;; Set up a specialized doc string. | 737 | ;; Set up a specialized doc string. |
| @@ -761,7 +768,6 @@ See `defclass' for more information." | |||
| 761 | nil))) | 768 | nil))) |
| 762 | (aset cache 0 'object) | 769 | (aset cache 0 'object) |
| 763 | (setf (eieio--object-class cache) cname) | 770 | (setf (eieio--object-class cache) cname) |
| 764 | (setf (eieio--object-name cache) 'default-cache-object) | ||
| 765 | (let ((eieio-skip-typecheck t)) | 771 | (let ((eieio-skip-typecheck t)) |
| 766 | ;; All type-checking has been done to our satisfaction | 772 | ;; All type-checking has been done to our satisfaction |
| 767 | ;; before this call. Don't waste our time in this call.. | 773 | ;; before this call. Don't waste our time in this call.. |
| @@ -1087,6 +1093,10 @@ the new child class." | |||
| 1087 | 1093 | ||
| 1088 | (defun eieio--defgeneric-init-form (method doc-string) | 1094 | (defun eieio--defgeneric-init-form (method doc-string) |
| 1089 | "Form to use for the initial definition of a generic." | 1095 | "Form to use for the initial definition of a generic." |
| 1096 | (while (and (fboundp method) (symbolp (symbol-function method))) | ||
| 1097 | ;; Follow aliases, so methods applied to obsolete aliases still work. | ||
| 1098 | (setq method (symbol-function method))) | ||
| 1099 | |||
| 1090 | (cond | 1100 | (cond |
| 1091 | ((or (not (fboundp method)) | 1101 | ((or (not (fboundp method)) |
| 1092 | (eq 'autoload (car-safe (symbol-function method)))) | 1102 | (eq 'autoload (car-safe (symbol-function method)))) |
| @@ -1198,6 +1208,11 @@ but remove reference to all implementations of METHOD." | |||
| 1198 | ;; Primary key. | 1208 | ;; Primary key. |
| 1199 | ;; (t eieio--method-primary) | 1209 | ;; (t eieio--method-primary) |
| 1200 | (t (error "Unknown method kind %S" kind))))) | 1210 | (t (error "Unknown method kind %S" kind))))) |
| 1211 | |||
| 1212 | (while (and (fboundp method) (symbolp (symbol-function method))) | ||
| 1213 | ;; Follow aliases, so methods applied to obsolete aliases still work. | ||
| 1214 | (setq method (symbol-function method))) | ||
| 1215 | |||
| 1201 | ;; Make sure there is a generic (when called from defclass). | 1216 | ;; Make sure there is a generic (when called from defclass). |
| 1202 | (eieio--defalias | 1217 | (eieio--defalias |
| 1203 | method (eieio--defgeneric-init-form | 1218 | method (eieio--defgeneric-init-form |
| @@ -1253,7 +1268,7 @@ an error." | |||
| 1253 | (if eieio-skip-typecheck | 1268 | (if eieio-skip-typecheck |
| 1254 | nil | 1269 | nil |
| 1255 | ;; Trim off object IDX junk added in for the object index. | 1270 | ;; Trim off object IDX junk added in for the object index. |
| 1256 | (setq slot-idx (- slot-idx 3)) | 1271 | (setq slot-idx (- slot-idx (eval-when-compile eieio--object-num-slots))) |
| 1257 | (let ((st (aref (eieio--class-public-type (eieio--class-v class)) slot-idx))) | 1272 | (let ((st (aref (eieio--class-public-type (eieio--class-v class)) slot-idx))) |
| 1258 | (if (not (eieio-perform-slot-validation st value)) | 1273 | (if (not (eieio-perform-slot-validation st value)) |
| 1259 | (signal 'invalid-slot-type (list class slot st value)))))) | 1274 | (signal 'invalid-slot-type (list class slot st value)))))) |
| @@ -1324,7 +1339,8 @@ Fills in OBJ's SLOT with its default value." | |||
| 1324 | ;;(signal 'invalid-slot-name (list (class-name cl) slot)) | 1339 | ;;(signal 'invalid-slot-name (list (class-name cl) slot)) |
| 1325 | ) | 1340 | ) |
| 1326 | (eieio-barf-if-slot-unbound | 1341 | (eieio-barf-if-slot-unbound |
| 1327 | (let ((val (nth (- c 3) (eieio--class-public-d (eieio--class-v cl))))) | 1342 | (let ((val (nth (- c (eval-when-compile eieio--object-num-slots)) |
| 1343 | (eieio--class-public-d (eieio--class-v cl))))) | ||
| 1328 | (eieio-default-eval-maybe val)) | 1344 | (eieio-default-eval-maybe val)) |
| 1329 | obj cl 'oref-default)))) | 1345 | obj cl 'oref-default)))) |
| 1330 | 1346 | ||
| @@ -1382,7 +1398,8 @@ Fills in the default value in CLASS' in SLOT with VALUE." | |||
| 1382 | (signal 'invalid-slot-name (list (eieio-class-name class) slot))) | 1398 | (signal 'invalid-slot-name (list (eieio-class-name class) slot))) |
| 1383 | (eieio-validate-slot-value class c value slot) | 1399 | (eieio-validate-slot-value class c value slot) |
| 1384 | ;; Set this into the storage for defaults. | 1400 | ;; Set this into the storage for defaults. |
| 1385 | (setcar (nthcdr (- c 3) (eieio--class-public-d (eieio--class-v class))) | 1401 | (setcar (nthcdr (- c (eval-when-compile eieio--object-num-slots)) |
| 1402 | (eieio--class-public-d (eieio--class-v class))) | ||
| 1386 | value) | 1403 | value) |
| 1387 | ;; Take the value, and put it into our cache object. | 1404 | ;; Take the value, and put it into our cache object. |
| 1388 | (eieio-oset (eieio--class-default-object-cache (eieio--class-v class)) | 1405 | (eieio-oset (eieio--class-default-object-cache (eieio--class-v class)) |
| @@ -1420,18 +1437,18 @@ reverse-lookup that name, and recurse with the associated slot value." | |||
| 1420 | (if (integerp fsi) | 1437 | (if (integerp fsi) |
| 1421 | (cond | 1438 | (cond |
| 1422 | ((not (cdr fsym)) | 1439 | ((not (cdr fsym)) |
| 1423 | (+ 3 fsi)) | 1440 | (+ (eval-when-compile eieio--object-num-slots) fsi)) |
| 1424 | ((and (eq (cdr fsym) 'protected) | 1441 | ((and (eq (cdr fsym) 'protected) |
| 1425 | (eieio--scoped-class) | 1442 | (eieio--scoped-class) |
| 1426 | (or (child-of-class-p class (eieio--scoped-class)) | 1443 | (or (child-of-class-p class (eieio--scoped-class)) |
| 1427 | (and (eieio-object-p obj) | 1444 | (and (eieio-object-p obj) |
| 1428 | (child-of-class-p class (eieio--object-class obj))))) | 1445 | (child-of-class-p class (eieio--object-class obj))))) |
| 1429 | (+ 3 fsi)) | 1446 | (+ (eval-when-compile eieio--object-num-slots) fsi)) |
| 1430 | ((and (eq (cdr fsym) 'private) | 1447 | ((and (eq (cdr fsym) 'private) |
| 1431 | (or (and (eieio--scoped-class) | 1448 | (or (and (eieio--scoped-class) |
| 1432 | (eieio-slot-originating-class-p (eieio--scoped-class) slot)) | 1449 | (eieio-slot-originating-class-p (eieio--scoped-class) slot)) |
| 1433 | eieio-initializing-object)) | 1450 | eieio-initializing-object)) |
| 1434 | (+ 3 fsi)) | 1451 | (+ (eval-when-compile eieio--object-num-slots) fsi)) |
| 1435 | (t nil)) | 1452 | (t nil)) |
| 1436 | (let ((fn (eieio-initarg-to-attribute class slot))) | 1453 | (let ((fn (eieio-initarg-to-attribute class slot))) |
| 1437 | (if fn (eieio-slot-name-index class obj fn) nil))))) | 1454 | (if fn (eieio-slot-name-index class obj fn) nil))))) |
| @@ -1778,12 +1795,8 @@ for this common case to improve performance." | |||
| 1778 | (setq mclass (eieio--object-class firstarg))) | 1795 | (setq mclass (eieio--object-class firstarg))) |
| 1779 | ((not firstarg) | 1796 | ((not firstarg) |
| 1780 | (error "Method %s called on nil" method)) | 1797 | (error "Method %s called on nil" method)) |
| 1781 | ((not (eieio-object-p firstarg)) | ||
| 1782 | (error "Primary-only method %s called on something not an object" method)) | ||
| 1783 | (t | 1798 | (t |
| 1784 | (error "EIEIO Error: Improperly classified method %s as primary only" | 1799 | (error "Primary-only method %s called on something not an object" method))) |
| 1785 | method) | ||
| 1786 | )) | ||
| 1787 | ;; Make sure the class is a valid class | 1800 | ;; Make sure the class is a valid class |
| 1788 | ;; mclass can be nil (meaning a generic for should be used. | 1801 | ;; mclass can be nil (meaning a generic for should be used. |
| 1789 | ;; mclass cannot have a value that is not a class, however. | 1802 | ;; mclass cannot have a value that is not a class, however. |
diff --git a/lisp/emacs-lisp/eieio-custom.el b/lisp/emacs-lisp/eieio-custom.el index 189337bd5f9..8172cbeef6f 100644 --- a/lisp/emacs-lisp/eieio-custom.el +++ b/lisp/emacs-lisp/eieio-custom.el | |||
| @@ -70,7 +70,7 @@ of these.") | |||
| 70 | :documentation "A number of thingies.")) | 70 | :documentation "A number of thingies.")) |
| 71 | "A class for testing the widget on.") | 71 | "A class for testing the widget on.") |
| 72 | 72 | ||
| 73 | (defcustom eieio-widget-test (eieio-widget-test-class "Foo") | 73 | (defcustom eieio-widget-test (eieio-widget-test-class) |
| 74 | "Test variable for editing an object." | 74 | "Test variable for editing an object." |
| 75 | :type 'object | 75 | :type 'object |
| 76 | :group 'eieio) | 76 | :group 'eieio) |
| @@ -317,7 +317,7 @@ Optional argument IGNORE is an extraneous parameter." | |||
| 317 | fgroup (cdr fgroup) | 317 | fgroup (cdr fgroup) |
| 318 | fcust (cdr fcust))) | 318 | fcust (cdr fcust))) |
| 319 | ;; Set any name updates on it. | 319 | ;; Set any name updates on it. |
| 320 | (if name (setf (eieio--object-name obj) name)) | 320 | (if name (eieio-object-set-name-string obj name)) |
| 321 | ;; This is the same object we had before. | 321 | ;; This is the same object we had before. |
| 322 | obj)) | 322 | obj)) |
| 323 | 323 | ||
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index f4e1d246011..51b8c3d2b4a 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -144,12 +144,7 @@ In EIEIO, the class' constructor requires a name for use when printing. | |||
| 144 | `make-instance' in CLOS doesn't use names the way Emacs does, so the | 144 | `make-instance' in CLOS doesn't use names the way Emacs does, so the |
| 145 | class is used as the name slot instead when INITARGS doesn't start with | 145 | class is used as the name slot instead when INITARGS doesn't start with |
| 146 | a string." | 146 | a string." |
| 147 | (if (and (car initargs) (stringp (car initargs))) | 147 | (apply (class-constructor class) initargs)) |
| 148 | (apply (class-constructor class) initargs) | ||
| 149 | (apply (class-constructor class) | ||
| 150 | (cond ((symbolp class) (symbol-name class)) | ||
| 151 | (t (format "%S" class))) | ||
| 152 | initargs))) | ||
| 153 | 148 | ||
| 154 | 149 | ||
| 155 | ;;; CLOS methods and generics | 150 | ;;; CLOS methods and generics |
| @@ -279,20 +274,28 @@ variable name of the same name as the slot." | |||
| 279 | If EXTRA, include that in the string returned to represent the symbol." | 274 | If EXTRA, include that in the string returned to represent the symbol." |
| 280 | (eieio--check-type eieio-object-p obj) | 275 | (eieio--check-type eieio-object-p obj) |
| 281 | (format "#<%s %s%s>" (symbol-name (eieio--object-class obj)) | 276 | (format "#<%s %s%s>" (symbol-name (eieio--object-class obj)) |
| 282 | (eieio--object-name obj) (or extra ""))) | 277 | (eieio-object-name-string obj) (or extra ""))) |
| 283 | (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") | 278 | (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") |
| 284 | 279 | ||
| 285 | (defun eieio-object-name-string (obj) "Return a string which is OBJ's name." | 280 | (defconst eieio--object-names (make-hash-table :test #'eq :weakness 'key)) |
| 286 | (eieio--check-type eieio-object-p obj) | 281 | |
| 287 | (eieio--object-name obj)) | 282 | ;; In the past, every EIEIO object had a `name' field, so we had the two method |
| 283 | ;; below "for free". Since this field is very rarely used, we got rid of it | ||
| 284 | ;; and instead we keep it in a weak hash-tables, for those very rare objects | ||
| 285 | ;; that use it. | ||
| 286 | (defmethod eieio-object-name-string (obj) | ||
| 287 | "Return a string which is OBJ's name." | ||
| 288 | (declare (obsolete eieio-named "25.1")) | ||
| 289 | (or (gethash obj eieio--object-names) | ||
| 290 | (symbol-name (eieio-object-class obj)))) | ||
| 288 | (define-obsolete-function-alias | 291 | (define-obsolete-function-alias |
| 289 | 'object-name-string #'eieio-object-name-string "24.4") | 292 | 'object-name-string #'eieio-object-name-string "24.4") |
| 290 | 293 | ||
| 291 | (defun eieio-object-set-name-string (obj name) | 294 | (defmethod eieio-object-set-name-string (obj name) |
| 292 | "Set the string which is OBJ's NAME." | 295 | "Set the string which is OBJ's NAME." |
| 293 | (eieio--check-type eieio-object-p obj) | 296 | (declare (obsolete eieio-named "25.1")) |
| 294 | (eieio--check-type stringp name) | 297 | (eieio--check-type stringp name) |
| 295 | (setf (eieio--object-name obj) name)) | 298 | (setf (gethash obj eieio--object-names) name)) |
| 296 | (define-obsolete-function-alias | 299 | (define-obsolete-function-alias |
| 297 | 'object-set-name-string 'eieio-object-set-name-string "24.4") | 300 | 'object-set-name-string 'eieio-object-set-name-string "24.4") |
| 298 | 301 | ||
| @@ -574,20 +577,19 @@ This class is not stored in the `parent' slot of a class vector." | |||
| 574 | 577 | ||
| 575 | (defalias 'standard-class 'eieio-default-superclass) | 578 | (defalias 'standard-class 'eieio-default-superclass) |
| 576 | 579 | ||
| 577 | (defgeneric constructor (class newname &rest slots) | 580 | (defgeneric eieio-constructor (class &rest slots) |
| 578 | "Default constructor for CLASS `eieio-default-superclass'.") | 581 | "Default constructor for CLASS `eieio-default-superclass'.") |
| 579 | 582 | ||
| 580 | (defmethod constructor :static | 583 | (define-obsolete-function-alias 'constructor #'eieio-constructor "25.1") |
| 581 | ((class eieio-default-superclass) newname &rest slots) | 584 | |
| 585 | (defmethod eieio-constructor :static | ||
| 586 | ((class eieio-default-superclass) &rest slots) | ||
| 582 | "Default constructor for CLASS `eieio-default-superclass'. | 587 | "Default constructor for CLASS `eieio-default-superclass'. |
| 583 | NEWNAME is the name to be given to the constructed object. | ||
| 584 | SLOTS are the initialization slots used by `shared-initialize'. | 588 | SLOTS are the initialization slots used by `shared-initialize'. |
| 585 | This static method is called when an object is constructed. | 589 | This static method is called when an object is constructed. |
| 586 | It allocates the vector used to represent an EIEIO object, and then | 590 | It allocates the vector used to represent an EIEIO object, and then |
| 587 | calls `shared-initialize' on that object." | 591 | calls `shared-initialize' on that object." |
| 588 | (let* ((new-object (copy-sequence (eieio--class-default-object-cache (eieio--class-v class))))) | 592 | (let* ((new-object (copy-sequence (eieio--class-default-object-cache (eieio--class-v class))))) |
| 589 | ;; Update the name for the newly created object. | ||
| 590 | (setf (eieio--object-name new-object) newname) | ||
| 591 | ;; Call the initialize method on the new object with the slots | 593 | ;; Call the initialize method on the new object with the slots |
| 592 | ;; that were passed down to us. | 594 | ;; that were passed down to us. |
| 593 | (initialize-instance new-object slots) | 595 | (initialize-instance new-object slots) |
| @@ -715,18 +717,10 @@ first and modify the returned object.") | |||
| 715 | 717 | ||
| 716 | (defmethod clone ((obj eieio-default-superclass) &rest params) | 718 | (defmethod clone ((obj eieio-default-superclass) &rest params) |
| 717 | "Make a copy of OBJ, and then apply PARAMS." | 719 | "Make a copy of OBJ, and then apply PARAMS." |
| 718 | (let ((nobj (copy-sequence obj)) | 720 | (let ((nobj (copy-sequence obj))) |
| 719 | (nm (eieio--object-name obj)) | 721 | (if (stringp (car params)) |
| 720 | (passname (and params (stringp (car params)))) | 722 | (message "Obsolete name %S passed to clone" (pop params))) |
| 721 | (num 1)) | 723 | (if params (shared-initialize nobj params)) |
| 722 | (if params (shared-initialize nobj (if passname (cdr params) params))) | ||
| 723 | (if (not passname) | ||
| 724 | (save-match-data | ||
| 725 | (if (string-match "-\\([0-9]+\\)" nm) | ||
| 726 | (setq num (1+ (string-to-number (match-string 1 nm))) | ||
| 727 | nm (substring nm 0 (match-beginning 0)))) | ||
| 728 | (setf (eieio--object-name nobj) (concat nm "-" (int-to-string num)))) | ||
| 729 | (setf (eieio--object-name nobj) (car params))) | ||
| 730 | nobj)) | 724 | nobj)) |
| 731 | 725 | ||
| 732 | (defgeneric destructor (this &rest params) | 726 | (defgeneric destructor (this &rest params) |
| @@ -889,7 +883,7 @@ variable PRINT-FUNCTION. Optional argument NOESCAPE is passed to | |||
| 889 | 883 | ||
| 890 | ;;; Start of automatically extracted autoloads. | 884 | ;;; Start of automatically extracted autoloads. |
| 891 | 885 | ||
| 892 | ;;;### (autoloads nil "eieio-custom" "eieio-custom.el" "6413249ec10091eb7094238637b40e2c") | 886 | ;;;### (autoloads nil "eieio-custom" "eieio-custom.el" "3a6fffe3af331fe960f967d0da99e8e9") |
| 893 | ;;; Generated autoloads from eieio-custom.el | 887 | ;;; Generated autoloads from eieio-custom.el |
| 894 | 888 | ||
| 895 | (autoload 'customize-object "eieio-custom" "\ | 889 | (autoload 'customize-object "eieio-custom" "\ |
| @@ -900,7 +894,7 @@ Optional argument GROUP is the sub-group of slots to display. | |||
| 900 | 894 | ||
| 901 | ;;;*** | 895 | ;;;*** |
| 902 | 896 | ||
| 903 | ;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "6f114a48de40212413d2776eedc3ec14") | 897 | ;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "2ff7d98da3f84c6af5c873ffb781930e") |
| 904 | ;;; Generated autoloads from eieio-opt.el | 898 | ;;; Generated autoloads from eieio-opt.el |
| 905 | 899 | ||
| 906 | (autoload 'eieio-browse "eieio-opt" "\ | 900 | (autoload 'eieio-browse "eieio-opt" "\ |
diff --git a/test/automated/eieio-test-methodinvoke.el b/test/automated/eieio-test-methodinvoke.el index 20b47a771d8..3f86d8fcc99 100644 --- a/test/automated/eieio-test-methodinvoke.el +++ b/test/automated/eieio-test-methodinvoke.el | |||
| @@ -174,17 +174,18 @@ | |||
| 174 | (defclass C-base2 () ()) | 174 | (defclass C-base2 () ()) |
| 175 | (defclass C (C-base1 C-base2) ()) | 175 | (defclass C (C-base1 C-base2) ()) |
| 176 | 176 | ||
| 177 | ;; Just use the obsolete name once, to make sure it also works. | ||
| 177 | (defmethod constructor :STATIC ((p C-base1) &rest args) | 178 | (defmethod constructor :STATIC ((p C-base1) &rest args) |
| 178 | (eieio-test-method-store) | 179 | (eieio-test-method-store) |
| 179 | (if (next-method-p) (call-next-method)) | 180 | (if (next-method-p) (call-next-method)) |
| 180 | ) | 181 | ) |
| 181 | 182 | ||
| 182 | (defmethod constructor :STATIC ((p C-base2) &rest args) | 183 | (defmethod eieio-constructor :STATIC ((p C-base2) &rest args) |
| 183 | (eieio-test-method-store) | 184 | (eieio-test-method-store) |
| 184 | (if (next-method-p) (call-next-method)) | 185 | (if (next-method-p) (call-next-method)) |
| 185 | ) | 186 | ) |
| 186 | 187 | ||
| 187 | (defmethod constructor :STATIC ((p C) &rest args) | 188 | (defmethod eieio-constructor :STATIC ((p C) &rest args) |
| 188 | (eieio-test-method-store) | 189 | (eieio-test-method-store) |
| 189 | (call-next-method) | 190 | (call-next-method) |
| 190 | ) | 191 | ) |
diff --git a/test/automated/eieio-test-persist.el b/test/automated/eieio-test-persist.el index d6f53cd9db2..00de3cf0d7c 100644 --- a/test/automated/eieio-test-persist.el +++ b/test/automated/eieio-test-persist.el | |||
| @@ -175,7 +175,7 @@ persistent class.") | |||
| 175 | 175 | ||
| 176 | (defclass persistent-with-objs-slot-subs (eieio-persistent) | 176 | (defclass persistent-with-objs-slot-subs (eieio-persistent) |
| 177 | ((pnp :initarg :pnp | 177 | ((pnp :initarg :pnp |
| 178 | :type (or null persist-not-persistent-child) | 178 | :type (or null persist-not-persistent) |
| 179 | :initform nil)) | 179 | :initform nil)) |
| 180 | "Class for testing the saving of slots with objects in them.") | 180 | "Class for testing the saving of slots with objects in them.") |
| 181 | 181 | ||
diff --git a/test/automated/eieio-tests.el b/test/automated/eieio-tests.el index 87151f6a0da..91ddfc4fcf3 100644 --- a/test/automated/eieio-tests.el +++ b/test/automated/eieio-tests.el | |||
| @@ -157,7 +157,7 @@ | |||
| 157 | (ert-deftest eieio-test-02-abstract-class () | 157 | (ert-deftest eieio-test-02-abstract-class () |
| 158 | ;; Abstract classes cannot be instantiated, so this should throw an | 158 | ;; Abstract classes cannot be instantiated, so this should throw an |
| 159 | ;; error | 159 | ;; error |
| 160 | (should-error (abstract-class "Test"))) | 160 | (should-error (abstract-class))) |
| 161 | 161 | ||
| 162 | (defgeneric generic1 () "First generic function") | 162 | (defgeneric generic1 () "First generic function") |
| 163 | 163 | ||
| @@ -179,7 +179,7 @@ | |||
| 179 | "Method generic1 that can take a non-object." | 179 | "Method generic1 that can take a non-object." |
| 180 | not-an-object) | 180 | not-an-object) |
| 181 | 181 | ||
| 182 | (let ((ans-obj (generic1 (class-a "test"))) | 182 | (let ((ans-obj (generic1 (class-a))) |
| 183 | (ans-num (generic1 666))) | 183 | (ans-num (generic1 666))) |
| 184 | (should (eq ans-obj 'monkey)) | 184 | (should (eq ans-obj 'monkey)) |
| 185 | (should (eq ans-num 666)))) | 185 | (should (eq ans-num 666)))) |
| @@ -200,7 +200,7 @@ Argument C is the class bound to this static method." | |||
| 200 | ;; Call static method on a class and see if it worked | 200 | ;; Call static method on a class and see if it worked |
| 201 | (static-method-class-method static-method-class 'class) | 201 | (static-method-class-method static-method-class 'class) |
| 202 | (should (eq (oref static-method-class some-slot) 'class)) | 202 | (should (eq (oref static-method-class some-slot) 'class)) |
| 203 | (static-method-class-method (static-method-class "test") 'object) | 203 | (static-method-class-method (static-method-class) 'object) |
| 204 | (should (eq (oref static-method-class some-slot) 'object))) | 204 | (should (eq (oref static-method-class some-slot) 'object))) |
| 205 | 205 | ||
| 206 | (ert-deftest eieio-test-05-static-method-2 () | 206 | (ert-deftest eieio-test-05-static-method-2 () |
| @@ -216,7 +216,7 @@ Argument C is the class bound to this static method." | |||
| 216 | 216 | ||
| 217 | (static-method-class-method static-method-class-2 'class) | 217 | (static-method-class-method static-method-class-2 'class) |
| 218 | (should (eq (oref static-method-class-2 some-slot) 'moose-class)) | 218 | (should (eq (oref static-method-class-2 some-slot) 'moose-class)) |
| 219 | (static-method-class-method (static-method-class-2 "test") 'object) | 219 | (static-method-class-method (static-method-class-2) 'object) |
| 220 | (should (eq (oref static-method-class-2 some-slot) 'moose-object))) | 220 | (should (eq (oref static-method-class-2 some-slot) 'moose-object))) |
| 221 | 221 | ||
| 222 | 222 | ||
| @@ -230,14 +230,14 @@ Argument C is the class bound to this static method." | |||
| 230 | (defvar eitest-b nil) | 230 | (defvar eitest-b nil) |
| 231 | (ert-deftest eieio-test-06-allocate-objects () | 231 | (ert-deftest eieio-test-06-allocate-objects () |
| 232 | ;; allocate an object to use | 232 | ;; allocate an object to use |
| 233 | (should (setq eitest-ab (class-ab "abby"))) | 233 | (should (setq eitest-ab (class-ab))) |
| 234 | (should (setq eitest-a (class-a "aye"))) | 234 | (should (setq eitest-a (class-a))) |
| 235 | (should (setq eitest-b (class-b "fooby")))) | 235 | (should (setq eitest-b (class-b)))) |
| 236 | 236 | ||
| 237 | (ert-deftest eieio-test-07-make-instance () | 237 | (ert-deftest eieio-test-07-make-instance () |
| 238 | (should (make-instance 'class-ab)) | 238 | (should (make-instance 'class-ab)) |
| 239 | (should (make-instance 'class-a :water 'cho)) | 239 | (should (make-instance 'class-a :water 'cho)) |
| 240 | (should (make-instance 'class-b "a name"))) | 240 | (should (make-instance 'class-b))) |
| 241 | 241 | ||
| 242 | (defmethod class-cn ((a class-a)) | 242 | (defmethod class-cn ((a class-a)) |
| 243 | "Try calling `call-next-method' when there isn't one. | 243 | "Try calling `call-next-method' when there isn't one. |
| @@ -354,7 +354,7 @@ METHOD is the method that was attempting to be called." | |||
| 354 | (call-next-method) | 354 | (call-next-method) |
| 355 | (oset a test-tag 1)) | 355 | (oset a test-tag 1)) |
| 356 | 356 | ||
| 357 | (let ((ca (class-a "class act"))) | 357 | (let ((ca (class-a))) |
| 358 | (should-not (/= (oref ca test-tag) 2)))) | 358 | (should-not (/= (oref ca test-tag) 2)))) |
| 359 | 359 | ||
| 360 | 360 | ||
| @@ -403,7 +403,7 @@ METHOD is the method that was attempting to be called." | |||
| 403 | (t (call-next-method)))) | 403 | (t (call-next-method)))) |
| 404 | 404 | ||
| 405 | (ert-deftest eieio-test-17-virtual-slot () | 405 | (ert-deftest eieio-test-17-virtual-slot () |
| 406 | (setq eitest-vsca (virtual-slot-class "eitest-vsca" :base-value 1)) | 406 | (setq eitest-vsca (virtual-slot-class :base-value 1)) |
| 407 | ;; Check slot values | 407 | ;; Check slot values |
| 408 | (should (= (oref eitest-vsca :base-value) 1)) | 408 | (should (= (oref eitest-vsca :base-value) 1)) |
| 409 | (should (= (oref eitest-vsca :derived-value) 2)) | 409 | (should (= (oref eitest-vsca :derived-value) 2)) |
| @@ -418,7 +418,7 @@ METHOD is the method that was attempting to be called." | |||
| 418 | 418 | ||
| 419 | ;; should also be possible to initialize instance using virtual slot | 419 | ;; should also be possible to initialize instance using virtual slot |
| 420 | 420 | ||
| 421 | (setq eitest-vscb (virtual-slot-class "eitest-vscb" :derived-value 5)) | 421 | (setq eitest-vscb (virtual-slot-class :derived-value 5)) |
| 422 | (should (= (oref eitest-vscb :base-value) 4)) | 422 | (should (= (oref eitest-vscb :base-value) 4)) |
| 423 | (should (= (oref eitest-vscb :derived-value) 5))) | 423 | (should (= (oref eitest-vscb :derived-value) 5))) |
| 424 | 424 | ||
| @@ -444,7 +444,7 @@ METHOD is the method that was attempting to be called." | |||
| 444 | ;; After setting 'water to 'moose, make sure a new object has | 444 | ;; After setting 'water to 'moose, make sure a new object has |
| 445 | ;; the right stuff. | 445 | ;; the right stuff. |
| 446 | (oset-default (eieio-object-class eitest-a) water 'penguin) | 446 | (oset-default (eieio-object-class eitest-a) water 'penguin) |
| 447 | (should (eq (oref (class-a "foo") water) 'penguin)) | 447 | (should (eq (oref (class-a) water) 'penguin)) |
| 448 | 448 | ||
| 449 | ;; Revert the above | 449 | ;; Revert the above |
| 450 | (defmethod slot-unbound ((a class-a) &rest foo) | 450 | (defmethod slot-unbound ((a class-a) &rest foo) |
| @@ -458,12 +458,12 @@ METHOD is the method that was attempting to be called." | |||
| 458 | ;; We should not be able to set a string here | 458 | ;; We should not be able to set a string here |
| 459 | (should-error (oset eitest-ab water "a string, not a symbol") :type 'invalid-slot-type) | 459 | (should-error (oset eitest-ab water "a string, not a symbol") :type 'invalid-slot-type) |
| 460 | (should-error (oset eitest-ab classslot "a string, not a symbol") :type 'invalid-slot-type) | 460 | (should-error (oset eitest-ab classslot "a string, not a symbol") :type 'invalid-slot-type) |
| 461 | (should-error (class-a "broken-type-a" :water "a string not a symbol") :type 'invalid-slot-type)) | 461 | (should-error (class-a :water "a string not a symbol") :type 'invalid-slot-type)) |
| 462 | 462 | ||
| 463 | (ert-deftest eieio-test-20-class-allocated-slots () | 463 | (ert-deftest eieio-test-20-class-allocated-slots () |
| 464 | ;; Test out class allocated slots | 464 | ;; Test out class allocated slots |
| 465 | (defvar eitest-aa nil) | 465 | (defvar eitest-aa nil) |
| 466 | (setq eitest-aa (class-a "another")) | 466 | (setq eitest-aa (class-a)) |
| 467 | 467 | ||
| 468 | ;; Make sure class slots do not track between objects | 468 | ;; Make sure class slots do not track between objects |
| 469 | (let ((newval 'moose)) | 469 | (let ((newval 'moose)) |
| @@ -498,7 +498,7 @@ METHOD is the method that was attempting to be called." | |||
| 498 | (ert-deftest eieio-test-21-eval-at-construction-time () | 498 | (ert-deftest eieio-test-21-eval-at-construction-time () |
| 499 | ;; initforms that need to be evalled at construction time. | 499 | ;; initforms that need to be evalled at construction time. |
| 500 | (setq eieio-test-permuting-value 2) | 500 | (setq eieio-test-permuting-value 2) |
| 501 | (setq eitest-pvinit (inittest "permuteme")) | 501 | (setq eitest-pvinit (inittest)) |
| 502 | 502 | ||
| 503 | (should (eq (oref eitest-pvinit staticval) 1)) | 503 | (should (eq (oref eitest-pvinit staticval) 1)) |
| 504 | (should (eq (oref eitest-pvinit symval) 'eieio-test-permuting-value)) | 504 | (should (eq (oref eitest-pvinit symval) 'eieio-test-permuting-value)) |
| @@ -514,11 +514,11 @@ METHOD is the method that was attempting to be called." | |||
| 514 | "Test class that will be a calculated value.") | 514 | "Test class that will be a calculated value.") |
| 515 | 515 | ||
| 516 | (defclass eitest-superior nil | 516 | (defclass eitest-superior nil |
| 517 | ((sub :initform (eitest-subordinate "test") | 517 | ((sub :initform (eitest-subordinate) |
| 518 | :type eitest-subordinate)) | 518 | :type eitest-subordinate)) |
| 519 | "A class with an initform that creates a class.") | 519 | "A class with an initform that creates a class.") |
| 520 | 520 | ||
| 521 | (should (setq eitest-tests (eitest-superior "test"))) | 521 | (should (setq eitest-tests (eitest-superior))) |
| 522 | 522 | ||
| 523 | (should-error | 523 | (should-error |
| 524 | (eval | 524 | (eval |
| @@ -546,8 +546,8 @@ METHOD is the method that was attempting to be called." | |||
| 546 | (should (not (class-a-child-p "foo")))) | 546 | (should (not (class-a-child-p "foo")))) |
| 547 | 547 | ||
| 548 | (ert-deftest eieio-test-24-object-predicates () | 548 | (ert-deftest eieio-test-24-object-predicates () |
| 549 | (let ((listooa (list (class-ab "ab") (class-a "a"))) | 549 | (let ((listooa (list (class-ab) (class-a))) |
| 550 | (listoob (list (class-ab "ab") (class-b "b")))) | 550 | (listoob (list (class-ab) (class-b)))) |
| 551 | (should (class-a-list-p listooa)) | 551 | (should (class-a-list-p listooa)) |
| 552 | (should (class-b-list-p listoob)) | 552 | (should (class-b-list-p listoob)) |
| 553 | (should-not (class-b-list-p listooa)) | 553 | (should-not (class-b-list-p listooa)) |
| @@ -555,7 +555,7 @@ METHOD is the method that was attempting to be called." | |||
| 555 | 555 | ||
| 556 | (defvar eitest-t1 nil) | 556 | (defvar eitest-t1 nil) |
| 557 | (ert-deftest eieio-test-25-slot-tests () | 557 | (ert-deftest eieio-test-25-slot-tests () |
| 558 | (setq eitest-t1 (class-c "C1")) | 558 | (setq eitest-t1 (class-c)) |
| 559 | ;; Slot initialization | 559 | ;; Slot initialization |
| 560 | (should (eq (oref eitest-t1 slot-1) 'moose)) | 560 | (should (eq (oref eitest-t1 slot-1) 'moose)) |
| 561 | (should (eq (oref eitest-t1 :moose) 'moose)) | 561 | (should (eq (oref eitest-t1 :moose) 'moose)) |
| @@ -564,7 +564,7 @@ METHOD is the method that was attempting to be called." | |||
| 564 | ;; Check private slot accessor | 564 | ;; Check private slot accessor |
| 565 | (should (string= (get-slot-2 eitest-t1) "penguin")) | 565 | (should (string= (get-slot-2 eitest-t1) "penguin")) |
| 566 | ;; Pass string instead of symbol | 566 | ;; Pass string instead of symbol |
| 567 | (should-error (class-c "C2" :moose "not a symbol") :type 'invalid-slot-type) | 567 | (should-error (class-c :moose "not a symbol") :type 'invalid-slot-type) |
| 568 | (should (eq (get-slot-3 eitest-t1) 'emu)) | 568 | (should (eq (get-slot-3 eitest-t1) 'emu)) |
| 569 | (should (eq (get-slot-3 class-c) 'emu)) | 569 | (should (eq (get-slot-3 class-c) 'emu)) |
| 570 | ;; Check setf | 570 | ;; Check setf |
| @@ -576,13 +576,13 @@ METHOD is the method that was attempting to be called." | |||
| 576 | (defvar eitest-t2 nil) | 576 | (defvar eitest-t2 nil) |
| 577 | (ert-deftest eieio-test-26-default-inheritance () | 577 | (ert-deftest eieio-test-26-default-inheritance () |
| 578 | ;; See previous test, nor for subclass | 578 | ;; See previous test, nor for subclass |
| 579 | (setq eitest-t2 (class-subc "subc")) | 579 | (setq eitest-t2 (class-subc)) |
| 580 | (should (eq (oref eitest-t2 slot-1) 'moose)) | 580 | (should (eq (oref eitest-t2 slot-1) 'moose)) |
| 581 | (should (eq (oref eitest-t2 :moose) 'moose)) | 581 | (should (eq (oref eitest-t2 :moose) 'moose)) |
| 582 | (should (string= (get-slot-2 eitest-t2) "linux")) | 582 | (should (string= (get-slot-2 eitest-t2) "linux")) |
| 583 | (should-error (oref eitest-t2 slot-2) :type 'invalid-slot-name) | 583 | (should-error (oref eitest-t2 slot-2) :type 'invalid-slot-name) |
| 584 | (should (string= (get-slot-2 eitest-t2) "linux")) | 584 | (should (string= (get-slot-2 eitest-t2) "linux")) |
| 585 | (should-error (class-subc "C2" :moose "not a symbol") :type 'invalid-slot-type)) | 585 | (should-error (class-subc :moose "not a symbol") :type 'invalid-slot-type)) |
| 586 | 586 | ||
| 587 | ;;(ert-deftest eieio-test-27-inherited-new-value () | 587 | ;;(ert-deftest eieio-test-27-inherited-new-value () |
| 588 | ;;; HACK ALERT: The new value of a class slot is inherited by the | 588 | ;;; HACK ALERT: The new value of a class slot is inherited by the |
| @@ -646,8 +646,8 @@ Do not override for `prot-2'." | |||
| 646 | (defvar eitest-p1 nil) | 646 | (defvar eitest-p1 nil) |
| 647 | (defvar eitest-p2 nil) | 647 | (defvar eitest-p2 nil) |
| 648 | (ert-deftest eieio-test-28-slot-protection () | 648 | (ert-deftest eieio-test-28-slot-protection () |
| 649 | (setq eitest-p1 (prot-1 "")) | 649 | (setq eitest-p1 (prot-1)) |
| 650 | (setq eitest-p2 (prot-2 "")) | 650 | (setq eitest-p2 (prot-2)) |
| 651 | ;; Access public slots | 651 | ;; Access public slots |
| 652 | (oref eitest-p1 slot-1) | 652 | (oref eitest-p1 slot-1) |
| 653 | (oref eitest-p2 slot-1) | 653 | (oref eitest-p2 slot-1) |
| @@ -742,7 +742,7 @@ Subclasses to override slot attributes.") | |||
| 742 | "This class should throw an error."))) | 742 | "This class should throw an error."))) |
| 743 | 743 | ||
| 744 | ;; Initform should override instance allocation | 744 | ;; Initform should override instance allocation |
| 745 | (let ((obj (slotattr-ok "moose"))) | 745 | (let ((obj (slotattr-ok))) |
| 746 | (should (eq (oref obj initform) 'no-init)))) | 746 | (should (eq (oref obj initform) 'no-init)))) |
| 747 | 747 | ||
| 748 | (defclass slotattr-class-base () | 748 | (defclass slotattr-class-base () |
| @@ -825,7 +825,7 @@ Subclasses to override slot attributes.") | |||
| 825 | 825 | ||
| 826 | (ert-deftest eieio-test-32-test-clone-boring-objects () | 826 | (ert-deftest eieio-test-32-test-clone-boring-objects () |
| 827 | ;; A simple make instance with EIEIO extension | 827 | ;; A simple make instance with EIEIO extension |
| 828 | (should (setq eitest-CLONETEST1 (make-instance 'class-a "a"))) | 828 | (should (setq eitest-CLONETEST1 (make-instance 'class-a))) |
| 829 | (should (setq eitest-CLONETEST2 (clone eitest-CLONETEST1))) | 829 | (should (setq eitest-CLONETEST2 (clone eitest-CLONETEST1))) |
| 830 | 830 | ||
| 831 | ;; CLOS form of make-instance | 831 | ;; CLOS form of make-instance |
| @@ -839,7 +839,7 @@ Subclasses to override slot attributes.") | |||
| 839 | 839 | ||
| 840 | (ert-deftest eieio-test-33-instance-tracker () | 840 | (ert-deftest eieio-test-33-instance-tracker () |
| 841 | (let (IT-list IT1) | 841 | (let (IT-list IT1) |
| 842 | (should (setq IT1 (IT "trackme"))) | 842 | (should (setq IT1 (IT))) |
| 843 | ;; The instance tracker must find this | 843 | ;; The instance tracker must find this |
| 844 | (should (eieio-instance-tracker-find 'die 'slot1 'IT-list)) | 844 | (should (eieio-instance-tracker-find 'die 'slot1 'IT-list)) |
| 845 | ;; Test deletion | 845 | ;; Test deletion |
| @@ -851,8 +851,8 @@ Subclasses to override slot attributes.") | |||
| 851 | "A Singleton test object.") | 851 | "A Singleton test object.") |
| 852 | 852 | ||
| 853 | (ert-deftest eieio-test-34-singletons () | 853 | (ert-deftest eieio-test-34-singletons () |
| 854 | (let ((obj1 (SINGLE "Moose")) | 854 | (let ((obj1 (SINGLE)) |
| 855 | (obj2 (SINGLE "Cow"))) | 855 | (obj2 (SINGLE))) |
| 856 | (should (eieio-object-p obj1)) | 856 | (should (eieio-object-p obj1)) |
| 857 | (should (eieio-object-p obj2)) | 857 | (should (eieio-object-p obj2)) |
| 858 | (should (eq obj1 obj2)) | 858 | (should (eq obj1 obj2)) |
| @@ -865,7 +865,7 @@ Subclasses to override slot attributes.") | |||
| 865 | 865 | ||
| 866 | (ert-deftest eieio-test-35-named-object () | 866 | (ert-deftest eieio-test-35-named-object () |
| 867 | (let (N) | 867 | (let (N) |
| 868 | (should (setq N (NAMED "Foo"))) | 868 | (should (setq N (NAMED :object-name "Foo"))) |
| 869 | (should (string= "Foo" (oref N object-name))) | 869 | (should (string= "Foo" (oref N object-name))) |
| 870 | (should-error (oref N missing-slot) :type 'invalid-slot-name) | 870 | (should-error (oref N missing-slot) :type 'invalid-slot-name) |
| 871 | (oset N object-name "NewName") | 871 | (oset N object-name "NewName") |