From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#29220: 26.0.90; eieio-persistent-read fail to restore saved object. Date: Tue, 05 Dec 2017 14:58:45 -0800 Message-ID: <874lp4aije.fsf@ericabrahamsen.net> References: <87y3nga0lv.fsf@killashandra.ballybran.fr> <87h8ts1cfp.fsf@users.sourceforge.net> <87zi7kyzcf.fsf@ericabrahamsen.net> <87efov1zzn.fsf@users.sourceforge.net> <87h8trzc6e.fsf@ericabrahamsen.net> <87bmjz0xez.fsf@users.sourceforge.net> <87zi7cpooo.fsf@killashandra.ballybran.fr> <87h8tkzgef.fsf@users.sourceforge.net> <87zi76f5hj.fsf@killashandra.ballybran.fr> <87shcycavk.fsf@ericabrahamsen.net> <87lgimpdhp.fsf@ericabrahamsen.net> <87h8t8is1u.fsf@ericabrahamsen.net> <87zi6zmzh7.fsf@killashandra.ballybran.fr> <87h8t69d7b.fsf@ericabrahamsen.net> <87609lcbip.fsf@ericabrahamsen.net> <87bmjcc2rh.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1512577186 23876 195.159.176.226 (6 Dec 2017 16:19:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 6 Dec 2017 16:19:46 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: John Wiegley , 29220@debbugs.gnu.org, Pierre =?UTF-8?Q?T=C3=A9choueyres?= , Noam Postavsky To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 06 17:19:38 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMcPR-0001Nn-2I for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Dec 2017 17:18:57 +0100 Original-Received: from localhost ([::1]:52388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMMEc-0000Ru-N6 for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Dec 2017 18:02:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMMD3-0007ZD-Hb for bug-gnu-emacs@gnu.org; Tue, 05 Dec 2017 18:01:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMMD0-0003Wk-Fy for bug-gnu-emacs@gnu.org; Tue, 05 Dec 2017 18:01:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39524) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eMMD0-0003Wd-BR for bug-gnu-emacs@gnu.org; Tue, 05 Dec 2017 18:01:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eMMD0-0008Hp-21 for bug-gnu-emacs@gnu.org; Tue, 05 Dec 2017 18:01:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Dec 2017 23:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29220 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 29220-submit@debbugs.gnu.org id=B29220.151251484231822 (code B ref 29220); Tue, 05 Dec 2017 23:01:01 +0000 Original-Received: (at 29220) by debbugs.gnu.org; 5 Dec 2017 23:00:42 +0000 Original-Received: from localhost ([127.0.0.1]:48205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMMCe-0008H9-H1 for submit@debbugs.gnu.org; Tue, 05 Dec 2017 18:00:42 -0500 Original-Received: from mail.ericabrahamsen.net ([50.56.99.223]:34719) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMMCc-0008H1-Fz for 29220@debbugs.gnu.org; Tue, 05 Dec 2017 18:00:39 -0500 Original-Received: from localhost (71-212-75-109.tukw.qwest.net [71.212.75.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 5A94DC07C4; Tue, 5 Dec 2017 23:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ericabrahamsen.net; s=mail; t=1512514837; bh=Z7/vrNS6uD+wMKC03BhUB6qPzf06olTHI5XWrQtK5Ug=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=JURd8kS7RRoPWtTen0Yrra6/rX6gSXNcA8M6U6J0dPETm/xRCW2+xnqo3lE1Bkwac d1zh0HfEOA3jHMWzTKfrjgxvZOg8V7wsGZUZbke0mXgx50J66WNx9Gfaa6g5Y8gSM/ b1qIhb5WsEhf513h8L1EVH+Ck1iLX+Et2bwSbTO0= In-Reply-To: (Stefan Monnier's message of "Tue, 05 Dec 2017 17:14:00 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:140748 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/05/17 17:14 PM, Stefan Monnier wrote: > Looks good to me. > > [ While looking at this code, I notice that with cl-defmethod (which can > dispatch not only on EIEIO objects, but other object types as well) > we can now fold eieio-override-prin1 into object-write (i.e. make one > into an alias for the other). ] Yup, I think there's a fair amount of modularization that can be done. I can make that part of the patch on #29541. >> If this is okay, it's going into emacs-26, right? > > I think so, but we're pretty late in the pretest, so better ask Eli&John > if they think it's OK for emacs-26. Okay: John and Eli, this patch is to handle changes in object implementation in Emacs 26: they are now implemented with records, which can't be round-tripped with prin1 and read, they have to be written and read specially. The eieio-persistent mechanism handles that, but previously did not look inside hash tables or vectors to see if there were objects in there. That's causing failure in the pcache library, which other libraries depend on. I'm hoping we can sneak this in under the wire so that pcache doesn't fail in Emacs 26. [...] On 12/05/17 23:20 PM, Pierre T=C3=A9choueyres wrote: > Eric Abrahamsen writes: > >> On 12/05/17 14:02 PM, Stefan Monnier wrote: >>>> Would it be too "heavy" to just copy the object and modify the copy? >>> >>> No, that's fine as well. >> >> Okay, the attached appears to work just fine. Pierre's recipe passes, >> as do all the tests in eieio-test-persist. Pierre, maybe you could eval >> this quickly and make sure that pcache works correctly again? > > Yes all my receipes tests are running fine. Many thanks. > I've tested also with the unicode-fonts package > (http://github.com/rolandwalker/unicode-fonts) from melpa. > Everything seem to work fine. Great! Thanks for testing. Eric --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Handle-hash-tables-and-vectors-when-reading-writing-.patch >From 9f946a968f41e16f7279c72706ccb839dcb7757c Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Tue, 5 Dec 2017 14:41:50 -0800 Subject: [PATCH] Handle hash tables and vectors when reading/writing EIEIO objects * lisp/emacs-lisp/eieio.el (eieio-override-prin1): EIEIO objects printed with `prin1' can no longer be read with `read'. Make sure they are printed with object-write instead, even when they're inside hash tables and vectors. * lisp/emacs-lisp/eieio-base.el (eieio-persistent-validate/fix-slot-value): Check for written representations of objects inside hash tables and vectors, and reconstruct them. --- lisp/emacs-lisp/eieio-base.el | 20 ++++++++++++++++++++ lisp/emacs-lisp/eieio.el | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index 58dcd09d7e..0241f27395 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el @@ -354,6 +354,26 @@ eieio-persistent-validate/fix-slot-value proposed-value)) (t proposed-value)))) + ;; For hash-tables and vectors, the top-level `read' will not + ;; "look inside" member values, so we need to do that + ;; explicitly. + ((hash-table-p proposed-value) + (maphash + (lambda (key value) + (when (class-p (car-safe value)) + (setf (gethash key proposed-value) + (eieio-persistent-convert-list-to-object + value)))) + proposed-value) + proposed-value) + + ((vectorp proposed-value) + (dotimes (i (length proposed-value)) + (when (class-p (car-safe (aref proposed-value i))) + (aset proposed-value i + (eieio-persistent-convert-list-to-object + (aref proposed-value i))))) + proposed-value) ((stringp proposed-value) ;; Else, check for strings, remove properties. diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index d0d2ff5145..ab96547f93 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -926,6 +926,25 @@ eieio-override-prin1 (object-write thing)) ((consp thing) (eieio-list-prin1 thing)) + ((hash-table-p thing) + (let ((copy (copy-hash-table thing))) + (maphash + (lambda (key val) + (setf (gethash key copy) + (read + (with-output-to-string + (eieio-override-prin1 val))))) + copy) + (prin1 copy))) + ((vectorp thing) + (let ((copy (copy-sequence thing))) + (dotimes (i (length copy)) + (aset copy i + (read + (with-output-to-string + (eieio-override-prin1 + (aref copy i)))))) + (prin1 copy))) ((eieio--class-p thing) (princ (eieio--class-print-name thing))) (t (prin1 thing)))) -- 2.15.1 --=-=-=--