dbus/dbus dbus-marshal-basic.c, 1.14, 1.15 dbus-marshal-basic.h, 1.12, 1.13 dbus-marshal-header.c, 1.1, 1.2 dbus-marshal-recursive.c, 1.39, 1.40 dbus-string.c, 1.61, 1.62 dbus-string.h, 1.35, 1.36

Havoc Pennington hp@freedesktop.org
Sat Jan 15 18:23:58 PST 2005


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv27412/dbus

Modified Files:
	dbus-marshal-basic.c dbus-marshal-basic.h 
	dbus-marshal-header.c dbus-marshal-recursive.c dbus-string.c 
	dbus-string.h 
Log Message:
2005-01-15  Havoc Pennington  <hp@redhat.com>

	* test/glib/test-profile.c (with_bus_server_filter): fix crash

	* dbus/dbus-marshal-basic.c (_dbus_unpack_uint32): inline as macro
	when DBUS_DISABLE_ASSERT
	(_dbus_marshal_set_basic): be sure we align for the string length

	* dbus/dbus-marshal-recursive.c (skip_one_complete_type): make
	this look faster

	* dbus/dbus-string.c (_dbus_string_get_const_data_len): add an
	inline macro version
	(_dbus_string_set_byte): provide inline macro version



Index: dbus-marshal-basic.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-basic.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- dbus-marshal-basic.c	15 Jan 2005 07:15:38 -0000	1.14
+++ dbus-marshal-basic.c	16 Jan 2005 02:23:56 -0000	1.15
@@ -103,18 +103,6 @@
   pack_4_octets ((dbus_uint32_t) value, byte_order, data);
 }
 
-static dbus_uint32_t
-unpack_4_octets (int                  byte_order,
-                 const unsigned char *data)
-{
-  _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
-
-  if (byte_order == DBUS_LITTLE_ENDIAN)
-    return DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)data);
-  else
-    return DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)data);
-}
-
 #ifndef DBUS_HAVE_INT64
 /* from ORBit */
 static void
@@ -174,6 +162,7 @@
 }
 #endif
 
+#ifndef _dbus_unpack_uint32
 /**
  * Unpacks a 32 bit unsigned integer from a data pointer
  *
@@ -185,8 +174,14 @@
 _dbus_unpack_uint32 (int                  byte_order,
                      const unsigned char *data)
 {
-  return unpack_4_octets (byte_order, data);
+  _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
+
+  if (byte_order == DBUS_LITTLE_ENDIAN)
+    return DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)data);
+  else
+    return DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)data);
 }
+#endif /* _dbus_unpack_uint32 */
 
 /**
  * Unpacks a 32 bit signed integer from a data pointer
@@ -199,7 +194,7 @@
 _dbus_unpack_int32 (int                  byte_order,
                     const unsigned char *data)
 {
-  return (dbus_int32_t) unpack_4_octets (byte_order, data);
+  return (dbus_int32_t) _dbus_unpack_uint32 (byte_order, data);
 }
 
 static void
@@ -285,7 +280,9 @@
 
   _dbus_string_init_const (&dstr, value);
 
-  old_len = _dbus_marshal_read_uint32 (str, pos, byte_order, NULL);
+  _dbus_assert (_DBUS_ALIGN_VALUE (pos, 4) == pos);
+  old_len = _dbus_unpack_uint32 (byte_order,
+                                 _dbus_string_get_const_data_len (str, pos, 4));
 
   new_len = _dbus_string_get_length (&dstr);
 
@@ -406,6 +403,7 @@
       break;
     case DBUS_TYPE_STRING:
     case DBUS_TYPE_OBJECT_PATH:
+      pos = _DBUS_ALIGN_VALUE (pos, 4);
       _dbus_assert (vp->str != NULL);
       return set_string (str, pos, vp->str, byte_order,
                          old_end_pos, new_end_pos);
@@ -422,23 +420,6 @@
     }
 }
 
-static dbus_uint32_t
-read_4_octets (const DBusString *str,
-               int               pos,
-               int               byte_order,
-               int              *new_pos)
-{
-  pos = _DBUS_ALIGN_VALUE (pos, 4);
-
-  if (new_pos)
-    *new_pos = pos + 4;
-
-  _dbus_assert (pos + 4 <= _dbus_string_get_length (str));
-  
-  return unpack_4_octets (byte_order,
-                          _dbus_string_get_const_data (str) + pos);
-}
-
 /**
  * Convenience function to demarshal a 32 bit unsigned integer.
  *
@@ -454,7 +435,15 @@
                             int               byte_order,
                             int              *new_pos)
 {
-  return read_4_octets (str, pos, byte_order, new_pos);
+  pos = _DBUS_ALIGN_VALUE (pos, 4);
+
+  if (new_pos)
+    *new_pos = pos + 4;
+
+  _dbus_assert (pos + 4 <= _dbus_string_get_length (str));
+  
+  return _dbus_unpack_uint32 (byte_order,
+                              _dbus_string_get_const_data (str) + pos);
 }
 
 /**

Index: dbus-marshal-basic.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-basic.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- dbus-marshal-basic.h	15 Jan 2005 07:15:38 -0000	1.12
+++ dbus-marshal-basic.h	16 Jan 2005 02:23:56 -0000	1.13
@@ -136,6 +136,13 @@
   char *str;
 } DBusBasicValue;
 
+#ifdef DBUS_DISABLE_ASSERT
+#define _dbus_unpack_uint32(byte_order, data)           \
+   (((byte_order) == DBUS_LITTLE_ENDIAN) ?              \
+     DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)(data)) :    \
+     DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(data)))
+#endif
+
 void          _dbus_pack_int32    (dbus_int32_t         value,
                                    int                  byte_order,
                                    unsigned char       *data);
@@ -144,9 +151,10 @@
 void          _dbus_pack_uint32   (dbus_uint32_t        value,
                                    int                  byte_order,
                                    unsigned char       *data);
+#ifndef _dbus_unpack_uint32
 dbus_uint32_t _dbus_unpack_uint32 (int                  byte_order,
                                    const unsigned char *data);
-
+#endif
 
 dbus_bool_t   _dbus_marshal_set_basic         (DBusString       *str,
                                                int               pos,

Index: dbus-marshal-header.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-header.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-marshal-header.c	15 Jan 2005 07:15:38 -0000	1.1
+++ dbus-marshal-header.c	16 Jan 2005 02:23:56 -0000	1.2
@@ -328,14 +328,16 @@
 {
   DBusTypeReader sub;
   DBusTypeReader variant;
-  unsigned char v_BYTE;
 
   _dbus_type_reader_recurse (reader, &sub);
 
   _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE);
 #ifndef DBUS_DISABLE_ASSERT
-  _dbus_type_reader_read_basic (&sub, &v_BYTE);
-  _dbus_assert (((int) v_BYTE) == field);
+ {
+   unsigned char v_BYTE;
+   _dbus_type_reader_read_basic (&sub, &v_BYTE);
+   _dbus_assert (((int) v_BYTE) == field);
+ }
 #endif
 
   if (!_dbus_type_reader_next (&sub))

Index: dbus-marshal-recursive.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- dbus-marshal-recursive.c	15 Jan 2005 07:15:38 -0000	1.39
+++ dbus-marshal-recursive.c	16 Jan 2005 02:23:56 -0000	1.40
@@ -119,7 +119,7 @@
 first_type_in_signature (const DBusString *str,
                          int               pos)
 {
-  int t;
+  unsigned char t;
 
   t = _dbus_string_get_byte (str, pos);
 
@@ -213,13 +213,10 @@
 
   len_pos = ARRAY_READER_LEN_POS (reader);
 
-  _dbus_marshal_read_basic (reader->value_str,
-                            len_pos,
-                            DBUS_TYPE_UINT32,
-                            &array_len,
-                            reader->byte_order,
-                            NULL);
-
+  _dbus_assert (_DBUS_ALIGN_VALUE (len_pos, 4) == (unsigned) len_pos);
+  array_len = _dbus_unpack_uint32 (reader->byte_order,
+                                   _dbus_string_get_const_data_len (reader->value_str, len_pos, 4));
+  
 #if RECURSIVE_MARSHAL_READ_TRACE
   _dbus_verbose ("   reader %p len_pos %d array len %u len_offset %d\n",
                  reader, len_pos, array_len, reader->array_len_offset);
@@ -311,37 +308,55 @@
   return reader->value_pos == end_pos;
 }
 
+/* this is written a little oddly to try and overoptimize */
 static void
 skip_one_complete_type (const DBusString *type_str,
                         int              *type_pos)
 {
-  while (_dbus_string_get_byte (type_str, *type_pos) == DBUS_TYPE_ARRAY)
-    *type_pos += 1;
+  const unsigned char *p;
+  const unsigned char *start;
+  
+  start = _dbus_string_get_const_data (type_str);
+  p = start + *type_pos;
 
-  if (_dbus_string_get_byte (type_str, *type_pos) == DBUS_STRUCT_BEGIN_CHAR)
+  while (*p == DBUS_TYPE_ARRAY)
+    ++p;
+  
+  if (*p == DBUS_STRUCT_BEGIN_CHAR)
     {
       int depth;
+      
       depth = 1;
-      *type_pos += 1;
-      while (depth > 0)
+      
+      while (TRUE)
         {
-          switch (_dbus_string_get_byte (type_str, *type_pos))
+          _dbus_assert (*p != DBUS_TYPE_INVALID);
+          
+          ++p;
+
+          _dbus_assert (*p != DBUS_TYPE_INVALID);
+          
+          if (*p == DBUS_STRUCT_BEGIN_CHAR)
+            depth += 1;
+          else if (*p == DBUS_STRUCT_END_CHAR)
             {
-            case DBUS_STRUCT_BEGIN_CHAR:
-              depth += 1;
-              break;
-            case DBUS_STRUCT_END_CHAR:
               depth -= 1;
-              break;
-            case DBUS_TYPE_INVALID:
-              _dbus_assert_not_reached ("unbalanced parens in signature");
-              break;
+              if (depth == 0)
+                {
+                  ++p;
+                  break;
+                }
             }
-          *type_pos += 1;
         }
     }
   else
-    *type_pos += 1;
+    {
+      ++p;
+    }
+
+  _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
+
+  *type_pos = (int) (p - start);
 }
 
 static int
