dbus/dbus dbus-connection.c, 1.85, 1.86 dbus-message.c, 1.144, 1.145 dbus-string.c, 1.54, 1.55 dbus-string.h, 1.30, 1.31

Havoc Pennington hp at freedesktop.org
Fri Nov 26 23:30:24 PST 2004


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

Modified Files:
	dbus-connection.c dbus-message.c dbus-string.c dbus-string.h 
Log Message:
2004-11-27  Havoc Pennington  <hp at redhat.com>

	* dbus/dbus-string.h (_dbus_string_get_byte): inline when asserts
	are disabled
	(_dbus_string_get_const_data): inline when asserts are disabled

	* dbus/dbus-message.c: record the _dbus_current_generation of
	creation so we can complain if dbus_shutdown() is used improperly.
	Do this only if checks are enabled.

	* dbus/dbus-connection.c: ditto
	


Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- dbus-connection.c	26 Nov 2004 01:53:13 -0000	1.85
+++ dbus-connection.c	27 Nov 2004 07:30:22 -0000	1.86
@@ -218,6 +218,10 @@
   DBusObjectTree *objects; /**< Object path handlers registered with this connection */
 
   unsigned int exit_on_disconnect : 1; /**< If #TRUE, exit after handling disconnect signal */
+
+#ifndef DBUS_DISABLE_CHECKS
+  int generation; /**< _dbus_current_generation that should correspond to this connection */
+#endif 
 };
 
 static void               _dbus_connection_remove_timeout_locked             (DBusConnection     *connection,
@@ -945,6 +949,9 @@
   connection->last_dispatch_status = DBUS_DISPATCH_COMPLETE; /* so we're notified first time there's data */
   connection->objects = objects;
   connection->exit_on_disconnect = FALSE;
+#ifndef DBUS_DISABLE_CHECKS
+  connection->generation = _dbus_current_generation;
+#endif
   
   _dbus_data_slot_list_init (&connection->slot_list);
 
@@ -1009,6 +1016,9 @@
 DBusConnection *
 _dbus_connection_ref_unlocked (DBusConnection *connection)
 {
+  _dbus_return_val_if_fail (connection != NULL, NULL);
+  _dbus_return_val_if_fail (connection->generation == _dbus_current_generation, NULL);
+  
 #ifdef DBUS_HAVE_ATOMIC_INT
   _dbus_atomic_inc (&connection->refcount);
 #else
@@ -1167,7 +1177,8 @@
 dbus_connection_ref (DBusConnection *connection)
 {
   _dbus_return_val_if_fail (connection != NULL, NULL);
-
+  _dbus_return_val_if_fail (connection->generation == _dbus_current_generation, NULL);
+  
   /* The connection lock is better than the global
    * lock in the atomic increment fallback
    */
@@ -1303,7 +1314,8 @@
   dbus_bool_t last_unref;
 
   _dbus_return_if_fail (connection != NULL);
-
+  _dbus_return_if_fail (connection->generation == _dbus_current_generation);
+  
   /* The connection lock is better than the global
    * lock in the atomic increment fallback
    */
@@ -1348,6 +1360,7 @@
   DBusDispatchStatus status;
   
   _dbus_return_if_fail (connection != NULL);
+  _dbus_return_if_fail (connection->generation == _dbus_current_generation);
 
   _dbus_verbose ("Disconnecting %p\n", connection);
   

Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -d -r1.144 -r1.145
--- dbus-message.c	26 Nov 2004 07:03:05 -0000	1.144
+++ dbus-message.c	27 Nov 2004 07:30:22 -0000	1.145
@@ -104,6 +104,10 @@
   dbus_uint32_t changed_stamp; /**< Incremented when iterators are invalidated. */
 
   DBusDataSlotList slot_list;   /**< Data stored by allocated integer ID */
+
+#ifndef DBUS_DISABLE_CHECKS
+  int generation; /**< _dbus_current_generation when message was created */
+#endif
 };
 
 enum {
@@ -248,6 +252,9 @@
   int offset;
   const char *data;
 
+  _dbus_return_val_if_fail (message->generation == _dbus_current_generation,
+                            NULL);
+  
   offset = message->header_fields[field].value_offset;
 
   _dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
@@ -1607,6 +1614,9 @@
       message = dbus_new (DBusMessage, 1);
       if (message == NULL)
         return NULL;
+#ifndef DBUS_DISABLE_CHECKS
+      message->generation = _dbus_current_generation;
+#endif
     }
 
   message->refcount.value = 1;
@@ -1947,6 +1957,9 @@
   retval->reply_serial = message->reply_serial;
   retval->header_padding = message->header_padding;
   retval->locked = FALSE;
+#ifndef DBUS_DISABLE_CHECKS
+  retval->generation = message->generation;
+#endif
   
   if (!_dbus_string_init_preallocated (&retval->header,
                                        _dbus_string_get_length (&message->header)))
@@ -2000,6 +2013,7 @@
   dbus_int32_t old_refcount;
 
   _dbus_return_val_if_fail (message != NULL, NULL);
+  _dbus_return_val_if_fail (message->generation == _dbus_current_generation, NULL);
   
   old_refcount = _dbus_atomic_inc (&message->refcount);
   _dbus_assert (old_refcount >= 1);
@@ -2019,6 +2033,7 @@
  dbus_int32_t old_refcount;
 
   _dbus_return_if_fail (message != NULL);
+  _dbus_return_if_fail (message->generation == _dbus_current_generation);
   
   old_refcount = _dbus_atomic_dec (&message->refcount);
   

Index: dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- dbus-string.c	26 Nov 2004 01:53:13 -0000	1.54
+++ dbus-string.c	27 Nov 2004 07:30:22 -0000	1.55
@@ -471,6 +471,8 @@
   return real->str;
 }
 
+/* only do the function if we don't have the macro */
+#ifndef _dbus_string_get_const_data
 /**
  * Gets the raw character buffer from a const string.
  *
@@ -484,6 +486,7 @@
   
   return real->str;
 }
+#endif /* _dbus_string_get_const_data */
 
 /**
  * Gets a sub-portion of the raw character buffer from the
@@ -553,6 +556,8 @@
   real->str[i] = byte;
 }
 
+/* only have the function if we didn't create a macro */
+#ifndef _dbus_string_get_byte
 /**
  * Gets the byte at the given position. It is
  * allowed to ask for the nul byte at the end of
@@ -572,6 +577,7 @@
   
   return real->str[start];
 }
+#endif /* _dbus_string_get_byte */
 
 /**
  * Inserts a number of bytes of a given value at the

Index: dbus-string.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- dbus-string.h	26 Nov 2004 01:53:13 -0000	1.30
+++ dbus-string.h	27 Nov 2004 07:30:22 -0000	1.31
@@ -49,11 +49,14 @@
   unsigned int dummy8 : 3; /**< placeholder */
 };
 
