dbus/dbus dbus-internals.c, 1.46, 1.47 dbus-internals.h, 1.57, 1.58 dbus-marshal-basic.c, 1.29, 1.30

John Palmieri johnp at kemper.freedesktop.org
Mon Sep 11 08:05:23 PDT 2006


Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv21824/dbus

Modified Files:
	dbus-internals.c dbus-internals.h dbus-marshal-basic.c 
Log Message:
* 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 


Index: dbus-internals.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-internals.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- dbus-internals.c	8 Aug 2006 20:22:14 -0000	1.46
+++ dbus-internals.c	11 Sep 2006 15:05:21 -0000	1.47
@@ -213,12 +213,31 @@
 #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 @@
                     ...)
 {
   va_list args;
-  static dbus_bool_t verbose = TRUE;
   static dbus_bool_t need_pid = TRUE;
   int len;
   
@@ -240,17 +258,8 @@
    * 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)

Index: dbus-internals.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-internals.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- dbus-internals.h	18 Aug 2006 15:46:59 -0000	1.57
+++ dbus-internals.h	11 Sep 2006 15:05:21 -0000	1.58
@@ -80,9 +80,11 @@
 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 @@
 #    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);

Index: dbus-marshal-basic.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-basic.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- dbus-marshal-basic.c	6 Sep 2006 00:14:06 -0000	1.29
+++ dbus-marshal-basic.c	11 Sep 2006 15:05:21 -0000	1.30
@@ -588,58 +588,6 @@
     *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 @@
 /**
  * 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_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 @@
 #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,



More information about the dbus-commit mailing list