Commit 62e46533 authored by Havoc Pennington's avatar Havoc Pennington

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.
parent 7bf62e31
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
......
......@@ -519,7 +519,7 @@ bus_driver_handle_service_exists (DBusConnection *connection,
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;
......
......@@ -343,7 +343,6 @@ _dbus_marshal_set_basic (DBusString *str,
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;
......@@ -351,6 +350,7 @@ _dbus_marshal_set_basic (DBusString *str,
*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);
......@@ -457,12 +457,12 @@ _dbus_marshal_read_basic (const DBusString *str,
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)
......@@ -756,13 +756,16 @@ _dbus_marshal_write_basic (DBusString *str,
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,
......@@ -952,12 +955,12 @@ _dbus_marshal_write_fixed_multi (DBusString *str,
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);
......@@ -998,9 +1001,9 @@ _dbus_marshal_skip_basic (const DBusString *str,
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);
......@@ -1082,10 +1085,10 @@ _dbus_type_get_alignment (int typecode)
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 */
......@@ -1528,7 +1531,7 @@ _dbus_marshal_test (void)
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;
......
......@@ -141,7 +141,6 @@ typedef union
#endif
double dbl; /**< as double */
unsigned char byt; /**< as byte */
unsigned char boo; /**< as boolean */
char *str; /**< as char* */
} DBusBasicValue;
......
......@@ -2141,7 +2141,7 @@ string_set_value (TestTypeNode *node,
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,
......@@ -2149,7 +2149,7 @@ bool_write_value (TestTypeNode *node,
DBusTypeWriter *writer,
int seed)
{
unsigned char v;
dbus_bool_t v;
v = BOOL_FROM_SEED (seed);
......@@ -2163,7 +2163,7 @@ bool_read_value (TestTypeNode *node,
DBusTypeReader *reader,
int seed)
{
unsigned char v;
dbus_bool_t v;
check_expected_type (reader, node->klass->typecode);
......@@ -2181,7 +2181,7 @@ bool_set_value (TestTypeNode *node,
DBusTypeReader *realign_root,
int seed)
{
unsigned char v;
dbus_bool_t v;
v = BOOL_FROM_SEED (seed);
......
......@@ -159,11 +159,6 @@ validate_body_helper (DBusTypeReader *reader,
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:
......@@ -179,6 +174,15 @@ validate_body_helper (DBusTypeReader *reader,
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;
......
......@@ -456,9 +456,9 @@ parse_basic_type (DBusString *src, char type,
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;
......@@ -514,9 +514,9 @@ parse_basic_array (DBusString *src, char type,
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;
......
......@@ -599,7 +599,7 @@ message_iter_test (DBusMessage *message)
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;
......@@ -659,7 +659,7 @@ verify_test_message (DBusMessage *message)
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;
......@@ -678,7 +678,7 @@ verify_test_message (DBusMessage *message)
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);
......@@ -844,8 +844,8 @@ _dbus_message_test (const char *test_data_dir)
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;
......@@ -860,7 +860,7 @@ _dbus_message_test (const char *test_data_dir)
#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",
......
......@@ -29,12 +29,13 @@
#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. */
/**
......
......@@ -34,6 +34,8 @@ dbus_gvalue_demarshal (DBusMessageIter *iter, GValue *value)
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))
{
......@@ -98,7 +100,7 @@ dbus_gvalue_marshal (DBusMessageIter *iter, GValue *value)
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))
......
......@@ -505,8 +505,8 @@ Message::message() const
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 );
}
......
......@@ -179,6 +179,7 @@ main (int argc, char *argv[])
dbus_int32_t int32;
double d;
unsigned char byte;
dbus_bool_t v_BOOLEAN;
type = DBUS_TYPE_INVALID;
arg = argv[i++];
......@@ -240,13 +241,13 @@ main (int argc, char *argv[])
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
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment