aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-03-22 23:24:49 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-03-22 23:24:49 +0100
commit7e2b54760d34064db25fcfcf93e79ebb01994744 (patch)
tree9caa9869898e3e9d20ebd7f9a594dfc044b1e6aa
parentAdd empty constructor for vcomponent. (diff)
downloadcalp-7e2b54760d34064db25fcfcf93e79ebb01994744.tar.gz
calp-7e2b54760d34064db25fcfcf93e79ebb01994744.tar.xz
Fix error when setting attr before ever accessing it.
-rw-r--r--src/guile_interface.scm.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/guile_interface.scm.c b/src/guile_interface.scm.c
index 3d0bff1e..7c6fee6f 100644
--- a/src/guile_interface.scm.c
+++ b/src/guile_interface.scm.c
@@ -74,16 +74,26 @@ SCM_DEFINE (vcomponent_set_attr_x, "%vcomponent-set-attribute!", 3, 0, 0,
vcomponent_push_val(com, key, "");
c = get_property (com, key);
} else {
- /* If the object already exists it should be protected,
- * so unprotect it
+ /*
+ * The SCM representation of an object is usually initialized
+ * when an attribute is first accessed from guile. If we
+ * however try to set it before accessing it then that field
+ * will still be NULL.
+ *
+ * If the object, and its SCM instance exist, unprotect it.
+ * Otherwise we know that it's NULL and safe to write a new
+ * SCM value there.
*/
- scm_gc_unprotect_object(c->cur->value->key.scm);
+ if (c->cur->value->key.scm != NULL) {
+ scm_gc_unprotect_object(c->cur->value->key.scm);
+ }
}
free(key);
- c->cur->value->key.scm = new_value;
- scm_gc_protect_object(c->cur->value->key.scm);
+ strbuf* target = &c->cur->value->key;
+ target->scm = new_value;
+ scm_gc_protect_object(target->scm);
return SCM_UNSPECIFIED;
}