dbus/mono/DBusType Array.cs,1.2,1.3 Dict.cs,1.2,1.3

Owen Fraser-Green ow3n at pdx.freedesktop.org
Sun May 2 05:56:29 EST 2004


Update of /cvs/dbus/dbus/mono/DBusType
In directory pdx:/tmp/cvs-serv22592/mono/DBusType

Modified Files:
	Array.cs Dict.cs 
Log Message:
Handle empty iterators.


Index: Array.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/DBusType/Array.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/Array.cs	24 Mar 2004 13:15:20 -0000	1.2
+++ b/Array.cs	1 May 2004 19:56:27 -0000	1.3
@@ -36,18 +36,20 @@
       IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
       
       int elementTypeCode;
-      dbus_message_iter_init_array_iterator(iter, arrayIter, out elementTypeCode);
+      bool empty = dbus_message_iter_init_array_iterator(iter, arrayIter, out elementTypeCode);
       this.elementType = (Type) Arguments.DBusTypes[(char) elementTypeCode];
 
       elements = new ArrayList();
 
-      do {
-	object [] pars = new Object[2];
-	pars[0] = arrayIter;
-	pars[1] = service;
-	DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
-	elements.Add(dbusType);
-      } while (dbus_message_iter_next(arrayIter));
+      if (!empty) {
+	do {
+	  object [] pars = new Object[2];
+	  pars[0] = arrayIter;
+	  pars[1] = service;
+	  DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
+	  elements.Add(dbusType);
+	} while (dbus_message_iter_next(arrayIter));
+      }
       
       Marshal.FreeCoTaskMem(arrayIter);
     }
@@ -118,7 +120,7 @@
     }    
 
     [DllImport("dbus-1")]
-    private extern static void dbus_message_iter_init_array_iterator(IntPtr iter,
+    private extern static bool dbus_message_iter_init_array_iterator(IntPtr iter,
 								     IntPtr arrayIter,
 								     out int elementType);
  

Index: Dict.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/DBusType/Dict.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/Dict.cs	24 Mar 2004 13:15:20 -0000	1.2
+++ b/Dict.cs	1 May 2004 19:56:27 -0000	1.3
@@ -31,20 +31,22 @@
     {
       IntPtr dictIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
       
-      dbus_message_iter_init_dict_iterator(iter, dictIter);
+      bool empty = dbus_message_iter_init_dict_iterator(iter, dictIter);
 
       this.val = new Hashtable();
 
-      do {
-	string key = dbus_message_iter_get_dict_key(dictIter);
-
-	// Get the argument type and get the value
-	Type elementType = (Type) DBus.Arguments.DBusTypes[(char) dbus_message_iter_get_arg_type(dictIter)];
-	object [] pars = new Object[1];
-	pars[0] = dictIter;
-	DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
-	this.val.Add(key, dbusType);
-      } while (dbus_message_iter_next(dictIter));
+      if (!empty) {
+	do {
+	  string key = dbus_message_iter_get_dict_key(dictIter);
+	  
+	  // Get the argument type and get the value
+	  Type elementType = (Type) DBus.Arguments.DBusTypes[(char) dbus_message_iter_get_arg_type(dictIter)];
+	  object [] pars = new Object[1];
+	  pars[0] = dictIter;
+	  DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
+	  this.val.Add(key, dbusType);
+	} while (dbus_message_iter_next(dictIter));
+      }
       
       Marshal.FreeCoTaskMem(dictIter);
     }
@@ -120,7 +122,7 @@
     }    
 
     [DllImport("dbus-1")]
-    private extern static void dbus_message_iter_init_dict_iterator(IntPtr iter,
+    private extern static bool dbus_message_iter_init_dict_iterator(IntPtr iter,
 								    IntPtr dictIter);
  
     [DllImport("dbus-1")]




More information about the dbus-commit mailing list