dbus/dbus dbus-marshal-validate.h, 1.5, 1.6 dbus-message-builder.c, 1.28, NONE dbus-message-builder.h, 1.5, NONE dbus-message-factory.c, 1.1, 1.2 dbus-message-factory.h, 1.1, 1.2 dbus-message-private.h, 1.1, 1.2 dbus-message-util.c, 1.3, 1.4 dbus-message.c, 1.153, 1.154 dbus-test.c, 1.36, 1.37 dbus-test.h, 1.27, 1.28

Havoc Pennington hp@freedesktop.org
Sat Jan 22 22:10:09 PST 2005


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv28482/dbus

Modified Files:
	dbus-marshal-validate.h dbus-message-factory.c 
	dbus-message-factory.h dbus-message-private.h 
	dbus-message-util.c dbus-message.c dbus-test.c dbus-test.h 
Removed Files:
	dbus-message-builder.c dbus-message-builder.h 
Log Message:
2005-01-23  Havoc Pennington  <hp@redhat.com>

	* dbus/dbus-message-factory.c, dbus/dbus-message-util.c: 
	get this all working, not many tests in the framework yet though




Index: dbus-marshal-validate.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-validate.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- dbus-marshal-validate.h	21 Jan 2005 06:18:04 -0000	1.5
+++ dbus-marshal-validate.h	23 Jan 2005 06:10:07 -0000	1.6
@@ -49,6 +49,9 @@
  */
 typedef enum
 {
+  DBUS_INVALID_FOR_UNKNOWN_REASON = -3,
+  DBUS_VALID_BUT_INCOMPLETE = -2,
+  DBUS_VALIDITY_UNKNOWN = -1,
   DBUS_VALID = 0,
   DBUS_INVALID_UNKNOWN_TYPECODE = 1,
   DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2,
@@ -98,7 +101,7 @@
   DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 46,
   DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 47,
   DBUS_INVALID_STRING_MISSING_NUL = 48,
-  DBUS_INVALID_SIGNATURE_MISSING_NUL = 49,
+  DBUS_INVALID_SIGNATURE_MISSING_NUL = 49
 } DBusValidity;
 
 DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,

--- dbus-message-builder.c DELETED ---

--- dbus-message-builder.h DELETED ---

Index: dbus-message-factory.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message-factory.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-message-factory.c	23 Jan 2005 00:30:48 -0000	1.1
+++ dbus-message-factory.c	23 Jan 2005 06:10:07 -0000	1.2
@@ -20,14 +20,17 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
+#include <config.h>
 
 #ifdef DBUS_BUILD_TESTS
-
 #include "dbus-message-factory.h"
 #include "dbus-message-private.h"
 
-typedef dbus_bool_t (* DBusMessageGeneratorFunc) (int           sequence,
+typedef dbus_bool_t (* DBusInnerGeneratorFunc)   (int           sequence,
                                                   DBusMessage **message_p);
+typedef dbus_bool_t (* DBusMessageGeneratorFunc) (int           sequence,
+                                                  DBusString   *data,
+                                                  DBusValidity *expected_validity);
 
 static void
 set_reply_serial (DBusMessage *message)
@@ -39,8 +42,8 @@
 }
 
 static dbus_bool_t
-generate_trivial (int           sequence,
-                  DBusMessage **message_p)
+generate_trivial_inner (int           sequence,
+                        DBusMessage **message_p)
 {
   DBusMessage *message;
 
@@ -63,6 +66,22 @@
       break;
     case 3:
       message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
+
+      if (!dbus_message_set_error_name (message,
+                                        "org.freedesktop.TestErrorName"))
+        _dbus_assert_not_reached ("oom");
+      
+      {
+        DBusMessageIter iter;
+        const char *v_STRING = "This is an error";
+        
+        dbus_message_iter_init_append (message, &iter);
+        if (!dbus_message_iter_append_basic (&iter,
+                                             DBUS_TYPE_STRING,
+                                             &v_STRING))
+          _dbus_assert_not_reached ("oom");
+      }
+      
       set_reply_serial (message);
       break;
     default:
@@ -77,6 +96,48 @@
   return TRUE;
 }
 