-/* Unless we want to run all the assertions in the function,
- * inline this thing, it shows up high in the profile
- */
 #ifdef DBUS_DISABLE_ASSERT
-#define _dbus_string_get_length(s) ((s)->dummy2)
+/* Some simple inlining hacks; the current linker is not smart enough
+ * to inline non-exported symbols across files in the library.
+ * Note that these break type safety (due to the casts)
+ */
+#define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2)
+#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))
 #endif
 
 dbus_bool_t   _dbus_string_init                  (DBusString        *str);
@@ -67,7 +70,9 @@
 void          _dbus_string_free                  (DBusString        *str);
 void          _dbus_string_lock                  (DBusString        *str);
 char*         _dbus_string_get_data              (DBusString        *str);
+#ifndef _dbus_string_get_const_data
 const char*   _dbus_string_get_const_data        (const DBusString  *str);
+#endif /* _dbus_string_get_const_data */
 char*         _dbus_string_get_data_len          (DBusString        *str,
                                                   int                start,
                                                   int                len);
@@ -77,8 +82,10 @@
 void          _dbus_string_set_byte              (DBusString        *str,
                                                   int                i,
                                                   unsigned char      byte);
+#ifndef _dbus_string_get_byte
 unsigned char _dbus_string_get_byte              (const DBusString  *str,
                                                   int                start);
+#endif /* _dbus_string_get_byte */
 dbus_bool_t   _dbus_string_insert_bytes          (DBusString        *str,
                                                   int                i,
 						  int                n_bytes,



More information about the dbus-commit mailing list