Hi again, After the last fix, I ran into another set of cases of gcc being too smart for its own good. In this case, we're calling the macro QOF_BOOK_LOOKUP_ENTITY, which checks its args for null pointers. However, several indirect callers such as gncInvoiceLookupFlip() and its siblings are passing the address of a stack variable, which can't be null. GCC then helpfully warns that this check will always be true, then killing the compile.
To fix it, I created an alternate QOF_BOOK_LOOKUP_ENTITY_NC that leaves arg checking to the caller and propagated that up to the places that died because of the always true warnings. This patch squelches the warnings but I can't help feeling like there should be a cleaner way of solving the problem. Opinions welcome, Jerry Quinn Index: src/business/business-core/gncTaxTable.h =================================================================== --- src/business/business-core/gncTaxTable.h (revision 16769) +++ src/business/business-core/gncTaxTable.h (working copy) @@ -145,6 +145,10 @@ #define gncTaxTableLookup(book,guid) \ QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_TAXTABLE, GncTaxTable) +/* Version of gncTaxTableLookup that does no null pointer check on its args */ +#define gncTaxTableLookupNC(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY_NC((book),(guid),GNC_ID_TAXTABLE, GncTaxTable) + GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name); GList * gncTaxTableGetTables (QofBook *book); Index: src/business/business-core/gncJob.h =================================================================== --- src/business/business-core/gncJob.h (revision 16769) +++ src/business/business-core/gncJob.h (working copy) @@ -93,6 +93,10 @@ #define gncJobLookup(book,guid) \ QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_JOB, GncJob) +/* Version of gncJobLookup that does no null pointer check on its args */ +#define gncJobLookupNC(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY_NC((book),(guid),GNC_ID_JOB, GncJob) + /* Other functions */ int gncJobCompare (const GncJob *a, const GncJob *b); Index: src/business/business-core/gncInvoice.h =================================================================== --- src/business/business-core/gncInvoice.h (revision 16769) +++ src/business/business-core/gncInvoice.h (working copy) @@ -179,6 +179,10 @@ #define gncInvoiceLookup(book,guid) \ QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_INVOICE, GncInvoice) +/* Version of gncInvoiceLookup that does no null pointer check on its args */ +#define gncInvoiceLookupNC(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY_NC((book),(guid),GNC_ID_INVOICE, GncInvoice) + void gncInvoiceBeginEdit (GncInvoice *invoice); void gncInvoiceCommitEdit (GncInvoice *invoice); int gncInvoiceCompare (GncInvoice *a, GncInvoice *b); Index: src/business/business-core/gncVendor.h =================================================================== --- src/business/business-core/gncVendor.h (revision 16769) +++ src/business/business-core/gncVendor.h (working copy) @@ -115,6 +115,10 @@ #define gncVendorLookup(book,guid) \ QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_VENDOR, GncVendor) +/* Version of gncVendorLookup that does no null pointer check on its args */ +#define gncVendorLookupNC(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY_NC((book),(guid),GNC_ID_VENDOR, GncVendor) + #define VENDOR_ID "id" #define VENDOR_NAME "name" #define VENDOR_ADDR "addr" Index: src/business/business-core/gncCustomer.h =================================================================== --- src/business/business-core/gncCustomer.h (revision 16769) +++ src/business/business-core/gncCustomer.h (working copy) @@ -118,6 +118,10 @@ #define gncCustomerLookup(book,guid) \ QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_CUSTOMER, GncCustomer) +/* Version of gncCustomerLookup that does no null pointer check on its args */ +#define gncCustomerLookupNC(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY_NC((book),(guid),GNC_ID_CUSTOMER, GncCustomer) + const char * gncCustomerGetID (GncCustomer *customer); const char * gncCustomerGetName (GncCustomer *customer); GncAddress * gncCustomerGetAddr (GncCustomer *customer); Index: src/business/business-core/gncEmployee.h =================================================================== --- src/business/business-core/gncEmployee.h (revision 16769) +++ src/business/business-core/gncEmployee.h (working copy) @@ -102,6 +102,10 @@ #define gncEmployeeLookup(book,guid) \ QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_EMPLOYEE, GncEmployee) +/* Version of gncJobLookup that does no null pointer check on its args */ +#define gncEmployeeLookupNC(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY_NC((book),(guid),GNC_ID_EMPLOYEE, GncEmployee) + gboolean gncEmployeeIsDirty (GncEmployee *employee); #define EMPLOYEE_ID "id" Index: src/business/business-core/business-core.i =================================================================== --- src/business/business-core/business-core.i (revision 16769) +++ src/business/business-core/business-core.i (working copy) @@ -44,22 +44,22 @@ { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); } static GncTaxTable * gncTaxTableLookupFlip(GUID g, QofBook *b) -{ return gncTaxTableLookup(b, &g); } +{ return (b) ? gncTaxTableLookupNC(b, &g) : NULL; } static GncInvoice * gncInvoiceLookupFlip(GUID g, QofBook *b) -{ return gncInvoiceLookup(b, &g); } +{ return (b) ? gncInvoiceLookupNC(b, &g) : NULL; } static GncJob * gncJobLookupFlip(GUID g, QofBook *b) -{ return gncJobLookup(b, &g); } +{ return (b) ? gncJobLookupNC(b, &g) : NULL; } static GncVendor * gncVendorLookupFlip(GUID g, QofBook *b) -{ return gncVendorLookup(b, &g); } +{ return (b) ? gncVendorLookupNC(b, &g) : NULL; } static GncCustomer * gncCustomerLookupFlip(GUID g, QofBook *b) -{ return gncCustomerLookup(b, &g); } +{ return (b) ? gncCustomerLookupNC(b, &g) : NULL; } static GncEmployee * gncEmployeeLookupFlip(GUID g, QofBook *b) -{ return gncEmployeeLookup(b, &g); } +{ return (b) ? gncEmployeeLookupNC(b, &g) : NULL; } %} Index: src/business/business-gnome/business-urls.c =================================================================== --- src/business/business-gnome/business-urls.c (revision 16769) +++ src/business/business-gnome/business-urls.c (working copy) @@ -219,8 +219,9 @@ switch (type) { case GNC_OWNER_CUSTOMER: { - GncCustomer *customer = - gncCustomerLookup (gnc_get_current_book (), &guid); + QofBook *book = gnc_get_current_book (); + GncCustomer *customer = (book) ? + gncCustomerLookupNC (gnc_get_current_book (), &guid) : NULL; RETURN_IF_NULL (customer); gncOwnerInitCustomer (&owner, customer); etype = "Customer"; @@ -228,8 +229,9 @@ } case GNC_OWNER_VENDOR: { - GncVendor *vendor = - gncVendorLookup (gnc_get_current_book (), &guid); + QofBook *book = gnc_get_current_book (); + GncVendor *vendor = (book) ? + gncVendorLookupNC (gnc_get_current_book (), &guid) : NULL; RETURN_IF_NULL (vendor); gncOwnerInitVendor (&owner, vendor); etype = "Vendor"; @@ -237,8 +239,9 @@ } case GNC_OWNER_EMPLOYEE: { - GncEmployee *employee = - gncEmployeeLookup (gnc_get_current_book (), &guid); + QofBook *book = gnc_get_current_book (); + GncEmployee *employee = (book) ? + gncEmployeeLookupNC (gnc_get_current_book (), &guid) : NULL; RETURN_IF_NULL(employee); gncOwnerInitEmployee (&owner, employee); etype = "Employee"; Index: src/business/business-gnome/dialog-invoice.c =================================================================== --- src/business/business-gnome/dialog-invoice.c (revision 16769) +++ src/business/business-gnome/dialog-invoice.c (working copy) @@ -1722,7 +1722,7 @@ goto give_up; } book = gnc_get_current_book(); - invoice = gncInvoiceLookup(gnc_get_current_book(), &guid); + invoice = (book) ? gncInvoiceLookupNC(gnc_get_current_book(), &guid) : NULL; if (invoice == NULL) { g_warning("Can't find invoice %s in current book.", tmp_string); goto give_up; Index: lib/libqof/qof/qofbook.h =================================================================== --- lib/libqof/qof/qofbook.h (revision 16769) +++ lib/libqof/qof/qofbook.h (working copy) @@ -139,6 +139,18 @@ (c_type *) val; \ }) +/** Lookup an entity by guid, returning pointer to the entity */ +/* Does not check validity of pointers. This is to support compiling + gncTaxTableLookupFlip with gcc 4.2.3, which warns and hence fails to + compile when guid is guaranteed to be non-null */ +#define QOF_BOOK_LOOKUP_ENTITY_NC(book,guid,e_type,c_type) ({ \ + QofInstance *val; \ + QofCollection *col; \ + col = qof_book_get_collection (book, e_type); \ + val = qof_collection_lookup_entity (col, guid); \ + (c_type *) val; \ +}) + /** GList of QofBook */ typedef GList QofBookList; _______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel