X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-internals.c;h=63559be9a3d187f1fae51aceda0df6e87dd45056;hb=757b80b9711d9733798c927495d74c7323e95400;hp=fcea07900743548808eb4e717cb6d4daeb241541;hpb=c99a3df254dbfcd945de919054c391c5565460af;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index fcea079..63559be 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -26,6 +26,7 @@ #include "dbus-protocol.h" #include "dbus-marshal-basic.h" #include "dbus-test.h" +#include "dbus-valgrind-internal.h" #include #include #include @@ -162,26 +163,11 @@ */ /** - * @def _DBUS_DEFINE_GLOBAL_LOCK - * - * Defines a global lock variable with the given name. - * The lock must be added to the list to initialize - * in dbus_threads_init(). - */ - -/** - * @def _DBUS_DECLARE_GLOBAL_LOCK - * - * Expands to declaration of a global lock defined - * with _DBUS_DEFINE_GLOBAL_LOCK. - * The lock must be added to the list to initialize - * in dbus_threads_init(). - */ - -/** * @def _DBUS_LOCK * - * Locks a global lock + * Locks a global lock, initializing it first if necessary. + * + * @returns #FALSE if not enough memory */ /** @@ -389,14 +375,13 @@ _dbus_is_verbose_real (void) * @param format printf-style format string. */ void +_dbus_verbose_real ( #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS -_dbus_verbose_real (const char *file, + const char *file, const int line, const char *function, - const char *format, -#else -_dbus_verbose_real (const char *format, #endif + const char *format, ...) { va_list args; @@ -465,6 +450,72 @@ _dbus_verbose_reset_real (void) verbose_initted = FALSE; } +void +_dbus_trace_ref (const char *obj_name, + void *obj, + int old_refcount, + int new_refcount, + const char *why, + const char *env_var, + int *enabled) +{ + _dbus_assert (obj_name != NULL); + _dbus_assert (obj != NULL); + _dbus_assert (old_refcount >= -1); + _dbus_assert (new_refcount >= -1); + + if (old_refcount == -1) + { + _dbus_assert (new_refcount == -1); + } + else + { + _dbus_assert (new_refcount >= 0); + _dbus_assert (old_refcount >= 0); + _dbus_assert (old_refcount > 0 || new_refcount > 0); + } + + _dbus_assert (why != NULL); + _dbus_assert (env_var != NULL); + _dbus_assert (enabled != NULL); + + if (*enabled < 0) + { + const char *s = _dbus_getenv (env_var); + + *enabled = FALSE; + + if (s && *s) + { + if (*s == '0') + *enabled = FALSE; + else if (*s == '1') + *enabled = TRUE; + else + _dbus_warn ("%s should be 0 or 1 if set, not '%s'", env_var, s); + } + } + + if (*enabled) + { + if (old_refcount == -1) + { + VALGRIND_PRINTF_BACKTRACE ("%s %p ref stolen (%s)", + obj_name, obj, why); + _dbus_verbose ("%s %p ref stolen (%s)", + obj_name, obj, why); + } + else + { + VALGRIND_PRINTF_BACKTRACE ("%s %p %d -> %d refs (%s)", + obj_name, obj, + old_refcount, new_refcount, why); + _dbus_verbose ("%s %p %d -> %d refs (%s)", + obj_name, obj, old_refcount, new_refcount, why); + } + } +} + #endif /* DBUS_ENABLE_VERBOSE_MODE */ /** @@ -594,7 +645,10 @@ _dbus_generate_uuid (DBusGUID *uuid) { long now; - _dbus_get_current_time (&now, NULL); + /* don't use monotonic time because the UUID may be saved to disk, e.g. + * it may persist across reboots + */ + _dbus_get_real_time (&now, NULL); uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now); @@ -778,7 +832,7 @@ _dbus_read_uuid_file (const DBusString *filename, } } -_DBUS_DEFINE_GLOBAL_LOCK (machine_uuid); +/* Protected by _DBUS_LOCK (machine_uuid) */ static int machine_uuid_initialized_generation = 0; static DBusGUID machine_uuid; @@ -797,7 +851,9 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str) { dbus_bool_t ok; - _DBUS_LOCK (machine_uuid); + if (!_DBUS_LOCK (machine_uuid)) + return FALSE; + if (machine_uuid_initialized_generation != _dbus_current_generation) { DBusError error = DBUS_ERROR_INIT; @@ -828,42 +884,6 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str) return ok; } -#ifdef DBUS_BUILD_TESTS -/** - * Returns a string describing the given name. - * - * @param header_field the field to describe - * @returns a constant string describing the field - */ -const char * -_dbus_header_field_to_string (int header_field) -{ - switch (header_field) - { - case DBUS_HEADER_FIELD_INVALID: - return "invalid"; - case DBUS_HEADER_FIELD_PATH: - return "path"; - case DBUS_HEADER_FIELD_INTERFACE: - return "interface"; - case DBUS_HEADER_FIELD_MEMBER: - return "member"; - case DBUS_HEADER_FIELD_ERROR_NAME: - return "error-name"; - case DBUS_HEADER_FIELD_REPLY_SERIAL: - return "reply-serial"; - case DBUS_HEADER_FIELD_DESTINATION: - return "destination"; - case DBUS_HEADER_FIELD_SENDER: - return "sender"; - case DBUS_HEADER_FIELD_SIGNATURE: - return "signature"; - default: - return "unknown"; - } -} -#endif /* DBUS_BUILD_TESTS */ - #ifndef DBUS_DISABLE_CHECKS /** String used in _dbus_return_if_fail macro */ const char *_dbus_return_if_fail_warning_format =