unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initialize slots
@ 2019-03-13 12:40 Vitalie Spinu
  2019-05-08 11:02 ` Vitalie Spinu
  0 siblings, 1 reply; 2+ messages in thread
From: Vitalie Spinu @ 2019-03-13 12:40 UTC (permalink / raw)
  To: 34840

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]


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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-initialize-slots-of-eieio-instance-inheritor-o.patch --]
[-- Type: text/x-diff, Size: 1239 bytes --]

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initialize slots
  2019-03-13 12:40 bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initialize slots Vitalie Spinu
@ 2019-05-08 11:02 ` Vitalie Spinu
  0 siblings, 0 replies; 2+ messages in thread
From: Vitalie Spinu @ 2019-05-08 11:02 UTC (permalink / raw)
  To: 34840

tags 34840 fixed
close 34840 26.3
quit

emacs-26 1c6484e975e8b0e50d22980d02a3be6c9bf93b49
Author:     Vitalie Spinu <spinuvit@gmail.com>
AuthorDate: Wed May 8 11:12:29 2019 +0200
Commit:     Vitalie Spinu <spinuvit@gmail.com>
CommitDate: Wed May 8 11:12:29 2019 +0200

Fix incorrect cloning of eieio-instance-inheritor objects (Bug#34840)
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1c6484e975e8b0e50d22980d02a3be6c9bf93b49





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-08 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-13 12:40 bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not initialize slots Vitalie Spinu
2019-05-08 11:02 ` Vitalie Spinu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).