From 97b19d187815e355e8bf28680b8a7af77c2ce569 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Fri, 5 Oct 2001 08:35:04 +0000 Subject: [PATCH] Work on moving entity tables into sessions. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5466 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/gnc-ui-util.c | 4 +- src/app-utils/guile-util.c | 12 +- src/app-utils/guile-util.h | 5 +- src/backend/file/gnc-transaction-xml-v2.c | 135 +++++++++++------- src/backend/file/gnc-xml.h | 14 +- src/backend/file/io-gncbin-r.c | 6 +- src/backend/file/io-gncxml-v1.c | 3 +- src/backend/postgres/txn.c | 2 +- src/backend/postgres/txnmass.c | 2 +- src/engine/AccountP.h | 3 +- src/engine/GNCIdP.h | 4 + src/engine/GroupP.h | 2 +- src/engine/SchedXaction.c | 21 ++- src/engine/Scrub.c | 2 +- src/engine/Transaction.c | 32 +++-- src/engine/Transaction.h | 10 +- src/engine/TransactionP.h | 9 +- src/engine/engine-helpers.c | 23 +++ src/engine/engine-helpers.h | 1 + src/engine/engine-interface.scm | 4 +- src/engine/gnc-session-p.h | 12 +- src/engine/gnc-session.c | 9 +- src/engine/gw-engine-spec.scm | 2 +- src/engine/test-core/test-engine-stuff.c | 4 +- src/gnome/dialog-account.c | 4 +- src/gnome/dialog-transfer.c | 4 +- src/gnome/druid-stock-split.c | 6 +- src/import-export/qif-import/qif-to-gnc.scm | 12 +- .../qif-io-core/qif-bank-xtn-import.scm | 2 +- .../qif-io-core/qif-invst-xtn-import.scm | 2 +- .../ledger-core/split-register-load.c | 2 +- .../ledger-core/split-register-model-save.c | 2 +- src/register/ledger-core/split-register.c | 17 ++- 33 files changed, 235 insertions(+), 137 deletions(-) diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index 314f51019f..eac01946c3 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -927,7 +927,7 @@ gnc_account_create_opening_balance (Account *account, xaccTransSetDateSecs (trans, date); xaccTransSetDescription (trans, _("Opening Balance")); - split = xaccMallocSplit (); + split = xaccMallocSplit (session); xaccTransAppendSplit (trans, split); xaccAccountInsertSplit (account, split); @@ -937,7 +937,7 @@ gnc_account_create_opening_balance (Account *account, balance = gnc_numeric_neg (balance); - split = xaccMallocSplit (); + split = xaccMallocSplit (session); xaccTransAppendSplit (trans, split); xaccAccountInsertSplit (equity_account, split); diff --git a/src/app-utils/guile-util.c b/src/app-utils/guile-util.c index 908b57ba19..37ed372135 100644 --- a/src/app-utils/guile-util.c +++ b/src/app-utils/guile-util.c @@ -733,10 +733,10 @@ gnc_copy_trans(Transaction *trans, gboolean use_cut_semantics) \********************************************************************/ void gnc_copy_trans_scm_onto_trans(SCM trans_scm, Transaction *trans, - gboolean do_commit) + gboolean do_commit, GNCSession *session) { gnc_copy_trans_scm_onto_trans_swap_accounts(trans_scm, trans, NULL, NULL, - do_commit); + do_commit, session); } @@ -758,7 +758,8 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm, Transaction *trans, const GUID *guid_1, const GUID *guid_2, - gboolean do_commit) + gboolean do_commit, + GNCSession *session) { static SCM trans_type = SCM_UNDEFINED; SCM result; @@ -771,6 +772,8 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm, if (trans == NULL) return; + g_return_if_fail (session); + func = gh_eval_str("gnc:transaction-scm?"); if (!gh_procedure_p(func)) return; @@ -798,6 +801,7 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm, commit = gh_bool2scm(do_commit); + args = gh_cons(gnc_session_to_scm (session), args); args = gh_cons(commit, args); args = gh_cons(SCM_EOL, args); args = gh_cons(arg, args); @@ -813,6 +817,8 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm, SCM commit; char *guid_str; + args = gh_cons(gnc_session_to_scm (session), args); + commit = gh_bool2scm(do_commit); args = gh_cons(commit, args); diff --git a/src/app-utils/guile-util.h b/src/app-utils/guile-util.h index f46d921967..7410a60c8e 100644 --- a/src/app-utils/guile-util.h +++ b/src/app-utils/guile-util.h @@ -68,12 +68,13 @@ gnc_numeric gnc_split_scm_get_value(SCM split_scm); SCM gnc_copy_trans(Transaction *trans, gboolean use_cut_semantics); void gnc_copy_trans_scm_onto_trans(SCM trans_scm, Transaction *trans, - gboolean do_commit); + gboolean do_commit, GNCSession *session); void gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm, Transaction *trans, const GUID *guid_1, const GUID *guid_2, - gboolean do_commit); + gboolean do_commit, + GNCSession *session); void gnc_trans_scm_set_date(SCM trans_scm, Timespec *ts); void gnc_trans_scm_set_num(SCM trans_scm, const char *num); diff --git a/src/backend/file/gnc-transaction-xml-v2.c b/src/backend/file/gnc-transaction-xml-v2.c index d52c0f9a43..c46cfe51c6 100644 --- a/src/backend/file/gnc-transaction-xml-v2.c +++ b/src/backend/file/gnc-transaction-xml-v2.c @@ -312,11 +312,13 @@ struct dom_tree_handler spl_dom_handlers[] = }; Split* -dom_tree_to_split(xmlNodePtr node) +dom_tree_to_split(xmlNodePtr node, GNCSession *session) { Split *ret; - ret = xaccMallocSplit(); + g_return_val_if_fail (session, NULL); + + ret = xaccMallocSplit(session); g_return_val_if_fail(ret, NULL); /* this isn't going to work in a testing setup */ @@ -331,43 +333,17 @@ dom_tree_to_split(xmlNodePtr node) } } - -static gboolean -trn_splits_handler(xmlNodePtr node, gpointer trn) -{ - xmlNodePtr mark; - - g_return_val_if_fail(node, FALSE); - g_return_val_if_fail(node->xmlChildrenNode, FALSE); - - for(mark = node->xmlChildrenNode; mark; mark = mark->next) - { - Split *spl; - - if(safe_strcmp("trn:split", mark->name)) - { - return FALSE; - } - - spl = dom_tree_to_split(mark); - - if(spl) - { - xaccTransAppendSplit((Transaction*)trn, spl); - } - else - { - return FALSE; - } - } - return TRUE; -} - /***********************************************************************/ +struct trans_pdata +{ + Transaction *trans; + GNCSession *session; +}; + static gboolean set_tran_string(xmlNodePtr node, Transaction *trn, - void (*func)(Transaction *trn, const char *txt)) + void (*func)(Transaction *trn, const char *txt)) { gchar *tmp; @@ -384,7 +360,7 @@ set_tran_string(xmlNodePtr node, Transaction *trn, static gboolean set_tran_date(xmlNodePtr node, Transaction *trn, - void (*func)(Transaction *trn, const Timespec *tm)) + void (*func)(Transaction *trn, const Timespec *tm)) { Timespec *tm; @@ -400,9 +376,12 @@ set_tran_date(xmlNodePtr node, Transaction *trn, } static gboolean -trn_id_handler(xmlNodePtr node, gpointer trn) +trn_id_handler(xmlNodePtr node, gpointer trans_pdata) { + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; GUID *tmp = dom_tree_to_guid(node); + g_return_val_if_fail(tmp, FALSE); xaccTransSetGUID((Transaction*)trn, tmp); @@ -413,8 +392,10 @@ trn_id_handler(xmlNodePtr node, gpointer trn) } static gboolean -trn_currency_handler(xmlNodePtr node, gpointer trn) +trn_currency_handler(xmlNodePtr node, gpointer trans_pdata) { + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; gnc_commodity *ref; ref = dom_tree_to_commodity_ref_no_engine(node); @@ -424,32 +405,46 @@ trn_currency_handler(xmlNodePtr node, gpointer trn) } static gboolean -trn_num_handler(xmlNodePtr node, gpointer trn) +trn_num_handler(xmlNodePtr node, gpointer trans_pdata) { - return set_tran_string(node, (Transaction*)trn, xaccTransSetNum); + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; + + return set_tran_string(node, trn, xaccTransSetNum); } static gboolean -trn_date_posted_handler(xmlNodePtr node, gpointer trn) +trn_date_posted_handler(xmlNodePtr node, gpointer trans_pdata) { - return set_tran_date(node, (Transaction*)trn, xaccTransSetDatePostedTS); + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; + + return set_tran_date(node, trn, xaccTransSetDatePostedTS); } static gboolean -trn_date_entered_handler(xmlNodePtr node, gpointer trn) +trn_date_entered_handler(xmlNodePtr node, gpointer trans_pdata) { - return set_tran_date(node, (Transaction*)trn, xaccTransSetDateEnteredTS); + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; + + return set_tran_date(node, trn, xaccTransSetDateEnteredTS); } static gboolean -trn_description_handler(xmlNodePtr node, gpointer trn) +trn_description_handler(xmlNodePtr node, gpointer trans_pdata) { - return set_tran_string(node, (Transaction*)trn, xaccTransSetDescription); + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; + + return set_tran_string(node, trn, xaccTransSetDescription); } static gboolean -trn_slots_handler(xmlNodePtr node, gpointer trn) +trn_slots_handler(xmlNodePtr node, gpointer trans_pdata) { + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; gboolean successful; successful = dom_tree_to_kvp_frame_given(node, xaccTransGetSlots(trn)); @@ -459,6 +454,38 @@ trn_slots_handler(xmlNodePtr node, gpointer trn) return TRUE; } +static gboolean +trn_splits_handler(xmlNodePtr node, gpointer trans_pdata) +{ + struct trans_pdata *pdata = trans_pdata; + Transaction *trn = pdata->trans; + xmlNodePtr mark; + + g_return_val_if_fail(node, FALSE); + g_return_val_if_fail(node->xmlChildrenNode, FALSE); + + for(mark = node->xmlChildrenNode; mark; mark = mark->next) + { + Split *spl; + + if(safe_strcmp("trn:split", mark->name)) + { + return FALSE; + } + + spl = dom_tree_to_split(mark, pdata->session); + + if(spl) + { + xaccTransAppendSplit(trn, spl); + } + else + { + return FALSE; + } + } + return TRUE; +} struct dom_tree_handler trn_dom_handlers[] = { @@ -516,15 +543,20 @@ dom_tree_to_transaction( xmlNodePtr node, GNCSession *session ) { Transaction *trn; gboolean successful; + struct trans_pdata pdata; - g_return_val_if_fail(node, FALSE); + g_return_val_if_fail(node, NULL); + g_return_val_if_fail(session, NULL); trn = xaccMallocTransaction(session); - g_return_val_if_fail(trn, FALSE); + g_return_val_if_fail(trn, NULL); xaccTransBeginEdit(trn); - successful = dom_tree_generic_parse(node, trn_dom_handlers, trn); - + pdata.trans = trn; + pdata.session = session; + + successful = dom_tree_generic_parse(node, trn_dom_handlers, &pdata); + xaccTransCommitEdit(trn); if ( !successful ) @@ -536,7 +568,6 @@ dom_tree_to_transaction( xmlNodePtr node, GNCSession *session ) trn = NULL; } - //xmlFreeNode(tree); return trn; } diff --git a/src/backend/file/gnc-xml.h b/src/backend/file/gnc-xml.h index b51da9ea44..216ec2780b 100644 --- a/src/backend/file/gnc-xml.h +++ b/src/backend/file/gnc-xml.h @@ -27,16 +27,12 @@ #include "config.h" -#include "gnc-xml-helper.h" - -#include "Account.h" -#include "gnc-commodity.h" - -#include "sixtp.h" -#include "gnc-pricedb.h" - #include "FreqSpec.h" #include "SchedXaction.h" +#include "gnc-pricedb.h" +#include "gnc-session.h" +#include "gnc-xml-helper.h" +#include "sixtp.h" xmlNodePtr gnc_account_dom_tree_create(Account *act); sixtp* gnc_account_sixtp_parser_create(void); @@ -48,7 +44,7 @@ xmlNodePtr gnc_transaction_dom_tree_create(Transaction *com); sixtp* gnc_transaction_sixtp_parser_create(void); xmlNodePtr split_to_dom_tree(const gchar *tag, Split *spl); -Split* dom_tree_to_split(xmlNodePtr node); +Split* dom_tree_to_split(xmlNodePtr node, GNCSession *session); xmlNodePtr gnc_pricedb_dom_tree_create(GNCPriceDB *db); sixtp* gnc_pricedb_sixtp_parser_create(void); diff --git a/src/backend/file/io-gncbin-r.c b/src/backend/file/io-gncbin-r.c index a20f37642b..783f06602c 100644 --- a/src/backend/file/io-gncbin-r.c +++ b/src/backend/file/io-gncbin-r.c @@ -1089,9 +1089,9 @@ readTransaction(GNCSession *session, int fd, Account *acc, int revision) /* The code below really wants to assume that there are a pair * of splits in every transaction, so make it so. */ - s = xaccMallocSplit (); + s = xaccMallocSplit (session); xaccTransAppendSplit (trans, s); - s = xaccMallocSplit (); + s = xaccMallocSplit (session); xaccTransAppendSplit (trans, s); s = xaccTransGetSplit (trans, 0); @@ -1275,7 +1275,7 @@ readSplit ( GNCSession *session, int fd, int token ) ENTER (" "); /* create a split structure */ - split = xaccMallocSplit(); + split = xaccMallocSplit(session); tmp = readString( fd, token ); if( NULL == tmp ) diff --git a/src/backend/file/io-gncxml-v1.c b/src/backend/file/io-gncxml-v1.c index af8f0e27ff..930f1db158 100644 --- a/src/backend/file/io-gncxml-v1.c +++ b/src/backend/file/io-gncxml-v1.c @@ -3064,7 +3064,8 @@ txn_restore_split_start_handler(GSList* sibling_data, gpointer parent_data, gpointer *data_for_children, gpointer *result, const gchar *tag, gchar **attrs) { - Split *s = xaccMallocSplit(); + GNCParseStatus *pstatus = (GNCParseStatus *) global_data; + Split *s = xaccMallocSplit(pstatus->session); g_return_val_if_fail(s, FALSE); *data_for_children = s; return(TRUE); diff --git a/src/backend/postgres/txn.c b/src/backend/postgres/txn.c index 3931b91ae8..38e2e436de 100644 --- a/src/backend/postgres/txn.c +++ b/src/backend/postgres/txn.c @@ -407,7 +407,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans) s = xaccSplitLookup (&guid); if (!s) { - s = xaccMallocSplit(); + s = xaccMallocSplit(be->session); xaccSplitSetGUID(s, &guid); } diff --git a/src/backend/postgres/txnmass.c b/src/backend/postgres/txnmass.c index 72e20b0402..724be8cc4c 100644 --- a/src/backend/postgres/txnmass.c +++ b/src/backend/postgres/txnmass.c @@ -141,7 +141,7 @@ get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data) s = xaccSplitLookup (&guid); if (!s) { - s = xaccMallocSplit(); + s = xaccMallocSplit(be->session); xaccSplitSetGUID(s, &guid); } diff --git a/src/engine/AccountP.h b/src/engine/AccountP.h index 66d0501460..a91b17f533 100644 --- a/src/engine/AccountP.h +++ b/src/engine/AccountP.h @@ -53,7 +53,8 @@ /** STRUCTS *********************************************************/ -struct _account { +struct account_s +{ /* public data, describes account */ GUID guid; /* globally unique account id */ diff --git a/src/engine/GNCIdP.h b/src/engine/GNCIdP.h index 6e006a064a..9cbed9eef3 100644 --- a/src/engine/GNCIdP.h +++ b/src/engine/GNCIdP.h @@ -24,11 +24,15 @@ #ifndef GNC_ID_P_H #define GNC_ID_P_H 1 +#include + #include "GNCId.h" /* This file defines an engine-only API for using gnucash entity * identifiers. */ +typedef GHashTable GNCEntityTable; + /* Generate a new id. This function is guaranteed to return an id that * is unique within the scope of all GnuCash entities being managed by * the current invocation of GnuCash. GnuCash routines should always diff --git a/src/engine/GroupP.h b/src/engine/GroupP.h index 131abeccb7..6d3d7daddc 100644 --- a/src/engine/GroupP.h +++ b/src/engine/GroupP.h @@ -46,7 +46,7 @@ /** STRUCTS *********************************************************/ -struct _account_group +struct account_group_s { /* The flags: */ unsigned int saved : 1; diff --git a/src/engine/SchedXaction.c b/src/engine/SchedXaction.c index 557e132368..ddf252e6a6 100644 --- a/src/engine/SchedXaction.c +++ b/src/engine/SchedXaction.c @@ -509,14 +509,15 @@ xaccSchedXactionIsDirty(SchedXaction *sx) static Split * -pack_split_info(TTSplitInfo *s_info, Account *parent_acct, Transaction *parent_trans) +pack_split_info (TTSplitInfo *s_info, Account *parent_acct, + Transaction *parent_trans, GNCSession *session) { Split *split; kvp_frame *split_frame, *sx_frame; kvp_value *tmp_value; const GUID *acc_guid; - split = xaccMallocSplit(); + split = xaccMallocSplit(session); xaccSplitSetMemo(split, gnc_ttsplitinfo_get_memo(s_info)); @@ -571,14 +572,15 @@ void xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list, GNCSession *session) { - Transaction *new_trans; TTInfo *tti; TTSplitInfo *s_info; Split *new_split; - /* delete any old transactions, if there are any */ - GList *split_list; + + g_return_if_fail (session); + + /* delete any old transactions, if there are any */ delete_template_trans( sx ); for(;t_t_list != NULL; t_t_list = t_t_list->next) @@ -600,15 +602,10 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list, split_list = split_list->next) { s_info = split_list->data; - new_split = pack_split_info(s_info, sx->template_acct, new_trans); + new_split = pack_split_info(s_info, sx->template_acct, + new_trans, session); xaccTransAppendSplit(new_trans, new_split); } xaccTransCommitEdit(new_trans); - } - - return; } - - - diff --git a/src/engine/Scrub.c b/src/engine/Scrub.c index 6c5d062de1..50a3948821 100644 --- a/src/engine/Scrub.c +++ b/src/engine/Scrub.c @@ -354,7 +354,7 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root, /* put split into account before setting split value */ if (!balance_split) { - balance_split = xaccMallocSplit (); + balance_split = xaccMallocSplit (session); xaccAccountBeginEdit (account); xaccAccountInsertSplit (account, balance_split); diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 4896216d8c..d47826fa11 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -31,13 +31,11 @@ #include #include -#include "Account.h" #include "AccountP.h" #include "BackendP.h" #include "GNCIdP.h" #include "Group.h" #include "Scrub.h" -#include "Transaction.h" #include "TransactionP.h" #include "TransLog.h" #include "date.h" @@ -45,6 +43,7 @@ #include "gnc-engine-util.h" #include "gnc-engine.h" #include "gnc-event-p.h" +#include "gnc-session-p.h" #include "messages.h" @@ -93,7 +92,7 @@ check_open (Transaction *trans) \********************************************************************/ static void -xaccInitSplit(Split * split) +xaccInitSplit(Split * split, GNCEntityTable *entity_table) { /* fill in some sane defaults */ xaccSplitSetAccount(split, NULL); @@ -122,14 +121,28 @@ xaccInitSplit(Split * split) /********************************************************************\ \********************************************************************/ -Split * -xaccMallocSplit(void) +static Split * +xaccMallocSplitEntityTable (GNCEntityTable *entity_table) { - Split *split = g_new(Split, 1); - xaccInitSplit (split); + Split *split; + + /* FIXME: uncomment this when done with moving entity + * tables into sessions. */ + /* g_return_val_if_fail (entity_table, NULL); */ + + split = g_new (Split, 1); + xaccInitSplit (split, entity_table); + return split; } +Split * +xaccMallocSplit(GNCSession *session) +{ + g_return_val_if_fail (session, NULL); + return xaccMallocSplitEntityTable (gnc_session_get_entity_table (session)); +} + /********************************************************************\ \********************************************************************/ /* This routine is not exposed externally, since it does weird things, @@ -638,6 +651,7 @@ xaccInitTransaction (Transaction * trans, GNCSession *session) xaccGUIDNew(&trans->guid); xaccStoreEntity(trans, &trans->guid, GNC_ID_TRANS); + trans->entity_table = NULL; } /********************************************************************\ @@ -1312,7 +1326,7 @@ xaccTransCommitEdit (Transaction *trans) trans->date_entered.tv_sec = tv.tv_sec; trans->date_entered.tv_nsec = 1000 * tv.tv_usec; } - + /* Alternately the transaction may have only one split in * it, in which case that's OK if and only if the split has no * value (i.e. is only recording a price). Otherwise, a single @@ -1324,7 +1338,7 @@ xaccTransCommitEdit (Transaction *trans) if ((1 == force_double_entry) && (NULL == g_list_nth(trans->splits, 1)) && (!gnc_numeric_zero_p(split->amount))) { - Split * s = xaccMallocSplit(); + Split * s = xaccMallocSplitEntityTable(trans->entity_table); xaccTransAppendSplit (trans, s); xaccAccountInsertSplit (xaccSplitGetAccount(s), s); xaccSplitSetMemo (s, split->memo); diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 707af10817..2c26a0f139 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -43,10 +43,10 @@ /** STRUCTS *********************************************************/ -typedef struct _account Account; -typedef struct _account_group AccountGroup; -typedef struct _split Split; -typedef struct _transaction Transaction; +typedef struct account_s Account; +typedef struct account_group_s AccountGroup; +typedef struct split_s Split; +typedef struct transaction_s Transaction; /** PROTOTYPES ******************************************************/ @@ -243,7 +243,7 @@ void xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr); gnc_numeric xaccTransGetImbalance (Transaction * trans); /* ------------- splits --------------- */ -Split * xaccMallocSplit (void); +Split * xaccMallocSplit (GNCSession *session); gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, diff --git a/src/engine/TransactionP.h b/src/engine/TransactionP.h index 8dece4ba3d..6b5164c9eb 100644 --- a/src/engine/TransactionP.h +++ b/src/engine/TransactionP.h @@ -52,7 +52,7 @@ #include "kvp_frame.h" #include "gnc-numeric.h" #include "Transaction.h" /* for typedefs */ -#include "GNCId.h" +#include "GNCIdP.h" /** STRUCTS *********************************************************/ @@ -74,7 +74,7 @@ */ -struct _split +struct split_s { GUID guid; /* globally unique id */ @@ -128,13 +128,16 @@ struct _split }; -struct _transaction +struct transaction_s { /* guid is a globally unique identifier which can be used to * reference the transaction. */ GUID guid; + /* entity_table is the table where the transaction is stored by guid */ + GNCEntityTable *entity_table; + Timespec date_entered; /* date register entry was made */ Timespec date_posted; /* date transaction was posted at bank */ diff --git a/src/engine/engine-helpers.c b/src/engine/engine-helpers.c index d672fef055..a1f70c741b 100644 --- a/src/engine/engine-helpers.c +++ b/src/engine/engine-helpers.c @@ -1554,6 +1554,29 @@ gnc_book_to_scm (GNCBook *book) return gw_wcp_assimilate_ptr ((void *) book, book_type); } +/******************************************************************** + * gnc_session_to_scm + ********************************************************************/ +SCM +gnc_session_to_scm (GNCSession *session) +{ + static SCM session_type = SCM_UNDEFINED; + + if (!session) + return SCM_BOOL_F; + + if (session_type == SCM_UNDEFINED) + { + session_type = gh_eval_str (""); + + /* don't really need this - types are bound globally anyway. */ + if (session_type != SCM_UNDEFINED) + scm_protect_object (session_type); + } + + return gw_wcp_assimilate_ptr ((void *) session, session_type); +} + /******************************************************************** * gnc_glist_commodity_ptr_to_scm ********************************************************************/ diff --git a/src/engine/engine-helpers.h b/src/engine/engine-helpers.h index abd43d964f..0f4f8d8e2f 100644 --- a/src/engine/engine-helpers.h +++ b/src/engine/engine-helpers.h @@ -81,6 +81,7 @@ int gnc_numeric_p(SCM arg); gnc_commodity * gnc_scm_to_commodity(SCM scm); SCM gnc_commodity_to_scm (const gnc_commodity *commodity); SCM gnc_book_to_scm (GNCBook *book); +SCM gnc_session_to_scm (GNCSession *session); /* The GList is freed */ SCM gnc_glist_account_ptr_to_scm(GList *account_list); diff --git a/src/engine/engine-interface.scm b/src/engine/engine-interface.scm index ec88b66420..76977b0875 100644 --- a/src/engine/engine-interface.scm +++ b/src/engine/engine-interface.scm @@ -240,7 +240,7 @@ ;; guid-mapping must be an alist, mapping guids to guids. This list is ;; used to use alternate account guids when creating splits. (define (gnc:transaction-scm-onto-transaction trans-scm trans guid-mapping - commit?) + commit? session) (if (not trans) #f (begin @@ -272,7 +272,7 @@ ;; order as in the original transaction. This is important. (let loop ((split-scms (gnc:transaction-scm-get-split-scms trans-scm))) (if (pair? split-scms) - (let* ((new-split (gnc:split-create)) + (let* ((new-split (gnc:split-create session)) (split-scm (car split-scms)) (old-guid (gnc:split-scm-get-account-guid split-scm)) (new-guid (assoc-ref guid-mapping old-guid))) diff --git a/src/engine/gnc-session-p.h b/src/engine/gnc-session-p.h index 1dccc4281f..75eab5c92a 100644 --- a/src/engine/gnc-session-p.h +++ b/src/engine/gnc-session-p.h @@ -29,16 +29,22 @@ #define GNC_SESSION_P_H #include "BackendP.h" +#include "GNCIdP.h" #include "TransLog.h" -#include "gnc-book.h" #include "gnc-engine-util.h" #include "gnc-engine.h" #include "gnc-session.h" struct gnc_session_struct { + /* The book is the cache for the underlying gnucash dataset. */ GNCBook *book; + /* The entity table associates the GUIDs of all the objects + * created in the session with their respective objects + * (pointer addresses) */ + GNCEntityTable *entity_table; + /* the requested book id, in the form or a URI, such as * file:/some/where, or sql:server.host.com:555 */ @@ -66,7 +72,9 @@ struct gnc_session_struct void gnc_session_set_book (GNCSession *session, GNCBook *book); -Backend * gnc_session_get_backend (GNCSession *session); +GNCEntityTable *gnc_session_get_entity_table (GNCSession *session); + +Backend * gnc_session_get_backend (GNCSession *session); /* * used by backends to mark the notsaved as FALSE just after diff --git a/src/engine/gnc-session.c b/src/engine/gnc-session.c index 221d9638bc..5f5c92f3b3 100644 --- a/src/engine/gnc-session.c +++ b/src/engine/gnc-session.c @@ -120,7 +120,7 @@ gnc_session_init (GNCSession *session) if (!session) return; session->book = gnc_book_new (); - + session->entity_table = NULL; session->book_id = NULL; session->fullpath = NULL; session->logpath = NULL; @@ -158,6 +158,13 @@ gnc_session_set_book (GNCSession *session, GNCBook *book) session->book = book; } +GNCEntityTable * +gnc_session_get_entity_table (GNCSession *session) +{ + if (!session) return NULL; + return session->entity_table; +} + Backend * gnc_session_get_backend (GNCSession *session) { diff --git a/src/engine/gw-engine-spec.scm b/src/engine/gw-engine-spec.scm index 80af364ac6..58c563dc6e 100644 --- a/src/engine/gw-engine-spec.scm +++ b/src/engine/gw-engine-spec.scm @@ -1682,7 +1682,7 @@ of having a parent transaction with which one is working...") 'gnc:split-create ' "xaccMallocSplit" - '() + '(( session>>)) "Create a Split structure") (gw:wrap-function diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c index 91a66977c0..5041bcc2bd 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.c @@ -502,8 +502,8 @@ get_random_split(GNCSession *session, gnc_numeric num) { Split *ret; gnc_numeric oneVal; - - ret = xaccMallocSplit(); + + ret = xaccMallocSplit(session); set_split_random_string(ret, xaccSplitSetMemo); set_split_random_string(ret, xaccSplitSetAction); diff --git a/src/gnome/dialog-account.c b/src/gnome/dialog-account.c index 755fca8e53..cb5e61c422 100644 --- a/src/gnome/dialog-account.c +++ b/src/gnome/dialog-account.c @@ -234,7 +234,7 @@ gnc_account_create_transfer_balance (Account *account, xaccTransSetDateSecs (trans, date); xaccTransSetDescription (trans, _("Opening Balance")); - split = xaccMallocSplit (); + split = xaccMallocSplit (gnc_get_current_session ()); xaccTransAppendSplit (trans, split); xaccAccountInsertSplit (account, split); @@ -244,7 +244,7 @@ gnc_account_create_transfer_balance (Account *account, balance = gnc_numeric_neg (balance); - split = xaccMallocSplit (); + split = xaccMallocSplit (gnc_get_current_session ()); xaccTransAppendSplit (trans, split); xaccAccountInsertSplit (transfer, split); diff --git a/src/gnome/dialog-transfer.c b/src/gnome/dialog-transfer.c index f38ce835e7..e2dc1af4c9 100644 --- a/src/gnome/dialog-transfer.c +++ b/src/gnome/dialog-transfer.c @@ -1126,11 +1126,11 @@ gnc_xfer_dialog_ok_cb(GtkWidget * widget, gpointer data) xaccTransSetDescription(trans, string); /* create from split */ - from_split = xaccMallocSplit(); + from_split = xaccMallocSplit(gnc_get_current_session ()); xaccTransAppendSplit(trans, from_split); /* create to split */ - to_split = xaccMallocSplit(); + to_split = xaccMallocSplit(gnc_get_current_session ()); xaccTransAppendSplit(trans, to_split); xaccAccountBeginEdit(from_account); diff --git a/src/gnome/druid-stock-split.c b/src/gnome/druid-stock-split.c index dd0c69d7cc..9ece27eb8c 100644 --- a/src/gnome/druid-stock-split.c +++ b/src/gnome/druid-stock-split.c @@ -382,7 +382,7 @@ stock_split_finish (GnomeDruidPage *druidpage, xaccTransSetDescription (trans, description); } - split = xaccMallocSplit (); + split = xaccMallocSplit (gnc_get_current_session ()); xaccAccountBeginEdit (account); account_commits = g_list_prepend (NULL, account); @@ -441,7 +441,7 @@ stock_split_finish (GnomeDruidPage *druidpage, account = gnc_account_tree_get_current_account (GNC_ACCOUNT_TREE (info->asset_tree)); - split = xaccMallocSplit (); + split = xaccMallocSplit (gnc_get_current_session ()); xaccAccountBeginEdit (account); account_commits = g_list_prepend (account_commits, account); @@ -460,7 +460,7 @@ stock_split_finish (GnomeDruidPage *druidpage, account = gnc_account_tree_get_current_account (GNC_ACCOUNT_TREE (info->income_tree)); - split = xaccMallocSplit (); + split = xaccMallocSplit (gnc_get_current_session ()); xaccAccountBeginEdit (account); account_commits = g_list_prepend (account_commits, account); diff --git a/src/import-export/qif-import/qif-to-gnc.scm b/src/import-export/qif-import/qif-to-gnc.scm index a31737efc3..24113f843e 100644 --- a/src/import-export/qif-import/qif-to-gnc.scm +++ b/src/import-export/qif-import/qif-to-gnc.scm @@ -364,7 +364,7 @@ gnc-acct-hash qif-acct-map qif-cat-map qif-memo-map) (let ((splits (qif-xtn:splits qif-xtn)) - (gnc-near-split (gnc:split-create)) + (gnc-near-split (gnc:split-create (gnc:get-current-session))) (near-split-total (gnc:numeric-zero)) (near-acct-info #f) (near-acct-name #f) @@ -413,7 +413,8 @@ (for-each (lambda (qif-split) (if (not (qif-split:mark qif-split)) - (let ((gnc-far-split (gnc:split-create)) + (let ((gnc-far-split (gnc:split-create + (gnc:get-current-session))) (far-acct-info #f) (far-acct-name #f) (far-acct-type #f) @@ -501,7 +502,7 @@ (commission-amt (qif-xtn:commission qif-xtn)) (commission-split #f) (defer-share-price #f) - (gnc-far-split (gnc:split-create))) + (gnc-far-split (gnc:split-create (gnc:get-current-session)))) (if (not num-shares) (set! num-shares (gnc:numeric-zero))) (if (not share-price) (set! share-price (gnc:numeric-zero))) @@ -616,10 +617,11 @@ (if (and commission-amt commission-acct) (begin - (set! commission-split (gnc:split-create)) + (set! commission-split (gnc:split-create + (gnc:get-current-session))) (gnc:split-set-value commission-split commission-amt) (gnc:split-set-amount commission-split commission-amt))) - + (if (and qif-near-acct qif-far-acct) (begin (gnc:transaction-append-split gnc-xtn gnc-near-split) diff --git a/src/import-export/qif-io-core/qif-bank-xtn-import.scm b/src/import-export/qif-io-core/qif-bank-xtn-import.scm index c9c316b5f6..861a57e9b7 100644 --- a/src/import-export/qif-io-core/qif-bank-xtn-import.scm +++ b/src/import-export/qif-io-core/qif-bank-xtn-import.scm @@ -55,7 +55,7 @@ (acct-type (cdr acct-info)) (acct (qif-io:acct-table-lookup gnc-acct-info acct-name acct-type)) - (split (gnc:split-create))) + (split (gnc:split-create (gnc:get-current-session)))) ;; make the account if necessary (if (not acct) (begin diff --git a/src/import-export/qif-io-core/qif-invst-xtn-import.scm b/src/import-export/qif-io-core/qif-invst-xtn-import.scm index 97e10e3851..18de4c4134 100644 --- a/src/import-export/qif-io-core/qif-invst-xtn-import.scm +++ b/src/import-export/qif-io-core/qif-invst-xtn-import.scm @@ -155,7 +155,7 @@ (acct-type (cdr acct-info)) (acct (qif-io:acct-table-lookup gnc-acct-info acct-name acct-type)) - (split (gnc:split-create))) + (split (gnc:split-create (gnc:get-current-session)))) ;; make the account if necessary (if (not acct) (begin diff --git a/src/register/ledger-core/split-register-load.c b/src/register/ledger-core/split-register-load.c index 5821f13f62..e1e5c0f6b8 100644 --- a/src/register/ledger-core/split-register-load.c +++ b/src/register/ledger-core/split-register-load.c @@ -179,7 +179,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist, xaccTransBeginEdit (trans); xaccTransSetCurrency (trans, gnc_default_currency ()); /* is this lame? */ xaccTransSetDateSecs (trans, info->last_date_entered); - blank_split = xaccMallocSplit (); + blank_split = xaccMallocSplit (gnc_get_current_session ()); xaccTransAppendSplit (trans, blank_split); xaccTransCommitEdit (trans); diff --git a/src/register/ledger-core/split-register-model-save.c b/src/register/ledger-core/split-register-model-save.c index 4682850ae6..f8b6ea1d52 100644 --- a/src/register/ledger-core/split-register-model-save.c +++ b/src/register/ledger-core/split-register-model-save.c @@ -204,7 +204,7 @@ gnc_split_register_save_cells (gpointer save_data, other_split = xaccTransGetSplit (trans, 1); if (!other_split) { - other_split = xaccMallocSplit (); + other_split = xaccMallocSplit (gnc_get_current_session ()); xaccTransAppendSplit (trans, other_split); } } diff --git a/src/register/ledger-core/split-register.c b/src/register/ledger-core/split-register.c index 6053aa1b14..f974d026fc 100644 --- a/src/register/ledger-core/split-register.c +++ b/src/register/ledger-core/split-register.c @@ -200,7 +200,8 @@ gnc_copy_trans_onto_trans(Transaction *from, Transaction *to, if (trans_scm == SCM_UNDEFINED) return; - gnc_copy_trans_scm_onto_trans(trans_scm, to, do_commit); + gnc_copy_trans_scm_onto_trans(trans_scm, to, do_commit, + gnc_get_current_session ()); } static int @@ -522,7 +523,7 @@ gnc_split_register_duplicate_current (SplitRegister *reg) /* We are on a split in an expanded transaction. * Just copy the split and add it to the transaction. */ - new_split = xaccMallocSplit (); + new_split = xaccMallocSplit (gnc_get_current_session ()); xaccTransBeginEdit (trans); xaccTransAppendSplit (trans, new_split); @@ -802,7 +803,7 @@ gnc_split_register_paste_current (SplitRegister *reg) xaccTransBeginEdit(trans); if (split == NULL) { /* We are on a null split in an expanded transaction. */ - split = xaccMallocSplit(); + split = xaccMallocSplit(gnc_get_current_session ()); xaccTransAppendSplit(trans, split); } @@ -851,10 +852,12 @@ gnc_split_register_paste_current (SplitRegister *reg) new_guid = &info->default_account; gnc_copy_trans_scm_onto_trans_swap_accounts(copied_item, trans, &copied_leader_guid, - new_guid, TRUE); + new_guid, TRUE, + gnc_get_current_session ()); } else - gnc_copy_trans_scm_onto_trans(copied_item, trans, TRUE); + gnc_copy_trans_scm_onto_trans(copied_item, trans, TRUE, + gnc_get_current_session ()); num_splits = xaccTransCountSplits(trans); if (split_index >= num_splits) @@ -1219,7 +1222,7 @@ gnc_split_register_save_to_scm (SplitRegister *reg, { Split *temp_split; - temp_split = xaccMallocSplit (); + temp_split = xaccMallocSplit (gnc_get_current_session ()); other_split_scm = gnc_copy_split (temp_split, use_cut_semantics); xaccSplitDestroy (temp_split); @@ -1389,7 +1392,7 @@ gnc_split_register_save (SplitRegister *reg, gboolean do_commit) * the split to the pre-existing transaction. */ Split *trans_split; - split = xaccMallocSplit (); + split = xaccMallocSplit (gnc_get_current_session ()); xaccTransAppendSplit (trans, split); gnc_table_set_virt_cell_data (reg->table,