summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--dbus/dbus-connection.c17
-rw-r--r--dbus/dbus-message.c15
-rw-r--r--dbus/dbus-string.c6
-rw-r--r--dbus/dbus-string.h15
-rw-r--r--test/glib/test-profile.c3
6 files changed, 62 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 89a258a6..621b3bfd 100644
--- 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
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 2f8b4c6f..e8c6a52b 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -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);
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index a76d3b55..df1c789a 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -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);
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 87969912..627fbb06 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -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
diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h
index 51f41a4c..c30a63fe 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -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,
diff --git a/test/glib/test-profile.c b/test/glib/test-profile.c
index 375a8408..8e636d0a 100644
--- a/test/glib/test-profile.c
+++ b/test/glib/test-profile.c
@@ -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;
}