+static dbus_bool_t
+generate_outer (int                    sequence,
+                DBusString            *data,
+                DBusValidity          *expected_validity,
+                DBusInnerGeneratorFunc func)
+{
+  DBusMessage *message;
+
+  message = NULL;
+  if (!(*func)(sequence, &message))
+    return FALSE;
+
+  _dbus_assert (message != NULL);
+
+  _dbus_message_set_serial (message, 1);
+  _dbus_message_lock (message);
+  
+  *expected_validity = DBUS_VALID;
+
+  /* move for efficiency, since we'll nuke the message anyway */
+  if (!_dbus_string_move (&message->header.data, 0,
+                          data, 0))
+    _dbus_assert_not_reached ("oom");
+
+  if (!_dbus_string_copy (&message->body, 0,
+                          data, _dbus_string_get_length (data)))
+    _dbus_assert_not_reached ("oom");
+
+  dbus_message_unref (message);
+
+  return TRUE;
+}
+
+static dbus_bool_t
+generate_trivial (int                    sequence,
+                  DBusString            *data,
+                  DBusValidity          *expected_validity)
+{
+  return generate_outer (sequence, data, expected_validity,
+                         generate_trivial_inner);
+}
+
 static const DBusMessageGeneratorFunc generators[] = {
   generate_trivial
 };
@@ -99,36 +160,25 @@
                                       DBusMessageData     *data)
 {
   DBusMessageGeneratorFunc func;
-  DBusMessage *message;
-  
+
+ restart:
   if (iter->generator == _DBUS_N_ELEMENTS (generators))
     return FALSE;
-
+  
   func = generators[iter->generator];
 
-  if ((*func)(iter->sequence, &message))
+  if (!_dbus_string_init (&data->data))
+    _dbus_assert_not_reached ("oom");
+  
+  if ((*func)(iter->sequence, &data->data, &data->expected_validity))
     iter->sequence += 1;
   else
     {
       iter->generator += 1;
       iter->sequence = 0;
+      _dbus_string_free (&data->data);
+      goto restart;
     }
-
-  _dbus_assert (message != NULL);
-
-  if (!_dbus_string_init (&data->data))
-    _dbus_assert_not_reached ("oom");
-
-  /* move for efficiency, since we'll nuke the message anyway */
-  if (!_dbus_string_move (&message->header.data, 0,
-                          &data->data, 0))
-    _dbus_assert_not_reached ("oom");
-
-  if (!_dbus_string_copy (&message->body, 0,
-                          &data->data, _dbus_string_get_length (&data->data)))
-    _dbus_assert_not_reached ("oom");
-
-  dbus_message_unref (message);
   
   return TRUE;
 }

Index: dbus-message-factory.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message-factory.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-message-factory.h	23 Jan 2005 00:30:49 -0000	1.1
+++ dbus-message-factory.h	23 Jan 2005 06:10:07 -0000	1.2
@@ -34,7 +34,6 @@
 
 typedef struct
 {
-  dbus_bool_t  validity_known;
   DBusValidity expected_validity;
   
   DBusString data;

Index: dbus-message-private.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-message-private.h	17 Jan 2005 03:53:40 -0000	1.1
+++ dbus-message-private.h	23 Jan 2005 06:10:07 -0000	1.2
@@ -70,6 +70,8 @@
   unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */
 
   unsigned int corrupted : 1; /**< We got broken data, and are no longer working */
+
+  DBusValidity corruption_reason; /**< why we were corrupted */
 };
 
 

Index: dbus-message-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message-util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbus-message-util.c	23 Jan 2005 00:25:39 -0000	1.3
+++ dbus-message-util.c	23 Jan 2005 06:10:07 -0000	1.4
@@ -78,6 +78,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+static void
+check_memleaks (void)
+{
+  dbus_shutdown ();
+
+  if (_dbus_get_malloc_blocks_outstanding () != 0)
+    {
+      _dbus_warn ("%d dbus_malloc blocks were not freed in %s\n",
+                  _dbus_get_malloc_blocks_outstanding (), __FILE__);
+      _dbus_assert_not_reached ("memleaks");
+    }
+}
+
 static dbus_bool_t
 check_have_valid_message (DBusMessageLoader *loader)
 {
@@ -87,12 +100,10 @@
   message = NULL;
   retval = FALSE;
 
-  if (!_dbus_message_loader_queue_messages (loader))
-    _dbus_assert_not_reached ("no memory to queue messages");
-
   if (_dbus_message_loader_get_is_corrupted (loader))
     {
-      _dbus_warn ("loader corrupted on message that was expected to be valid\n");
+      _dbus_warn ("loader corrupted on message that was expected to be valid; invalid reason %d\n",
+                  loader->corruption_reason);
       goto failed;
     }
 
@@ -129,21 +140,27 @@
 }
 
 static dbus_bool_t
