From aa90c52e43d32d88d4a0fd8d1a42714a1a0adff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 8 Mar 2019 13:53:37 +0100 Subject: Fix error when looking at cloned events. --- guile_interface.scm.c | 8 ++------ strbuf.c | 3 +++ test.scm | 13 +++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/guile_interface.scm.c b/guile_interface.scm.c index a134848d..a5921869 100644 --- a/guile_interface.scm.c +++ b/guile_interface.scm.c @@ -25,9 +25,7 @@ SCM_DEFINE (make_vcomponent, "%vcomponent-make", 1, 0, 0, read_vcalendar(cal, p); free(p); - return scm_make_foreign_object_1 - (vcomponent_type, cal); - + return scm_from_vcomponent (cal); } /* @@ -188,10 +186,8 @@ SCM_DEFINE(vcomponent_shallow_copy, "%vcomponent-shallow-copy", 1, 0, 0, (vcomponent*) scm_gc_malloc ( sizeof(*dest), "vcomponent"); INIT(vcomponent, dest, src->type, NULL); - vcomponent_copy (dest, src); - return scm_make_foreign_object_1 - (vcomponent_type, dest); + return scm_from_vcomponent (dest); } void init_lib (void) { diff --git a/strbuf.c b/strbuf.c index 455100a2..0e56468b 100644 --- a/strbuf.c +++ b/strbuf.c @@ -70,7 +70,10 @@ int DEEP_COPY(strbuf)(strbuf* dest, strbuf* src) { } if (src->scm != NULL) { + /* The magic SCM type is copied when reassigned. */ dest->scm = src->scm; + /* NOTE This is a bit of a leaky abstraction. */ + scm_gc_protect_object(dest->scm); } dest->len = src->len; diff --git a/test.scm b/test.scm index 536944b2..eaf5e311 100755 --- a/test.scm +++ b/test.scm @@ -22,6 +22,8 @@ (assert (equal? (children ev) (children ev-copy))) +(define strm (recur-event ev)) + (stream-for-each (lambda (ev) (format #t "~a -- ~a~%" @@ -29,8 +31,11 @@ (time->string (attr ev "DTEND") "~1 ~3"))) (stream-take 10 (recur-event ev))) -(define stream-cadr (compose stream-car stream-cdr)) - (newline) -(display (time->string (attr ev "DTSTART") "~1 ~3")) (newline) -(display (time->string (attr (stream-cadr (recur-event ev)) "DTSTART") "~1 ~3")) (newline) + +(for-each + (lambda (ev) + (format #t "~a -- ~a~%" + (time->string (attr ev "DTSTART") "~1 ~3") + (time->string (attr ev "DTEND") "~1 ~3"))) + (stream->list (stream-take 20 (recur-event ev)))) -- cgit v1.2.3