aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-25 23:45:49 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-25 23:45:49 +0100
commitb99692e7b9c66d0ae692fa4212471277a24251a2 (patch)
treea91dd7e3faf1ad55926d2afdc6ac6c1d69c0468c
parentAdd scm field to strbuf. (diff)
downloadcalp-b99692e7b9c66d0ae692fa4212471277a24251a2.tar.gz
calp-b99692e7b9c66d0ae692fa4212471277a24251a2.tar.xz
Add GC guards.
-rw-r--r--guile_interface.h10
-rw-r--r--guile_interface.scm.c2
-rw-r--r--guile_type_helpers.c1
3 files changed, 12 insertions, 1 deletions
diff --git a/guile_interface.h b/guile_interface.h
index 4864407f..3776d88c 100644
--- a/guile_interface.h
+++ b/guile_interface.h
@@ -3,7 +3,15 @@
#include <libguile.h>
-#define SCM_IS_LIST(x) scm_is_true(scm_list_p(x))
+/*
+ * At a number of places scm_gc_{un,}protect_object is called.
+ * This is needed since most of my structures are allocated with the
+ * regular malloc, instead of the scm_gc_malloc variants.
+ * This leads to the garbage collector not realizing that I still have
+ * the components, and deletes them.
+ *
+ * The protection markers stop the GC from doing its thing.
+ */
void init_vcomponent ();
void init_vcomponent_type (void);
diff --git a/guile_interface.scm.c b/guile_interface.scm.c
index 6b9de8dc..120806d8 100644
--- a/guile_interface.scm.c
+++ b/guile_interface.scm.c
@@ -68,7 +68,9 @@ SCM_DEFINE (vcomponent_set_attr_x, "vcomponent-set-attribute!", 3, 0, 0,
// TODO if list is a value store it as is, else wrap it in a list
// of length one.
+ scm_gc_unprotect_object(c->val.cur->value->key.scm);
c->val.cur->value->key.scm = new_value;
+ scm_gc_protect_object(c->val.cur->value->key.scm);
return SCM_UNSPECIFIED;
}
diff --git a/guile_type_helpers.c b/guile_type_helpers.c
index 485827a0..74223bae 100644
--- a/guile_type_helpers.c
+++ b/guile_type_helpers.c
@@ -5,6 +5,7 @@
SCM scm_from_strbuf(strbuf* s) {
if (s->scm == NULL) {
s->scm = scm_from_utf8_stringn (s->mem, s->len - 1);
+ scm_gc_protect_object(s->scm);
}
return s->scm;