Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Jan 26, 2023
2 parents 4739e8c + f4c6d65 commit 17820ec
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 93 deletions.
26 changes: 22 additions & 4 deletions libgnucash/engine/Account.cpp
Expand Up @@ -1356,7 +1356,7 @@ xaccFreeAccount (Account *acc)
PERR (" instead of calling xaccFreeAccount(), please call\n"
" xaccAccountBeginEdit(); xaccAccountDestroy();\n");

/* First, recursively free children */
/* First, recursively free children, also frees list */
xaccFreeAccountChildren(acc);
}

Expand Down Expand Up @@ -6348,14 +6348,32 @@ gnc_account_delete_all_bayes_maps (Account *acc)
/* ================================================================ */
/* QofObject function implementation and registration */

static void
destroy_all_child_accounts (Account *acc, gpointer data)
{
xaccAccountBeginEdit (acc);
xaccAccountDestroy (acc);
}

static void
gnc_account_book_end(QofBook* book)
{
Account *root_account = gnc_book_get_root_account(book);
Account *root_account = gnc_book_get_root_account (book);
GList *accounts;

if (!root_account)
return;
xaccAccountBeginEdit(root_account);
xaccAccountDestroy(root_account);

accounts = gnc_account_get_descendants (root_account);

if (accounts)
{
accounts = g_list_reverse (accounts);
g_list_foreach (accounts, (GFunc)destroy_all_child_accounts, nullptr);
g_list_free (accounts);
}
xaccAccountBeginEdit (root_account);
xaccAccountDestroy (root_account);
}

#ifdef _MSC_VER
Expand Down
4 changes: 2 additions & 2 deletions libgnucash/engine/SX-book.c
Expand Up @@ -180,7 +180,7 @@ static QofObject sxtg_object_def =
{
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) GNC_ID_SXTG,
DI(.type_label = ) "Scheduled Transaction Templates",
DI(.type_label = ) "Scheduled Transaction Group",
DI(.create = ) NULL,
DI(.book_begin = ) sxtg_book_begin,
DI(.book_end = ) sxtg_book_end,
Expand Down Expand Up @@ -281,7 +281,7 @@ book_sxes_end(QofBook* book)
sxes = qof_collection_get_data(col);
if (sxes != NULL)
{
g_list_free (sxes->sx_list);
g_list_free(sxes->sx_list);
g_object_unref(sxes);
qof_collection_set_data(col, NULL);
}
Expand Down
17 changes: 6 additions & 11 deletions libgnucash/engine/SchedXaction.c
Expand Up @@ -32,6 +32,7 @@

#include "Account.h"
#include "SX-book.h"
#include "SX-book-p.h"
#include "SX-ttinfo.h"
#include "SchedXaction.h"
#include "Transaction.h"
Expand Down Expand Up @@ -497,17 +498,8 @@ xaccSchedXactionFree( SchedXaction *sx )

delete_template_trans( sx );

/*
* xaccAccountDestroy removes the account from
* its group for us AFAICT. If shutting down,
* the account is being deleted separately.
*/

if (!qof_book_shutting_down(qof_instance_get_book(sx)))
{
xaccAccountBeginEdit(sx->template_acct);
xaccAccountDestroy(sx->template_acct);
}
xaccAccountBeginEdit( sx->template_acct );
xaccAccountDestroy( sx->template_acct );

for ( l = sx->deferredList; l; l = l->next )
{
Expand Down Expand Up @@ -1220,6 +1212,9 @@ gnc_sx_book_end(QofBook* book)

col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
qof_collection_foreach(col, destroy_sx_on_book_close, NULL);

// Now destroy the template root account
gnc_book_set_template_root (book, NULL);
}

#ifdef _MSC_VER
Expand Down
7 changes: 5 additions & 2 deletions libgnucash/engine/Transaction.c
Expand Up @@ -1788,7 +1788,7 @@ xaccTransRollbackEdit (Transaction *trans)
xaccSplitRollbackEdit(s);
SWAP_STR(s->action, so->action);
SWAP_STR(s->memo, so->memo);
qof_instance_copy_kvp (QOF_INSTANCE (s), QOF_INSTANCE (so));
qof_instance_copy_kvp (QOF_INSTANCE (s), QOF_INSTANCE (so));
s->reconciled = so->reconciled;
s->amount = so->amount;
s->value = so->value;
Expand All @@ -1797,7 +1797,6 @@ xaccTransRollbackEdit (Transaction *trans)
//SET_GAINS_A_VDIRTY(s);
s->date_reconciled = so->date_reconciled;
qof_instance_mark_clean(QOF_INSTANCE(s));
xaccFreeSplit(so);
}
else
{
Expand All @@ -1824,6 +1823,10 @@ xaccTransRollbackEdit (Transaction *trans)
}
}
g_list_free(slist);

