GNU bug report logs -
#34840
[PATCH] Cloning of eieio-instance-inheritor should not initialize slots
Previous Next
Reported by: Vitalie Spinu <spinuvit <at> gmail.com>
Date: Wed, 13 Mar 2019 12:41:02 UTC
Severity: normal
Tags: fixed, patch
Fixed in version 26.3
Done: Vitalie Spinu <spinuvit <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
[0001-Don-t-initialize-slots-of-eieio-instance-inheritor-o.patch (text/x-diff, inline)]
From 03e18e4eec518660e8dae6ae66ef21d4946f6220 Mon Sep 17 00:00:00 2001
From: Vitalie Spinu <spinuvit <at> 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
This bug report was last modified 6 years and 76 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.