]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2004-11-27 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Sat, 27 Nov 2004 07:30:22 +0000 (07:30 +0000)
committerHavoc Pennington <hp@redhat.com>
Sat, 27 Nov 2004 07:30:22 +0000 (07:30 +0000)
* 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

ChangeLog
dbus/dbus-connection.c
dbus/dbus-message.c
dbus/dbus-string.c
dbus/dbus-string.h
test/glib/test-profile.c

index 89a258a602a0e5de31a54c5ef88145e5fdad26da..621b3bfd3cb645b4fb216c3d170f376a5959e946 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2004-11-27  Havoc Pennington  <hp@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
+       
 2004-11-26  Havoc Pennington  <hp@redhat.com>
 
        * test/glib/test-profile.c: add with_bus mode to profile echoes
index 2f8b4c6fec0665831857f7ed4498f5e053abb6fa..e8c6a52be7a65e2287db58d8bceaad3b8166ac61 100644 (file)
@@ -218,6 +218,10 @@ struct DBusConnection
   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 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
   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 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
 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 @@ DBusConnection *
 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_connection_unref (DBusConnection *connection)
   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 @@ dbus_connection_disconnect (DBusConnection *connection)
   DBusDispatchStatus status;
   
   _dbus_return_if_fail (connection != NULL);
+  _dbus_return_if_fail (connection->generation == _dbus_current_generation);
 
   _dbus_verbose ("Disconnecting %p\n", connection);
   
index a76d3b55609bc3aed3d2309aa3ce477fb62b6701..df1c789a75af88d09d765b3f691925ca36c26710 100644 (file)
@@ -104,6 +104,10 @@ struct DBusMessage
   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 @@ get_string_field (DBusMessage *message,
   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 @@ dbus_message_new_empty_header (void)
       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 @@ dbus_message_copy (const DBusMessage *message)
   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_message_ref (DBusMessage *message)
   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_message_unref (DBusMessage *message)
  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 87969912cb0fc9d618d872fd390da9618ae3cadb..627fbb064469ca34c6e0fee44ae3e74a7a01ac48 100644 (file)
@@ -471,6 +471,8 @@ _dbus_string_get_data (DBusString *str)
   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 @@ _dbus_string_get_const_data (const DBusString  *str)
   
   return real->str;
 }
+#endif /* _dbus_string_get_const_data */
 
 /**
  * Gets a sub-portion of the raw character buffer from the
@@ -553,6 +556,8 @@ _dbus_string_set_byte (DBusString    *str,
   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 @@ _dbus_string_get_byte (const DBusString  *str,
   
   return real->str[start];
 }
+#endif /* _dbus_string_get_byte */
 
 /**
  * Inserts a number of bytes of a given value at the
index 51f41a4c948f36e5587237ec132a822a4390031c..c30a63fe4bf4a3697ca669d8f18b97e1d5e22c7f 100644 (file)
@@ -49,11 +49,14 @@ struct DBusString
   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 @@ dbus_bool_t   _dbus_string_init_preallocated     (DBusString        *str,
 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 @@ const char*   _dbus_string_get_const_data_len    (const DBusString  *str,
 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,
index 375a8408c1cbd0b5e5d689cca5d9ac2de8ebf9ae..8e636d0a43c893236a0ec2b27425837166f52bcf 100644 (file)
@@ -1148,6 +1148,9 @@ main (int argc, char *argv[])
       g_printerr ("Specify profile type plain_sockets, plain_sockets_with_malloc, no_bus, with_bus, all\n");
       exit (1);
     }
+
+  /* Make valgrind happy */
+  dbus_shutdown ();
   
   return 0;
 }