summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-01-17 00:16:28 +0000
committerHavoc Pennington <hp@redhat.com>2005-01-17 00:16:28 +0000
commitaad6fa897f85486386b030847151cb09943c97c0 (patch)
tree3996469d2be2df0bc63a4e8dd0aa3ac6cdfaddcb
parent7f9721a6d36697a57170c604aa845af3531bd157 (diff)
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
-rw-r--r--ChangeLog24
-rw-r--r--dbus/dbus-connection.c12
-rw-r--r--dbus/dbus-internals.c8
-rw-r--r--dbus/dbus-internals.h7
-rw-r--r--dbus/dbus-marshal-basic.c2
-rw-r--r--dbus/dbus-marshal-header.c2
-rw-r--r--dbus/dbus-marshal-recursive.c30
-rw-r--r--dbus/dbus-message.c10
-rw-r--r--dbus/dbus-pending-call.c2
-rw-r--r--dbus/dbus-test.c2
10 files changed, 56 insertions, 43 deletions
diff --git a/ChangeLog b/ChangeLog
index af5c2073..64258d78 100644
--- 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
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 197d186c..d338b786 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -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;
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c
index 2aa26805..eba3174d 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -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 ();
}
}
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index d1c65615..5d6f31f2 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -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__); \
diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c
index 0da10358..df154b54 100644
--- a/dbus/dbus-marshal-basic.c
+++ b/dbus/dbus-marshal-basic.c
@@ -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));
diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c
index a3711155..8c5120cf 100644
--- a/dbus/dbus-marshal-header.c
+++ b/dbus/dbus-marshal-header.c
@@ -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;
diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c
index 2d4338ad..05b827a0 100644
--- a/dbus/dbus-marshal-recursive.c
+++ b/dbus/dbus-marshal-recursive.c
@@ -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;
}
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 70e1d022..fc83a07e 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -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 */
diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c
index d6b343b0..d0403b03 100644
--- a/dbus/dbus-pending-call.c
+++ b/dbus/dbus-pending-call.c
@@ -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;
diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c
index 8654d86e..7fae00d4 100644
--- a/dbus/dbus-test.c
+++ b/dbus/dbus-test.c
@@ -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
*