From 793c14d240856b844fa96fc7c656555a473684fc Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 14 Oct 2024 11:52:25 +0800 Subject: [PATCH] fixup! [account.cpp] don't nullcheck acc and inst --- libgnucash/engine/Account.cpp | 37 +++++++++++++++++++------------ libgnucash/engine/qofinstance.cpp | 2 -- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 0604c0f234e..cad4c838754 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -2481,8 +2481,6 @@ static void set_kvp_gnc_numeric_path (Account *acc, const std::vector& path, std::optional value) { - g_return_if_fail(GNC_IS_ACCOUNT(acc)); - xaccAccountBeginEdit(acc); qof_instance_set_path_kvp (QOF_INSTANCE(acc), value, path); xaccAccountCommitEdit(acc); @@ -2491,7 +2489,6 @@ set_kvp_gnc_numeric_path (Account *acc, const std::vector& path, static std::optional get_kvp_gnc_numeric_path (const Account *acc, const Path& path) { - g_return_val_if_fail (acc, std::nullopt); return qof_instance_get_path_kvp (QOF_INSTANCE(acc), path); } @@ -2499,8 +2496,6 @@ static void set_kvp_string_path (Account *acc, std::vector const & path, const char *value) { - g_return_if_fail(GNC_IS_ACCOUNT(acc)); - std::optional val; if (value && *value) val = g_strdup(value); @@ -2513,7 +2508,6 @@ set_kvp_string_path (Account *acc, std::vector const & path, static const char* get_kvp_string_path (const Account *acc, const Path& path) { - g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr); auto rv{qof_instance_get_path_kvp (QOF_INSTANCE(acc), path)}; return rv ? *rv : nullptr; } @@ -2521,7 +2515,6 @@ get_kvp_string_path (const Account *acc, const Path& path) static void set_kvp_account_path (Account* acc, const Path& path, const Account* kvp_account) { - g_return_if_fail (GNC_IS_ACCOUNT(acc)); std::optional val; if (kvp_account) val = guid_copy(xaccAccountGetGUID (kvp_account)); @@ -2534,7 +2527,6 @@ set_kvp_account_path (Account* acc, const Path& path, const Account* kvp_account static Account* get_kvp_account_path (const Account *acc, const Path& path) { - g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr); auto val{qof_instance_get_path_kvp (QOF_INSTANCE(acc), path)}; return val ? xaccAccountLookup (*val, gnc_account_get_book (acc)) : nullptr; } @@ -2542,14 +2534,12 @@ get_kvp_account_path (const Account *acc, const Path& path) static void set_kvp_boolean_path (Account *acc, const Path& path, gboolean option) { - g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, path, option ? "true" : nullptr); } static gboolean get_kvp_boolean_path (const Account *acc, const Path& path) { - g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)}; if (!slot) return false; switch (slot->get_type()) @@ -2566,8 +2556,6 @@ get_kvp_boolean_path (const Account *acc, const Path& path) static void set_kvp_int64_path (Account *acc, const Path& path, std::optional value) { - g_return_if_fail(GNC_IS_ACCOUNT(acc)); - xaccAccountBeginEdit(acc); qof_instance_set_path_kvp (QOF_INSTANCE(acc), value, path); xaccAccountCommitEdit(acc); @@ -2576,31 +2564,34 @@ set_kvp_int64_path (Account *acc, const Path& path, std::optional value) static const std::optional get_kvp_int64_path (const Account *acc, const Path& path) { - g_return_val_if_fail (GNC_IS_ACCOUNT(acc), std::nullopt); return qof_instance_get_path_kvp (QOF_INSTANCE(acc), path); } void xaccAccountSetColor (Account *acc, const char *str) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, {"color"}, str); } void xaccAccountSetFilter (Account *acc, const char *str) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, {"filter"}, str); } void xaccAccountSetSortOrder (Account *acc, const char *str) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, {"sort-order"}, str); } void xaccAccountSetSortReversed (Account *acc, gboolean sortreversed) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_boolean_path (acc, {"sort-reversed"}, sortreversed); } @@ -2625,6 +2616,7 @@ qofAccountSetParent (Account *acc, QofInstance *parent) void xaccAccountSetNotes (Account *acc, const char *str) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, {"notes"}, str); } @@ -3904,7 +3896,8 @@ xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod (Account *acc, time64 t1 const SplitsVec xaccAccountGetSplits (const Account *account) { - return GNC_IS_ACCOUNT(account) ? GET_PRIVATE(account)->splits : SplitsVec{}; + g_return_val_if_fail (GNC_IS_ACCOUNT(account), SplitsVec{}); + return GET_PRIVATE(account)->splits; } SplitList * @@ -3919,6 +3912,7 @@ xaccAccountGetSplitList (const Account *acc) size_t xaccAccountGetSplitsSize (const Account *account) { + g_return_val_if_fail (GNC_IS_ACCOUNT(account), 0); return GNC_IS_ACCOUNT(account) ? GET_PRIVATE(account)->splits.size() : 0; } @@ -3994,12 +3988,14 @@ xaccAccountForEachLot(const Account *acc, gboolean xaccAccountGetTaxRelated (const Account *acc) { + g_return_val_if_fail(GNC_IS_ACCOUNT(acc), false); return get_kvp_boolean_path(acc, {"tax-related"}); } void xaccAccountSetTaxRelated (Account *acc, gboolean tax_related) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_boolean_path(acc, {"tax-related"}, tax_related); } @@ -4013,6 +4009,7 @@ xaccAccountGetTaxUSCode (const Account *acc) void xaccAccountSetTaxUSCode (Account *acc, const char *code) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, {"tax-US", "code"}, code); } @@ -4026,6 +4023,7 @@ xaccAccountGetTaxUSPayerNameSource (const Account *acc) void xaccAccountSetTaxUSPayerNameSource (Account *acc, const char *source) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_string_path (acc, {"tax-US", "payer-name-source"}, source); } @@ -4078,30 +4076,35 @@ const char *gnc_account_get_credit_string (GNCAccountType acct_type) gboolean xaccAccountGetPlaceholder (const Account *acc) { + g_return_val_if_fail (GNC_IS_ACCOUNT(acc), false); return get_kvp_boolean_path(acc, {"placeholder"}); } void xaccAccountSetPlaceholder (Account *acc, gboolean val) { + g_return_if_fail (GNC_IS_ACCOUNT(acc)); set_kvp_boolean_path(acc, {"placeholder"}, val); } gboolean xaccAccountGetAppendText (const Account *acc) { + g_return_val_if_fail (GNC_IS_ACCOUNT(acc), false); return get_kvp_boolean_path(acc, {"import-append-text"}); } void xaccAccountSetAppendText (Account *acc, gboolean val) { + g_return_if_fail (GNC_IS_ACCOUNT(acc)); set_kvp_boolean_path(acc, {"import-append-text"}, val); } gboolean xaccAccountGetIsOpeningBalance (const Account *acc) { + g_return_val_if_fail (GNC_IS_ACCOUNT(acc), false); if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY) return false; @@ -4111,6 +4114,7 @@ xaccAccountGetIsOpeningBalance (const Account *acc) void xaccAccountSetIsOpeningBalance (Account *acc, gboolean val) { + g_return_if_fail (GNC_IS_ACCOUNT(acc)); if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY) return; set_kvp_string_path(acc, {"equity-type"}, val ? "opening-balance" : nullptr); @@ -4132,12 +4136,14 @@ xaccAccountGetDescendantPlaceholder (const Account *acc) gboolean xaccAccountGetAutoInterest (const Account *acc) { + g_return_val_if_fail(GNC_IS_ACCOUNT(acc), false); return get_kvp_boolean_path (acc, {KEY_RECONCILE_INFO, "auto-interest-transfer"}); } void xaccAccountSetAutoInterest (Account *acc, gboolean val) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_boolean_path (acc, {KEY_RECONCILE_INFO, "auto-interest-transfer"}, val); } @@ -4147,12 +4153,14 @@ xaccAccountSetAutoInterest (Account *acc, gboolean val) gboolean xaccAccountGetHidden (const Account *acc) { + g_return_val_if_fail(GNC_IS_ACCOUNT(acc), false); return get_kvp_boolean_path (acc, {"hidden"}); } void xaccAccountSetHidden (Account *acc, gboolean val) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); set_kvp_boolean_path (acc, {"hidden"}, val); } @@ -5532,6 +5540,7 @@ gnc_account_imap_find_account_bayes (Account *acc, GList *tokens) static void change_imap_entry (Account *acc, std::string const & path, int64_t token_count) { + g_return_if_fail(GNC_IS_ACCOUNT(acc)); PINFO("Source Account is '%s', Count is '%" G_GINT64_FORMAT "'", xaccAccountGetName (acc), token_count); diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp index f392d15bf64..470b47663a1 100644 --- a/libgnucash/engine/qofinstance.cpp +++ b/libgnucash/engine/qofinstance.cpp @@ -1066,7 +1066,6 @@ qof_instance_set_kvp (QofInstance * inst, GValue const * value, unsigned count, template std::optional qof_instance_get_path_kvp (QofInstance* inst, const Path& path) { - g_return_val_if_fail(inst, std::nullopt); auto kvp_value{inst->kvp_data->get_slot(path)}; return kvp_value ? std::make_optional(kvp_value->get()) : std::nullopt; } @@ -1074,7 +1073,6 @@ qof_instance_get_path_kvp (QofInstance* inst, const Path& path) template void qof_instance_set_path_kvp (QofInstance* inst, std::optional value, const Path& path) { - g_return_if_fail(inst); delete inst->kvp_data->set_path(path, value ? new KvpValue(*value) : nullptr); qof_instance_set_dirty (inst); }