From 7e2b54760d34064db25fcfcf93e79ebb01994744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 22 Mar 2019 23:24:49 +0100 Subject: Fix error when setting attr before ever accessing it. --- src/guile_interface.scm.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3