[Account] g_value_unset

This commit is contained in:
Christopher Lam 2021-06-06 22:58:47 +08:00
parent bfdec74a48
commit c8a7b9edb3

View File

@ -2481,6 +2481,7 @@ set_kvp_string_tag (Account *acc, const char *tag, const char *value)
g_value_init (&v, G_TYPE_STRING); g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, tmp); g_value_set_string (&v, tmp);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {tag}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {tag});
g_value_unset (&v);
} }
else else
qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, {tag}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, {tag});
@ -4036,21 +4037,24 @@ set_boolean_key (Account *acc, std::vector<std::string> const & path, gboolean o
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path);
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
static gboolean static gboolean
boolean_from_key (const Account *acc, std::vector<std::string> const & path) boolean_from_key (const Account *acc, std::vector<std::string> const & path)
{ {
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
gboolean retval = FALSE;
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, path); qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, path);
if (G_VALUE_HOLDS_INT64 (&v)) if (G_VALUE_HOLDS_INT64 (&v))
return g_value_get_int64 (&v) != 0; retval = (g_value_get_int64 (&v) != 0);
if (G_VALUE_HOLDS_BOOLEAN (&v)) if (G_VALUE_HOLDS_BOOLEAN (&v))
return g_value_get_boolean (&v); retval = (g_value_get_boolean (&v));
if (G_VALUE_HOLDS_STRING (&v)) if (G_VALUE_HOLDS_STRING (&v))
return strcmp (g_value_get_string (&v), "true") == 0; retval = !strcmp (g_value_get_string (&v), "true");
return FALSE; g_value_unset (&v);
return retval;
} }
/********************************************************************\ /********************************************************************\
@ -4090,6 +4094,7 @@ xaccAccountSetTaxUSCode (Account *acc, const char *code)
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "code"}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "code"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
const char * const char *
@ -4113,6 +4118,7 @@ xaccAccountSetTaxUSPayerNameSource (Account *acc, const char *source)
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "payer-name-source"}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "payer-name-source"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
gint64 gint64
@ -4125,6 +4131,7 @@ xaccAccountGetTaxUSCopyNumber (const Account *acc)
if (G_VALUE_HOLDS_INT64 (&v)) if (G_VALUE_HOLDS_INT64 (&v))
copy_number = g_value_get_int64 (&v); copy_number = g_value_get_int64 (&v);
g_value_unset (&v);
return (copy_number == 0) ? 1 : copy_number; return (copy_number == 0) ? 1 : copy_number;
} }
@ -4139,6 +4146,7 @@ xaccAccountSetTaxUSCopyNumber (Account *acc, gint64 copy_number)
g_value_init (&v, G_TYPE_INT64); g_value_init (&v, G_TYPE_INT64);
g_value_set_int64 (&v, copy_number); g_value_set_int64 (&v, copy_number);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "copy-number"}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "copy-number"});
g_value_unset (&v);
} }
else else
{ {
@ -4627,18 +4635,21 @@ xaccAccountGetReconcileLastDate (const Account *acc, time64 *last_date)
{ {
gint64 date = 0; gint64 date = 0;
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
gboolean retval = FALSE;
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, {KEY_RECONCILE_INFO, "last-date"}); qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, {KEY_RECONCILE_INFO, "last-date"});
if (G_VALUE_HOLDS_INT64 (&v)) if (G_VALUE_HOLDS_INT64 (&v))
date = g_value_get_int64 (&v); date = g_value_get_int64 (&v);
g_value_unset (&v);
if (date) if (date)
{ {
if (last_date) if (last_date)
*last_date = date; *last_date = date;
return TRUE; retval = TRUE;
} }
return FALSE; g_value_unset (&v);
return retval;
} }
/********************************************************************\ /********************************************************************\
@ -4656,6 +4667,7 @@ xaccAccountSetReconcileLastDate (Account *acc, time64 last_date)
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {KEY_RECONCILE_INFO, "last-date"}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {KEY_RECONCILE_INFO, "last-date"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
/********************************************************************\ /********************************************************************\
@ -4667,6 +4679,7 @@ xaccAccountGetReconcileLastInterval (const Account *acc,
{ {
GValue v1 = G_VALUE_INIT, v2 = G_VALUE_INIT; GValue v1 = G_VALUE_INIT, v2 = G_VALUE_INIT;
int64_t m = 0, d = 0; int64_t m = 0, d = 0;
gboolean retval = FALSE;
if (!acc) return FALSE; if (!acc) return FALSE;
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
@ -4684,9 +4697,11 @@ xaccAccountGetReconcileLastInterval (const Account *acc,
*months = m; *months = m;
if (days) if (days)
*days = d; *days = d;
return TRUE; retval = TRUE;
} }
return FALSE; g_value_unset (&v1);
g_value_unset (&v2);
return retval;
} }
/********************************************************************\ /********************************************************************\
@ -4709,6 +4724,8 @@ xaccAccountSetReconcileLastInterval (Account *acc, int months, int days)
{KEY_RECONCILE_INFO, "last-interval", "days"}); {KEY_RECONCILE_INFO, "last-interval", "days"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v1);
g_value_unset (&v2);
} }
/********************************************************************\ /********************************************************************\
@ -4718,6 +4735,7 @@ gboolean
xaccAccountGetReconcilePostponeDate (const Account *acc, time64 *postpone_date) xaccAccountGetReconcilePostponeDate (const Account *acc, time64 *postpone_date)
{ {
gint64 date = 0; gint64 date = 0;
gboolean retval = FALSE;
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v,
@ -4729,9 +4747,10 @@ xaccAccountGetReconcilePostponeDate (const Account *acc, time64 *postpone_date)
{ {
if (postpone_date) if (postpone_date)
*postpone_date = date; *postpone_date = date;
return TRUE; retval = TRUE;
} }
return FALSE; g_value_unset (&v);
return retval;
} }
/********************************************************************\ /********************************************************************\
@ -4750,6 +4769,7 @@ xaccAccountSetReconcilePostponeDate (Account *acc, time64 postpone_date)
{KEY_RECONCILE_INFO, KEY_POSTPONE, "date"}); {KEY_RECONCILE_INFO, KEY_POSTPONE, "date"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
/********************************************************************\ /********************************************************************\
@ -4761,20 +4781,22 @@ xaccAccountGetReconcilePostponeBalance (const Account *acc,
{ {
gnc_numeric bal = gnc_numeric_zero (); gnc_numeric bal = gnc_numeric_zero ();
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
gboolean retval = FALSE;
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v,
{KEY_RECONCILE_INFO, KEY_POSTPONE, "balance"}); {KEY_RECONCILE_INFO, KEY_POSTPONE, "balance"});
if (!G_VALUE_HOLDS_INT64 (&v)) if (G_VALUE_HOLDS_INT64 (&v))
return FALSE; {
bal = *(gnc_numeric*)g_value_get_boxed (&v); bal = *(gnc_numeric*)g_value_get_boxed (&v);
if (!bal.denom) if (bal.denom)
return FALSE; {
if (balance) if (balance)
*balance = bal; *balance = bal;
retval = TRUE;
return TRUE; }
}
g_value_unset (&v);
return retval;
} }
/********************************************************************\ /********************************************************************\
@ -4793,6 +4815,7 @@ xaccAccountSetReconcilePostponeBalance (Account *acc, gnc_numeric balance)
{KEY_RECONCILE_INFO, KEY_POSTPONE, "balance"}); {KEY_RECONCILE_INFO, KEY_POSTPONE, "balance"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
/********************************************************************\ /********************************************************************\
@ -4837,6 +4860,7 @@ xaccAccountSetLastNum (Account *acc, const char *num)
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"last-num"}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"last-num"});
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
static Account * static Account *
@ -4909,6 +4933,7 @@ xaccAccountGainsAccount (Account *acc, gnc_commodity *curr)
g_value_set_boxed (&vr, guid); g_value_set_boxed (&vr, guid);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &vr, path); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &vr, path);
qof_instance_set_dirty (QOF_INSTANCE (acc)); qof_instance_set_dirty (QOF_INSTANCE (acc));
g_value_unset (&vr);
} }
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
} }
@ -4916,6 +4941,7 @@ xaccAccountGainsAccount (Account *acc, gnc_commodity *curr)
gains_account = xaccAccountLookup (guid, gains_account = xaccAccountLookup (guid,
qof_instance_get_book(acc)); qof_instance_get_book(acc));
g_value_unset (&v);
return gains_account; return gains_account;
} }
@ -4936,6 +4962,7 @@ dxaccAccountSetPriceSrc(Account *acc, const char *src)
g_value_init (&v, G_TYPE_STRING); g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, src); g_value_set_string (&v, src);
qof_instance_set_path_kvp (QOF_INSTANCE(acc), &v, {"old-price-source"}); qof_instance_set_path_kvp (QOF_INSTANCE(acc), &v, {"old-price-source"});
g_value_unset (&v);
} }
else else
qof_instance_set_path_kvp (QOF_INSTANCE(acc), nullptr, {"old-price-source"}); qof_instance_set_path_kvp (QOF_INSTANCE(acc), nullptr, {"old-price-source"});
@ -5010,6 +5037,7 @@ xaccAccountSetReconcileChildrenStatus(Account *acc, gboolean status)
{KEY_RECONCILE_INFO, KEY_INCLUDE_CHILDREN}); {KEY_RECONCILE_INFO, KEY_INCLUDE_CHILDREN});
mark_account(acc); mark_account(acc);
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_value_unset (&v);
} }
/********************************************************************\ /********************************************************************\
@ -5023,10 +5051,13 @@ xaccAccountGetReconcileChildrenStatus(const Account *acc)
* the default behaviour * the default behaviour
*/ */
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
gboolean retval;
if (!acc) return FALSE; if (!acc) return FALSE;
qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v,
{KEY_RECONCILE_INFO, KEY_INCLUDE_CHILDREN}); {KEY_RECONCILE_INFO, KEY_INCLUDE_CHILDREN});
return G_VALUE_HOLDS_INT64 (&v) ? g_value_get_int64 (&v) : FALSE; retval = G_VALUE_HOLDS_INT64 (&v) ? g_value_get_int64 (&v) : FALSE;
g_value_unset (&v);
return retval;
} }
/********************************************************************\ /********************************************************************\
@ -5399,6 +5430,7 @@ gnc_account_imap_find_account (GncImportMatchMap *imap,
{ {
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
GncGUID * guid = NULL; GncGUID * guid = NULL;
Account *retval;
if (!imap || !key) return NULL; if (!imap || !key) return NULL;
std::vector<std::string> path {IMAP_FRAME}; std::vector<std::string> path {IMAP_FRAME};
if (category) if (category)
@ -5407,7 +5439,9 @@ gnc_account_imap_find_account (GncImportMatchMap *imap,
qof_instance_get_path_kvp (QOF_INSTANCE (imap->acc), &v, path); qof_instance_get_path_kvp (QOF_INSTANCE (imap->acc), &v, path);
if (G_VALUE_HOLDS_BOXED (&v)) if (G_VALUE_HOLDS_BOXED (&v))
guid = (GncGUID*)g_value_get_boxed (&v); guid = (GncGUID*)g_value_get_boxed (&v);
return xaccAccountLookup (guid, imap->book); retval = xaccAccountLookup (guid, imap->book);
g_value_unset (&v);
return retval;
} }
/* Store an Account in the map */ /* Store an Account in the map */
@ -5429,6 +5463,7 @@ gnc_account_imap_add_account (GncImportMatchMap *imap,
qof_instance_set_path_kvp (QOF_INSTANCE (imap->acc), &v, path); qof_instance_set_path_kvp (QOF_INSTANCE (imap->acc), &v, path);
qof_instance_set_dirty (QOF_INSTANCE (imap->acc)); qof_instance_set_dirty (QOF_INSTANCE (imap->acc));
xaccAccountCommitEdit (imap->acc); xaccAccountCommitEdit (imap->acc);
g_value_unset (&v);
} }
/* Remove a reference to an Account in the map */ /* Remove a reference to an Account in the map */
@ -5798,6 +5833,7 @@ change_imap_entry (GncImportMatchMap *imap, std::string const & path, int64_t to
// Add or Update the entry based on guid // Add or Update the entry based on guid
qof_instance_set_path_kvp (QOF_INSTANCE (imap->acc), &value, {path}); qof_instance_set_path_kvp (QOF_INSTANCE (imap->acc), &value, {path});
gnc_features_set_used (imap->book, GNC_FEATURE_GUID_FLAT_BAYESIAN); gnc_features_set_used (imap->book, GNC_FEATURE_GUID_FLAT_BAYESIAN);
g_value_unset (&value);
} }
/** Updates the imap for a given account using a list of tokens */ /** Updates the imap for a given account using a list of tokens */
@ -5968,6 +6004,7 @@ gnc_account_get_map_entry (Account *acc, const char *head, const char *category)
text = g_strdup (string); text = g_strdup (string);
} }
} }
g_value_unset (&v);
return text; return text;
} }