+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
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,
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);
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
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
*/
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
*/
DBusDispatchStatus status;
_dbus_return_if_fail (connection != NULL);
+ _dbus_return_if_fail (connection->generation == _dbus_current_generation);
_dbus_verbose ("Disconnecting %p\n", connection);
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 {
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);
message = dbus_new (DBusMessage, 1);
if (message == NULL)
return NULL;
+#ifndef DBUS_DISABLE_CHECKS
+ message->generation = _dbus_current_generation;
+#endif
}
message->refcount.value = 1;
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)))
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);
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);
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.
*
return real->str;
}
+#endif /* _dbus_string_get_const_data */
/**
* Gets a sub-portion of the raw character buffer from the
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
return real->str[start];
}
+#endif /* _dbus_string_get_byte */
/**
* Inserts a number of bytes of a given value at the
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);
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);
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,
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;
}