[Gnucash-changes] r12315 - gnucash/trunk/lib/libqof/qof - Add const to gnc_string_cache_insert argument.

Chris Shoemaker chris at cvs.gnucash.org
Tue Jan 10 21:56:03 EST 2006


Author: chris
Date: 2006-01-10 21:56:02 -0500 (Tue, 10 Jan 2006)
New Revision: 12315
Trac: http://svn.gnucash.org/trac/changeset/12315

Modified:
   gnucash/trunk/lib/libqof/qof/gnc-engine-util.c
   gnucash/trunk/lib/libqof/qof/gnc-engine-util.h
Log:
Add const to gnc_string_cache_insert argument.
Handle NULL values gracefully.


Modified: gnucash/trunk/lib/libqof/qof/gnc-engine-util.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-engine-util.c	2006-01-11 02:41:26 UTC (rev 12314)
+++ gnucash/trunk/lib/libqof/qof/gnc-engine-util.c	2006-01-11 02:56:02 UTC (rev 12315)
@@ -273,14 +273,19 @@
 void
 gnc_string_cache_remove(gconstpointer key)
 {
-    g_cache_remove(gnc_engine_get_string_cache(), key);
+    if (key) 
+        g_cache_remove(gnc_engine_get_string_cache(), key);
 }
 
-
+/* TODO: It would be better if this returned gpointerconst.  The
+   returned strings really should be treated as const.  Callers must
+   not modify them. */
 gpointer
-gnc_string_cache_insert(gpointer key)
+gnc_string_cache_insert(gconstpointer key)
 {
-    return g_cache_insert(gnc_engine_get_string_cache(), key);
+    if (key) 
+        return g_cache_insert(gnc_engine_get_string_cache(), (gpointer)key);
+    return NULL;
 }
 
 void

Modified: gnucash/trunk/lib/libqof/qof/gnc-engine-util.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-engine-util.h	2006-01-11 02:41:26 UTC (rev 12314)
+++ gnucash/trunk/lib/libqof/qof/gnc-engine-util.h	2006-01-11 02:56:02 UTC (rev 12315)
@@ -300,12 +300,12 @@
 */
 void gnc_string_cache_remove(gconstpointer key);
 
-/** You can use this function with g_hash_table_insert(), or the key
+/** You can use this function with g_hash_table_insert(), for the key
    (or value), as long as you use the destroy notifier above.
 */
-gpointer gnc_string_cache_insert(gpointer key);
+gpointer gnc_string_cache_insert(gconstpointer key);
 
-#define CACHE_INSERT(str) gnc_string_cache_insert((gpointer)(str));
+#define CACHE_INSERT(str) gnc_string_cache_insert((gconstpointer)(str));
 #define CACHE_REMOVE(str) gnc_string_cache_remove((str));
 
 #endif /* QOF_UTIL_H */



More information about the gnucash-changes mailing list