From db21e7c41f0c336c0534d9cdc451e9bdbb7387da Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Mon, 15 Jul 2013 13:51:18 +0800 Subject: [PATCH 05/10] Cleanup: simplify assertion check --- bus/driver.c | 17 +++-------------- dbus/dbus-connection.c | 8 +------- dbus/dbus-memory.c | 16 ++-------------- dbus/dbus-object-tree.c | 8 +------- dbus/dbus-server.c | 11 ++--------- dbus/dbus-string.c | 7 ++----- 6 files changed, 11 insertions(+), 56 deletions(-) diff --git a/bus/driver.c b/bus/driver.c index 01e56fb..e6c348e 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -884,13 +884,7 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection, /* The message signature has already been checked for us, * so let's just assert it's right. */ -#ifndef DBUS_DISABLE_ASSERT - { - int msg_type = dbus_message_iter_get_arg_type (&iter); - - _dbus_assert (msg_type == DBUS_TYPE_ARRAY); - } -#endif + _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &dict_iter); @@ -1931,13 +1925,8 @@ bus_driver_handle_message (DBusConnection *connection, _dbus_verbose ("Driver got a method call: %s\n", name); /* security checks should have kept this from getting here */ -#ifndef DBUS_DISABLE_ASSERT - { - const char *sender = dbus_message_get_sender (message); - - _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0); - } -#endif + _dbus_assert (dbus_message_get_sender (message) != NULL || + strcmp (name, "Hello") == 0); for (ih = interface_handlers; ih->name != NULL; ih++) { diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index c2f66ea..2d37404 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -350,14 +350,8 @@ static dbus_bool_t _dbus_connection_peek_for_reply_unlocked (DB static DBusMessageFilter * _dbus_message_filter_ref (DBusMessageFilter *filter) { -#ifdef DBUS_DISABLE_ASSERT + _dbus_assert (_dbus_atomic_get (&filter->refcount) > 0); _dbus_atomic_inc (&filter->refcount); -#else - dbus_int32_t old_value; - - old_value = _dbus_atomic_inc (&filter->refcount); - _dbus_assert (old_value > 0); -#endif return filter; } diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index d59e8f8..b681d34 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -706,14 +706,8 @@ dbus_free (void *memory) check_guards (memory, TRUE); if (memory) { -#ifdef DBUS_DISABLE_ASSERT + _dbus_assert (_dbus_atomic_get (&n_blocks_outstanding) >= 1); _dbus_atomic_dec (&n_blocks_outstanding); -#else - dbus_int32_t old_value; - - old_value = _dbus_atomic_dec (&n_blocks_outstanding); - _dbus_assert (old_value >= 1); -#endif free (((unsigned char*)memory) - GUARD_START_OFFSET); } @@ -725,14 +719,8 @@ dbus_free (void *memory) if (memory) /* we guarantee it's safe to free (NULL) */ { #ifdef DBUS_ENABLE_EMBEDDED_TESTS -#ifdef DBUS_DISABLE_ASSERT + _dbus_assert (_dbus_atomic_get (&n_blocks_outstanding) >= 1); _dbus_atomic_dec (&n_blocks_outstanding); -#else - dbus_int32_t old_value; - - old_value = _dbus_atomic_dec (&n_blocks_outstanding); - _dbus_assert (old_value >= 1); -#endif #endif free (memory); diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c index 086fc64..2a9adc1 100644 --- a/dbus/dbus-object-tree.c +++ b/dbus/dbus-object-tree.c @@ -1006,14 +1006,8 @@ _dbus_object_subtree_new (const char *name, static DBusObjectSubtree * _dbus_object_subtree_ref (DBusObjectSubtree *subtree) { -#ifdef DBUS_DISABLE_ASSERT + _dbus_assert (_dbus_atomic_get (&subtree->refcount) > 0); _dbus_atomic_inc (&subtree->refcount); -#else - dbus_int32_t old_value; - - old_value = _dbus_atomic_inc (&subtree->refcount); - _dbus_assert (old_value > 0); -#endif return subtree; } diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index efe7d1d..993b867 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -112,17 +112,10 @@ _dbus_server_init_base (DBusServer *server, const DBusServerVTable *vtable, const DBusString *address) { - server->vtable = vtable; + _dbus_assert (_dbus_atomic_get (&server->refcount) == 0); -#ifdef DBUS_DISABLE_ASSERT + server->vtable = vtable; _dbus_atomic_inc (&server->refcount); -#else - { - dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount); - - _dbus_assert (old_refcount == 0); - } -#endif server->address = NULL; server->watches = NULL; diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 18e87eb..81140a6 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -335,14 +335,11 @@ reallocate_for_length (DBusRealString *real, * disable asserts to profile, you don't get this destroyer * of profiles. */ -#ifdef DBUS_DISABLE_ASSERT -#else -#ifdef DBUS_ENABLE_EMBEDDED_TESTS +#if defined (DBUS_ENABLE_EMBEDDED_TESTS) && !defined (DBUS_DISABLE_ASSERT) new_allocated = 0; /* ensure a realloc every time so that we go * through all malloc failure codepaths */ -#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ -#endif /* !DBUS_DISABLE_ASSERT */ +#endif /* But be sure we always alloc at least space for the new length */ new_allocated = MAX (new_allocated, -- 1.7.9.5