Skip to content

Commit

Permalink
[gnc-optiondb.i] instead of scm_list_ref, walk the list
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Jul 27, 2024
1 parent 3e5d6a5 commit 664b1cb
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions bindings/guile/gnc-optiondb.i
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,9 @@ gnc_option_test_book_destroy(QofBook* book)

%typemap(in) RelativeDatePeriodVec& (RelativeDatePeriodVec period_set)
{
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM s_reldateperiod = scm_list_ref($input, scm_from_size_t(i));
SCM s_reldateperiod = scm_car (node);
period_set.push_back(scm_relative_date_get_period(s_reldateperiod));
}
$1 = &period_set;
Expand All @@ -607,10 +606,9 @@ gnc_option_test_book_destroy(QofBook* book)
{
if (scm_is_true($input))
{
auto len{scm_to_size_t(scm_length($input))};
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
auto val{scm_list_ref($input, scm_from_size_t(i))};
auto val{scm_car (node)};
if (scm_is_unsigned_integer(val, 0, UINT_MAX))
indexes.push_back(scm_to_unsigned_integer(val, 0, UINT_MAX));
}
Expand All @@ -621,10 +619,9 @@ gnc_option_test_book_destroy(QofBook* book)
%typemap(in) GncMultichoiceOptionChoices&& (GncMultichoiceOptionChoices choices)
{
using KeyType = GncOptionMultichoiceKeyType;
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM vec = scm_list_ref($input, scm_from_size_t(i));
SCM vec = scm_car (node);
SCM keyval, v_ref_0 = SCM_SIMPLE_VECTOR_REF(vec, 0);
GncOptionMultichoiceKeyType keytype;
if (scm_is_symbol(v_ref_0))
Expand Down Expand Up @@ -656,10 +653,9 @@ gnc_option_test_book_destroy(QofBook* book)

%typemap(in) GncOptionAccountList
{
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM s_account = scm_list_ref($input, scm_from_size_t(i));
SCM s_account = scm_car (node);
Account* acct = (Account*)SWIG_MustGetPtr(s_account,
SWIGTYPE_p_Account, 1, 0);
if (GNC_IS_ACCOUNT(acct))
Expand All @@ -669,10 +665,9 @@ gnc_option_test_book_destroy(QofBook* book)

%typemap(in) GncOptionAccountTypeList& (GncOptionAccountTypeList types)
{
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM s_type = scm_list_ref($input, scm_from_size_t(i));
SCM s_type = scm_car (node);
GNCAccountType type = (GNCAccountType)scm_to_int(s_type);
types.push_back(type);
}
Expand All @@ -681,10 +676,9 @@ gnc_option_test_book_destroy(QofBook* book)

%typemap(in) GncOptionAccountTypeList&& (GncOptionAccountTypeList types)
{
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM s_type = scm_list_ref($input, scm_from_size_t(i));
SCM s_type = scm_car (node);
GNCAccountType type = (GNCAccountType)scm_to_int(s_type);
types.push_back(type);
}
Expand All @@ -693,10 +687,9 @@ gnc_option_test_book_destroy(QofBook* book)

%typemap(in) GncOptionAccountList const & (GncOptionAccountList alist)
{
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM s_account = scm_list_ref($input, scm_from_size_t(i));
SCM s_account = scm_car (node);
Account* acct = (Account*)SWIG_MustGetPtr(s_account,
SWIGTYPE_p_Account, 1, 0);
if (GNC_IS_ACCOUNT(acct))
Expand All @@ -709,9 +702,9 @@ gnc_option_test_book_destroy(QofBook* book)
{
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
acclist.reserve(len);
for (std::size_t i = 0; i < len; ++i)
for (SCM node = $input; !scm_is_null (node); node = scm_cdr (node))
{
SCM s_account = scm_list_ref($input, scm_from_size_t(i));
SCM s_account = scm_car (node);
Account* acct = (Account*)SWIG_MustGetPtr(s_account,
SWIGTYPE_p_Account, 1, 0);
if (!GNC_IS_ACCOUNT(acct)) continue;
Expand Down Expand Up @@ -1019,10 +1012,9 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
{
if (!choice_is_list)
throw std::invalid_argument{"Attempt to set multichoice with a list of values."};
auto len{scm_to_size_t(scm_length(new_value))};
for (std::size_t i = 0; i < len; ++i)
for (SCM node = new_value; !scm_is_null (node); node = scm_cdr (node))
{
auto item{scm_list_ref(new_value, scm_from_size_t(i))};
auto item{scm_car (node)};
auto item_str{scm_to_str(item)};
auto index{option.permissible_value_index(item_str)};
free (item_str);
Expand Down

0 comments on commit 664b1cb

Please sign in to comment.