@@ -1831,10 +1846,13 @@
         {
           dbus_uint32_t len;
 
-          len = _dbus_marshal_read_uint32 (sub->value_str,
-                                           sub->u.array.len_pos,
-                                           sub->byte_order, NULL);
-
+          _dbus_assert (_DBUS_ALIGN_VALUE (sub->u.array.len_pos, 4) ==
+                        (unsigned) sub->u.array.len_pos);
+          len = _dbus_unpack_uint32 (sub->byte_order,
+                                     _dbus_string_get_const_data_len (sub->value_str,
+                                                                      sub->u.array.len_pos,
+                                                                      4));
+          
           sub->value_pos += len;
         }
     }
@@ -2432,9 +2450,12 @@
                 start_after_new_len +
                 bytes_written_after_start_after;
 
-              old_len = _dbus_marshal_read_uint32 (reader->value_str,
-                                                   fixup.len_pos_in_reader,
-                                                   reader->byte_order, NULL);
+              _dbus_assert (_DBUS_ALIGN_VALUE (fixup.len_pos_in_reader, 4) ==
+                            (unsigned) fixup.len_pos_in_reader);
+              
+              old_len = _dbus_unpack_uint32 (reader->byte_order,
+                                             _dbus_string_get_const_data_len (reader->value_str,
+                                                                              fixup.len_pos_in_reader, 4));
 
               if (old_len != fixup.new_len && !append_fixup (fixups, &fixup))
                 goto oom;

Index: dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- dbus-string.c	15 Jan 2005 07:15:38 -0000	1.61
+++ dbus-string.c	16 Jan 2005 02:23:56 -0000	1.62
@@ -1,7 +1,7 @@
 /* -*- mode: C; c-file-style: "gnu" -*- */
 /* dbus-string.c String utility class (internal to D-BUS implementation)
  * 
- * Copyright (C) 2002, 2003, 2004 Red Hat, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
  *
  * Licensed under the Academic Free License version 2.1
  * 
@@ -517,6 +517,8 @@
   return real->str + start;
 }
 
+/* only do the function if we don't have the macro */
+#ifndef _dbus_string_get_const_data_len
 /**
  * const version of _dbus_string_get_data_len().
  *
@@ -538,7 +540,10 @@
   
   return real->str + start;
 }
+#endif /* _dbus_string_get_const_data_len */
 
+/* only do the function if we don't have the macro */
+#ifndef _dbus_string_set_byte
 /**
  * Sets the value of the byte at the given position.
  *
@@ -557,6 +562,7 @@
   
   real->str[i] = byte;
 }
+#endif /* _dbus_string_set_byte */
 
 /* only have the function if we didn't create a macro */
 #ifndef _dbus_string_get_byte

Index: dbus-string.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- dbus-string.h	15 Jan 2005 07:15:38 -0000	1.35
+++ dbus-string.h	16 Jan 2005 02:23:56 -0000	1.36
@@ -55,8 +55,10 @@
  * Note that these break type safety (due to the casts)
  */
 #define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2)
+#define _dbus_string_set_byte(s, i, b) ((((unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) = (unsigned char) (b))
 #define _dbus_string_get_byte(s, i) (((const unsigned char*)(((DBusString*)(s))->dummy1))[(i)])
 #define _dbus_string_get_const_data(s) ((const char*)(((DBusString*)(s))->dummy1))
+#define _dbus_string_get_const_data_len(s,start,len) (((const char*)(((DBusString*)(s))->dummy1)) + (start))
 #endif
 
 dbus_bool_t   _dbus_string_init                  (DBusString        *str);
@@ -76,12 +78,16 @@
 char*         _dbus_string_get_data_len          (DBusString        *str,
                                                   int                start,
                                                   int                len);
+#ifndef _dbus_string_get_const_data_len
 const char*   _dbus_string_get_const_data_len    (const DBusString  *str,
                                                   int                start,
                                                   int                len);
+#endif
+#ifndef _dbus_string_set_byte
 void          _dbus_string_set_byte              (DBusString        *str,
                                                   int                i,
                                                   unsigned char      byte);
+#endif
 #ifndef _dbus_string_get_byte
 unsigned char _dbus_string_get_byte              (const DBusString  *str,
                                                   int                start);



More information about the dbus-commit mailing list