-check_invalid_message (DBusMessageLoader *loader)
+check_invalid_message (DBusMessageLoader *loader,
+                       DBusValidity       expected_validity)
 {
   dbus_bool_t retval;
 
   retval = FALSE;
 
-  if (!_dbus_message_loader_queue_messages (loader))
-    _dbus_assert_not_reached ("no memory to queue messages");
-
   if (!_dbus_message_loader_get_is_corrupted (loader))
     {
       _dbus_warn ("loader not corrupted on message that was expected to be invalid\n");
       goto failed;
     }
 
+  if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON &&
+      loader->corruption_reason != expected_validity)
+    {
+      _dbus_warn ("expected message to be corrupted for reason %d and was corrupted for %d instead\n",
+                  expected_validity, loader->corruption_reason);
+      goto failed;
+    }
+
   retval = TRUE;
 
  failed:
@@ -159,12 +176,10 @@
   message = NULL;
   retval = FALSE;
 
-  if (!_dbus_message_loader_queue_messages (loader))
-    _dbus_assert_not_reached ("no memory to queue messages");
-
   if (_dbus_message_loader_get_is_corrupted (loader))
     {
-      _dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete)\n");
+      _dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete), corruption reason %d\n",
+                  loader->corruption_reason);
       goto failed;
     }
 
@@ -185,70 +200,51 @@
 
 static dbus_bool_t
 check_loader_results (DBusMessageLoader      *loader,
-                      DBusMessageValidity     validity)
+                      DBusValidity            expected_validity)
 {
   if (!_dbus_message_loader_queue_messages (loader))
     _dbus_assert_not_reached ("no memory to queue messages");
 
-  switch (validity)
+  if (expected_validity == DBUS_VALID)
+    return check_have_valid_message (loader);
+  else if (expected_validity == DBUS_VALID_BUT_INCOMPLETE)
+    return check_incomplete_message (loader);
+  else if (expected_validity == DBUS_VALIDITY_UNKNOWN)
     {
-    case _DBUS_MESSAGE_VALID:
-      return check_have_valid_message (loader);
-    case _DBUS_MESSAGE_INVALID:
-      return check_invalid_message (loader);
-    case _DBUS_MESSAGE_INCOMPLETE:
-      return check_incomplete_message (loader);
-    case _DBUS_MESSAGE_UNKNOWN:
+      /* here we just know we didn't segfault and that was the
+       * only test
+       */
       return TRUE;
     }
-
-  _dbus_assert_not_reached ("bad DBusMessageValidity");
-  return FALSE;
+  else
+    return check_invalid_message (loader, expected_validity);
 }
 
-
 /**
  * Loads the message in the given message file.
  *
  * @param filename filename to load
- * @param is_raw if #TRUE load as binary data, if #FALSE as message builder language
  * @param data string to load message into
  * @returns #TRUE if the message was loaded
  */
 dbus_bool_t
 dbus_internal_do_not_use_load_message_file (const DBusString    *filename,
-                                            dbus_bool_t          is_raw,
                                             DBusString          *data)
 {
   dbus_bool_t retval;
-
+  DBusError error;
+  
   retval = FALSE;
 
-  if (is_raw)
-    {
-      DBusError error;
-
-      _dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename));
-      dbus_error_init (&error);
-      if (!_dbus_file_get_contents (data, filename, &error))
-        {
-          _dbus_warn ("Could not load message file %s: %s\n",
-                      _dbus_string_get_const_data (filename),
-                      error.message);
-          dbus_error_free (&error);
-          goto failed;
-        }
-    }
-  else
+  _dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename));
+  dbus_error_init (&error);
+  if (!_dbus_file_get_contents (data, filename, &error))
     {
-      if (FALSE) /* Message builder disabled, probably permanently,
-                  * I want to do it another way
-                  */
-        {
-          _dbus_warn ("Could not load message file %s\n",
-                      _dbus_string_get_const_data (filename));
-          goto failed;
-        }
+      _dbus_warn ("Could not load message file %s: %s\n",
+                  _dbus_string_get_const_data (filename),
+                  error.message);
+      dbus_error_free (&error);
+      goto failed;
     }
 
   retval = TRUE;
