diff --git a/lib/libqof/qof/qofinstance.c b/lib/libqof/qof/qofinstance.c index 4664bea6dc..b76c773df8 100644 --- a/lib/libqof/qof/qofinstance.c +++ b/lib/libqof/qof/qofinstance.c @@ -65,7 +65,7 @@ typedef struct QofInstancePrivate QofCollection *collection; /**< Entity collection */ /* The entity_table in which this instance is stored */ -// QofBook * book; + QofBook * book; /* kvp_data is a key-value pair database for storing arbirtary * information associated with this instance. @@ -210,7 +210,7 @@ qof_instance_init (QofInstance *inst) QofInstancePrivate *priv; priv = GET_PRIVATE(inst); - inst->book = NULL; + priv->book = NULL; inst->kvp_data = kvp_frame_new(); priv->last_update.tv_sec = 0; priv->last_update.tv_nsec = -1; @@ -229,9 +229,9 @@ qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book) g_return_if_fail(QOF_IS_INSTANCE(inst)); priv = GET_PRIVATE(inst); - g_return_if_fail(!inst->book); + g_return_if_fail(!priv->book); - inst->book = book; + priv->book = book; col = qof_book_get_collection (book, type); g_return_if_fail(col != NULL); @@ -313,7 +313,7 @@ qof_instance_get_property (GObject *object, g_value_set_pointer(value, priv->collection); break; case PROP_BOOK: - g_value_set_object(value, inst->book); + g_value_set_object(value, priv->book); break; case PROP_KVP_DATA: g_value_set_pointer(value, inst->kvp_data); @@ -426,17 +426,41 @@ qof_instance_set_collection (gconstpointer ptr, QofCollection *col) } QofBook * -qof_instance_get_book (const QofInstance *inst) +qof_instance_get_book (gconstpointer inst) { if (!inst) return NULL; - return inst->book; + g_return_val_if_fail(QOF_IS_INSTANCE(inst), NULL); + return GET_PRIVATE(inst)->book; } void qof_instance_set_book (gconstpointer inst, QofBook *book) { g_return_if_fail(QOF_IS_INSTANCE(inst)); - QOF_INSTANCE(inst)->book = book; + GET_PRIVATE(inst)->book = book; +} + +void +qof_instance_copy_book (gpointer ptr1, gconstpointer ptr2) +{ + g_return_if_fail(QOF_IS_INSTANCE(ptr1)); + g_return_if_fail(QOF_IS_INSTANCE(ptr2)); + + GET_PRIVATE(ptr1)->book = GET_PRIVATE(ptr2)->book; +} + +gboolean +qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2) +{ + const QofInstancePrivate *priv1, *priv2; + + g_return_val_if_fail(QOF_IS_INSTANCE(ptr1), FALSE); + g_return_val_if_fail(QOF_IS_INSTANCE(ptr2), FALSE); + + priv1 = GET_PRIVATE(ptr1); + priv2 = GET_PRIVATE(ptr2); + + return (priv1->book == priv2->book); } KvpFrame* @@ -627,11 +651,11 @@ qof_instance_gemini (QofInstance *to, const QofInstance *from) from_priv = GET_PRIVATE(from); to_priv = GET_PRIVATE(to); - fb_priv = GET_PRIVATE(QOF_INSTANCE(from)->book); - tb_priv = GET_PRIVATE(QOF_INSTANCE(to)->book); + fb_priv = GET_PRIVATE(from_priv->book); + tb_priv = GET_PRIVATE(to_priv->book); /* Books must differ for a gemini to be meaningful */ - if (from->book == to->book) + if (from_priv->book == to_priv->book) return; now = time(0); @@ -639,11 +663,11 @@ qof_instance_gemini (QofInstance *to, const QofInstance *from) /* Make a note of where the copy came from */ gnc_kvp_bag_add (to->kvp_data, "gemini", now, "inst_guid", &from->guid, - "book_guid", &from->book->inst.guid, + "book_guid", &from_priv->book->inst.guid, NULL); gnc_kvp_bag_add (from->kvp_data, "gemini", now, "inst_guid", &to->guid, - "book_guid", &to->book->inst.guid, + "book_guid", &to_priv->book->inst.guid, NULL); to_priv->dirty = TRUE; @@ -690,7 +714,7 @@ qof_begin_edit (QofInstance *inst) if (0 >= priv->editlevel) priv->editlevel = 1; - be = qof_book_get_backend(inst->book); + be = qof_book_get_backend(priv->book); if (be && qof_backend_begin_exists(be)) qof_backend_run_begin(be, inst); else @@ -711,7 +735,7 @@ gboolean qof_commit_edit (QofInstance *inst) if (0 < priv->editlevel) return FALSE; if ((0 == priv->editlevel) && priv->dirty) { - be = qof_book_get_backend(inst->book); + be = qof_book_get_backend(priv->book); if (be && qof_backend_commit_exists(be)) { qof_backend_run_commit(be, inst); } @@ -737,7 +761,7 @@ qof_commit_edit_part2(QofInstance *inst, dirty = priv->dirty; /* See if there's a backend. If there is, invoke it. */ - be = qof_book_get_backend(inst->book); + be = qof_book_get_backend(priv->book); if (be && qof_backend_commit_exists(be)) { QofBackendError errcode; @@ -764,7 +788,7 @@ qof_commit_edit_part2(QofInstance *inst, if (dirty && qof_get_alt_dirty_mode() && !(priv->infant && priv->do_free)) { qof_collection_mark_dirty(priv->collection); - qof_book_mark_dirty(inst->book); + qof_book_mark_dirty(priv->book); } priv->infant = FALSE; diff --git a/lib/libqof/qof/qofinstance.h b/lib/libqof/qof/qofinstance.h index 6212aa7787..68ae663097 100644 --- a/lib/libqof/qof/qofinstance.h +++ b/lib/libqof/qof/qofinstance.h @@ -69,9 +69,6 @@ struct QofInstance_s QofIdType e_type; /**< Entity type */ GUID guid; /**< GUID for the entity */ - /* The entity_table in which this instance is stored */ - QofBook * book; - /* kvp_data is a key-value pair database for storing arbirtary * information associated with this instance. * See src/engine/kvp_doc.txt for a list and description of the @@ -91,11 +88,17 @@ GType qof_instance_get_type(void); void qof_instance_init_data (QofInstance *, QofIdType, QofBook *); /** Return the book pointer */ -QofBook * qof_instance_get_book (const QofInstance *); +QofBook *qof_instance_get_book (gconstpointer); /** Set the book pointer */ void qof_instance_set_book (gconstpointer inst, QofBook *book); +/** Copy the book from one QofInstances to another. */ +void qof_instance_copy_book (gpointer ptr1, gconstpointer ptr2); + +/** See if two QofInstances share the same book. */ +gboolean qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2); + /** Return the GUID of this instance */ const GUID * qof_instance_get_guid (const QofInstance *); diff --git a/src/backend/postgres/txn.c b/src/backend/postgres/txn.c index 964b25e2d2..38ea1ac4ac 100644 --- a/src/backend/postgres/txn.c +++ b/src/backend/postgres/txn.c @@ -467,7 +467,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans) s = pgendSplitLookup (be, &guid); if (!s) { - s = xaccMallocSplit(trans->inst.book); + s = xaccMallocSplit(qof_instance_get_book(trans)); xaccSplitSetGUID(s, &guid); } diff --git a/src/business/business-core/gncBillTerm.c b/src/business/business-core/gncBillTerm.c index 8d33886ff4..233985fb35 100644 --- a/src/business/business-core/gncBillTerm.c +++ b/src/business/business-core/gncBillTerm.c @@ -98,14 +98,14 @@ static inline void maybe_resort_list (GncBillTerm *term) struct _book_info *bi; if (term->parent || term->invisible) return; - bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME); bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare); } static inline void addObj (GncBillTerm *term) { struct _book_info *bi; - bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME); bi->terms = g_list_insert_sorted (bi->terms, term, (GCompareFunc)gncBillTermCompare); } @@ -113,7 +113,7 @@ static inline void addObj (GncBillTerm *term) static inline void remObj (GncBillTerm *term) { struct _book_info *bi; - bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME); bi->terms = g_list_remove (bi->terms, term); } @@ -524,7 +524,7 @@ static GncBillTerm *gncBillTermCopy (GncBillTerm *term) GncBillTerm *t; if (!term) return NULL; - t = gncBillTermCreate (term->inst.book); + t = gncBillTermCreate (qof_instance_get_book(term)); gncBillTermBeginEdit(t); diff --git a/src/business/business-core/gncInvoice.c b/src/business/business-core/gncInvoice.c index de952d75c8..c1d68ea321 100644 --- a/src/business/business-core/gncInvoice.c +++ b/src/business/business-core/gncInvoice.c @@ -858,6 +858,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, const char * memo, gboolean accumulatesplits) { Transaction *txn; + QofBook *book; GNCLot *lot = NULL; GList *iter; GList *splitinfo = NULL; @@ -871,6 +872,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, if (!invoice || !acc) return NULL; gncInvoiceBeginEdit (invoice); + book = qof_instance_get_book(invoice); /* Stabilize the Billing Terms of this invoice */ if (invoice->terms) @@ -903,7 +905,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, /* Create a new lot for this invoice, if we need to do so */ if (!lot) - lot = gnc_lot_new (invoice->inst.book); + lot = gnc_lot_new (book); type = gncInvoiceGetType (invoice); @@ -913,7 +915,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, g_free (lot_title); /* Create a new transaction */ - txn = xaccMallocTransaction (invoice->inst.book); + txn = xaccMallocTransaction (book); xaccTransBeginEdit (txn); name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice))); @@ -971,7 +973,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, } else { Split *split; - split = xaccMallocSplit (invoice->inst.book); + split = xaccMallocSplit (book); /* set action and memo? */ xaccSplitSetMemo (split, gncEntryGetDescription (entry)); @@ -1002,7 +1004,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD) { Split *split; - split = xaccMallocSplit (invoice->inst.book); + split = xaccMallocSplit (book); /* set action? */ xaccSplitSetMemo (split, gncEntryGetDescription (entry)); xaccSplitSetAction (split, type); @@ -1036,7 +1038,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, Split *split; GncAccountValue *acc_val = iter->data; - split = xaccMallocSplit (invoice->inst.book); + split = xaccMallocSplit (book); /* set action and memo? */ xaccSplitSetMemo (split, memo); @@ -1055,7 +1057,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, * we should make that now.. */ if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount)) { - Split *split = xaccMallocSplit (invoice->inst.book); + Split *split = xaccMallocSplit (book); /* Set memo. action? */ xaccSplitSetMemo (split, _("Extra to Charge Card")); @@ -1075,7 +1077,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, /* Now create the Posted split (which is negative -- it's a credit) */ { - Split *split = xaccMallocSplit (invoice->inst.book); + Split *split = xaccMallocSplit (book); /* Set action/memo */ xaccSplitSetMemo (split, memo); @@ -1118,8 +1120,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, char *memo2 = _("Automatic Payment Forward"); char *action2 = _("Auto Split"); - t2 = xaccMallocTransaction (invoice->inst.book); - lot2 = gnc_lot_new (invoice->inst.book); + t2 = xaccMallocTransaction (book); + lot2 = gnc_lot_new (book); gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)), lot2); @@ -1136,7 +1138,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, xaccTransSetDatePostedTS (t2, post_date); /* Balance out this lot */ - split = xaccMallocSplit (invoice->inst.book); + split = xaccMallocSplit (book); xaccSplitSetMemo (split, memo2); xaccSplitSetAction (split, action2); xaccAccountInsertSplit (acc, split); @@ -1146,7 +1148,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, gnc_lot_add_split (lot, split); /* And apply the pre-payment to a new lot */ - split = xaccMallocSplit (invoice->inst.book); + split = xaccMallocSplit (book); xaccSplitSetMemo (split, memo2); xaccSplitSetAction (split, action2); xaccAccountInsertSplit (acc, split); diff --git a/src/business/business-core/gncTaxTable.c b/src/business/business-core/gncTaxTable.c index a3cc3588d2..9e43a5911a 100644 --- a/src/business/business-core/gncTaxTable.c +++ b/src/business/business-core/gncTaxTable.c @@ -158,7 +158,7 @@ maybe_resort_list (GncTaxTable *table) struct _book_info *bi; if (table->parent || table->invisible) return; - bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME); bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare); } @@ -171,7 +171,7 @@ mod_table (GncTaxTable *table) static inline void addObj (GncTaxTable *table) { struct _book_info *bi; - bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME); bi->tables = g_list_insert_sorted (bi->tables, table, (GCompareFunc)gncTaxTableCompare); } @@ -179,7 +179,7 @@ static inline void addObj (GncTaxTable *table) static inline void remObj (GncTaxTable *table) { struct _book_info *bi; - bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME); bi->tables = g_list_remove (bi->tables, table); } @@ -449,7 +449,7 @@ void gncTaxTableMakeInvisible (GncTaxTable *table) if (!table) return; gncTaxTableBeginEdit (table); table->invisible = TRUE; - bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME); bi->tables = g_list_remove (bi->tables, table); gncTaxTableCommitEdit (table); } @@ -600,7 +600,7 @@ static GncTaxTable *gncTaxTableCopy (GncTaxTable *table) GList *list; if (!table) return NULL; - t = gncTaxTableCreate (table->inst.book); + t = gncTaxTableCreate (qof_instance_get_book(table)); gncTaxTableSetName (t, table->name); for (list = table->entries; list; list=list->next) { GncTaxTableEntry *entry, *e; diff --git a/src/engine/Account.c b/src/engine/Account.c index cfa9430102..eb8b2240c2 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -1106,6 +1106,7 @@ void xaccAccountCommitEdit (Account *acc) { AccountPrivate *priv; + QofBook *book; g_return_if_fail(acc); if (!qof_commit_edit(&acc->inst)) return; @@ -1141,8 +1142,9 @@ xaccAccountCommitEdit (Account *acc) g_assert(priv->splits == NULL || qof_book_shutting_down(acc->inst.book)); */ - if (!qof_book_shutting_down(acc->inst.book)) { - col = qof_book_get_collection(acc->inst.book, GNC_ID_TRANS); + book = qof_instance_get_book(acc); + if (!qof_book_shutting_down(book)) { + col = qof_book_get_collection(book, GNC_ID_TRANS); qof_collection_foreach(col, destroy_pending_splits_for_account, acc); } @@ -1816,7 +1818,7 @@ xaccAccountMoveAllSplits (Account *accfrom, Account *accto) return; /* check for book mix-up */ - g_return_if_fail (accfrom->inst.book == accto->inst.book); + g_return_if_fail (qof_instance_books_equal(accfrom, accto)); ENTER ("(accfrom=%p, accto=%p)", accfrom, accto); xaccAccountBeginEdit(accfrom); @@ -1895,7 +1897,7 @@ xaccAccountRecomputeBalance (Account * acc) if (qof_instance_get_editlevel(acc) > 0) return; if (!priv->balance_dirty) return; if (qof_instance_get_destroying(acc)) return; - if (qof_book_shutting_down(acc->inst.book)) return; + if (qof_book_shutting_down(qof_instance_get_book(acc))) return; balance = priv->starting_balance; cleared_balance = priv->starting_cleared_balance; @@ -2257,6 +2259,7 @@ xaccAccountGetNonStdSCU (const Account * acc) void DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency) { + QofBook *book; const char *string; gnc_commodity *commodity; @@ -2272,7 +2275,8 @@ DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency) commodity = DxaccAccountGetCurrency (acc); if (!commodity) { - gnc_commodity_table_insert (gnc_commodity_table_get_table (acc->inst.book), currency); + book = qof_instance_get_book(acc); + gnc_commodity_table_insert (gnc_commodity_table_get_table (book), currency); } } @@ -2302,7 +2306,7 @@ gnc_account_append_child (Account *new_parent, Account *child) if (old_parent) { gnc_account_remove_child(old_parent, child); - if (old_parent->inst.book != new_parent->inst.book) { + if (!qof_instance_books_equal(old_parent, new_parent)) { /* hack alert -- this implementation is not exactly correct. * If the entity tables are not identical, then the 'from' book * may have a different backend than the 'to' book. This means @@ -2317,7 +2321,8 @@ gnc_account_append_child (Account *new_parent, Account *child) PWARN ("reparenting accounts across books is not correctly supported\n"); qof_event_gen (&child->inst, QOF_EVENT_DESTROY, NULL); - col = qof_book_get_collection (new_parent->inst.book, GNC_ID_ACCOUNT); + col = qof_book_get_collection (qof_instance_get_book(new_parent), + GNC_ID_ACCOUNT); qof_collection_insert_entity (col, &child->inst); qof_event_gen (&child->inst, QOF_EVENT_CREATE, NULL); } @@ -2847,7 +2852,7 @@ DxaccAccountGetCurrency (const Account *acc) s = kvp_value_get_string (v); if (!s) return NULL; - table = gnc_commodity_table_get_table (acc->inst.book); + table = gnc_commodity_table_get_table (qof_instance_get_book(acc)); return gnc_commodity_table_lookup_unique (table, s); } diff --git a/src/engine/Period.c b/src/engine/Period.c index 4b81363353..558d4604dc 100644 --- a/src/engine/Period.c +++ b/src/engine/Period.c @@ -72,7 +72,7 @@ gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans) if (!trans || !book) return; /* If this is the same book, its a no-op. */ - if (trans->inst.book == book) return; + if (qof_instance_get_book(trans) == book) return; ENTER ("trans=%p %s", trans, trans->description); newtrans = xaccDupeTransaction (trans); @@ -90,7 +90,7 @@ gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans) /* Fiddle the transaction into place in the new book */ col = qof_book_get_collection (book, GNC_ID_TRANS); qof_collection_insert_entity (col, &newtrans->inst); - newtrans->inst.book = book; + qof_instance_set_book(newtrans, book); col = qof_book_get_collection (book, GNC_ID_SPLIT); xaccTransBeginEdit (newtrans); @@ -100,7 +100,7 @@ gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans) Split *s = node->data; /* move the split into the new book ... */ - s->inst.book = book; + qof_instance_set_book(s, book); qof_collection_insert_entity(col, &s->inst); /* find the twin account, and re-parent to that. */ @@ -130,16 +130,18 @@ void gnc_book_insert_trans (QofBook *book, Transaction *trans) { QofCollection *col; + QofBook *trans_book; GList *node; if (!trans || !book) return; /* If this is the same book, its a no-op. */ - if (trans->inst.book == book) return; + trans_book = qof_instance_get_book(trans); + if (trans_book == book) return; /* If the old and new book don't share backends, then clobber-copy; * i.e. destroy it in one backend, create it in another. */ - if (qof_book_get_backend(book) != qof_book_get_backend(trans->inst.book)) + if (qof_book_get_backend(book) != qof_book_get_backend(trans_book)) { gnc_book_insert_trans_clobber (book, trans); return; @@ -150,7 +152,7 @@ gnc_book_insert_trans (QofBook *book, Transaction *trans) xaccTransBeginEdit (trans); col = qof_book_get_collection (book, GNC_ID_TRANS); - trans->inst.book = book; + qof_instance_set_book(trans, book); qof_collection_insert_entity (col, &trans->inst); col = qof_book_get_collection (book, GNC_ID_SPLIT); @@ -160,9 +162,9 @@ gnc_book_insert_trans (QofBook *book, Transaction *trans) Split *s = node->data; /* Move the splits over (only if they haven't already been moved). */ - if (s->inst.book != book) + if (qof_instance_get_book(s) != book) { - s->inst.book = book; + qof_instance_set_book(s, book); qof_collection_insert_entity (col, &s->inst); } @@ -225,7 +227,7 @@ gnc_book_insert_lot (QofBook *book, GNCLot *lot) ENTER ("lot=%p", lot); col = qof_book_get_collection (book, GNC_ID_LOT); - lot->inst.book = book; + qof_instance_set_book(lot, book); qof_collection_insert_entity (col, &lot->inst); /* Move the splits over (only if they haven't already been moved). */ @@ -233,9 +235,9 @@ gnc_book_insert_lot (QofBook *book, GNCLot *lot) for (snode = lot->splits; snode; snode=snode->next) { Split *s = snode->data; - if (s->inst.book != book) + if (qof_instance_get_book(s) != book) { - s->inst.book = book; + qof_instance_set_book(s, book); qof_collection_insert_entity (col, &s->inst); } } @@ -258,14 +260,17 @@ void gnc_book_insert_price (QofBook *book, GNCPrice *pr) { QofCollection *col; + QofBook *pr_book; + if (!pr || !book) return; /* If this is the same book, its a no-op. */ - if (pr->inst.book == book) return; + pr_book = qof_instance_get_book(pr); + if (pr_book == book) return; /* If the old and new book don't share backends, then clobber-copy; * i.e. destroy it in one backend, create it in another. */ - if (qof_book_get_backend(book) != qof_book_get_backend(pr->inst.book)) + if (qof_book_get_backend(book) != qof_book_get_backend(pr_book)) { gnc_book_insert_price_clobber (book, pr); return; @@ -277,7 +282,7 @@ gnc_book_insert_price (QofBook *book, GNCPrice *pr) gnc_price_begin_edit (pr); col = qof_book_get_collection (book, GNC_ID_PRICE); - pr->inst.book = book; + qof_instance_set_book(pr, book); qof_collection_insert_entity (col, &pr->inst); gnc_pricedb_remove_price (pr->db, pr); diff --git a/src/engine/Scrub.c b/src/engine/Scrub.c index b5c20dc656..36c00e5098 100644 --- a/src/engine/Scrub.c +++ b/src/engine/Scrub.c @@ -398,7 +398,7 @@ xaccTransScrubImbalance (Transaction *trans, Account *root, /* Put split into account before setting split value */ if (!balance_split) { - balance_split = xaccMallocSplit (trans->inst.book); + balance_split = xaccMallocSplit (qof_instance_get_book(trans)); xaccTransBeginEdit (trans); xaccSplitSetParent(balance_split, trans); @@ -575,7 +575,7 @@ xaccTransScrubCurrency (Transaction *trans) currency = xaccTransGetCurrency (trans); if (currency) return; - currency = xaccTransFindOldCommonCurrency (trans, trans->inst.book); + currency = xaccTransFindOldCommonCurrency (trans, qof_instance_get_book(trans)); if (currency) { xaccTransBeginEdit (trans); diff --git a/src/engine/Split.c b/src/engine/Split.c index 48354635f0..a7e5f79c4c 100644 --- a/src/engine/Split.c +++ b/src/engine/Split.c @@ -174,7 +174,7 @@ xaccDupeSplit (const Split *s) */ split->inst.e_type = NULL; split->inst.guid = s->inst.guid; - split->inst.book = s->inst.book; + qof_instance_copy_book(split, s); split->parent = s->parent; split->acc = s->acc; @@ -221,7 +221,7 @@ xaccSplitClone (const Split *s) split->gains = GAINS_STATUS_UNKNOWN; split->gains_split = NULL; - qof_instance_init_data(&split->inst, GNC_ID_SPLIT, s->inst.book); + qof_instance_init_data(&split->inst, GNC_ID_SPLIT, qof_instance_get_book(s)); kvp_frame_delete(split->inst.kvp_data); split->inst.kvp_data = kvp_frame_copy(s->inst.kvp_data); @@ -239,7 +239,7 @@ xaccSplitDump (const Split *split, const char *tag) { printf(" %s Split %p", tag, split); printf(" GUID: %s\n", guid_to_string(&split->guid)); - printf(" Book: %p\n", split->inst.book); + printf(" Book: %p\n", qof_instance_get_book(split)); printf(" Account: %p\n", split->acc); printf(" Lot: %p\n", split->lot); printf(" Parent: %p\n", split->parent); @@ -487,7 +487,7 @@ xaccSplitSetAccount (Split *s, Account *acc) Transaction *trans; g_return_if_fail(s && acc); - g_return_if_fail(acc->inst.book == s->inst.book); + g_return_if_fail(qof_instance_books_equal(acc, s)); trans = s->parent; if (trans) @@ -636,7 +636,7 @@ xaccSplitDetermineGainStatus (Split *split) split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY; } else { QofCollection *col; - col = qof_book_get_collection (split->inst.book, GNC_ID_SPLIT); + col = qof_book_get_collection (qof_instance_get_book(split), GNC_ID_SPLIT); split->gains = GAINS_STATUS_GAINS; other = (Split *) qof_collection_lookup_entity (col, kvp_value_get_guid (val)); diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index f38ca7f00c..ead1e3c9f6 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -397,7 +397,7 @@ xaccDupeTransaction (const Transaction *t) */ trans->inst.e_type = NULL; trans->inst.guid = *guid_null(); - trans->inst.book = t->inst.book; + qof_instance_copy_book(trans, t); trans->inst.kvp_data = kvp_frame_copy (t->inst.kvp_data); return trans; @@ -428,7 +428,7 @@ xaccTransClone (const Transaction *t) trans->orig = NULL; trans->idata = 0; - qof_instance_init_data (&trans->inst, GNC_ID_TRANS, t->inst.book); + qof_instance_init_data (&trans->inst, GNC_ID_TRANS, qof_instance_get_book(t)); kvp_frame_delete (trans->inst.kvp_data); trans->inst.kvp_data = kvp_frame_copy (t->inst.kvp_data); @@ -841,7 +841,7 @@ xaccTransBeginEdit (Transaction *trans) if (!trans) return; if (!qof_begin_edit(&trans->inst)) return; - if (qof_book_shutting_down(trans->inst.book)) return; + if (qof_book_shutting_down(qof_instance_get_book(trans))) return; xaccOpenLog (); xaccTransWriteLog (trans, 'B'); @@ -860,7 +860,7 @@ xaccTransDestroy (Transaction *trans) if (!trans) return; if (!xaccTransGetReadOnly (trans) || - qof_book_shutting_down(trans->inst.book)) { + qof_book_shutting_down(qof_instance_get_book(trans))) { xaccTransBeginEdit(trans); qof_instance_set_destroying(trans, TRUE); xaccTransCommitEdit(trans); @@ -891,7 +891,7 @@ static void do_destroy (Transaction *trans) { SplitList *node; - gboolean shutting_down = qof_book_shutting_down(trans->inst.book); + gboolean shutting_down = qof_book_shutting_down(qof_instance_get_book(trans)); /* If there are capital-gains transactions associated with this, * they need to be destroyed too. */ @@ -1156,7 +1156,7 @@ xaccTransRollbackEdit (Transaction *trans) /* Now that the engine copy is back to its original version, * get the backend to fix it in the database */ - be = qof_book_get_backend (trans->inst.book); + be = qof_book_get_backend(qof_instance_get_book(trans)); /** \todo Fix transrollbackedit in QOF so that rollback is exposed via the API. */ if (be && be->rollback) @@ -1812,7 +1812,7 @@ xaccTransGetReversedBy(const Transaction *trans) g_return_val_if_fail(trans, NULL); guid = kvp_frame_get_guid(trans->inst.kvp_data, TRANS_REVERSED_BY); - return xaccTransLookup(guid, trans->inst.book); + return xaccTransLookup(guid, qof_instance_get_book(trans)); } void diff --git a/src/engine/cap-gains.c b/src/engine/cap-gains.c index 0c1ba4ff96..1988651a3e 100644 --- a/src/engine/cap-gains.c +++ b/src/engine/cap-gains.c @@ -310,7 +310,7 @@ xaccAccountGetDefaultGainAccount (Account *acc, gnc_commodity * currency) vvv = kvp_frame_get_slot (cwd, cur_name); gain_acct_guid = kvp_value_get_guid (vvv); - gain_acct = xaccAccountLookup (gain_acct_guid, acc->inst.book); + gain_acct = xaccAccountLookup (gain_acct_guid, qof_instance_get_book(acc)); return gain_acct; } @@ -338,7 +338,7 @@ GetOrMakeGainAcct (Account *acc, gnc_commodity * currency) vvv = kvp_frame_get_slot (cwd, cur_name); gain_acct_guid = kvp_value_get_guid (vvv); - gain_acct = xaccAccountLookup (gain_acct_guid, acc->inst.book); + gain_acct = xaccAccountLookup (gain_acct_guid, qof_instance_get_book(acc)); /* If there is no default place to put gains/losses * for this account, then create such a place */ @@ -529,7 +529,7 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot) /* Put the remainder of the balance into a new split, * which is in other respects just a clone of this one. */ - new_split = xaccMallocSplit (acc->inst.book); + new_split = xaccMallocSplit (qof_instance_get_book(acc)); /* Copy most of the split attributes */ xaccSplitSetMemo (new_split, xaccSplitGetMemo (split)); @@ -578,7 +578,7 @@ MakeDefaultLot (Account *acc) gint64 id; char buff[200]; - lot = gnc_lot_new (acc->inst.book); + lot = gnc_lot_new (qof_instance_get_book(acc)); /* Provide a reasonable title for the new lot */ id = kvp_frame_get_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id"); @@ -945,7 +945,7 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc) if (NULL == lot_split) { Account *lot_acc = lot->account; - QofBook *book = lot_acc->inst.book; + QofBook *book = qof_instance_get_book(lot_acc); new_gain_split = TRUE; diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index e5de9a1655..b639a2da89 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -816,7 +816,7 @@ add_price(GNCPriceDB *db, GNCPrice *p) db, p, qof_instance_get_dirty_flag(p), qof_instance_get_destroying(p)); - if (db->inst.book != p->inst.book) + if (!qof_instance_books_equal(db, p)) { PERR ("attempted to mix up prices across different books"); LEAVE (" ");