GNU bug report logs - #34840
[PATCH] Cloning of eieio-instance-inheritor should not initialize slots

Previous Next

Package: emacs;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34840 in the body.
You can then email your comments to 34840 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#34840; Package emacs. (Wed, 13 Mar 2019 12:41:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vitalie Spinu <spinuvit <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 13 Mar 2019 12:41:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vitalie Spinu <spinuvit <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Cloning of eieio-instance-inheritor should not initialize
 slots
Date: Wed, 13 Mar 2019 13:40:29 +0100
[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


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34840; Package emacs. (Wed, 08 May 2019 11:03:01 GMT) Full text and rfc822 format available.

Message #8 received at 34840 <at> debbugs.gnu.org (full text, mbox):

From: Vitalie Spinu <spinuvit <at> gmail.com>
To: 34840 <at> debbugs.gnu.org
Subject: Re: bug#34840: [PATCH] Cloning of eieio-instance-inheritor should not
 initialize slots
Date: Wed, 08 May 2019 13:02:04 +0200
tags 34840 fixed
close 34840 26.3
quit

emacs-26 1c6484e975e8b0e50d22980d02a3be6c9bf93b49
Author:     Vitalie Spinu <spinuvit <at> gmail.com>
AuthorDate: Wed May 8 11:12:29 2019 +0200
Commit:     Vitalie Spinu <spinuvit <at> 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




Added tag(s) fixed. Request was from Vitalie Spinu <spinuvit <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 08 May 2019 11:03:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.3, send any further explanations to 34840 <at> debbugs.gnu.org and Vitalie Spinu <spinuvit <at> gmail.com> Request was from Vitalie Spinu <spinuvit <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 08 May 2019 11:03:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 05 Jun 2019 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 325 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.