@@ -263,14 +259,12 @@
  * and verifies that DBusMessageLoader can handle it.
  *
  * @param filename filename to load
- * @param is_raw if #TRUE load as binary data, if #FALSE as message builder language
  * @param expected_validity what the message has to be like to return #TRUE
  * @returns #TRUE if the message has the expected validity
  */
 dbus_bool_t
 dbus_internal_do_not_use_try_message_file (const DBusString    *filename,
-                                           dbus_bool_t          is_raw,
-                                           DBusMessageValidity  expected_validity)
+                                           DBusValidity         expected_validity)
 {
   DBusString data;
   dbus_bool_t retval;
@@ -280,8 +274,7 @@
   if (!_dbus_string_init (&data))
     _dbus_assert_not_reached ("could not allocate string\n");
 
-  if (!dbus_internal_do_not_use_load_message_file (filename, is_raw,
-                                                   &data))
+  if (!dbus_internal_do_not_use_load_message_file (filename, &data))
     goto failed;
 
   retval = dbus_internal_do_not_use_try_message_data (&data, expected_validity);
@@ -313,7 +306,7 @@
  */
 dbus_bool_t
 dbus_internal_do_not_use_try_message_data (const DBusString    *data,
-                                           DBusMessageValidity  expected_validity)
+                                           DBusValidity         expected_validity)
 {
   DBusMessageLoader *loader;
   dbus_bool_t retval;
@@ -405,7 +398,7 @@
 static dbus_bool_t
 process_test_subdir (const DBusString          *test_base_dir,
                      const char                *subdir,
-                     DBusMessageValidity        validity,
+                     DBusValidity               expected_validity,
                      DBusForeachMessageFileFunc function,
                      void                      *user_data)
 {
@@ -451,7 +444,6 @@
   while (_dbus_directory_get_next_file (dir, &filename, &error))
     {
       DBusString full_path;
-      dbus_bool_t is_raw;
 
       if (!_dbus_string_init (&full_path))
         _dbus_assert_not_reached ("couldn't init string");
@@ -462,12 +454,16 @@
       if (!_dbus_concat_dir_and_file (&full_path, &filename))
         _dbus_assert_not_reached ("couldn't concat file to dir");
 
-      if (_dbus_string_ends_with_c_str (&filename, ".message"))
-        is_raw = FALSE;
-      else if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
-        is_raw = TRUE;
+      if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
+        ;
       else
         {
+          if (_dbus_string_ends_with_c_str (&filename, ".message"))
+            {
+              _dbus_warn ("Could not load %s, message builder language no longer supported\n",
+                          _dbus_string_get_const_data (&filename));
+            }
+          
           _dbus_verbose ("Skipping non-.message file %s\n",
                          _dbus_string_get_const_data (&filename));
 	  _dbus_string_free (&full_path);
@@ -477,13 +473,8 @@
       printf ("    %s\n",
               _dbus_string_get_const_data (&filename));
 
-      _dbus_verbose (" expecting %s for %s\n",
-                     validity == _DBUS_MESSAGE_VALID ? "valid" :
-                     (validity == _DBUS_MESSAGE_INVALID ? "invalid" :
-                      (validity == _DBUS_MESSAGE_INCOMPLETE ? "incomplete" : "unknown")),
-                     _dbus_string_get_const_data (&filename));
-
-      if (! (*function) (&full_path, is_raw, validity, user_data))
+      if (! (*function) (&full_path,
+                         expected_validity, user_data))
         {
           _dbus_string_free (&full_path);
           goto failed;
@@ -533,21 +524,27 @@
   retval = FALSE;
 
   _dbus_string_init_const (&test_directory, test_data_dir);
-
+  
   if (!process_test_subdir (&test_directory, "valid-messages",
-                            _DBUS_MESSAGE_VALID, func, user_data))
+                            DBUS_VALID, func, user_data))
     goto failed;
 
+  check_memleaks ();
+  
   if (!process_test_subdir (&test_directory, "invalid-messages",
-                            _DBUS_MESSAGE_INVALID, func, user_data))
+                            DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
     goto failed;
 
+  check_memleaks ();
+  
   if (!process_test_subdir (&test_directory, "incomplete-messages",
-                            _DBUS_MESSAGE_INCOMPLETE, func, user_data))
+                            DBUS_VALID_BUT_INCOMPLETE, func, user_data))
     goto failed;
 
+  check_memleaks ();
+  
   retval = TRUE;
-
+  
  failed:
 
   _dbus_string_free (&test_directory);
@@ -660,11 +657,12 @@
   DBusMessageIter iter;
   DBusError error;
   dbus_int32_t our_int;
+  dbus_uint32_t our_uint;
   const char *our_str;
   double our_double;
+  double v_DOUBLE;
   dbus_bool_t our_bool;
   unsigned char our_byte_1, our_byte_2;
-  dbus_uint32_t our_uint32;
   const dbus_int32_t *our_uint32_array = (void*)0xdeadbeef;
   int our_uint32_array_len;
   dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
@@ -689,6 +687,7 @@
   dbus_error_init (&error);
   if (!dbus_message_iter_get_args (&iter, &error,
 				   DBUS_TYPE_INT32, &our_int,
+                                   DBUS_TYPE_UINT32, &our_uint,
 #ifdef DBUS_HAVE_INT64
                                    DBUS_TYPE_INT64, &our_int64,
                                    DBUS_TYPE_UINT64, &our_uint64,
@@ -724,6 +723,9 @@
   if (our_int != -0x12345678)
     _dbus_assert_not_reached ("integers differ!");
 
+  if (our_uint != 0x12300042)
+    _dbus_assert_not_reached ("uints differ!");
+
 #ifdef DBUS_HAVE_INT64
   if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
     _dbus_assert_not_reached ("64-bit integers differ!");
@@ -731,7 +733,8 @@
     _dbus_assert_not_reached ("64-bit unsigned integers differ!");
 #endif
 
-  if (our_double != 3.14159)
+  v_DOUBLE = 3.14159;
+  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double, v_DOUBLE))
     _dbus_assert_not_reached ("doubles differ!");
 
   if (strcmp (our_str, "Test string") != 0)
@@ -782,9 +785,14 @@
   /* On all IEEE machines (i.e. everything sane) exact equality
    * should be preserved over the wire
    */
-  if (our_double_array[0] != 0.1234 ||
-      our_double_array[1] != 9876.54321 ||
-      our_double_array[2] != -300.0)
+  v_DOUBLE = 0.1234;
+  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[0], v_DOUBLE))
+    _dbus_assert_not_reached ("double array had wrong values");
+  v_DOUBLE = 9876.54321;
+  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[1], v_DOUBLE))
+    _dbus_assert_not_reached ("double array had wrong values");
+  v_DOUBLE = -300.0;
+  if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[2], v_DOUBLE))
     _dbus_assert_not_reached ("double array had wrong values");
 
   if (our_byte_array_len != 4)
