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 af5c207..64258d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
 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
        only by the bus (not libdbus) or used only by tests or not used at
        all. It has some false alarms, but looks like we can clean up a
index 197d186..d338b78 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 2aa2680..eba3174 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 d1c6561..5d6f31f 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 0da1035..df154b5 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 a371115..8c5120c 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 2d4338a..05b827a 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);
 }
 
@@ -849,17 +854,6 @@ _dbus_type_reader_get_value_pos (const DBusTypeReader  *reader)
 }
 
 /**
- * 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
  * value you want to read. Most of the demarshal routines do this for
@@ -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 70e1d02..fc83a07 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 d6b343b..d0403b0 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 8654d86..7fae00d 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
  *