[tracker/return-types: 12/18] Fixing issues with variable-names returning



commit c3a24c8c0fac0eb95d1fb066aa77884c532a962e
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Sep 10 13:53:37 2010 +0200

    Fixing issues with variable-names returning

 src/libtracker-bus/tracker-bus-fd-cursor.c    |    2 +-
 src/libtracker-common/tracker-dbus.c          |   17 ++++++++++-------
 tests/functional-tests/shared-query-test.vala |   15 ++++++++++-----
 3 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index 15a5523..2d54aa5 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -178,7 +178,7 @@ tracker_bus_fd_cursor_get_value_type (TrackerBusFDCursor *cursor,  guint column)
 static const gchar*
 tracker_bus_fd_cursor_get_variable_name (TrackerBusFDCursor *cursor,  guint column)
 {
-	return cursor->variable_names[column - 1];
+	return cursor->variable_names[column];
 }
 
 static const gchar *
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index 340703c..faa38b3 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -795,11 +795,11 @@ tracker_dbus_send_and_splice (DBusConnection  *connection,
 				dbus_message_iter_init (reply, &iter);
 				dbus_message_iter_recurse (&iter, &arr);
 
-				while (dbus_message_iter_has_next(&arr)) {
+				while (dbus_message_iter_get_arg_type (&arr) != DBUS_TYPE_INVALID) {
 					gchar *str;
-
 					dbus_message_iter_get_basic (&arr, &str);
-					g_ptr_array_add (found, str);
+					/* Make a copy here, we wont own when returning */
+					g_ptr_array_add (found, g_strdup (str));
 					dbus_message_iter_next (&arr);
 				}
 
@@ -809,7 +809,7 @@ tracker_dbus_send_and_splice (DBusConnection  *connection,
 				}
 
 				*variable_names = v_names;
-				g_ptr_array_free (found, FALSE);
+				g_ptr_array_free (found, TRUE);
 			}
 
 			ret_value = TRUE;
@@ -917,9 +917,11 @@ send_and_splice_async_callback (GObject      *source,
 				dbus_message_iter_init (reply, &iter);
 				dbus_message_iter_recurse (&iter, &arr);
 
-				while (dbus_message_iter_has_next(&arr)) {
+				while (dbus_message_iter_get_arg_type (&arr) != DBUS_TYPE_INVALID) {
 					gchar *str;
 
+					/* No need for a copy here, we own it. But then don't use
+					 * g_strfreev lower */
 					dbus_message_iter_get_basic (&arr, &str);
 					g_ptr_array_add (found, str);
 					dbus_message_iter_next (&arr);
@@ -930,7 +932,7 @@ send_and_splice_async_callback (GObject      *source,
 					v_names[i] = g_ptr_array_index (found, i);
 				}
 
-				g_ptr_array_free (found, FALSE);
+				g_ptr_array_free (found, TRUE);
 			}
 
 			dbus_pending_call_cancel (data->call);
@@ -941,7 +943,8 @@ send_and_splice_async_callback (GObject      *source,
 			                    NULL,
 			                    data->user_data);
 
-			g_strfreev (v_names);
+			/* Don't use g_strfreev here, see above */
+			g_free (v_names);
 		}
 	} else {
 		/* If any error happened, we're not passing any received data, so we
diff --git a/tests/functional-tests/shared-query-test.vala b/tests/functional-tests/shared-query-test.vala
index d3b35da..182e046 100644
--- a/tests/functional-tests/shared-query-test.vala
+++ b/tests/functional-tests/shared-query-test.vala
@@ -11,14 +11,19 @@ public class TestApp : GLib.Object {
 	}
 
 	int iter_cursor (Cursor cursor) {
-		int i;
-
-		for (i = 0; i < cursor.n_columns; i++) {
-			print ("%s%s", i != 0 ? " | " : "", cursor.get_variable_name (i));
-		}
+		bool first = true;
 
 		try {
 			while (cursor.next()) {
+				int i;
+
+				if (first) {
+					for (i = 0; i < cursor.n_columns; i++) {
+						print ("| %s ", cursor.get_variable_name (i));
+					}
+					print ("| -> %d columns\n", cursor.n_columns);
+					first = false;
+				}
 
 				for (i = 0; i < cursor.n_columns; i++) {
 					print ("%s%s", i != 0 ? ",":"", cursor.get_string (i));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]