@@ -821,7 +829,6 @@
 {
   DBusMessage *message;
   DBusMessageLoader *loader;
-  DBusMessageIter iter, child_iter, child_iter2, child_iter3;
   int i;
   const char *data;
   DBusMessage *copy;
@@ -851,8 +858,6 @@
   const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
   char sig[64];
   const char *s;
-  char *t;
-  DBusError error;
   const char *v_STRING;
   double v_DOUBLE;
   dbus_int32_t v_INT32;
@@ -967,8 +972,10 @@
                                           "Foo.TestInterface",
                                           "TestMethod");
   _dbus_message_set_serial (message, 1);
+  dbus_message_set_reply_serial (message, 5678);
 
   v_INT32 = -0x12345678;
+  v_UINT32 = 0x12300042;
 #ifdef DBUS_HAVE_INT64
   v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
   v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
@@ -981,6 +988,7 @@
 
   dbus_message_append_args (message,
 			    DBUS_TYPE_INT32, &v_INT32,
+                            DBUS_TYPE_UINT32, &v_UINT32,
 #ifdef DBUS_HAVE_INT64
                             DBUS_TYPE_INT64, &v_INT64,
                             DBUS_TYPE_UINT64, &v_UINT64,
@@ -1010,6 +1018,7 @@
 
   i = 0;
   sig[i++] = DBUS_TYPE_INT32;
+  sig[i++] = DBUS_TYPE_UINT32;
 #ifdef DBUS_HAVE_INT64
   sig[i++] = DBUS_TYPE_INT64;
   sig[i++] = DBUS_TYPE_UINT64;
@@ -1125,7 +1134,7 @@
   if (!message)
     _dbus_assert_not_reached ("received a NULL message");
 
-  if (dbus_message_get_reply_serial (message) != 0x12345678)
+  if (dbus_message_get_reply_serial (message) != 5678)
     _dbus_assert_not_reached ("reply serial fields differ");
 
   verify_test_message (message);
@@ -1133,7 +1142,33 @@
   dbus_message_unref (message);
   _dbus_message_loader_unref (loader);
 
+  check_memleaks ();
 
+  /* Load all the sample messages from the message factory */
+  {
+    DBusMessageDataIter diter;
+    DBusMessageData mdata;
+
+    _dbus_message_data_iter_init (&diter);
+    
+    while (_dbus_message_data_iter_get_and_next (&diter,
+                                                 &mdata))
+      {
+        if (!dbus_internal_do_not_use_try_message_data (&mdata.data,
+                                                        mdata.expected_validity))
+          {
+            _dbus_warn ("expected validity %d and did not get it; generator %d sequence %d\n",
+                        mdata.expected_validity,
+                        diter.generator, diter.sequence);
+            _dbus_assert_not_reached ("message data failed");
+          }
+
+        _dbus_message_data_free (&mdata);
+      }
+  }
+  
+  check_memleaks ();
+  
   /* Now load every message in test_data_dir if we have one */
   if (test_data_dir == NULL)
     return TRUE;

Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- dbus-message.c	21 Jan 2005 06:18:04 -0000	1.153
+++ dbus-message.c	23 Jan 2005 06:10:07 -0000	1.154
@@ -570,7 +570,7 @@
 {
   dbus_bool_t was_cached;
   int i;
-
+  
   _dbus_assert (message->refcount.value == 0);
 
   /* This calls application code and has to be done first thing
@@ -654,7 +654,7 @@
       message->generation = _dbus_current_generation;
 #endif
     }
-
+  
   message->refcount.value = 1;
   message->byte_order = DBUS_COMPILER_BYTE_ORDER;
   message->locked = FALSE;
@@ -2881,9 +2881,12 @@
   loader = dbus_new0 (DBusMessageLoader, 1);
   if (loader == NULL)
     return NULL;
-
+  
   loader->refcount = 1;
 
+  loader->corrupted = FALSE;
+  loader->corruption_reason = DBUS_VALID;
+  
   /* Try to cap message size at something that won't *totally* hose
    * the system if we have a couple of them.
    */
@@ -3018,7 +3021,7 @@
  * loader->data and only delete it occasionally, instead of after
  * each message is loaded.
  *
- * load_message() returns FALSE if not enough memory
+ * load_message() returns FALSE if not enough memory OR the loader was corrupted
  */
 static dbus_bool_t
 load_message (DBusMessageLoader *loader,
@@ -3059,6 +3062,11 @@
       _dbus_verbose ("Failed to load header for new message code %d\n", validity);
       if (validity == DBUS_VALID)
         oom = TRUE;
+      else
+        {
+          loader->corrupted = TRUE;
+          loader->corruption_reason = validity;
+        }
       goto failed;
     }
 
@@ -3084,6 +3092,10 @@
       if (validity != DBUS_VALID)
         {
           _dbus_verbose ("Failed to validate message body code %d\n", validity);
+
+          loader->corrupted = TRUE;
+          loader->corruption_reason = validity;
+          
           goto failed;
         }
     }
@@ -3117,6 +3129,8 @@
 
   _dbus_assert (!oom);
   _dbus_assert (!loader->corrupted);
+  _dbus_assert (loader->messages != NULL);
+  _dbus_assert (_dbus_list_find_last (&loader->messages, message) != NULL);
 
   return TRUE;
 
@@ -3126,13 +3140,15 @@
 
   /* does nothing if the message isn't in the list */
   _dbus_list_remove_last (&loader->messages, message);
-
-  if (!oom)
-    loader->corrupted = TRUE;
+  
+  if (oom)
+    _dbus_assert (!loader->corrupted);
+  else
+    _dbus_assert (loader->corrupted);
 
   _dbus_verbose_bytes_of_string (&loader->data, 0, _dbus_string_get_length (&loader->data));
 
-  return !oom;
+  return FALSE;
 }
 
 /**
@@ -3180,15 +3196,24 @@
                              header_len, body_len))
             {
               dbus_message_unref (message);
-              return FALSE;
+              /* load_message() returns false if corrupted or OOM; if
+               * corrupted then return TRUE for not OOM
+               */
+              return loader->corrupted;
             }
