aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-25 23:46:15 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-25 23:56:32 +0100
commit9d479ca655aee6108e92c9d0e46dc4f8d898c89f (patch)
tree9e93ba6cc231e3402c48431983d20697316e61dd
parentAdd GC guards. (diff)
downloadcalp-9d479ca655aee6108e92c9d0e46dc4f8d898c89f.tar.gz
calp-9d479ca655aee6108e92c9d0e46dc4f8d898c89f.tar.xz
Store static reference to SCM version of vcomponent.
-rw-r--r--guile_interface.scm.c1
-rw-r--r--guile_type_helpers.c9
-rw-r--r--guile_type_helpers.h2
-rw-r--r--vcal.c1
-rw-r--r--vcal.h4
5 files changed, 13 insertions, 4 deletions
diff --git a/guile_interface.scm.c b/guile_interface.scm.c
index 120806d8..fa4f2f5f 100644
--- a/guile_interface.scm.c
+++ b/guile_interface.scm.c
@@ -84,7 +84,6 @@ SCM_DEFINE (vcomponent_child_count, "vcomponent-child-count", 1, 0, 0,
return scm_from_size_t (SIZE(VECT(vcomponent))(&c->components));
}
-/* TODO This currently returns a new_ foreign object each time I call it. */
SCM_DEFINE(vcomponent_children, "vcomponent-children", 1, 0, 0,
(SCM component),
"")
diff --git a/guile_type_helpers.c b/guile_type_helpers.c
index 74223bae..00c68b18 100644
--- a/guile_type_helpers.c
+++ b/guile_type_helpers.c
@@ -14,9 +14,12 @@ SCM scm_from_strbuf(strbuf* s) {
SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type) {
SCM l = SCM_EOL;
for (size_t i = 0; i < vect->length; i++) {
- l = scm_cons(
- scm_make_foreign_object_1 (element_type, GET(VECT(vcomponent))(vect, i)),
- l);
+ vcomponent* v = GET(VECT(vcomponent))(vect, i);
+ if (v->scm == NULL) {
+ v->scm = scm_make_foreign_object_1 (element_type, v);
+ scm_gc_protect_object(v->scm);
+ }
+ l = scm_cons(v->scm, l);
}
return scm_reverse(l);
}
diff --git a/guile_type_helpers.h b/guile_type_helpers.h
index bb69312d..427c55c6 100644
--- a/guile_type_helpers.h
+++ b/guile_type_helpers.h
@@ -6,6 +6,8 @@
#include "calendar.h"
#include "strbuf.h"
+#define SCM_IS_LIST(x) scm_is_true(scm_list_p(x))
+
SCM scm_from_strbuf(strbuf* s);
SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type);
diff --git a/vcal.c b/vcal.c
index 2f736892..9aa08c7c 100644
--- a/vcal.c
+++ b/vcal.c
@@ -60,6 +60,7 @@ INIT_F(vcomponent, const char* type, const char* filename) {
strcpy(self->type, type);
self->parent = NULL;
+ self->scm = NULL;
return 0;
}
diff --git a/vcal.h b/vcal.h
index 02a51ff5..bedf22ee 100644
--- a/vcal.h
+++ b/vcal.h
@@ -3,6 +3,8 @@
#include <stdlib.h>
+#include <libguile.h>
+
#include "strbuf.h"
#define TYPE strbuf
@@ -101,6 +103,8 @@ struct s_vcomponent {
vcomponent* parent;
TRIE(content_line) clines;
VECT(vcomponent) components;
+
+ SCM scm;
};
#define FCHILD(v) GET(VECT(vcomponent))(&(v)->components, 0)