* dbus/dbus-internal.c: Add dbus_is_verbose so we can have more

complex debugging code

* dbus/dbus-marshal-basic.c (_dbus_marshal_read_fixed_multi): Move
  between the test suite ifdefs
  (_dbus_verbose_bytes): return if verbosity is not enabled
This commit is contained in:
John (J5) Palmieri 2006-09-11 15:05:21 +00:00
parent eed8a8a7bd
commit 05d90f4f20
4 changed files with 84 additions and 66 deletions

View file

@ -1,3 +1,12 @@
2006-09-08 John (J5) Palmieri <johnp@redhat.com>
* dbus/dbus-internal.c: Add dbus_is_verbose so we can have more
complex debugging code
* dbus/dbus-marshal-basic.c (_dbus_marshal_read_fixed_multi): Move
between the test suite ifdefs
(_dbus_verbose_bytes): return if verbosity is not enabled
2006-09-08 John (J5) Palmieri <johnp@redhat.com>
* dbus/dbus-marshal-recursive-util.c, dbus/dbus-marshal-recursive.c:

View file

@ -213,12 +213,31 @@ _dbus_warn (const char *format,
#ifdef DBUS_ENABLE_VERBOSE_MODE
static dbus_bool_t verbose_initted = FALSE;
static dbus_bool_t verbose = TRUE;
#define PTHREAD_IN_VERBOSE 0
#if PTHREAD_IN_VERBOSE
#include <pthread.h>
#endif
static inline void
_dbus_verbose_init (void)
{
if (!verbose_initted)
{
const char *p = _dbus_getenv ("DBUS_VERBOSE");
verbose = p != NULL && *p == '1';
verbose_initted = TRUE;
}
}
dbus_bool_t
_dbus_is_verbose_real (void)
{
_dbus_verbose_init ();
return verbose;
}
/**
* Prints a warning message to stderr
* if the user has enabled verbose mode.
@ -232,7 +251,6 @@ _dbus_verbose_real (const char *format,
...)
{
va_list args;
static dbus_bool_t verbose = TRUE;
static dbus_bool_t need_pid = TRUE;
int len;
@ -240,17 +258,8 @@ _dbus_verbose_real (const char *format,
* in the non-verbose case we just have the one
* conditional and return immediately.
*/
if (!verbose)
if (!_dbus_is_verbose_real())
return;
if (!verbose_initted)
{
const char *p = _dbus_getenv ("DBUS_VERBOSE");
verbose = p != NULL && *p == '1';
verbose_initted = TRUE;
if (!verbose)
return;
}
/* Print out pid before the line */
if (need_pid)

View file

@ -80,9 +80,11 @@ void _dbus_warn (const char *format,
void _dbus_verbose_real (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
void _dbus_verbose_reset_real (void);
dbus_bool_t _dbus_is_verbose_real (void);
# define _dbus_verbose _dbus_verbose_real
# define _dbus_verbose_reset _dbus_verbose_reset_real
# define _dbus_is_verbose _dbus_is_verbose_real
#else
# ifdef HAVE_ISO_VARARGS
# define _dbus_verbose(...)
@ -92,6 +94,7 @@ void _dbus_verbose_reset_real (void);
# error "This compiler does not support varargs macros and thus verbose mode can't be disabled meaningfully"
# endif
# define _dbus_verbose_reset()
# define _dbus_is_verbose() FALSE
#endif /* !DBUS_ENABLE_VERBOSE_MODE */
const char* _dbus_strerror (int error_number);

View file

@ -588,58 +588,6 @@ _dbus_marshal_read_basic (const DBusString *str,
*new_pos = pos;
}
/**
* Reads a block of fixed-length basic values, as an optimization
* vs. reading each one individually into a new buffer.
*
* This function returns the data in-place; it does not make a copy,
* and it does not swap the bytes.
*
* If you ask for #DBUS_TYPE_DOUBLE you will get a "const double*" back
* and the "value" argument should be a "const double**" and so on.
*
* @todo 1.0 we aren't using this function (except in the test suite)
* add #ifdefs around it
*
* @param str the string to read from
* @param pos position to read from
* @param element_type type of array elements
* @param value place to return the array
* @param n_elements number of array elements to read
* @param byte_order the byte order, used to read the array length
* @param new_pos #NULL or location to store a position after the elements
*/
void
_dbus_marshal_read_fixed_multi (const DBusString *str,
int pos,
int element_type,
void *value,
int n_elements,
int byte_order,
int *new_pos)
{
int array_len;
int alignment;
_dbus_assert (dbus_type_is_fixed (element_type));
_dbus_assert (dbus_type_is_basic (element_type));
#if 0
_dbus_verbose ("reading %d elements of %s\n",
n_elements, _dbus_type_to_string (element_type));
#endif
alignment = _dbus_type_get_alignment (element_type);
pos = _DBUS_ALIGN_VALUE (pos, alignment);
array_len = n_elements * alignment;
*(const DBusBasicValue**) value = (void*) _dbus_string_get_const_data_len (str, pos, array_len);
if (new_pos)
*new_pos = pos + array_len;
}
static dbus_bool_t
marshal_2_octets (DBusString *str,
int insert_at,
@ -1360,9 +1308,6 @@ _dbus_type_to_string (int typecode)
/**
* If in verbose mode, print a block of binary data.
*
* @todo 1.0 right now it prints even if not in verbose mode
* check for verbose mode and return if not
*
* @param data the data
* @param len the length of the data
* @param offset where to start counting for byte indexes
@ -1377,6 +1322,9 @@ _dbus_verbose_bytes (const unsigned char *data,
_dbus_assert (len >= 0);
if (!_dbus_is_verbose())
return;
/* Print blanks on first row if appropriate */
aligned = _DBUS_ALIGN_ADDRESS (data, 4);
if (aligned > data)
@ -1534,6 +1482,55 @@ _dbus_first_type_in_signature_c_str (const char *str,
#include "dbus-test.h"
#include <stdio.h>
/**
* Reads a block of fixed-length basic values, as an optimization
* vs. reading each one individually into a new buffer.
*
* This function returns the data in-place; it does not make a copy,
* and it does not swap the bytes.
*
* If you ask for #DBUS_TYPE_DOUBLE you will get a "const double*" back
* and the "value" argument should be a "const double**" and so on.
*
* @param str the string to read from
* @param pos position to read from
* @param element_type type of array elements
* @param value place to return the array
* @param n_elements number of array elements to read
* @param byte_order the byte order, used to read the array length
* @param new_pos #NULL or location to store a position after the elements
*/
void
_dbus_marshal_read_fixed_multi (const DBusString *str,
int pos,
int element_type,
void *value,
int n_elements,
int byte_order,
int *new_pos)
{
int array_len;
int alignment;
_dbus_assert (dbus_type_is_fixed (element_type));
_dbus_assert (dbus_type_is_basic (element_type));
#if 0
_dbus_verbose ("reading %d elements of %s\n",
n_elements, _dbus_type_to_string (element_type));
#endif
alignment = _dbus_type_get_alignment (element_type);
pos = _DBUS_ALIGN_VALUE (pos, alignment);
array_len = n_elements * alignment;
*(const DBusBasicValue**) value = (void*) _dbus_string_get_const_data_len (str, pos, array_len);
if (new_pos)
*new_pos = pos + array_len;
}
static void
swap_test_array (void *array,
int len_bytes,