* src/engine/gnc-engine-util.c | 57 ++++++++++++++++----- * src/engine/gnc-engine-util.h | 44 ++++++++++------ - Previously, gnc-engine-util exposed direct access to the static GCache. This makes debugging various uses (and misuses) very difficult. Now, the static GCache itself is private, and all access is through gnc_string_cache_{remove,insert}().
* src/app-utils/gnc-component-manager.c | 8 +-- * src/business/business-core/gncAddress.c | 3 - * src/business/business-core/gncBillTerm.c | 3 - * src/business/business-core/gncCustomer.c | 3 - * src/business/business-core/gncEmployee.c | 3 - * src/business/business-core/gncEntry.c | 3 - * src/business/business-core/gncInvoice.c | 3 - * src/business/business-core/gncJob.c | 3 - * src/business/business-core/gncOrder.c | 3 - * src/business/business-core/gncTaxTable.c | 3 - * src/business/business-core/gncVendor.c | 3 - * src/business/business-core/test/test-customer.c | 10 +-- * src/business/business-core/test/test-employee.c | 4 - * src/business/business-core/test/test-job.c | 2 * src/business/business-core/test/test-vendor.c | 2 * src/engine/Transaction.c | 64 ++++++++++++------------ * src/engine/gnc-commodity.c | 33 ++++-------- * src/engine/gnc-engine.c | 2 * src/engine/gnc-pricedb.c | 16 ++---- * src/engine/kvp_frame.c | 12 ++-- * src/engine/qofid.c | 3 - * src/engine/qofquery-deserial.c | 6 -- * src/engine/test/test-commodities.c | 24 ++++----- * src/gnome-utils/QuickFill.c | 18 +----- - Convert all gcache users to use only public functions - consolidate CACHE_INSERT and CACHE_REMOVE macros into one place * src/engine/qofquery-deserial.c - annotate one possible bug discovered during the above src/app-utils/gnc-component-manager.c | 8 +-- src/business/business-core/gncAddress.c | 3 - src/business/business-core/gncBillTerm.c | 3 - src/business/business-core/gncCustomer.c | 3 - src/business/business-core/gncEmployee.c | 3 - src/business/business-core/gncEntry.c | 3 - src/business/business-core/gncInvoice.c | 3 - src/business/business-core/gncJob.c | 3 - src/business/business-core/gncOrder.c | 3 - src/business/business-core/gncTaxTable.c | 3 - src/business/business-core/gncVendor.c | 3 - src/business/business-core/test/test-customer.c | 10 +-- src/business/business-core/test/test-employee.c | 4 - src/business/business-core/test/test-job.c | 2 src/business/business-core/test/test-vendor.c | 2 src/engine/Transaction.c | 64 ++++++++++++------------ src/engine/gnc-commodity.c | 33 ++++-------- src/engine/gnc-engine-util.c | 57 ++++++++++++++++----- src/engine/gnc-engine-util.h | 44 ++++++++++------ src/engine/gnc-engine.c | 2 src/engine/gnc-pricedb.c | 16 ++---- src/engine/kvp_frame.c | 12 ++-- src/engine/qofid.c | 3 - src/engine/qofquery-deserial.c | 6 -- src/engine/test/test-commodities.c | 24 ++++----- src/gnome-utils/QuickFill.c | 18 +----- 26 files changed, 153 insertions(+), 182 deletions(-) Index: gnucash/src/app-utils/gnc-component-manager.c =================================================================== --- gnucash.orig/src/app-utils/gnc-component-manager.c +++ gnucash/src/app-utils/gnc-component-manager.c @@ -64,6 +64,7 @@ typedef struct /** Static Variables ************************************************/ static guint suspend_counter = 0; +/* Some code foolishly uses 0 instead of NO_COMPONENT, so we start with 1. */ static gint next_component_id = 1; static GList *components = NULL; @@ -127,9 +128,7 @@ clear_mask_hash (GHashTable *hash) static gboolean destroy_mask_hash_helper (gpointer key, gpointer value, gpointer user_data) { - GCache *gc = gnc_engine_get_string_cache (); - - g_cache_remove (gc, key); + gnc_string_cache_remove (key); g_free (value); return TRUE; @@ -246,8 +245,7 @@ add_event_type (ComponentEventInfo *cei, mask = g_hash_table_lookup (cei->event_masks, entity_type); if (!mask) { - char * key = g_cache_insert (gnc_engine_get_string_cache (), - (gpointer) entity_type); + char * key = gnc_string_cache_insert ((gpointer) entity_type); mask = g_new0 (GNCEngineEventType, 1); g_hash_table_insert (cei->event_masks, key, mask); } Index: gnucash/src/business/business-core/gncAddress.c =================================================================== --- gnucash.orig/src/business/business-core/gncAddress.c +++ gnucash/src/business/business-core/gncAddress.c @@ -52,9 +52,6 @@ struct _gncAddress #define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - G_INLINE_FUNC void mark_address (GncAddress *address); void mark_address (GncAddress *address) { Index: gnucash/src/business/business-core/gncBillTerm.c =================================================================== --- gnucash.orig/src/business/business-core/gncBillTerm.c +++ gnucash/src/business/business-core/gncBillTerm.c @@ -66,9 +66,6 @@ static QofLogModule log_module = GNC_MOD #define _GNC_MOD_NAME GNC_ID_BILLTERM -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - #define SET_STR(obj, member, str) { \ char * tmp; \ \ Index: gnucash/src/business/business-core/gncCustomer.c =================================================================== --- gnucash.orig/src/business/business-core/gncCustomer.c +++ gnucash/src/business/business-core/gncCustomer.c @@ -76,9 +76,6 @@ static QofLogModule log_module = GNC_MOD /* ============================================================== */ /* misc inline funcs */ -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - G_INLINE_FUNC void mark_customer (GncCustomer *customer); void mark_customer (GncCustomer *customer) { Index: gnucash/src/business/business-core/gncEmployee.c =================================================================== --- gnucash.orig/src/business/business-core/gncEmployee.c +++ gnucash/src/business/business-core/gncEmployee.c @@ -59,9 +59,6 @@ static QofLogModule log_module = GNC_MOD #define _GNC_MOD_NAME GNC_ID_EMPLOYEE -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - G_INLINE_FUNC void mark_employee (GncEmployee *employee); void mark_employee (GncEmployee *employee) { Index: gnucash/src/business/business-core/gncEntry.c =================================================================== --- gnucash.orig/src/business/business-core/gncEntry.c +++ gnucash/src/business/business-core/gncEntry.c @@ -156,9 +156,6 @@ gboolean gncEntryPaymentStringToType (co #define _GNC_MOD_NAME GNC_ID_ENTRY -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - #define SET_STR(obj, member, str) { \ char * tmp; \ \ Index: gnucash/src/business/business-core/gncInvoice.c =================================================================== --- gnucash.orig/src/business/business-core/gncInvoice.c +++ gnucash/src/business/business-core/gncInvoice.c @@ -76,9 +76,6 @@ static QofLogModule log_module = GNC_MOD #define GNC_INVOICE_ID "gncInvoice" #define GNC_INVOICE_GUID "invoice-guid" -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - #define SET_STR(obj, member, str) { \ char * tmp; \ \ Index: gnucash/src/business/business-core/gncJob.c =================================================================== --- gnucash.orig/src/business/business-core/gncJob.c +++ gnucash/src/business/business-core/gncJob.c @@ -54,9 +54,6 @@ static QofLogModule log_module = GNC_MOD /* ================================================================== */ /* misc inline functions */ -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - G_INLINE_FUNC void mark_job (GncJob *job); void mark_job (GncJob *job) { Index: gnucash/src/business/business-core/gncOrder.c =================================================================== --- gnucash.orig/src/business/business-core/gncOrder.c +++ gnucash/src/business/business-core/gncOrder.c @@ -57,9 +57,6 @@ static QofLogModule log_module = GNC_MOD #define _GNC_MOD_NAME GNC_ID_ORDER -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - #define SET_STR(obj, member, str) { \ char * tmp; \ \ Index: gnucash/src/business/business-core/gncTaxTable.c =================================================================== --- gnucash.orig/src/business/business-core/gncTaxTable.c +++ gnucash/src/business/business-core/gncTaxTable.c @@ -131,9 +131,6 @@ gncTaxIncludedStringToType (const char * #define _GNC_MOD_NAME GNC_ID_TAXTABLE -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - #define SET_STR(obj, member, str) { \ char * tmp; \ \ Index: gnucash/src/business/business-core/gncVendor.c =================================================================== --- gnucash.orig/src/business/business-core/gncVendor.c +++ gnucash/src/business/business-core/gncVendor.c @@ -65,9 +65,6 @@ static QofLogModule log_module = GNC_MOD /* ============================================================ */ /* Misc inline funcs */ -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); - G_INLINE_FUNC void mark_vendor (GncVendor *vendor); void mark_vendor (GncVendor *vendor) { Index: gnucash/src/business/business-core/test/test-customer.c =================================================================== --- gnucash.orig/src/business/business-core/test/test-customer.c +++ gnucash/src/business/business-core/test/test-customer.c @@ -205,17 +205,15 @@ test_bool_fcn (QofBook *book, const char int main (int argc, char **argv) { - gnc_engine_get_string_cache (); guid_init (); - qof_query_init (); + qof_query_init (); qof_object_initialize (); qof_book_register (); - do_test (cashobjects_register(), "Cannot register cash objects"); + do_test (cashobjects_register(), "Cannot register cash objects"); test_customer(); print_test_results(); - qof_query_shutdown(); + qof_query_shutdown(); guid_shutdown(); - qof_object_shutdown (); - gnc_engine_string_cache_destroy(); + qof_object_shutdown (); return 0; } Index: gnucash/src/business/business-core/test/test-employee.c =================================================================== --- gnucash.orig/src/business/business-core/test/test-employee.c +++ gnucash/src/business/business-core/test/test-employee.c @@ -217,7 +217,6 @@ test_gint_fcn (QofBook *book, const char int main (int argc, char **argv) { - gnc_engine_get_string_cache (); guid_init (); qof_query_init (); qof_object_initialize (); @@ -225,12 +224,11 @@ main (int argc, char **argv) do_test (gncInvoiceRegister(), "Cannot register GncInvoice"); do_test (gncJobRegister (), "Cannot register GncJob"); do_test (gncCustomerRegister(), "Cannot register GncCustomer"); - do_test (gncEmployeeRegister(), "Cannot register GncEmployee"); + do_test (gncEmployeeRegister(), "Cannot register GncEmployee"); test_employee(); print_test_results(); qof_query_shutdown(); guid_shutdown(); qof_object_shutdown (); - gnc_engine_string_cache_destroy(); return 0; } Index: gnucash/src/business/business-core/test/test-job.c =================================================================== --- gnucash.orig/src/business/business-core/test/test-job.c +++ gnucash/src/business/business-core/test/test-job.c @@ -234,7 +234,6 @@ test_gint_fcn (QofBook *book, const char int main (int argc, char **argv) { - gnc_engine_get_string_cache (); guid_init (); qof_query_init (); qof_object_initialize (); @@ -247,7 +246,6 @@ main (int argc, char **argv) qof_query_shutdown(); guid_shutdown(); qof_object_shutdown (); - gnc_engine_string_cache_destroy(); return 0; } Index: gnucash/src/business/business-core/test/test-vendor.c =================================================================== --- gnucash.orig/src/business/business-core/test/test-vendor.c +++ gnucash/src/business/business-core/test/test-vendor.c @@ -215,7 +215,6 @@ test_gint_fcn (QofBook *book, const char int main (int argc, char **argv) { - gnc_engine_get_string_cache (); guid_init (); qof_query_init (); qof_object_initialize (); @@ -229,6 +228,5 @@ main (int argc, char **argv) qof_query_shutdown(); guid_shutdown(); qof_object_shutdown (); - gnc_engine_string_cache_destroy(); return 0; } Index: gnucash/src/engine/Transaction.c =================================================================== --- gnucash.orig/src/engine/Transaction.c +++ gnucash/src/engine/Transaction.c @@ -101,8 +101,8 @@ xaccInitSplit(Split * split, QofBook *bo split->parent = NULL; split->lot = NULL; - split->action = g_cache_insert(gnc_engine_get_string_cache(), ""); - split->memo = g_cache_insert(gnc_engine_get_string_cache(), ""); + split->action = gnc_string_cache_insert(""); + split->memo = gnc_string_cache_insert(""); split->reconciled = NREC; split->amount = gnc_numeric_zero(); split->value = gnc_numeric_zero(); @@ -168,8 +168,8 @@ xaccDupeSplit (Split *s) split->acc = s->acc; split->lot = s->lot; - split->memo = g_cache_insert (gnc_engine_get_string_cache(), s->memo); - split->action = g_cache_insert (gnc_engine_get_string_cache(), s->action); + split->memo = gnc_string_cache_insert(s->memo); + split->action = gnc_string_cache_insert(s->action); split->kvp_data = kvp_frame_copy (s->kvp_data); @@ -196,8 +196,8 @@ xaccSplitClone (Split *s) split->book = s->book; split->parent = NULL; - split->memo = g_cache_insert(gnc_engine_get_string_cache(), s->memo); - split->action = g_cache_insert(gnc_engine_get_string_cache(), s->action); + split->memo = gnc_string_cache_insert(s->memo); + split->action = gnc_string_cache_insert(s->action); split->kvp_data = kvp_frame_copy(s->kvp_data); split->reconciled = s->reconciled; split->date_reconciled = s->date_reconciled; @@ -260,8 +260,8 @@ xaccFreeSplit (Split *split) PERR ("double-free %p", split); return; } - g_cache_remove(gnc_engine_get_string_cache(), split->memo); - g_cache_remove(gnc_engine_get_string_cache(), split->action); + gnc_string_cache_remove(split->memo); + gnc_string_cache_remove(split->action); kvp_frame_delete (split->kvp_data); split->kvp_data = NULL; @@ -798,8 +798,8 @@ xaccInitTransaction (Transaction * trans { ENTER ("trans=%p", trans); /* Fill in some sane defaults */ - trans->num = g_cache_insert(gnc_engine_get_string_cache(), ""); - trans->description = g_cache_insert(gnc_engine_get_string_cache(), ""); + trans->num = gnc_string_cache_insert(""); + trans->description = gnc_string_cache_insert(""); trans->common_currency = NULL; trans->splits = NULL; @@ -911,8 +911,8 @@ xaccDupeTransaction (Transaction *t) trans = g_new0 (Transaction, 1); - trans->num = g_cache_insert (gnc_engine_get_string_cache(), t->num); - trans->description = g_cache_insert (gnc_engine_get_string_cache(), t->description); + trans->num = gnc_string_cache_insert (t->num); + trans->description = gnc_string_cache_insert (t->description); trans->splits = g_list_copy (t->splits); for (node = trans->splits; node; node = node->next) @@ -959,8 +959,8 @@ xaccTransClone (Transaction *t) trans->date_entered = t->date_entered; trans->date_posted = t->date_posted; - trans->num = g_cache_insert (gnc_engine_get_string_cache(), t->num); - trans->description = g_cache_insert (gnc_engine_get_string_cache(), t->description); + trans->num = gnc_string_cache_insert (t->num); + trans->description = gnc_string_cache_insert (t->description); trans->common_currency = t->common_currency; trans->version = t->version; trans->version_check = t->version_check; @@ -1010,8 +1010,8 @@ xaccFreeTransaction (Transaction *trans) trans->splits = NULL; /* free up transaction strings */ - g_cache_remove(gnc_engine_get_string_cache(), trans->num); - g_cache_remove(gnc_engine_get_string_cache(), trans->description); + gnc_string_cache_remove(trans->num); + gnc_string_cache_remove(trans->description); /* Just in case someone looks up freed memory ... */ trans->num = (char *) 1; @@ -1689,13 +1689,13 @@ xaccTransRollbackEdit (Transaction *tran trans->common_currency = orig->common_currency; - g_cache_remove (gnc_engine_get_string_cache(), trans->num); + gnc_string_cache_remove (trans->num); trans->num = orig->num; - orig->num = g_cache_insert(gnc_engine_get_string_cache(), ""); + orig->num = gnc_string_cache_insert(""); - g_cache_remove (gnc_engine_get_string_cache(), trans->description); + gnc_string_cache_remove (trans->description); trans->description = orig->description; - orig->description = g_cache_insert(gnc_engine_get_string_cache(), ""); + orig->description = gnc_string_cache_insert(""); kvp_frame_delete (trans->inst.kvp_data); trans->inst.kvp_data = orig->inst.kvp_data; @@ -1741,13 +1741,13 @@ xaccTransRollbackEdit (Transaction *tran break; } - g_cache_remove (gnc_engine_get_string_cache(), s->action); + gnc_string_cache_remove (s->action); s->action = so->action; - so->action = g_cache_insert(gnc_engine_get_string_cache(), ""); + so->action = gnc_string_cache_insert(""); - g_cache_remove (gnc_engine_get_string_cache(), s->memo); + gnc_string_cache_remove (s->memo); s->memo = so->memo; - so->memo = g_cache_insert(gnc_engine_get_string_cache(), ""); + so->memo = gnc_string_cache_insert(""); kvp_frame_delete (s->kvp_data); s->kvp_data = so->kvp_data; @@ -2477,8 +2477,8 @@ xaccTransSetNum (Transaction *trans, con if (!trans || !xnum) return; check_open (trans); - tmp = g_cache_insert(gnc_engine_get_string_cache(), (gpointer) xnum); - g_cache_remove(gnc_engine_get_string_cache(), trans->num); + tmp = gnc_string_cache_insert((gpointer) xnum); + gnc_string_cache_remove(trans->num); trans->num = tmp; } @@ -2497,8 +2497,8 @@ xaccTransSetDescription (Transaction *tr if (!trans || !desc) return; check_open (trans); - tmp = g_cache_insert(gnc_engine_get_string_cache(), (gpointer) desc); - g_cache_remove(gnc_engine_get_string_cache(), trans->description); + tmp = gnc_string_cache_insert((gpointer) desc); + gnc_string_cache_remove(trans->description); trans->description = tmp; } @@ -2724,8 +2724,8 @@ xaccSplitSetMemo (Split *split, const ch if (!split || !memo) return; check_open (split->parent); - tmp = g_cache_insert(gnc_engine_get_string_cache(), (gpointer) memo); - g_cache_remove(gnc_engine_get_string_cache(), split->memo); + tmp = gnc_string_cache_insert((gpointer) memo); + gnc_string_cache_remove(split->memo); split->memo = tmp; } @@ -2736,8 +2736,8 @@ xaccSplitSetAction (Split *split, const if (!split || !actn) return; check_open (split->parent); - tmp = g_cache_insert(gnc_engine_get_string_cache(), (gpointer) actn); - g_cache_remove(gnc_engine_get_string_cache(), split->action); + tmp = gnc_string_cache_insert((gpointer) actn); + gnc_string_cache_remove(split->action); split->action = tmp; } Index: gnucash/src/engine/gnc-commodity.c =================================================================== --- gnucash.orig/src/engine/gnc-commodity.c +++ gnucash/src/engine/gnc-commodity.c @@ -447,11 +447,14 @@ gnc_quote_source_set_fq_installed (GList * gnc_commodity_new ********************************************************************/ +/* TODO: convert these to their more conventional form */ +#undef CACHE_INSERT +#undef CACHE_REMOVE #define CACHE_INSERT(dest,src) \ - if(src) { dest = g_cache_insert(str_cache, (gpointer)src); } + if(src) { dest = gnc_string_cache_insert((gpointer)src); } #define CACHE_REMOVE(str) \ - if(str) { g_cache_remove(str_cache, str); str = NULL; } + if(str) { gnc_string_cache_remove(str); str=NULL; } static void mark_commodity_dirty (gnc_commodity *cm) @@ -488,7 +491,6 @@ gnc_commodity_new(QofBook *book, const c const char * exchange_code, int fraction) { - GCache *str_cache = gnc_engine_get_string_cache (); gnc_commodity * retval = g_new0(gnc_commodity, 1); gnc_commodity_table *table; @@ -526,7 +528,6 @@ gnc_commodity_new(QofBook *book, const c void gnc_commodity_destroy(gnc_commodity * cm) { - GCache *str_cache = gnc_engine_get_string_cache (); if(!cm) return; gnc_engine_gen_event (&cm->inst.entity, GNC_EVENT_DESTROY); @@ -569,7 +570,6 @@ gnc_commodity_copy(gnc_commodity * dest, gnc_commodity * gnc_commodity_clone(gnc_commodity *src) { - GCache *str_cache = gnc_engine_get_string_cache (); gnc_commodity * dest = g_new0(gnc_commodity, 1); CACHE_INSERT (dest->fullname, src->fullname); @@ -739,7 +739,6 @@ gnc_commodity_get_quote_tz(const gnc_com void gnc_commodity_set_mnemonic(gnc_commodity * cm, const char * mnemonic) { - GCache *str_cache = gnc_engine_get_string_cache (); if(!cm) return; if(cm->mnemonic == mnemonic) return; @@ -782,7 +781,6 @@ gnc_commodity_set_namespace(gnc_commodit void gnc_commodity_set_fullname(gnc_commodity * cm, const char * fullname) { - GCache *str_cache = gnc_engine_get_string_cache (); if(!cm) return; if(cm->fullname == fullname) return; @@ -801,7 +799,6 @@ void gnc_commodity_set_exchange_code(gnc_commodity * cm, const char * exchange_code) { - GCache *str_cache = gnc_engine_get_string_cache (); if(!cm) return; if(cm->exchange_code == exchange_code) return; @@ -870,7 +867,6 @@ gnc_commodity_set_quote_source(gnc_commo void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz) { - GCache *str_cache = gnc_engine_get_string_cache (); ENTER ("(cm=%p, tz=%s)", cm, tz); if(!cm) return; @@ -1173,7 +1169,6 @@ gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table * table, gnc_commodity * comm) { - GCache *str_cache; gnc_commodity_namespace * nsp = NULL; gnc_commodity *c; const char *ns_name; @@ -1197,11 +1192,11 @@ gnc_commodity_table_insert(gnc_commodity } nsp = gnc_commodity_table_add_namespace(table, ns_name); - str_cache = gnc_engine_get_string_cache (); - PINFO ("insert %p %s into nsp=%p %s", comm->mnemonic, comm->mnemonic, nsp->cm_table, nsp->name); + PINFO ("insert %p %s into nsp=%p %s", comm->mnemonic, comm->mnemonic, + nsp->cm_table, nsp->name); g_hash_table_insert(nsp->cm_table, - (gpointer)g_cache_insert(str_cache, comm->mnemonic), + gnc_string_cache_insert(comm->mnemonic), (gpointer)comm); nsp->cm_list = g_list_append(nsp->cm_list, comm); @@ -1432,10 +1427,9 @@ gnc_commodity_table_add_namespace(gnc_co ns = gnc_commodity_table_find_namespace(table, namespace); if(!ns) { - GCache *str_cache = gnc_engine_get_string_cache (); ns = g_new0(gnc_commodity_namespace, 1); ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal); - ns->name = g_cache_insert(str_cache, (gpointer)namespace); + ns->name = gnc_string_cache_insert((gpointer)namespace); gnc_engine_gen_event (&ns->inst.entity, GNC_EVENT_CREATE); g_hash_table_insert(table->ns_table, @@ -1487,10 +1481,9 @@ gnc_commodity_find_namespace_by_guid(con static int ns_helper(gpointer key, gpointer value, gpointer user_data) { - GCache *str_cache = user_data; gnc_commodity * c = value; gnc_commodity_destroy(c); - g_cache_remove (str_cache, key); /* key is commodity mnemonic */ + gnc_string_cache_remove(key); /* key is commodity mnemonic */ return TRUE; } @@ -1499,7 +1492,6 @@ gnc_commodity_table_delete_namespace(gnc const char * namespace) { gnc_commodity_namespace * ns; - GCache *str_cache; if (!table) return; @@ -1514,10 +1506,9 @@ gnc_commodity_table_delete_namespace(gnc g_list_free(ns->cm_list); ns->cm_list = NULL; - str_cache = gnc_engine_get_string_cache (); - g_hash_table_foreach_remove(ns->cm_table, ns_helper, str_cache); + g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL); g_hash_table_destroy(ns->cm_table); - g_cache_remove (str_cache, ns->name); + gnc_string_cache_remove(ns->name); gnc_engine_gen_event (&ns->inst.entity, GNC_EVENT_DESTROY); g_free(ns); Index: gnucash/src/engine/gnc-engine-util.c =================================================================== --- gnucash.orig/src/engine/gnc-engine-util.c +++ gnucash/src/engine/gnc-engine-util.c @@ -221,16 +221,43 @@ qof_util_bool_to_int (const char * val) static GCache * gnc_string_cache = NULL; -/* maybe better to make this function static */ -GCache* +#ifdef THESE_CAN_BE_USEFUL_FOR_DEGUGGING +static guint g_str_hash_KEY(gconstpointer v) { + return g_str_hash(v); +} +static guint g_str_hash_VAL(gconstpointer v) { + return g_str_hash(v); +} +static gpointer g_strdup_VAL(gpointer v) { + return g_strdup(v); +} +static gpointer g_strdup_KEY(gpointer v) { + return g_strdup(v); +} +static void g_free_VAL(gpointer v) { + return g_free(v); +} +static void g_free_KEY(gpointer v) { + return g_free(v); +} +static gboolean gnc_str_equal(gconstpointer v, gconstpointer v2) +{ + return (v && v2) ? g_str_equal(v, v2) : FALSE; +} +#endif + +static GCache* gnc_engine_get_string_cache(void) { - if(!gnc_string_cache) - { + if(!gnc_string_cache) { gnc_string_cache = g_cache_new( - (GCacheNewFunc) g_strdup, g_free, - (GCacheDupFunc) g_strdup, g_free, g_str_hash, - g_str_hash, g_str_equal); + (GCacheNewFunc) g_strdup, /* value_new_func */ + g_free, /* value_destroy_func */ + (GCacheDupFunc) g_strdup, /* key_dup_func */ + g_free, /* key_destroy_func */ + g_str_hash, /* hash_key_func */ + g_str_hash, /* hash_value_func */ + g_str_equal); /* key_equal_func */ } return gnc_string_cache; } @@ -238,18 +265,22 @@ gnc_engine_get_string_cache(void) void gnc_engine_string_cache_destroy (void) { - g_cache_destroy (gnc_string_cache); - gnc_string_cache = NULL; + if (gnc_string_cache) + g_cache_destroy (gnc_string_cache); + gnc_string_cache = NULL; } -void gnc_string_cache_remove(gpointer key) +void +gnc_string_cache_remove(gconstpointer key) { - g_cache_remove(gnc_engine_get_string_cache(), key); + g_cache_remove(gnc_engine_get_string_cache(), key); } -gpointer gnc_string_cache_insert(gpointer key) + +gpointer +gnc_string_cache_insert(gpointer key) { - return g_cache_insert(gnc_engine_get_string_cache(), key); + return g_cache_insert(gnc_engine_get_string_cache(), key); } void Index: gnucash/src/engine/gnc-engine-util.h =================================================================== --- gnucash.orig/src/engine/gnc-engine-util.h +++ gnucash/src/engine/gnc-engine-util.h @@ -211,38 +211,48 @@ const char * qof_util_whitespace_filter * return that number. (Leading whitespace is ignored). */ int qof_util_bool_to_int (const char * val); -/** Many strings used throughout the engine are likely to be duplicated. + +/** Gnucash's String Cache: + * + * Many strings used throughout the engine are likely to be duplicated. * So we provide a reference counted cache system for the strings, which * shares strings whenever possible. * - * Use g_cache_insert to insert a string into the cache (it will return a - * pointer to the cached string). - * Basically you should use this instead of g_strdup. - * - * Use g_cache_remove (giving it a pointer to a cached string) if the string - * is unused. If this is the last reference to the string it will be - * removed from the cache, otherwise it will just decrement the - * reference count. - * Basically you should use this instead of g_free. + * Use gnc_string_cache_insert to insert a string into the cache (it + * will return a pointer to the cached string). Basically you should + * use this instead of g_strdup. + * + * Use gnc_string_cache_remove (giving it a pointer to a cached + * string) if the string is unused. If this is the last reference to + * the string it will be removed from the cache, otherwise it will + * just decrement the reference count. Basically you should use this + * instead of g_free. + * + * Just in case it's not clear: The remove function must NOT be called + * for the string you passed INTO the insert function. It must be + * called for the _cached_ string that is _returned_ by the insert + * function. * * Note that all the work is done when inserting or removing. Once * cached the strings are just plain C strings. - */ - -/** Get the gnc_string_cache. Create it if it doesn't exist already - -\todo hide the gcache as a static */ -GCache* gnc_engine_get_string_cache(void); + * + * The string cache is demand-created on first use. + * + **/ +/** Destroy the gnc_string_cache */ void gnc_engine_string_cache_destroy (void); /* You can use this function as a destroy notifier for a GHashTable that uses common strings as keys (or values, for that matter.) */ -void gnc_string_cache_remove(gpointer key); +void gnc_string_cache_remove(gconstpointer key); /* You can use this function with g_hash_table_insert(), or the key (or value), as long as you use the destroy notifier above. */ gpointer gnc_string_cache_insert(gpointer key); +#define CACHE_INSERT(str) gnc_string_cache_insert((gpointer)(str)); +#define CACHE_REMOVE(str) gnc_string_cache_remove((str)); + #endif /* QOF_UTIL_H */ /** @} */ Index: gnucash/src/engine/gnc-engine.c =================================================================== --- gnucash.orig/src/engine/gnc-engine.c +++ gnucash/src/engine/gnc-engine.c @@ -84,8 +84,6 @@ gnc_engine_init(int argc, char ** argv) gnc_set_log_level(GNC_MOD_IO, GNC_LOG_WARNING); gnc_set_log_level(GNC_MOD_GUI, GNC_LOG_WARNING); qof_log_set_default(GNC_LOG_WARNING); - /* initialize the string cache */ - gnc_engine_get_string_cache(); guid_init (); qof_object_initialize (); Index: gnucash/src/engine/gnc-pricedb.c =================================================================== --- gnucash.orig/src/engine/gnc-pricedb.c +++ gnucash/src/engine/gnc-pricedb.c @@ -67,8 +67,8 @@ gnc_price_destroy (GNCPrice *p) ENTER(" "); gnc_engine_gen_event (&p->inst.entity, GNC_EVENT_DESTROY); - if(p->type) g_cache_remove(gnc_engine_get_string_cache(), p->type); - if(p->source) g_cache_remove(gnc_engine_get_string_cache(), p->source); + if(p->type) gnc_string_cache_remove(p->type); + if(p->source) gnc_string_cache_remove(p->source); qof_instance_release (&p->inst); memset(p, 0, sizeof(GNCPrice)); @@ -243,13 +243,11 @@ gnc_price_set_source(GNCPrice *p, const if(!p) return; if(safe_strcmp(p->source, s) != 0) { - GCache *cache; char *tmp; gnc_price_begin_edit (p); - cache = gnc_engine_get_string_cache(); - tmp = g_cache_insert(cache, (gpointer) s); - if(p->source) g_cache_remove(cache, p->source); + tmp = gnc_string_cache_insert((gpointer) s); + if(p->source) gnc_string_cache_remove(p->source); p->source = tmp; if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); @@ -262,13 +260,11 @@ gnc_price_set_type(GNCPrice *p, const ch if(!p) return; if(safe_strcmp(p->type, type) != 0) { - GCache *cache; gchar *tmp; gnc_price_begin_edit (p); - cache = gnc_engine_get_string_cache(); - tmp = g_cache_insert(cache, (gpointer) type); - if(p->type) g_cache_remove(cache, p->type); + tmp = gnc_string_cache_insert((gpointer) type); + if(p->type) gnc_string_cache_remove(p->type); p->type = tmp; if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); Index: gnucash/src/engine/kvp_frame.c =================================================================== --- gnucash.orig/src/engine/kvp_frame.c +++ gnucash/src/engine/kvp_frame.c @@ -43,6 +43,8 @@ * (gnc_string_cache), as it is very likely we will see the * same keys over and over again */ +/* TODO: set the cache handling functions with hash_table_new_full */ + struct _KvpFrame { GHashTable * hash; @@ -113,7 +115,7 @@ kvp_frame_new(void) static void kvp_frame_delete_worker(gpointer key, gpointer value, gpointer user_data) { - g_cache_remove(gnc_engine_get_string_cache(), key); + gnc_string_cache_remove(key); kvp_value_delete((KvpValue *)value); } @@ -148,7 +150,7 @@ kvp_frame_copy_worker(gpointer key, gpoi { KvpFrame * dest = (KvpFrame *)user_data; g_hash_table_insert(dest->hash, - (gpointer)g_cache_insert(gnc_engine_get_string_cache(), key), + gnc_string_cache_insert(key), (gpointer)kvp_value_copy(value)); } @@ -189,7 +191,7 @@ kvp_frame_replace_slot_nc (KvpFrame * fr if(key_exists) { g_hash_table_remove(frame->hash, slot); - g_cache_remove(gnc_engine_get_string_cache(), orig_key); + gnc_string_cache_remove(orig_key); } else { @@ -199,8 +201,7 @@ kvp_frame_replace_slot_nc (KvpFrame * fr if(new_value) { g_hash_table_insert(frame->hash, - g_cache_insert(gnc_engine_get_string_cache(), - (gpointer) slot), + gnc_string_cache_insert((gpointer) slot), new_value); } @@ -1745,6 +1746,7 @@ kvp_value_to_string(const KvpValue *val) break; case KVP_TYPE_GUID: + /* THREAD-UNSAFE */ ctmp = guid_to_string(kvp_value_get_guid(val)); tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", ctmp ? ctmp : ""); return tmp2; Index: gnucash/src/engine/qofid.c =================================================================== --- gnucash.orig/src/engine/qofid.c +++ gnucash/src/engine/qofid.c @@ -32,9 +32,6 @@ #include "gnc-trace.h" #include "gnc-engine-util.h" -#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); -#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (gpointer)(str)); - static QofLogModule log_module = QOF_MOD_ENGINE; struct QofCollection_s Index: gnucash/src/engine/qofquery-deserial.c =================================================================== --- gnucash.orig/src/engine/qofquery-deserial.c +++ gnucash/src/engine/qofquery-deserial.c @@ -33,11 +33,6 @@ #include "qofquerycore-p.h" #include "gnc-engine-util.h" -#define CACHE_INSERT(str) \ - g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)) -#define CACHE_REMOVE(str) \ - g_cache_remove(gnc_engine_get_string_cache(), (gpointer)(str)) - /* =========================================================== */ #define GET_TEXT(node) ({ \ @@ -483,6 +478,7 @@ qof_query_param_path_from_xml (xmlNodePt if (0 == strcmp (node->name, "qofquery:param")) { const char *str = GET_TEXT (node); + /* BUG? I can't find the matching cache removal. */ plist = g_slist_append (plist, CACHE_INSERT(str)); } } Index: gnucash/src/engine/test/test-commodities.c =================================================================== --- gnucash.orig/src/engine/test/test-commodities.c +++ gnucash/src/engine/test/test-commodities.c @@ -179,17 +179,15 @@ test_commodity(void) int main (int argc, char **argv) { - gnc_engine_get_string_cache (); - guid_init (); - qof_object_initialize (); - qof_query_init (); - qof_book_register (); - gnc_commodity_table_register(); - test_commodity(); - print_test_results(); - qof_query_shutdown(); - guid_shutdown(); - qof_object_shutdown (); - gnc_engine_string_cache_destroy(); - return 0; + guid_init (); + qof_object_initialize (); + qof_query_init (); + qof_book_register (); + gnc_commodity_table_register(); + test_commodity(); + print_test_results(); + qof_query_shutdown(); + guid_shutdown(); + qof_object_shutdown (); + return 0; } Index: gnucash/src/gnome-utils/QuickFill.c =================================================================== --- gnucash.orig/src/gnome-utils/QuickFill.c +++ gnucash/src/gnome-utils/QuickFill.c @@ -49,10 +49,6 @@ static void quickfill_insert_recursive ( /* This static indicates the debugging module that this .o belongs to. */ static QofLogModule log_module = GNC_MOD_REGISTER; -/* A cache for quickfill strings */ -static GCache * qf_string_cache = NULL; - - /********************************************************************\ \********************************************************************/ @@ -85,10 +81,6 @@ gnc_quickfill_new (void) return NULL; } - /* For now, use the engine cache. */ - if (qf_string_cache == NULL) - qf_string_cache = gnc_engine_get_string_cache (); - qf = g_new (QuickFill, 1); qf->text = NULL; @@ -120,7 +112,7 @@ gnc_quickfill_destroy (QuickFill *qf) qf->matches = NULL; if (qf->text) - g_cache_remove (qf_string_cache, qf->text); + gnc_string_cache_remove(qf->text); qf->text = NULL; qf->len = 0; @@ -136,7 +128,7 @@ gnc_quickfill_purge (QuickFill *qf) g_hash_table_foreach_remove (qf->matches, destroy_helper, NULL); if (qf->text) - g_cache_remove (qf_string_cache, qf->text); + gnc_string_cache_remove (qf->text); qf->text = NULL; qf->len = 0; } @@ -318,7 +310,7 @@ quickfill_insert_recursive (QuickFill *q /* If there's no string there already, just put the new one in. */ if (old_text == NULL) { - match_qf->text = g_cache_insert (qf_string_cache, (gpointer) text); + match_qf->text = gnc_string_cache_insert((gpointer) text); match_qf->len = len; break; } @@ -328,8 +320,8 @@ quickfill_insert_recursive (QuickFill *q (strncmp(text, old_text, strlen(old_text)) == 0)) break; - g_cache_remove (qf_string_cache, old_text); - match_qf->text = g_cache_insert (qf_string_cache, (gpointer) text); + gnc_string_cache_remove(old_text); + match_qf->text = gnc_string_cache_insert((gpointer) text); match_qf->len = len; break; } -- _______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel