]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2005-01-16 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Mon, 17 Jan 2005 00:16:28 +0000 (00:16 +0000)
committerHavoc Pennington <hp@redhat.com>
Mon, 17 Jan 2005 00:16:28 +0000 (00:16 +0000)
* dbus/dbus-internals.c (_dbus_real_assert): print the function
name the assertion failed in

* dbus/dbus-internals.h (_dbus_return_if_fail)
(_dbus_return_val_if_fail): assert that the name of the function
containing the check doesn't start with '_', since we only want to
use checks on public functions

* dbus/dbus-connection.c (_dbus_connection_ref_unlocked): change
checks to assertions

* dbus/dbus-marshal-header.c (_dbus_header_set_field_basic):
change checks to asserts for private function

* dbus/dbus-message.c (_dbus_message_set_serial): checks
to asserts for private function

* dbus/dbus-marshal-recursive.c (skip_one_complete_type): remove
broken assertion that was breaking make check
(_dbus_type_reader_array_is_empty): remove this rather than fix
it, was only used in assertions

ChangeLog
dbus/dbus-connection.c
dbus/dbus-internals.c
dbus/dbus-internals.h
dbus/dbus-marshal-basic.c
dbus/dbus-marshal-header.c
dbus/dbus-marshal-recursive.c
dbus/dbus-message.c
dbus/dbus-pending-call.c
dbus/dbus-test.c

index af5c2073f6bad7fac3cec1f5d6d4f7a9a81038a6..64258d78bdcea0d591f3714b40142614ed2367af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2005-01-16  Havoc Pennington  <hp@redhat.com>
+
+       * dbus/dbus-internals.c (_dbus_real_assert): print the function
+       name the assertion failed in
+
+       * dbus/dbus-internals.h (_dbus_return_if_fail) 
+       (_dbus_return_val_if_fail): assert that the name of the function
+       containing the check doesn't start with '_', since we only want to 
+       use checks on public functions
+       
+       * dbus/dbus-connection.c (_dbus_connection_ref_unlocked): change
+       checks to assertions
+
+       * dbus/dbus-marshal-header.c (_dbus_header_set_field_basic):
+       change checks to asserts for private function
+
+       * dbus/dbus-message.c (_dbus_message_set_serial): checks
+       to asserts for private function
+
+       * dbus/dbus-marshal-recursive.c (skip_one_complete_type): remove
+       broken assertion that was breaking make check
+       (_dbus_type_reader_array_is_empty): remove this rather than fix
+       it, was only used in assertions
+
 2005-01-16  Havoc Pennington  <hp@redhat.com>
 
        * test/unused-code-gc.py: hacky script to find code that's used
