Empty arrays

Olivier Andrieu oliv__a at users.sourceforge.net
Mon Aug 9 15:42:43 PDT 2004


Hi,

about this:
,----
| 2004-07-12  Seth Nickell  <seth at gnome.org>
| 	* python/dbus_bindings.pyx.in:
| 	Automatically return NIL when passed an empty list
| 	(we can't pass back a list since lists are typed
| 	and we don't have any idea what type the the client
| 	intended the list to be... :-( )
`----

dbus_message_iter_init_array_iterator need to be modified so that it
accepts NIL as well.

-- 
   Olivier
-------------- next part --------------
Index: dbus/dbus-message.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.h,v
retrieving revision 1.50
diff -u -r1.50 dbus-message.h
--- dbus/dbus-message.h	16 Mar 2004 18:00:35 -0000	1.50
+++ dbus/dbus-message.h	19 Mar 2004 14:28:14 -0000
@@ -150,7 +150,7 @@
 					       va_list          var_args);
 
 
-void                   dbus_message_iter_init            (DBusMessage      *message,
+dbus_bool_t            dbus_message_iter_init            (DBusMessage      *message,
                                                           DBusMessageIter  *iter);
 dbus_bool_t            dbus_message_iter_has_next        (DBusMessageIter  *iter);
 dbus_bool_t            dbus_message_iter_next            (DBusMessageIter  *iter);
@@ -173,10 +173,10 @@
                                                           unsigned char   **value,
                                                           int              *len);
 
-void        dbus_message_iter_init_array_iterator (DBusMessageIter   *iter,
+dbus_bool_t dbus_message_iter_init_array_iterator (DBusMessageIter   *iter,
 						   DBusMessageIter   *array_iter,
 						   int               *array_type);
-void        dbus_message_iter_init_dict_iterator  (DBusMessageIter   *iter,
+dbus_bool_t dbus_message_iter_init_dict_iterator  (DBusMessageIter   *iter,
 						   DBusMessageIter   *dict_iter);
 dbus_bool_t dbus_message_iter_get_byte_array      (DBusMessageIter   *iter,
 						   unsigned char    **value,
Index: dbus/dbus-marshal.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal.c,v
retrieving revision 1.48
diff -u -r1.48 dbus-marshal.c
--- dbus/dbus-marshal.c	12 Mar 2004 14:18:35 -0000	1.48
+++ dbus/dbus-marshal.c	19 Mar 2004 14:28:14 -0000
@@ -2116,7 +2116,10 @@
         
 	len = demarshal_and_validate_len (str, byte_order, pos, &pos);
         if (len < 0)
-          return FALSE;
+	  {
+	    _dbus_verbose ("invalid array length (<0)\n");
+	    return FALSE;
+	  }
 
         if (len > _dbus_string_get_length (str) - pos)
           {
@@ -2126,10 +2129,13 @@
 	
 	end = pos + len;
 
-        if (!validate_array_data (str, byte_order, depth + 1,
-                                  array_type, array_type_pos,
-                                  pos, &pos, end))
-          return FALSE;
+        if (len > 0 && !validate_array_data (str, byte_order, depth + 1,
+					     array_type, array_type_pos,
+					     pos, &pos, end))
+	  {
+	    _dbus_verbose ("invalid array data\n");
+	    return FALSE;
+	  }
 
         if (pos < end)
           {
Index: dbus/dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.122
diff -u -r1.122 dbus-message.c
--- dbus/dbus-message.c	18 Mar 2004 11:10:59 -0000	1.122
+++ dbus/dbus-message.c	19 Mar 2004 14:28:15 -0000
@@ -2361,15 +2361,16 @@
  *
  * @param message the message
  * @param iter pointer to an iterator to initialize
+ * @returns #FALSE if the message has no arguments
  */
-void
+dbus_bool_t
 dbus_message_iter_init (DBusMessage     *message,
 			DBusMessageIter *iter)
 {
   DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
 
-  _dbus_return_if_fail (message != NULL);
-  _dbus_return_if_fail (iter != NULL);
+  _dbus_return_val_if_fail (message != NULL, FALSE);
+  _dbus_return_val_if_fail (iter != NULL, FALSE);
   
   _dbus_assert (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
   
@@ -2385,6 +2386,8 @@
   real->container_length_pos = 0;
   real->wrote_dict_key = 0;
   real->array_type_pos = 0;
+
+  return real->end > real->pos;
 }
 
 #ifndef DBUS_DISABLE_CHECKS
@@ -2946,8 +2949,9 @@
  * @param iter the iterator
  * @param array_iter pointer to an iterator to initialize
  * @param array_type gets set to the type of the array elements
+ * @returns #FALSE if the array is empty
  */
-void
+dbus_bool_t
 dbus_message_iter_init_array_iterator (DBusMessageIter *iter,
 				       DBusMessageIter *array_iter,
 				       int             *array_type)
@@ -2957,7 +2961,7 @@
   int type, pos, len_pos, len, array_type_pos;
   int _array_type;
 
-  _dbus_return_if_fail (dbus_message_iter_check (real));
+  _dbus_return_val_if_fail (dbus_message_iter_check (real), FALSE);
 
   pos = dbus_message_iter_get_data_start (real, &type);
   
@@ -2985,6 +2989,8 @@
   
   if (array_type != NULL)
     *array_type = _array_type;
+
+  return len > 0;
 }
 
 
@@ -2995,8 +3001,9 @@
  *
  * @param iter the iterator
  * @param dict_iter pointer to an iterator to initialize
+ * @returns #FALSE if the dict is empty
  */
-void
+dbus_bool_t
 dbus_message_iter_init_dict_iterator (DBusMessageIter *iter,
 				      DBusMessageIter *dict_iter)
 {
@@ -3004,7 +3011,7 @@
   DBusMessageRealIter *dict_real = (DBusMessageRealIter *)dict_iter;
   int type, pos, len_pos, len;
 
-  _dbus_return_if_fail (dbus_message_iter_check (real));
+  _dbus_return_val_if_fail (dbus_message_iter_check (real), FALSE);
 
   pos = dbus_message_iter_get_data_start (real, &type);
   
@@ -3025,6 +3032,8 @@
   dict_real->container_start = pos;
   dict_real->container_length_pos = len_pos;
   dict_real->wrote_dict_key = 0;
+
+  return len > 0;
 }
 
 /**
@@ -6055,6 +6064,39 @@
   if (dbus_message_iter_get_byte (&iter) != 0xF0)
     _dbus_assert_not_reached ("wrong value after custom");
 
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)
+    _dbus_assert_not_reached ("no array");
+
+  if (dbus_message_iter_get_array_type (&iter) != DBUS_TYPE_INT32)
+    _dbus_assert_not_reached ("Array type not int32");
+
+  if (dbus_message_iter_init_array_iterator (&iter, &array, NULL))
+    _dbus_assert_not_reached ("non empty array");
+  
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_byte (&iter) != 0xF0)
+    _dbus_assert_not_reached ("wrong value after empty array");
+
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_DICT)
+    _dbus_assert_not_reached ("non dict");
+
+  if (dbus_message_iter_init_dict_iterator (&iter, &dict))
+    _dbus_assert_not_reached ("non empty dict");
+
+  if (!dbus_message_iter_next (&iter))
+    _dbus_assert_not_reached ("Reached end of arguments");
+
+  if (dbus_message_iter_get_byte (&iter) != 0xF0)
+    _dbus_assert_not_reached ("wrong value after empty dict");
+
   if (dbus_message_iter_next (&iter))
     _dbus_assert_not_reached ("Didn't reach end of arguments");
 }
@@ -7194,6 +7236,14 @@
   
   dbus_message_iter_append_byte (&iter, 0xF0);
 
+  dbus_message_iter_append_array (&iter, &child_iter, DBUS_TYPE_INT32);
+
+  dbus_message_iter_append_byte (&iter, 0xF0);
+
+  dbus_message_iter_append_dict (&iter, &child_iter);
+
+  dbus_message_iter_append_byte (&iter, 0xF0);
+
   message_iter_test (message);
   
   /* Message loader test */
Index: dbus/dbus-pending-call.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-pending-call.c,v
retrieving revision 1.6
diff -u -r1.6 dbus-pending-call.c
--- dbus/dbus-pending-call.c	2 Dec 2003 10:44:21 -0000	1.6
+++ dbus/dbus-pending-call.c	19 Mar 2004 14:28:15 -0000
@@ -143,7 +143,7 @@
 DBusPendingCall *
 dbus_pending_call_ref (DBusPendingCall *pending)
 {
-  _dbus_return_if_fail (pending != NULL);
+  _dbus_return_val_if_fail (pending != NULL, NULL);
 
   _dbus_atomic_inc (&pending->refcount);
 
Index: dbus/dbus-server.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server.c,v
retrieving revision 1.32
diff -u -r1.32 dbus-server.c
--- dbus/dbus-server.c	2 Dec 2003 10:44:21 -0000	1.32
+++ dbus/dbus-server.c	19 Mar 2004 14:28:15 -0000
@@ -455,7 +455,7 @@
 DBusServer *
 dbus_server_ref (DBusServer *server)
 {
-  _dbus_return_if_fail (server != NULL);
+  _dbus_return_val_if_fail (server != NULL, NULL);
   
   server->refcount += 1;
 


More information about the dbus mailing list