r16211 - gnucash/trunk/lib/libqof/qof - Avoid a global static variable by using g_list_sort_with_data.

Andreas Köhler andi5 at cvs.gnucash.org
Mon Jun 25 13:18:14 EDT 2007


Author: andi5
Date: 2007-06-25 13:18:11 -0400 (Mon, 25 Jun 2007)
New Revision: 16211
Trac: http://svn.gnucash.org/trac/changeset/16211

Modified:
   gnucash/trunk/lib/libqof/qof/qofquery.c
Log:
Avoid a global static variable by using g_list_sort_with_data.


Modified: gnucash/trunk/lib/libqof/qof/qofquery.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofquery.c	2007-06-24 08:48:01 UTC (rev 16210)
+++ gnucash/trunk/lib/libqof/qof/qofquery.c	2007-06-25 17:18:11 UTC (rev 16211)
@@ -319,11 +319,10 @@
   return sort->obj_cmp (conva, convb);
 }
 
-static QofQuery * sortQuery = NULL;
-
-static int sort_func (gconstpointer a, gconstpointer b)
+static int sort_func (gconstpointer a, gconstpointer b, gpointer q)
 {
   int retval;
+  QofQuery *sortQuery = q;
 
   g_return_val_if_fail (sortQuery, 0);
 
@@ -735,16 +734,11 @@
    */
   matching_objects = g_list_reverse(matching_objects);
 
-  /* Now sort the matching objects based on the search criteria
-   * sortQuery is an unforgivable use of static global data...  
-   * I just can't figure out how else to do this sanely.
-   */
+  /* Now sort the matching objects based on the search criteria */
   if (q->primary_sort.comp_fcn || q->primary_sort.obj_cmp ||
       (q->primary_sort.use_default && q->defaultSort))
   {
-    sortQuery = q;
-    matching_objects = g_list_sort(matching_objects, sort_func);
-    sortQuery = NULL;
+    matching_objects = g_list_sort_with_data(matching_objects, sort_func, q);
   }
 
   /* Crop the list to limit the number of splits. */



More information about the gnucash-changes mailing list