From: pierre.techoueyres@free.fr (Pierre Téchoueyres)
To: Noam Postavsky <npostavs@users.sourceforge.net>
Cc: Eric Abrahamsen <eric@ericabrahamsen.net>,
jwiegley@gmail.com, 29220@debbugs.gnu.org,
monnier@iro.umontreal.ca
Subject: bug#29220: 26.0.90; eieio-persistent-read fail to restore saved object.
Date: Fri, 15 Dec 2017 23:26:17 +0100 [thread overview]
Message-ID: <87wp1nsk52.fsf@killashandra.ballybran.fr> (raw)
In-Reply-To: <87mv2jkaap.fsf@killashandra.ballybran.fr> ("Pierre \=\?utf-8\?Q\?T\=C3\=A9choueyres\=22's\?\= message of "Fri, 15 Dec 2017 21:26:06 +0100")
[-- Attachment #1: Type: text/plain, Size: 71 bytes --]
Of course with the good example and patch this will be more obvious.
[-- Attachment #2: Simple tests eieio-persistent class --]
[-- Type: text/plain, Size: 724 bytes --]
;;; -*- lexical-binding: t -*-
(require 'eieio)
(require 'eieio-base)
(defclass person ()
((name :type string :initarg :name)))
(defclass classy (eieio-persistent)
((teacher
:type person
:initarg :teacher)
(students
:initarg :students :initform (make-hash-table :test 'equal))))
(let* ((jane (make-instance 'person :name "Jane"))
(bob (make-instance 'person :name "Bob"))
(class (make-instance 'classy
:teacher jane
:file (concat "classy-" emacs-version ".eieio"))))
(puthash "Bob" bob (slot-value class 'students))
(eieio-persistent-save class (concat "classy-" emacs-version ".eieio"))
(eieio-persistent-read (concat "classy-" emacs-version ".eieio") 'classy t))
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: Tests for eieio-persistent class --]
[-- Type: text/x-patch, Size: 4207 bytes --]
From 26341ec498e4ffdea1a3c8173c3831c01a745bb9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre=20T=C3=A9choueyres?= <pierre.techoueyres@free.fr>
Date: Fri, 15 Dec 2017 21:42:21 +0100
Subject: [PATCH] Add test for eieio persistence checks
* test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el:
(hash-equal): New comparaison test for hash-tables.
(persist-test-save-and-compare): specialize test for hash-tables.
(eieio-test-persist-hash-and-objects): New test.
---
.../emacs-lisp/eieio-tests/eieio-test-persist.el | 58 +++++++++++++++++++---
1 file changed, 50 insertions(+), 8 deletions(-)
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el b/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
index 738711c9c8..cfc51e42a2 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
@@ -1,4 +1,4 @@
-;;; eieio-persist.el --- Tests for eieio-persistent class
+;;; eieio-test-persist.el --- Tests for eieio-persistent class
;; Copyright (C) 2011-2017 Free Software Foundation, Inc.
@@ -40,6 +40,17 @@ eieio--attribute-to-initarg
(car tuple)
nil)))
+(defun hash-equal (hash1 hash2)
+ "Compare two hash tables to see whether they are equal."
+ (and (= (hash-table-count hash1)
+ (hash-table-count hash2))
+ (catch 'flag
+ (maphash (lambda (x y)
+ (or (equal (gethash x hash2) y)
+ (throw 'flag nil)))
+ hash1)
+ (throw 'flag t))))
+
(defun persist-test-save-and-compare (original)
"Compare the object ORIGINAL against the one read fromdisk."
@@ -49,8 +60,8 @@ persist-test-save-and-compare
(class (eieio-object-class original))
(fromdisk (eieio-persistent-read file class))
(cv (cl--find-class class))
- (slots (eieio--class-slots cv))
- )
+ (slots (eieio--class-slots cv)))
+
(unless (object-of-class-p fromdisk class)
(error "Persistent class %S != original class %S"
(eieio-object-class fromdisk)
@@ -62,17 +73,24 @@ persist-test-save-and-compare
(origvalue (eieio-oref original oneslot))
(fromdiskvalue (eieio-oref fromdisk oneslot))
(initarg-p (eieio--attribute-to-initarg
- (cl--find-class class) oneslot))
- )
+ (cl--find-class class) oneslot)))
(if initarg-p
- (unless (equal origvalue fromdiskvalue)
+ (unless
+ (cond ((and (hash-table-p origvalue) (hash-table-p fromdiskvalue))
+ (hash-equal origvalue fromdiskvalue))
+ (t (equal origvalue fromdiskvalue)))
(error "Slot %S Original Val %S != Persistent Val %S"
oneslot origvalue fromdiskvalue))
;; Else !initarg-p
- (unless (equal (cl--slot-descriptor-initform slot) fromdiskvalue)
+ (let ((origval (cl--slot-descriptor-initform slot))
+ (diskval fromdiskvalue))
+ (unless
+ (cond ((and (hash-table-p origval) (hash-table-p diskval))
+ (hash-equal origval diskval))
+ (t (equal origval diskval)))
(error "Slot %S Persistent Val %S != Default Value %S"
- oneslot fromdiskvalue (cl--slot-descriptor-initform slot))))
+ oneslot diskval origvalue))))
))))
;;; Simple Case
@@ -238,4 +256,28 @@ persistent-with-objs-list-slot
(persist-test-save-and-compare persist-wols)
(delete-file (oref persist-wols file))))
+(defclass person ()
+ ((name :type string :initarg :name)))
+
+(defclass classy (eieio-persistent)
+ ((teacher
+ :type person
+ :initarg :teacher)
+ (students
+ :initarg :students :initform (make-hash-table :test 'equal))))
+
+;;; Slot with a hash-table another with an non persistent Object
+;;
+;; see bug#29220
+(ert-deftest eieio-test-persist-hash-and-objects ()
+ (let* ((jane (make-instance 'person :name "Jane"))
+ (bob (make-instance 'person :name "Bob"))
+ (class (make-instance 'classy
+ :teacher jane
+ :file (concat default-directory "classy-" emacs-version ".eieio"))))
+ (puthash "Bob" bob (slot-value class 'students))
+ (persist-test-save-and-compare class)
+ (delete-file (oref class file))))
+
+
;;; eieio-test-persist.el ends here
--
2.14.3
next prev parent reply other threads:[~2017-12-15 22:26 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-08 22:04 bug#29220: 26.0.90; eieio-persistent-read fail to restore saved object Pierre Téchoueyres
2017-11-08 22:48 ` Eric Abrahamsen
2017-11-10 17:31 ` Pierre Téchoueyres
2017-11-10 18:12 ` Eric Abrahamsen
2017-11-10 18:32 ` Pierre Téchoueyres
2017-11-12 19:10 ` Noam Postavsky
2017-11-14 22:30 ` Pierre Téchoueyres
2017-11-15 2:02 ` Noam Postavsky
2017-11-15 15:29 ` Stefan Monnier
2017-11-17 19:56 ` Pierre Téchoueyres
2017-11-18 3:40 ` Noam Postavsky
2017-11-18 4:39 ` Eric Abrahamsen
2017-11-18 13:24 ` Noam Postavsky
2017-11-18 18:14 ` Eric Abrahamsen
2017-11-19 3:17 ` Noam Postavsky
2017-11-19 5:57 ` Eric Abrahamsen
2017-11-23 23:20 ` Pierre Téchoueyres
2017-11-24 0:09 ` Noam Postavsky
2017-11-28 21:39 ` Pierre Téchoueyres
2017-11-28 21:52 ` Noam Postavsky
2017-11-28 22:18 ` Pierre Téchoueyres
2017-11-29 1:09 ` Noam Postavsky
2017-11-29 15:18 ` Stefan Monnier
2017-11-28 22:10 ` Eric Abrahamsen
2017-11-29 15:15 ` Stefan Monnier
2017-12-01 17:25 ` Eric Abrahamsen
2017-12-01 17:55 ` Stefan Monnier
2017-12-03 0:17 ` Eric Abrahamsen
2017-12-03 18:35 ` Pierre Téchoueyres
2017-12-05 1:27 ` Eric Abrahamsen
2017-12-05 2:08 ` Stefan Monnier
2017-12-05 17:47 ` Eric Abrahamsen
2017-12-05 19:02 ` Stefan Monnier
2017-12-05 20:56 ` Eric Abrahamsen
2017-12-05 22:14 ` Stefan Monnier
2017-12-05 22:58 ` Eric Abrahamsen
2017-12-08 10:41 ` Eli Zaretskii
2017-12-09 16:59 ` Eric Abrahamsen
2017-12-12 23:21 ` Noam Postavsky
2017-12-15 20:26 ` Pierre Téchoueyres
2017-12-15 22:26 ` Pierre Téchoueyres [this message]
2017-12-16 23:42 ` Eric Abrahamsen
2018-02-20 19:50 ` Pierre Téchoueyres
2018-02-24 21:23 ` Eric Abrahamsen
2018-02-24 23:21 ` Pierre Téchoueyres
2018-02-24 23:40 ` Eric Abrahamsen
2018-02-25 0:34 ` Pierre Téchoueyres
2018-02-25 18:59 ` Eric Abrahamsen
2019-05-27 23:36 ` Noam Postavsky
2019-05-28 21:17 ` Eric Abrahamsen
2019-05-30 22:50 ` Noam Postavsky
2017-12-18 19:52 ` Eric Abrahamsen
2017-12-18 21:38 ` Stefan Monnier
2017-12-20 18:29 ` Eric Abrahamsen
2017-12-20 20:54 ` Stefan Monnier
2017-12-21 2:21 ` Eric Abrahamsen
2017-12-24 2:18 ` Eric Ludlam
2017-12-28 18:44 ` Eric Abrahamsen
2017-12-05 22:20 ` Pierre Téchoueyres
2018-01-24 19:17 ` Pierre Téchoueyres
2018-01-25 3:09 ` Eric Abrahamsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wp1nsk52.fsf@killashandra.ballybran.fr \
--to=pierre.techoueyres@free.fr \
--cc=29220@debbugs.gnu.org \
--cc=eric@ericabrahamsen.net \
--cc=jwiegley@gmail.com \
--cc=monnier@iro.umontreal.ca \
--cc=npostavs@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.