+
+          _dbus_assert (loader->messages != NULL);
+          _dbus_assert (_dbus_list_find_last (&loader->messages, message) != NULL);
 	}
       else
         {
           _dbus_verbose ("Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
                          validity);
           if (validity != DBUS_VALID)
-            loader->corrupted = TRUE;
+            {
+              loader->corrupted = TRUE;
+              loader->corruption_reason = validity;
+            }
           return TRUE;
         }
     }
@@ -3265,6 +3290,8 @@
 dbus_bool_t
 _dbus_message_loader_get_is_corrupted (DBusMessageLoader *loader)
 {
+  _dbus_assert ((loader->corrupted && loader->corruption_reason != DBUS_VALID) ||
+                (!loader->corrupted && loader->corruption_reason == DBUS_VALID));
   return loader->corrupted;
 }
 

Index: dbus-test.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-test.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- dbus-test.c	17 Jan 2005 00:16:28 -0000	1.36
+++ dbus-test.c	23 Jan 2005 06:10:07 -0000	1.37
@@ -118,7 +118,7 @@
 
   check_memleaks ();
 
-#if 1
+#if 0
   printf ("%s: running recursive marshalling tests\n", "dbus-test");
   if (!_dbus_marshal_recursive_test ())
     die ("recursive marshal");
