qof_instance_set/get_kvp cannot handle boolean?

Carsten Rinke carsten.rinke at gmx.de
Wed Sep 21 09:35:36 EDT 2016


Hi,

I try to make use of the "TaxRelated" flag of the accounts by calling 
xaccAccountSetTaxRelated (Account.c).

I notice that on master this does not lead to the same result as on maint.

To figure out what is wrong/different on master I simply added some 
printouts:

========= snip start ===========================

gboolean
xaccAccountGetTaxRelated (const Account *acc)
{
     GValue v = G_VALUE_INIT;
     g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
     qof_instance_get_kvp (QOF_INSTANCE(acc), "tax-related", &v);

if (G_VALUE_HOLDS_BOOLEAN (&v))
printf("G_VALUE_HOLDS_BOOLEAN returns TRUE\n");  <=============
else
printf("G_VALUE_HOLDS_BOOLEAN returns FALSE, actually it is 
%s\n",G_VALUE_TYPE_NAME(&v));  <=============

if (g_value_get_boolean (&v))
printf("g_value_get_boolean returns TRUE\n");  <=============
else
printf("g_value_get_boolean returns FALSE\n");  <=============

     return G_VALUE_HOLDS_BOOLEAN (&v) ? g_value_get_boolean (&v) : FALSE;
}

void
xaccAccountSetTaxRelated (Account *acc, gboolean tax_related)
{
if (tax_related)
printf("Request to set TaxRelated TRUE\n");  <=============
else
printf("Request to set TaxRelated FALSE\n");  <=============

     GValue v = G_VALUE_INIT;
     g_return_if_fail(GNC_IS_ACCOUNT(acc));

     g_value_init (&v, G_TYPE_BOOLEAN);
     g_value_set_boolean (&v, tax_related);

     xaccAccountBeginEdit(acc);
     qof_instance_set_kvp (QOF_INSTANCE (acc), "tax-related", &v);
     mark_account (acc);
     xaccAccountCommitEdit(acc);

if (xaccAccountGetTaxRelated(acc))
printf("TaxRelated is now TRUE\n");  <=============
else
printf("TaxRelated is now FALSE\n");  <=============
}

=========== snip end =========================

The printout shows

Request to set TaxRelated TRUE
G_VALUE_HOLDS_BOOLEAN returns FALSE, actually it is gchararray
g_value_get_boolean returns FALSE
TaxRelated is now FALSE

My suspicion:

in kvp_frame.cpp in function

KvpValue*
kvp_value_from_gvalue (const GValue *gval)

============= snip start ===========
     else if (type == G_TYPE_BOOLEAN)
     {
         auto bval = g_value_get_boolean(gval);
         if (bval)
             val = new KvpValue(g_strdup("true"));
======= snip end =================

the information is lost that the origin is boolean. After this point I 
get lost.

What to do? Open a bug report?

Kind regards,
Carsten



More information about the gnucash-devel mailing list