Thanks, Andy, for your reply -- with your patch, save-objects now completes.

However, it still appears not to create output with enough information
to re-create the objects.  If I do this...:

$ cat persistence-test.scm
(use-modules (oop goops))
(use-modules (oop goops describe))
(use-modules (oop goops save))

;; Apply Andy's fix to the readable? function
(set! (@@ (oop goops save) readable?)
        (lambda (x) (hashq-ref (@@ (oop goops save) readables) x)))

;; make a new class, make an instance of it, and show it
(define-class <ag-complex> (<number>) r i)
(define c (make <ag-complex>))
(slot-set! c 'r 3)
(slot-set! c 'i 4)
(describe c)

;; persist the instance
(define a '())
(set! a (acons 'c c a))
(save-objects a (current-output-port))

$ guile ./persistence-test.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/apg/t/./persistence-test.scm
;;; compiled
/home/apg/.cache/guile/ccache/2.0-LE-4-2.0/home/apg/t/persistence-test.scm.go
#<<ag-complex> 932ace0> is an instance of class <ag-complex>
Slots are:
     r = 3
     i = 4
(define c '#<<ag-complex> 932ace0>)

... then that last line, which is the output of save-objects,  doesn't look
sufficient
(to my untrained eye, at any rate) to re-create the object in a
freshly-launched
guile in a new address space.  I'd expect it to contain the values for the
slots
as shown in the output from 'describe', as well as the class definition.

My assumptions derive from these comments in oop/goops/save.scm:

*;;; Save OBJECT ... to PORT so that when the data is read and evaluated
;;; OBJECT ... are re-created under names NAME ... .

*
What am I missing?

- Andrew


On Sun, Jan 20, 2013 at 10:15 PM, Andy Wingo <[email protected]> wrote:

> Hi,
>
> On Fri 18 Jan 2013 11:25, Andrew Gaylard <[email protected]> writes:
>
> > I'm trying to persist a GOOPS object.
> >
> > I've found oop/goops/save.scm, which defines save-object.
> > That looks like what I need.
>
> Cool.  I don't know of anyone that has used this code in many years, so
> be prepared for some bugs.  OTOH if it works fine, documentation is
> appreciated :)
>
> > scheme@(guile-user)> (save-objects l (current-output-port))
> > (define c 'c)
> > ERROR: In procedure hashq-get-handle:
> > ERROR: In procedure hashq-get-handle: Handle access not permitted on
> > weak table
>
> This is an implementation bug, introduced May 2011 by a change to the
> weak table interface.  See commit
> 1d9c2e6271105ee0f728127d9b544432b7cc0f4f for full details.
>
> I have fixed this in stable-2.0.  You can fix in in your copy by:
>
>   (set! (@@ (oop goops save) readable?)
>         (lambda (x) (hashq-ref (@@ (oop goops save) readables) x)))
>
> Regards,
>
> Andy
> --
> http://wingolog.org/
>

Reply via email to