@@ -134,11 +134,13 @@
   
   check_memleaks ();
 
+#if 0
   printf ("%s: running memory pool tests\n", "dbus-test");
   if (!_dbus_mem_pool_test ())
     die ("memory pools");
 
   check_memleaks ();
+#endif
   
   printf ("%s: running linked list tests\n", "dbus-test");
   if (!_dbus_list_test ())

Index: dbus-test.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-test.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- dbus-test.h	15 Jan 2005 07:15:38 -0000	1.27
+++ dbus-test.h	23 Jan 2005 06:10:07 -0000	1.28
@@ -26,14 +26,7 @@
 
 #include <dbus/dbus-types.h>
 #include <dbus/dbus-string.h>
-
-typedef enum
-{
-  _DBUS_MESSAGE_VALID,
-  _DBUS_MESSAGE_INVALID,
-  _DBUS_MESSAGE_INCOMPLETE,
-  _DBUS_MESSAGE_UNKNOWN
-} DBusMessageValidity;
+#include <dbus/dbus-marshal-validate.h>
 
 dbus_bool_t _dbus_hash_test              (void);
 dbus_bool_t _dbus_dict_test              (void);
@@ -61,19 +54,16 @@
 
 void        dbus_internal_do_not_use_run_tests         (const char          *test_data_dir);
 dbus_bool_t dbus_internal_do_not_use_try_message_file  (const DBusString    *filename,
-                                                        dbus_bool_t          is_raw,
-                                                        DBusMessageValidity  expected_validity);
+                                                        DBusValidity         expected_validity);
 dbus_bool_t dbus_internal_do_not_use_try_message_data  (const DBusString    *data,
-                                                        DBusMessageValidity  expected_validity);
+                                                        DBusValidity         expected_validity);
 dbus_bool_t dbus_internal_do_not_use_load_message_file (const DBusString    *filename,
-                                                        dbus_bool_t          is_raw,
                                                         DBusString          *data);
 
 
 /* returns FALSE on fatal failure */
 typedef dbus_bool_t (* DBusForeachMessageFileFunc) (const DBusString   *filename,
-                                                    dbus_bool_t         is_raw,
-                                                    DBusMessageValidity expected_validity,
+                                                    DBusValidity        expected_validity,
                                                     void               *data);
 
 dbus_bool_t dbus_internal_do_not_use_foreach_message_file (const char                 *test_data_dir,



More information about the dbus-commit mailing list