diff --git a/lib/libqof/backend/file/qsf-backend.c b/lib/libqof/backend/file/qsf-backend.c index 17951e64b9..63072644b8 100644 --- a/lib/libqof/backend/file/qsf-backend.c +++ b/lib/libqof/backend/file/qsf-backend.c @@ -709,6 +709,7 @@ reference_list_lookup(gpointer data, gpointer user_data) ref_param = (QofParam*)data; object_node = params->output_node; ent = params->qsf_ent; + g_return_if_fail(ent); ns = params->qsf_ns; starter = g_new(QofInstanceReference, 1); starter->ent_guid = qof_instance_get_guid(ent); @@ -766,6 +767,7 @@ qsf_entity_foreach(QofInstance *ent, gpointer data) const GUID *cm_guid; gchar cm_sa[GUID_ENCODING_LENGTH + 1]; + g_return_if_fail(ent != NULL); g_return_if_fail(data != NULL); params = (qsf_param*)data; param_count = ++params->count; diff --git a/lib/libqof/qof/qofbook.c b/lib/libqof/qof/qofbook.c index 7d00d19177..1c819e95fb 100644 --- a/lib/libqof/qof/qofbook.c +++ b/lib/libqof/qof/qofbook.c @@ -418,7 +418,7 @@ qof_book_get_counter (QofBook *book, const char *counter_name) gboolean qof_book_register (void) { static QofParam params[] = { - { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, + { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL }, { QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL }, { NULL }, }; diff --git a/lib/libqof/qof/qofbook.h b/lib/libqof/qof/qofbook.h index f44ff4d190..8e16690b3a 100644 --- a/lib/libqof/qof/qofbook.h +++ b/lib/libqof/qof/qofbook.h @@ -267,7 +267,7 @@ gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2); gint64 qof_book_get_counter (QofBook *book, const char *counter_name); /** deprecated */ -#define qof_book_get_guid(X) qof_instance_get_guid (QOF_INSTANCE(X)) +#define qof_book_get_guid(X) qof_entity_get_guid (QOF_INSTANCE(X)) #endif /* QOF_BOOK_H */ /** @} */ diff --git a/lib/libqof/qof/qofbookmerge.c b/lib/libqof/qof/qofbookmerge.c index a807ead51c..a793af0b30 100644 --- a/lib/libqof/qof/qofbookmerge.c +++ b/lib/libqof/qof/qofbookmerge.c @@ -702,6 +702,7 @@ qof_book_merge_commit_rule_loop(QofBookMergeData *mergeData, g_return_if_fail(rule != NULL); g_return_if_fail(mergeData != NULL); g_return_if_fail(mergeData->targetBook != NULL); + g_return_if_fail(rule->importEnt && rule->targetEnt); g_return_if_fail((rule->mergeResult != MERGE_NEW)||(rule->mergeResult != MERGE_UPDATE)); DEBUG ("qof_book_merge_commit_rule_loop rule: type: %s, result: %s, importEnt Type: %s, guid: %s", diff --git a/lib/libqof/qof/qofinstance.c b/lib/libqof/qof/qofinstance.c index 413c3a7130..622d64b8df 100644 --- a/lib/libqof/qof/qofinstance.c +++ b/lib/libqof/qof/qofinstance.c @@ -465,6 +465,12 @@ qof_instance_get_guid (gconstpointer inst) return &(priv->guid); } +const GUID * +qof_entity_get_guid (gconstpointer ent) +{ + return ent ? qof_instance_get_guid(ent) : guid_null(); +} + void qof_instance_set_guid (gpointer ptr, const GUID *guid) { diff --git a/lib/libqof/qof/qofinstance.h b/lib/libqof/qof/qofinstance.h index 4cd9075301..5b4f4c51ad 100644 --- a/lib/libqof/qof/qofinstance.h +++ b/lib/libqof/qof/qofinstance.h @@ -101,6 +101,10 @@ gboolean qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2); /** Return the GUID of this instance */ const GUID * qof_instance_get_guid (gconstpointer); +/** \deprecated Use qof_instance_get_guid instead. + * Works like qof_instance_get_guid, but returns NULL on NULL */ +const GUID * qof_entity_get_guid (gconstpointer); + /** Return the collection this instance belongs to */ QofCollection* qof_instance_get_collection (gconstpointer inst); diff --git a/lib/libqof/qof/qofquery.c b/lib/libqof/qof/qofquery.c index 71c85cd8df..05dd34f2ff 100644 --- a/lib/libqof/qof/qofquery.c +++ b/lib/libqof/qof/qofquery.c @@ -1275,7 +1275,7 @@ void qof_query_set_book (QofQuery *q, QofBook *book) slist = g_slist_prepend (slist, QOF_PARAM_GUID); slist = g_slist_prepend (slist, QOF_PARAM_BOOK); qof_query_add_guid_match (q, slist, - qof_book_get_guid(book), QOF_QUERY_AND); + qof_instance_get_guid(book), QOF_QUERY_AND); } GList * qof_query_get_books (QofQuery *q) diff --git a/lib/libqof/qof/qofquerycore.c b/lib/libqof/qof/qofquerycore.c index 2e2857af51..d78ab7c5e5 100644 --- a/lib/libqof/qof/qofquerycore.c +++ b/lib/libqof/qof/qofquerycore.c @@ -1455,8 +1455,7 @@ query_collect_cb(QofInstance* ent, gpointer user_data) query_coll_t pdata; GUID *guid; - guid = guid_malloc(); - guid = (GUID*)qof_instance_get_guid(ent); + guid = (GUID*)qof_entity_get_guid(ent); pdata = (query_coll_t)user_data; pdata->guids = g_list_append(pdata->guids, guid); } diff --git a/lib/libqof/qof/qofreference.c b/lib/libqof/qof/qofreference.c index 4d235fbb98..0ba0d5758c 100644 --- a/lib/libqof/qof/qofreference.c +++ b/lib/libqof/qof/qofreference.c @@ -39,7 +39,7 @@ entity_set_reference_cb(QofInstance *ent, gpointer user_data) QofBook *partial_book; partial_book = (QofBook*)user_data; - g_return_if_fail(partial_book || ent); + g_return_if_fail(partial_book && ent); reference = NULL; coll = NULL; book_ref_list = qof_book_get_data(partial_book, ENTITYREFERENCE); @@ -122,6 +122,7 @@ create_reference(QofInstance *ent, const QofParam *param) char cm_sa[GUID_ENCODING_LENGTH + 1]; gchar *cm_string; + g_return_val_if_fail(ent, NULL); ref_ent = QOF_INSTANCE(param->param_getfcn(ent, param)); if(!ref_ent) { return NULL; } reference = g_new0(QofInstanceReference, 1); diff --git a/lib/libqof/qof/qofsession.c b/lib/libqof/qof/qofsession.c index bf664b9555..01e6420000 100644 --- a/lib/libqof/qof/qofsession.c +++ b/lib/libqof/qof/qofsession.c @@ -368,15 +368,17 @@ col_ref_cb (QofInstance* ref_ent, gpointer user_data) char cm_sa[GUID_ENCODING_LENGTH + 1]; gchar *cm_string; + g_return_if_fail(user_data); qecd = (QofInstanceCopyData*)user_data; ent = qecd->from; + g_return_if_fail(ent); ref = g_new0(QofInstanceReference, 1); ref->type = ent->e_type; ref->ref_guid = g_new(GUID, 1); ref->ent_guid = qof_instance_get_guid(ent); ref->param = qof_class_get_parameter(ent->e_type, qecd->param->param_name); - cm_guid = qof_instance_get_guid(ref_ent); + cm_guid = qof_entity_get_guid(ref_ent); guid_to_string_buff(cm_guid, cm_sa); cm_string = g_strdup(cm_sa); if(TRUE == string_to_guid(cm_string, ref->ref_guid)) { @@ -594,7 +596,8 @@ qof_instance_coll_foreach(QofInstance *original, gpointer user_data) QofBook *targetBook; QofCollection *coll; QofInstance *copy; - + + g_return_if_fail(original != NULL); g_return_if_fail(user_data != NULL); copy = NULL; qecd = (QofInstanceCopyData*)user_data; @@ -612,7 +615,8 @@ qof_instance_coll_copy(QofInstance *original, gpointer user_data) QofBook *book; QofInstance *inst; const GUID *g; - + + g_return_if_fail(original != NULL); g_return_if_fail(user_data != NULL); qecd = (QofInstanceCopyData*)user_data; book = qof_session_get_book(qecd->new_session); diff --git a/src/app-utils/gnc-component-manager.c b/src/app-utils/gnc-component-manager.c index 91a1cc23bb..a2e4b4f638 100644 --- a/src/app-utils/gnc-component-manager.c +++ b/src/app-utils/gnc-component-manager.c @@ -258,7 +258,7 @@ gnc_cm_event_handler (QofInstance *entity, gpointer user_data, gpointer event_data) { - const GUID *guid = qof_instance_get_guid(entity); + const GUID *guid = qof_entity_get_guid(entity); #if CM_DEBUG fprintf (stderr, "event_handler: event %d, entity %p, guid %s\n", event_type, entity, guid); diff --git a/src/backend/postgres/book.c b/src/backend/postgres/book.c index 0e7a7985f8..3d4755ec69 100644 --- a/src/backend/postgres/book.c +++ b/src/backend/postgres/book.c @@ -208,7 +208,7 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) for (node=blist; node; node=node->next) { book = node->data; - if (guid_equal (qof_instance_get_guid(QOF_INSTANCE(book)), &guid)) break; + if (guid_equal (qof_entity_get_guid(QOF_INSTANCE(book)), &guid)) break; book = NULL; } diff --git a/src/backend/postgres/putil.h b/src/backend/postgres/putil.h index 978b598e1e..529b5a7d97 100644 --- a/src/backend/postgres/putil.h +++ b/src/backend/postgres/putil.h @@ -358,7 +358,7 @@ int finishQuery(PGBackend *be); for (node=be->blist; node; node=node->next) \ { \ book = node->data; \ - if (guid_equal (qof_instance_get_guid((QofInstance*)book), &book_guid)) break; \ + if (guid_equal (qof_entity_get_guid((QofInstance*)book), &book_guid)) break; \ book = NULL; \ } \ if (!book) return data; \ diff --git a/src/backend/postgres/table.m4 b/src/backend/postgres/table.m4 index af0360ad19..35c9aad180 100644 --- a/src/backend/postgres/table.m4 +++ b/src/backend/postgres/table.m4 @@ -13,7 +13,7 @@ define(`account', `gncAccount, Account, Account, a, commodity, , char *, gnc_commodity_get_unique_name(xaccAccountGetCommodity(ptr)), version, , int32, qof_instance_get_version(ptr), iguid, , int32, qof_instance_get_idata(ptr), - bookGUID, , GUID *, qof_instance_get_guid((QofInstance*)gnc_account_get_book(ptr)), + bookGUID, , GUID *, qof_entity_get_guid((QofInstance*)gnc_account_get_book(ptr)), parentGUID, , GUID *, xaccAccountGetGUID(gnc_account_get_parent(ptr)), accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr), ') @@ -362,7 +362,7 @@ define(`compare_version', p = be->buff; *p = 0; p = stpcpy (p, "SELECT version FROM tablename($@) WHERE key_fieldname($@) = ''`"); - p = guid_to_string_buff (qof_instance_get_guid(QOF_INSTANCE(ptr)), p); + p = guid_to_string_buff (qof_entity_get_guid(QOF_INSTANCE(ptr)), p); p = stpcpy (p, "''`;"); SEND_QUERY (be,be->buff, -1); sql_version = GPOINTER_TO_INT(pgendGetResults (be, get_version_cb, (gpointer) -1)); @@ -392,7 +392,7 @@ define(`is_deleted', p = be->buff; *p = 0; p = stpcpy (p, "SELECT version FROM tablename($@)" "Trail WHERE key_fieldname($@) = ''`"); - p = guid_to_string_buff (qof_instance_get_guid(QOF_INSTANCE(ptr)), p); + p = guid_to_string_buff (qof_entity_get_guid(QOF_INSTANCE(ptr)), p); p = stpcpy (p, "''` AND change = ''`d''`;"); SEND_QUERY (be,be->buff, -1); sql_version = GPOINTER_TO_INT(pgendGetResults (be, get_version_cb, (gpointer) -1)); diff --git a/src/business/business-core/gncEmployee.h b/src/business/business-core/gncEmployee.h index 03e83229d8..da7441eef9 100644 --- a/src/business/business-core/gncEmployee.h +++ b/src/business/business-core/gncEmployee.h @@ -114,9 +114,9 @@ gboolean gncEmployeeIsDirty (GncEmployee *employee); #define EMPLOYEE_CC "credit_card_account" /** deprecated routines */ -#define gncEmployeeGetGUID(E) qof_instance_get_guid(QOF_INSTANCE(E)) +#define gncEmployeeGetGUID(E) qof_entity_get_guid(QOF_INSTANCE(E)) #define gncEmployeeGetBook(E) qof_instance_get_book(QOF_INSTANCE(E)) -#define gncEmployeeRetGUID(E) (E ? *(qof_instance_get_guid(QOF_INSTANCE(E))) : *(guid_null())) +#define gncEmployeeRetGUID(E) (E ? *(qof_entity_get_guid(QOF_INSTANCE(E))) : *(guid_null())) #define gncEmployeeLookupDirect(G,B) gncEmployeeLookup((B),&(G)) #endif /* GNC_EMPLOYEE_H_ */ diff --git a/src/engine/Account.h b/src/engine/Account.h index 72f5121ead..c0c499efdf 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -232,8 +232,8 @@ Account *gnc_book_get_root_account(QofBook *book); void gnc_book_set_root_account(QofBook *book, Account *root); /** @deprecated */ -#define xaccAccountGetGUID(X) qof_instance_get_guid(QOF_INSTANCE(X)) -#define xaccAccountReturnGUID(X) (X ? *(qof_instance_get_guid(QOF_INSTANCE(X))) : *(guid_null())) +#define xaccAccountGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X)) +#define xaccAccountReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) /** The xaccAccountLookup() subroutine will return the * account associated with the given id, or NULL diff --git a/src/engine/SchedXaction.h b/src/engine/SchedXaction.h index ed08fa3334..a249d63eeb 100644 --- a/src/engine/SchedXaction.h +++ b/src/engine/SchedXaction.h @@ -318,7 +318,7 @@ gboolean SXRegister (void); /** \deprecated */ #define xaccSchedXactionIsDirty(X) qof_instance_is_dirty (QOF_INSTANCE(X)) /** \deprecated */ -#define xaccSchedXactionGetGUID(X) qof_instance_get_guid(QOF_INSTANCE(X)) +#define xaccSchedXactionGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X)) /** \deprecated */ #define xaccSchedXactionGetSlots(X) qof_instance_get_slots(QOF_INSTANCE(X)) diff --git a/src/engine/Split.c b/src/engine/Split.c index f6e306b7a1..0656e23b3c 100644 --- a/src/engine/Split.c +++ b/src/engine/Split.c @@ -1814,7 +1814,7 @@ gboolean xaccSplitRegister (void) { "d-share-amount", QOF_TYPE_DOUBLE, (QofAccessFunc)DxaccSplitGetShareAmount, NULL }, { "d-share-int64", QOF_TYPE_INT64, - (QofAccessFunc)qof_instance_get_guid, NULL }, + (QofAccessFunc)qof_entity_get_guid, NULL }, { SPLIT_BALANCE, QOF_TYPE_NUMERIC, (QofAccessFunc)xaccSplitGetBalance, NULL }, { SPLIT_CLEARED_BALANCE, QOF_TYPE_NUMERIC, @@ -1855,7 +1855,7 @@ gboolean xaccSplitRegister (void) { SPLIT_KVP, QOF_TYPE_KVP, (QofAccessFunc)xaccSplitGetSlots, NULL }, { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)xaccSplitGetBook, NULL }, { QOF_PARAM_GUID, QOF_TYPE_GUID, - (QofAccessFunc)qof_instance_get_guid, NULL }, + (QofAccessFunc)qof_entity_get_guid, NULL }, { NULL }, }; diff --git a/src/engine/Split.h b/src/engine/Split.h index 4818685576..a079b718f0 100644 --- a/src/engine/Split.h +++ b/src/engine/Split.h @@ -500,9 +500,9 @@ gnc_numeric xaccSplitVoidFormerValue(const Split *split); /** @} */ /** \deprecated */ -#define xaccSplitGetGUID(X) qof_instance_get_guid(QOF_INSTANCE(X)) +#define xaccSplitGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X)) /** \deprecated */ -#define xaccSplitReturnGUID(X) (X ? *(qof_instance_get_guid(QOF_INSTANCE(X))) : *(guid_null())) +#define xaccSplitReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) #endif /* XACC_SPLIT_H */ /** @} */ diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 0ec9d75b9e..dc5efd7787 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1971,7 +1971,7 @@ gboolean xaccTransRegister (void) { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, { QOF_PARAM_GUID, QOF_TYPE_GUID, - (QofAccessFunc)qof_instance_get_guid, NULL }, + (QofAccessFunc)qof_entity_get_guid, NULL }, { NULL }, }; diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 053e4c9376..a9d1b97a6b 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -567,9 +567,9 @@ Timespec xaccTransGetVoidTime(const Transaction *tr); /** \deprecated */ #define xaccTransGetBook(X) qof_instance_get_book (QOF_INSTANCE(X)) /** \deprecated */ -#define xaccTransGetGUID(X) qof_instance_get_guid(QOF_INSTANCE(X)) +#define xaccTransGetGUID(X) qof_entity_get_guid(QOF_INSTANCE(X)) /** \deprecated */ -#define xaccTransReturnGUID(X) (X ? *(qof_instance_get_guid(QOF_INSTANCE(X))) : *(guid_null())) +#define xaccTransReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) /** \deprecated */ #define xaccTransGetSlots(X) qof_instance_get_slots (QOF_INSTANCE(X)) diff --git a/src/engine/gnc-budget.h b/src/engine/gnc-budget.h index 23eeec4fb6..c9292ff32c 100644 --- a/src/engine/gnc-budget.h +++ b/src/engine/gnc-budget.h @@ -105,7 +105,7 @@ void gnc_budget_commit_edit(GncBudget *bgt); const GUID* gnc_budget_get_guid(GncBudget* budget); #define gnc_budget_return_guid(X) \ - (X ? *(qof_instance_get_guid(QOF_INSTANCE(X))) : *(guid_null())) + (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null())) /** Set/Get the name of the Budget */ void gnc_budget_set_name(GncBudget* budget, const gchar* name); diff --git a/src/engine/gnc-lot.c b/src/engine/gnc-lot.c index 16732fc0dd..a71ef646b4 100644 --- a/src/engine/gnc-lot.c +++ b/src/engine/gnc-lot.c @@ -440,7 +440,7 @@ gboolean gnc_lot_register (void) (QofAccessFunc) gnc_lot_get_notes, (QofSetterFunc) gnc_lot_set_notes }, { QOF_PARAM_GUID, QOF_TYPE_GUID, - (QofAccessFunc) qof_instance_get_guid, NULL }, + (QofAccessFunc) qof_entity_get_guid, NULL }, { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc) gnc_lot_get_book, NULL }, { LOT_IS_CLOSED, QOF_TYPE_BOOLEAN, diff --git a/src/engine/gnc-lot.h b/src/engine/gnc-lot.h index 194765a750..20195c96b6 100644 --- a/src/engine/gnc-lot.h +++ b/src/engine/gnc-lot.h @@ -156,7 +156,7 @@ void gnc_lot_set_notes (GNCLot *, const char *); * */ KvpFrame * gnc_lot_get_slots (const GNCLot *); -#define gnc_lot_get_guid(X) qof_instance_get_guid(QOF_INSTANCE(X)) +#define gnc_lot_get_guid(X) qof_entity_get_guid(QOF_INSTANCE(X)) #define LOT_IS_CLOSED "is-closed?" #define LOT_BALANCE "balance" diff --git a/src/engine/gnc-pricedb.h b/src/engine/gnc-pricedb.h index 241e1702bd..94bae3962c 100644 --- a/src/engine/gnc-pricedb.h +++ b/src/engine/gnc-pricedb.h @@ -227,8 +227,8 @@ const char * gnc_price_get_typestr(const GNCPrice *p); gnc_numeric gnc_price_get_value(const GNCPrice *p); gboolean gnc_price_equal(const GNCPrice *p1, const GNCPrice *p2); -#define gnc_price_get_guid(X) qof_instance_get_guid(QOF_INSTANCE(X)) -#define gnc_price_return_guid(X) (*(qof_instance_get_guid(QOF_INSTANCE(X)))) +#define gnc_price_get_guid(X) qof_entity_get_guid(QOF_INSTANCE(X)) +#define gnc_price_return_guid(X) (*(qof_entity_get_guid(QOF_INSTANCE(X)))) #define gnc_price_get_book(X) qof_instance_get_book(QOF_INSTANCE(X)) /** @} */ diff --git a/src/gnome/dialog-chart-export.c b/src/gnome/dialog-chart-export.c index 740ad578c9..3ede1dbe03 100644 --- a/src/gnome/dialog-chart-export.c +++ b/src/gnome/dialog-chart-export.c @@ -75,7 +75,7 @@ chart_collection_cb(QofInstance *ent, gpointer user_data) { success = qof_instance_copy_to_session(data->chart_session, ent); if(!success) { return; } - guid = qof_instance_get_guid(ent); + guid = qof_entity_get_guid(ent); book = qof_session_get_book(data->chart_session); copy_coll = qof_book_get_collection(book, GNC_ID_ACCOUNT); data->equity_account = (Account*)qof_collection_lookup_entity(copy_coll, guid); @@ -119,7 +119,7 @@ chart_entity_cb(QofInstance *ent, gpointer user_data) data = (chart_data*)user_data; trans_time = data->chart_time_t; data->param_ref_list = NULL; - guid = qof_instance_get_guid(ent); + guid = qof_entity_get_guid(ent); acc_ent = (Account*)ent; ref = NULL; equity_account = data->equity_account; diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 74e1755617..d3880463c9 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -230,7 +230,7 @@ gnc_restore_all_state (gpointer session, gpointer unused) /* Get the book GUID */ book = qof_session_get_book(session); - guid = qof_instance_get_guid(QOF_INSTANCE(book)); + guid = qof_entity_get_guid(QOF_INSTANCE(book)); guid_string = guid_to_string(guid); keyfile = gnc_find_state_file(url, guid_string, &filename); @@ -317,7 +317,7 @@ gnc_save_all_state (gpointer session, gpointer unused) /* Get the book GUID */ book = qof_session_get_book(session); - guid = qof_instance_get_guid(QOF_INSTANCE(book)); + guid = qof_entity_get_guid(QOF_INSTANCE(book)); guid_string = guid_to_string(guid); /* Find the filename to use. This returns the data from the