// orig->splits may still have duped splits so free them
for (node = orig->splits; node; node = node->next)
xaccFreeSplit(node->data);
g_list_free(orig->splits);
orig->splits = NULL;

Expand Down
71 changes: 12 additions & 59 deletions libgnucash/engine/gnc-commodity.c
Expand Up @@ -38,6 +38,8 @@
#include "gnc-commodity.h"
#include "gnc-locale-utils.h"
#include "gnc-prefs.h"
#include "guid.h"
#include "qofinstance.h"

static QofLogModule log_module = GNC_MOD_COMMODITY;

Expand Down Expand Up @@ -1647,77 +1649,28 @@ gnc_commodity_equiv(const gnc_commodity * a, const gnc_commodity * b)
priv_b = GET_PRIVATE(b);
if (priv_a->name_space != priv_b->name_space) return FALSE;
if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;

return TRUE;
}

gboolean
gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b)
{
gnc_commodityPrivate* priv_a;
gnc_commodityPrivate* priv_b;
gboolean same_book;

if (a == b) return TRUE;

if (!a || !b)
{
DEBUG ("one is NULL");
return FALSE;
}

priv_a = GET_PRIVATE(a);
priv_b = GET_PRIVATE(b);
same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));

if ((same_book && priv_a->name_space != priv_b->name_space)
|| (!same_book && g_strcmp0( gnc_commodity_namespace_get_name(priv_a->name_space),
gnc_commodity_namespace_get_name(priv_b->name_space)) != 0))
{
DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
priv_a->name_space, gnc_commodity_namespace_get_name(priv_a->name_space),
priv_b->name_space, gnc_commodity_namespace_get_name(priv_b->name_space));
return FALSE;
}

if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
{
DEBUG ("mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
return FALSE;
}

if (g_strcmp0(priv_a->fullname, priv_b->fullname) != 0)
{
DEBUG ("fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
return FALSE;
}

if (g_strcmp0(priv_a->cusip, priv_b->cusip) != 0)
{
DEBUG ("cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
return FALSE;
}

if (priv_a->fraction != priv_b->fraction)
{
DEBUG ("fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
return FALSE;
}

return TRUE;
return gnc_commodity_compare(a, b) == 0;
}

// Used as a sorting callback for deleting old prices, so it needs to be
// stable but doesn't need to be in any particular order sensible to humans.
int gnc_commodity_compare(const gnc_commodity * a, const gnc_commodity * b)
{
if (gnc_commodity_equal(a, b))
{
return 0;
}
else
{
return 1;
}
if (a == b) return 0;
if (a && !b) return 1;
if (b && !a) return -1;
return qof_instance_guid_compare(a, b);
}

// Used as a callback to g_list_find_custom, it should return 0
// when the commodities match.
int gnc_commodity_compare_void(const void * a, const void * b)
{
return gnc_commodity_compare(a, b);
Expand Down
3 changes: 3 additions & 0 deletions libgnucash/engine/gnc-pricedb.c
Expand Up @@ -2492,6 +2492,9 @@ convert_price (const gnc_commodity *from, const gnc_commodity *to, PriceTuple tu

price = gnc_numeric_div (to_val, from_val, GNC_DENOM_AUTO, no_round);

gnc_price_unref (tuple.from);
gnc_price_unref (tuple.to);

if (from_cur == from && to_cur == to)
return price;

Expand Down
14 changes: 14 additions & 0 deletions libgnucash/engine/gncBillTerm.c
Expand Up @@ -839,14 +839,28 @@ static void _gncBillTermCreate (QofBook *book)
qof_book_set_data (book, _GNC_MOD_NAME, bi);
}


static void
destroy_billterm_on_book_close (QofInstance *ent, gpointer data)
{
GncBillTerm *term = GNC_BILLTERM(ent);

gncBillTermBeginEdit (term);
gncBillTermDestroy (term);
}

static void _gncBillTermDestroy (QofBook *book)
{
struct _book_info *bi;
QofCollection *col;

if (!book) return;

bi = qof_book_get_data (book, _GNC_MOD_NAME);

col = qof_book_get_collection (book, GNC_ID_BILLTERM);
qof_collection_foreach (col, destroy_billterm_on_book_close, NULL);

g_list_free (bi->terms);
g_free (bi);
}
Expand Down
11 changes: 7 additions & 4 deletions libgnucash/engine/gncCustomer.c
Expand Up @@ -353,14 +353,17 @@ static void gncCustomerFree (GncCustomer *cust)
gncAddressDestroy (cust->addr);
gncAddressBeginEdit (cust->shipaddr);
gncAddressDestroy (cust->shipaddr);

gncJobFreeList (cust->jobs);
g_list_free (cust->jobs);
g_free (cust->balance);

if (cust->terms)
gncBillTermDecRef (cust->terms);
if (cust->taxtable)
if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(cust))))
{
gncTaxTableDecRef (cust->taxtable);
if (cust->terms)
gncBillTermDecRef (cust->terms);
if (cust->taxtable)
gncTaxTableDecRef (cust->taxtable);
}

/* qof_instance_release (&cust->inst); */
Expand Down
12 changes: 8 additions & 4 deletions libgnucash/engine/gncEntry.c
Expand Up @@ -463,10 +463,14 @@ static void gncEntryFree (GncEntry *entry)
gncAccountValueDestroy (entry->i_tax_values);
if (entry->b_tax_values)
gncAccountValueDestroy (entry->b_tax_values);
if (entry->i_tax_table)
gncTaxTableDecRef (entry->i_tax_table);
if (entry->b_tax_table)
gncTaxTableDecRef (entry->b_tax_table);

if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(entry))))
{
if (entry->i_tax_table)
gncTaxTableDecRef (entry->i_tax_table);
if (entry->b_tax_table)
gncTaxTableDecRef (entry->b_tax_table);
}

