Skip to content

Commit

Permalink
partial changes
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Apr 8, 2022
1 parent 221f77d commit 6d77c3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions bindings/guile/gnc-kvp-guile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ extern "C"

static bool scm_is_list_of_string_pairs (SCM val)
{
restart:
if (scm_is_null (val)) return true;
if (!scm_is_pair (val)) return false;
if (!scm_is_pair (scm_car (val))) return false;
if (!scm_is_string (scm_caar (val))) return false;
val = scm_cdr (val);
goto restart; // poor man's tailcall optimization
if (scm_is_null (val))
return false; // A null value on the original val is not a list of pairs
for (; !scm_is_null (val); val = scm_cdr (val))
{
if (!(scm_is_pair (val) && scm_is_pair (scm_car (val)) &&
scm_is_string (scm_caar (val))))
return false;
}
return true;
}

KvpValue *
Expand Down Expand Up @@ -74,7 +76,7 @@ gnc_scm_to_kvp_value_ptr(SCM val)
else if (scm_is_list_of_string_pairs (val))
{
auto frame = new KvpFrame;
for (SCM n = val; !scm_is_null (val); val = scm_cdr (val))
for (; !scm_is_null (val); val = scm_cdr (val))
{
auto key_str = scm_to_utf8_stringn (scm_caar (val), nullptr);
auto val_scm = scm_cdar (val);
Expand All @@ -89,9 +91,9 @@ gnc_scm_to_kvp_value_ptr(SCM val)
else if (scm_is_list (val))
{
GList *kvplist = nullptr;
for (SCM node = val; !scm_is_null (node); node = scm_cdr (node))
for (; !scm_is_null (val); node = scm_cdr (val))
{
auto elt = gnc_scm_to_kvp_value_ptr (scm_car (node));
auto elt = gnc_scm_to_kvp_value_ptr (scm_car (val));
kvplist = g_list_prepend (kvplist, elt);
}
return new KvpValue (g_list_reverse (kvplist));
Expand Down
2 changes: 1 addition & 1 deletion bindings/guile/test/test-scm-apputils.scm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'(("lvl2" ("lvl3" . "baf")))
(qof-book-get-option book '("top" "lvl1c")))

;; this tests the reading & writing of hash-table, copying branch
;; this tests the reading & writing of KvpFrame, copying branch
;; from top/lvl1c to top/lvl1d
(qof-book-set-option book
(qof-book-get-option book '("top" "lvl1c"))
Expand Down

0 comments on commit 6d77c3c

Please sign in to comment.