[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initia
From: |
Vitalie Spinu |
Subject: |
bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initialize slots |
Date: |
Wed, 13 Mar 2019 13:40:29 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Hi,
The clone method of eieio-instance-inheritor sets the slots of the new
objects. For example:
(defclass A (eieio-instance-inheritor)
((foo
:initarg :foo
:initform "something")))
(defvar a (A))
(defvar b (clone a))
(slot-boundp b :foo) ; => t
This is in contrast to the doc which says "All slots are unbound, except those
initialized with PARAMS". The original eieio implementation initialized the
objects with unbound values like this:
╭──────── #68 ─ emacs-source/lisp/emacs-lisp/eieio-base.el ──
│ (let ((nobj (make-vector (length obj) eieio-unbound))
╰──────── #68 ─
The current implementation dispatches to cl-call-next-method. I am attaching a
patch which preserves the call to cl-call-next-method.
Vitalie
>From 03e18e4eec518660e8dae6ae66ef21d4946f6220 Mon Sep 17 00:00:00 2001
From: Vitalie Spinu <spinuvit@gmail.com>
Date: Wed, 13 Mar 2019 13:32:22 +0100
Subject: [PATCH] Don't initialize slots of eieio-instance-inheritor objects on
clone
---
lisp/emacs-lisp/eieio-base.el | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index 3a0109877e..b2007a7476 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -64,10 +64,15 @@ eieio-instance-inheritor
;; Throw the regular signal.
(cl-call-next-method)))
-(cl-defmethod clone ((obj eieio-instance-inheritor) &rest _params)
+(cl-defmethod clone ((obj eieio-instance-inheritor) &rest params)
"Clone OBJ, initializing `:parent' to OBJ.
All slots are unbound, except those initialized with PARAMS."
- (let ((nobj (cl-call-next-method)))
+ (let ((nobj (cl-call-next-method obj)))
+ (dolist (descriptor (eieio-class-slots (class-of nobj)))
+ (let ((slot (eieio-slot-descriptor-name descriptor)))
+ (slot-makeunbound nobj slot)))
+ (when params
+ (shared-initialize nobj params))
(oset nobj parent-instance obj)
nobj))
--
2.17.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initialize slots,
Vitalie Spinu <=