+2005-01-17 Havoc Pennington <hp@redhat.com>
+
+ * dbus/dbus-types.h: hardcode dbus_bool_t to 32 bits
+
+ * Throughout: modify DBUS_TYPE_BOOLEAN to be a 32-bit type instead
+ of an 8-bit type. Now dbus_bool_t is the type to use whenever you
+ are marshaling/unmarshaling a boolean.
+
2005-01-16 Havoc Pennington <hp@redhat.com>
This is about it on what can be disabled/deleted from libdbus
DBusMessage *reply;
DBusString service_name;
BusService *service;
- unsigned char service_exists;
+ dbus_bool_t service_exists;
const char *name;
dbus_bool_t retval;
BusRegistry *registry;
switch (type)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
_dbus_string_set_byte (str, pos, vp->byt);
if (old_end_pos)
*old_end_pos = pos + 1;
*new_end_pos = pos + 1;
return TRUE;
break;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
pos = _DBUS_ALIGN_VALUE (pos, 4);
switch (type)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
vp->byt = _dbus_string_get_byte (str, pos);
(pos)++;
break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
+ case DBUS_TYPE_BOOLEAN:
pos = _DBUS_ALIGN_VALUE (pos, 4);
vp->u32 = *(dbus_uint32_t *)(str_data + pos);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
switch (type)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
if (!_dbus_string_insert_byte (str, insert_at, vp->byt))
return FALSE;
if (pos_after)
*pos_after = insert_at + 1;
return TRUE;
break;
+ case DBUS_TYPE_BOOLEAN:
+ return marshal_4_octets (str, insert_at, vp->u32 != FALSE,
+ byte_order, pos_after);
+ break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
return marshal_4_octets (str, insert_at, vp->u32,
switch (element_type)
{
- case DBUS_TYPE_BOOLEAN:
- /* FIXME: we canonicalize to 0 or 1 for the single boolean case
- * should we here too ? */
case DBUS_TYPE_BYTE:
return marshal_1_octets_array (str, insert_at, vp, n_elements, byte_order, pos_after);
break;
+ /* FIXME: we canonicalize to 0 or 1 for the single boolean case
+ * should we here too ? */
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 4, pos_after);
switch (type)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
(*pos)++;
break;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
*pos = _DBUS_ALIGN_VALUE (*pos, 4);
switch (typecode)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_VARIANT:
case DBUS_TYPE_SIGNATURE:
return 1;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
/* this stuff is 4 since it starts with a length */
dbus_int64_t v_INT64;
dbus_uint64_t v_UINT64;
unsigned char v_BYTE;
- unsigned char v_BOOLEAN;
+ dbus_bool_t v_BOOLEAN;
const char *v_STRING;
const char *v_SIGNATURE;
const char *v_OBJECT_PATH;
#endif
double dbl; /**< as double */
unsigned char byt; /**< as byte */
- unsigned char boo; /**< as boolean */
char *str; /**< as char* */
} DBusBasicValue;
realign_root);
}
-#define BOOL_FROM_SEED(seed) (seed % 2)
+#define BOOL_FROM_SEED(seed) ((dbus_bool_t)((seed) % 2))
static dbus_bool_t
bool_write_value (TestTypeNode *node,
DBusTypeWriter *writer,
int seed)
{
- unsigned char v;
+ dbus_bool_t v;
v = BOOL_FROM_SEED (seed);
DBusTypeReader *reader,
int seed)
{
- unsigned char v;
+ dbus_bool_t v;
check_expected_type (reader, node->klass->typecode);
DBusTypeReader *realign_root,
int seed)
{
- unsigned char v;
+ dbus_bool_t v;
v = BOOL_FROM_SEED (seed);
break;
case DBUS_TYPE_BOOLEAN:
- if (!(*p == 0 || *p == 1))
- return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
- ++p;
- break;
-
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT64:
return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;
++p;
}
+
+ if (current_type == DBUS_TYPE_BOOLEAN)
+ {
+ dbus_uint32_t v = _dbus_unpack_uint32 (byte_order,
+ p);
+ if (!(v == 0 || v == 1))
+ return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE;
+ }
+
p += alignment;
break;
switch (type)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
align = 1;
break;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT32:
align = 4;
switch (type)
{
case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
elem_size = 1;
break;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT32:
elem_size = 4;
dbus_uint64_t v_UINT64;
#endif
unsigned char v_BYTE;
- unsigned char v_BOOLEAN;
+ dbus_bool_t v_BOOLEAN;
const dbus_int32_t *our_int_array;
int len;
dbus_int32_t our_int;
const char *our_str;
double our_double;
- unsigned char our_bool;
+ dbus_bool_t our_bool;
unsigned char our_byte_1, our_byte_2;
dbus_uint32_t our_uint32;
const dbus_int32_t *our_uint32_array = (void*)0xdeadbeef;
int our_double_array_len;
const unsigned char *our_byte_array = (void*)0xdeadbeef;
int our_byte_array_len;
- const unsigned char *our_boolean_array = (void*)0xdeadbeef;
+ const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;
int our_boolean_array_len;
dbus_message_iter_init (message, &iter);
const double *v_ARRAY_DOUBLE = our_double_array;
const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 };
const unsigned char *v_ARRAY_BYTE = our_byte_array;
- const unsigned char our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE };
- const unsigned char *v_ARRAY_BOOLEAN = our_boolean_array;
+ const dbus_bool_t our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE };
+ const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
char sig[64];
const char *s;
char *t;
#endif
unsigned char v_BYTE;
unsigned char v2_BYTE;
- unsigned char v_BOOLEAN;
+ dbus_bool_t v_BOOLEAN;
message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
"/org/freedesktop/TestPath",
#include <stddef.h>
-typedef unsigned int dbus_bool_t;
typedef unsigned short dbus_uint16_t;
typedef short dbus_int16_t;
typedef unsigned int dbus_uint32_t;
typedef int dbus_int32_t;
typedef dbus_uint32_t dbus_unichar_t;
+/* boolean size must be fixed at 4 bytes due to wire protocol! */
+typedef dbus_uint32_t dbus_bool_t;
/* Normally docs are in .c files, but there isn't a .c file for this. */
/**
g_value_init (value, G_TYPE_##g_t); \
dbus_message_iter_get_basic (iter, &value->data[0]); \
break
+
+ g_assert (sizeof (dbus_bool_t) == sizeof (value->data[0].v_int));
switch (dbus_message_iter_get_arg_type (iter))
{
break;
case G_TYPE_BOOLEAN:
{
- unsigned char b = g_value_get_boolean (value);
+ dbus_bool_t b = g_value_get_boolean (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_BOOLEAN,
&b))
Message& Message::operator<<( bool b )
{
- const unsigned char byte = b;
- dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &byte,
+ const dbus_bool_t right_size_bool = b;
+ dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &right_size_bool,
DBUS_TYPE_INVALID );
}
dbus_int32_t int32;
double d;
unsigned char byte;
+ dbus_bool_t v_BOOLEAN;
type = DBUS_TYPE_INVALID;
arg = argv[i++];
case DBUS_TYPE_BOOLEAN:
if (strcmp(c, "true") == 0)
{
- byte = TRUE;
- dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &c);
+ v_BOOLEAN = TRUE;
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
}
else if (strcmp(c, "false") == 0)
{
- byte = FALSE;
- dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &c);
+ v_BOOLEAN = FALSE;
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
}
else
{