+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
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);
{
DBusPreallocatedSend *preallocated;
- _dbus_return_val_if_fail (connection != NULL, NULL);
+ _dbus_assert (connection != NULL);
preallocated = dbus_new (DBusPreallocatedSend, 1);
if (preallocated == NULL)
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;
* @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 ();
}
}
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
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__); \
} } 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__); \
_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));
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;
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;
++p;
}
- _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
-
*type_pos = (int) (p - start);
}
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
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 */
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);
}
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 &&
}
}
}
- else
- {
- _dbus_assert (_dbus_type_reader_array_is_empty (reader));
- }
return TRUE;
}
_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);
}
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);
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 */
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;
/* -*- 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
*