From 7bc58226a529293c42e82eba3b37eecf7f5978c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 4 Mar 2019 18:31:00 +0100 Subject: set-attr! can now add new keys. --- guile_interface.scm.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'guile_interface.scm.c') diff --git a/guile_interface.scm.c b/guile_interface.scm.c index 41d13c3c..761bf7c2 100644 --- a/guile_interface.scm.c +++ b/guile_interface.scm.c @@ -68,9 +68,22 @@ SCM_DEFINE (vcomponent_set_attr_x, "%vcomponent-set-attribute!", 3, 0, 0, char* key = scm_to_utf8_stringn(scm_string_upcase(attr), NULL); content_line* c = get_property (com, key); + + /* Create the position in the TRIE if it doesn't already exist */ + if (c == NULL) { + /* Insert empty key since this allows me to use the helper + * function */ + vcomponent_push_val(com, key, ""); + c = get_property (com, key); + } else { + /* If the object already exists it should be protected, + * so unprotect it + */ + scm_gc_unprotect_object(c->cur->value->key.scm); + } + free(key); - scm_gc_unprotect_object(c->cur->value->key.scm); c->cur->value->key.scm = new_value; scm_gc_protect_object(c->cur->value->key.scm); -- cgit v1.2.3