/* qof_instance_release (&entry->inst); */
g_object_unref (entry);
Expand Down
10 changes: 7 additions & 3 deletions libgnucash/engine/gncInvoice.c
Expand Up @@ -435,10 +435,14 @@ static void gncInvoiceFree (GncInvoice *invoice)
g_list_free (invoice->entries);
g_list_free (invoice->prices);

if (invoice->printname) g_free (invoice->printname);
if (invoice->printname)
g_free (invoice->printname);

if (invoice->terms)
gncBillTermDecRef (invoice->terms);
if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(invoice))))
{
if (invoice->terms)
gncBillTermDecRef (invoice->terms);
}

if (invoice->doclink != is_unset)
g_free (invoice->doclink);
Expand Down
12 changes: 12 additions & 0 deletions libgnucash/engine/gncJob.c
Expand Up @@ -231,6 +231,18 @@ GncJob *gncJobCreate (QofBook *book)
return job;
}

static void free_job_list (GncJob *job)
{
gncJobBeginEdit (job);
gncJobDestroy (job);
}

void gncJobFreeList (GList *jobs)
{
GList *job_list = g_list_copy (jobs);
g_list_free_full (job_list, (GDestroyNotify)free_job_list);
}

void gncJobDestroy (GncJob *job)
{
if (!job) return;
Expand Down
1 change: 1 addition & 0 deletions libgnucash/engine/gncJob.h
Expand Up @@ -61,6 +61,7 @@ GType gnc_job_get_type(void);

GncJob *gncJobCreate (QofBook *book);
void gncJobDestroy (GncJob *job);
void gncJobFreeList (GList *jobs);

/** \name Set Functions
@{
Expand Down
13 changes: 13 additions & 0 deletions libgnucash/engine/gncTaxTable.c
Expand Up @@ -1015,14 +1015,27 @@ static void _gncTaxTableCreate (QofBook *book)
qof_book_set_data (book, _GNC_MOD_NAME, bi);
}

static void
destroy_taxtable_on_book_close (QofInstance *ent, gpointer data)
{
GncTaxTable *table = GNC_TAXTABLE(ent);

gncTaxTableBeginEdit (table);
gncTaxTableDestroy (table);
}

static void _gncTaxTableDestroy (QofBook *book)
{
struct _book_info *bi;
QofCollection *col;

if (!book) return;

bi = qof_book_get_data (book, _GNC_MOD_NAME);

col = qof_book_get_collection (book, GNC_ID_TAXTABLE);
qof_collection_foreach (col, destroy_taxtable_on_book_close, NULL);

g_list_free (bi->tables);
g_free (bi);
}
Expand Down

0 comments on commit 17820ec

Please sign in to comment.