index 197d186ce650b3834783664135b172872ff4c4e5..d338b786e8b7756762cbaa8cf1efef6970320243 100644 (file)
@@ -1004,8 +1004,8 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
 DBusConnection *
 _dbus_connection_ref_unlocked (DBusConnection *connection)
 {
-  _dbus_return_val_if_fail (connection != NULL, NULL);
-  _dbus_return_val_if_fail (connection->generation == _dbus_current_generation, NULL);
+  _dbus_assert (connection != NULL);
+  _dbus_assert (connection->generation == _dbus_current_generation);
   
 #ifdef DBUS_HAVE_ATOMIC_INT
   _dbus_atomic_inc (&connection->refcount);
@@ -1442,7 +1442,7 @@ _dbus_connection_preallocate_send_unlocked (DBusConnection *connection)
 {
   DBusPreallocatedSend *preallocated;
 
-  _dbus_return_val_if_fail (connection != NULL, NULL);
+  _dbus_assert (connection != NULL);
   
   preallocated = dbus_new (DBusPreallocatedSend, 1);
   if (preallocated == NULL)
@@ -1897,9 +1897,9 @@ _dbus_connection_block_for_reply (DBusConnection     *connection,
   long tv_sec, tv_usec;
   DBusDispatchStatus status;
 
-  _dbus_return_val_if_fail (connection != NULL, NULL);
-  _dbus_return_val_if_fail (client_serial != 0, NULL);
-  _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
+  _dbus_assert (connection != NULL);
+  _dbus_assert (client_serial != 0);
+  _dbus_assert (timeout_milliseconds >= 0 || timeout_milliseconds == -1);
   
   if (timeout_milliseconds == -1)
     timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
index 2aa26805b96701da44cb5171be1f565c5ffd1944..eba3174d29e1e6b84a4ff865da460fd7694f1d4c 100644 (file)
@@ -406,17 +406,19 @@ const char _dbus_return_if_fail_warning_format[] =
  * @param condition_text condition as a string
  * @param file file the assertion is in
  * @param line line the assertion is in
+ * @param func function the assertion is in
  */
 void
 _dbus_real_assert (dbus_bool_t  condition,
                    const char  *condition_text,
                    const char  *file,
-                   int          line)
+                   int          line,
+                   const char  *func)
 {
   if (_DBUS_UNLIKELY (!condition))
     {
-      _dbus_warn ("%lu: assertion failed \"%s\" file \"%s\" line %d\n",
-                  _dbus_getpid (), condition_text, file, line);
+      _dbus_warn ("%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n",
+                  _dbus_getpid (), condition_text, file, line, func);
       _dbus_abort ();
     }
 }
index d1c656154f75c7d9d1f293a54f3d2fabc451cd75..5d6f31f21b2b096b0dc9fd60085278fe29661e75 100644 (file)
@@ -100,9 +100,10 @@ const char* _dbus_strerror (int error_number);
 void _dbus_real_assert (dbus_bool_t  condition,
                         const char  *condition_text,
                         const char  *file,
-                        int          line);
+                        int          line,
+                        const char  *func);
 #define _dbus_assert(condition)                                         \
-  _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__)
+  _dbus_real_assert ((condition) != 0, #condition, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)
 #endif /* !DBUS_DISABLE_ASSERT */
 
 #ifdef DBUS_DISABLE_ASSERT
@@ -122,6 +123,7 @@ void _dbus_real_assert_not_reached (const char *explanation,
 extern const char _dbus_return_if_fail_warning_format[];
 
 #define _dbus_return_if_fail(condition) do {                                            \
+   _dbus_assert ((*(const char*)_DBUS_FUNCTION_NAME) != '_');                           \
   if (!(condition)) {                                                                   \
     _dbus_warn (_dbus_return_if_fail_warning_format,                                    \
                 _dbus_getpid (), _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__);  \
@@ -129,6 +131,7 @@ extern const char _dbus_return_if_fail_warning_format[];
   } } while (0)
 
 #define _dbus_return_val_if_fail(condition, val) do {                                   \
+   _dbus_assert ((*(const char*)_DBUS_FUNCTION_NAME) != '_');                           \
   if (!(condition)) {                                                                   \
     _dbus_warn (_dbus_return_if_fail_warning_format,                                    \
                 _dbus_getpid (), _DBUS_FUNCTION_NAME, #condition, __FILE__, __LINE__);  \
index 0da10358eed5b0a36fc648aaede91d119adf0f44..df154b5407bb854d0be7bbce4dacf98acae786d3 100644 (file)
@@ -280,7 +280,7 @@ set_string (DBusString          *str,
 
   _dbus_string_init_const (&dstr, value);
 
-  _dbus_assert (_DBUS_ALIGN_VALUE (pos, 4) == pos);
+  _dbus_assert (_DBUS_ALIGN_VALUE (pos, 4) == (unsigned) pos);
   old_len = _dbus_unpack_uint32 (byte_order,
                                  _dbus_string_get_const_data_len (str, pos, 4));
 
index a371115522d7afb3b2f65adfded40f24f9b9d661..8c5120cf048d19c1125c2365f1f4658a0acc8349 100644 (file)
@@ -1219,7 +1219,7 @@ _dbus_header_set_field_basic (DBusHeader       *header,
                               int               type,
                               const void       *value)
 {
-  _dbus_return_val_if_fail (field <= DBUS_HEADER_FIELD_LAST, FALSE);
+  _dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
 
   if (!reserve_header_padding (header))
     return FALSE;
index 2d4338ad2ffce6af20d0dbebe1b5a2b0040c62ef..05b827a097cce8607a34e9edf3d0219145ff2a9d 100644 (file)
@@ -324,12 +324,19 @@ skip_one_complete_type (const DBusString *type_str,
   const unsigned char *p;
   const unsigned char *start;
 
+  _dbus_assert (type_str != NULL);
+  _dbus_assert (type_pos != NULL);
+  
   start = _dbus_string_get_const_data (type_str);
   p = start + *type_pos;
 
+  _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
+  
   while (*p == DBUS_TYPE_ARRAY)
     ++p;
 
+  _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
+  
   if (*p == DBUS_STRUCT_BEGIN_CHAR)
     {
       int depth;
@@ -362,8 +369,6 @@ skip_one_complete_type (const DBusString *type_str,
       ++p;
     }
 
-  _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
-
   *type_pos = (int) (p - start);
 }
 
@@ -848,17 +853,6 @@ _dbus_type_reader_get_value_pos (const DBusTypeReader  *reader)
   return reader->value_pos;
 }
 
-/**
- * Checks whether an array has any elements.
- *
- * @param reader the reader
- */
-static dbus_bool_t
-_dbus_type_reader_array_is_empty (const DBusTypeReader *reader)
-{
-  return array_reader_get_array_len (reader) == 0;
-}
-
 /**
  * Get the address of the marshaled value in the data being read.  The
  * address may not be aligned; you have to align it to the type of the
@@ -3839,7 +3833,6 @@ run_test_delete_values (NodeIterationData *nid)
               int elem;
 
               _dbus_assert (n_elements > 0);
-              _dbus_assert (!_dbus_type_reader_array_is_empty (&reader));
 
               elem = cycle;
               if (elem == 3 || elem >= n_elements) /* end of array */
@@ -3878,9 +3871,6 @@ run_test_delete_values (NodeIterationData *nid)
 
   while ((t = _dbus_type_reader_get_current_type (&reader)) != DBUS_TYPE_INVALID)
     {
-      if (t == DBUS_TYPE_ARRAY)
-        _dbus_assert (_dbus_type_reader_array_is_empty (&reader));
-
       _dbus_type_reader_next (&reader);
     }
 
@@ -5428,8 +5418,6 @@ array_read_or_set_value (TestTypeNode   *node,
 
   if (n_copies > 0)
     {
-      _dbus_assert (!_dbus_type_reader_array_is_empty (reader));
-
       _dbus_type_reader_recurse (reader, &sub);
 
       if (realign_root == NULL && arrays_write_fixed_in_blocks &&
@@ -5478,10 +5466,6 @@ array_read_or_set_value (TestTypeNode   *node,
             }
         }
     }
-  else
-    {
-      _dbus_assert (_dbus_type_reader_array_is_empty (reader));
-    }
 
   return TRUE;
 }
index 70e1d022b7434aa05796b18b4613d70044301f97..fc83a07e9ff521882c74f8fd33cb7809635bc08f 100644 (file)
@@ -153,9 +153,9 @@ void
 _dbus_message_set_serial (DBusMessage   *message,
                           dbus_uint32_t  serial)
 {
-  _dbus_return_if_fail (message != NULL);
-  _dbus_return_if_fail (!message->locked);
-  _dbus_return_if_fail (dbus_message_get_serial (message) == 0);
+  _dbus_assert (message != NULL);
+  _dbus_assert (!message->locked);
+  _dbus_assert (dbus_message_get_serial (message) == 0);
 
   _dbus_header_set_serial (&message->header, serial);
 }
@@ -4121,7 +4121,7 @@ message_iter_test (DBusMessage *message)
   if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)
     _dbus_assert_not_reached ("Argument type not an array");
 
-  if (dbus_message_iter_get_array_type (&iter) != DBUS_TYPE_DOUBLE)
+  if (dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_DOUBLE)
     _dbus_assert_not_reached ("Array type not double");
 
   dbus_message_iter_recurse (&iter, &array);
@@ -4140,7 +4140,7 @@ message_iter_test (DBusMessage *message)
   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)
+  if (dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_INT32)
     _dbus_assert_not_reached ("Array type not int32");
 
   /* Empty array */
index d6b343b061db4d32b25b9d4ca6a2525b4880c260..d0403b03fa71b76ffd4f1369bae79feb2851b4c6 100644 (file)
@@ -56,7 +56,7 @@ _dbus_pending_call_new (DBusConnection    *connection,
   DBusPendingCall *pending;
   DBusTimeout *timeout;
 
-  _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
+  _dbus_assert (timeout_milliseconds >= 0 || timeout_milliseconds == -1);
   
   if (timeout_milliseconds == -1)
     timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
index 8654d86e7f66f6e08e632d64f6ecaaf25f2bdc82..7fae00d4810f181aa7e414fb970f0495a2c80279 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: C; c-file-style: "gnu" -*- */
 /* dbus-test.c  Program to run all tests
  *
- * Copyright (C) 2002, 2003  Red Hat Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005  Red Hat Inc.
  *
  * Licensed under the Academic Free License version 2.1
  *