From fa28f0e4f09dcada9123e855d7b85398b0c174a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Mon, 25 Jun 2007 17:18:11 +0000 Subject: [PATCH] Avoid a global static variable by using g_list_sort_with_data. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16211 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/qofquery.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/libqof/qof/qofquery.c b/lib/libqof/qof/qofquery.c index e3e15545f7..71c85cd8df 100644 --- a/lib/libqof/qof/qofquery.c +++ b/lib/libqof/qof/qofquery.c @@ -319,11 +319,10 @@ static int cmp_func (QofQuerySort *sort, QofSortFunc default_sort, 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 @@ static GList * qof_query_run_internal (QofQuery *q, */ 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. */