Commit 3ed9db54 authored by Havoc Pennington's avatar Havoc Pennington

2005-01-27 Havoc Pennington <hp@redhat.com>

	* dbus/dbus-arch-deps.h.in: add 16/32-bit types

	* configure.in: find the right type for 16 and 32 bit ints as well
	as 64

	* dbus/dbus-protocol.h (DBUS_TYPE_INT16, DBUS_TYPE_UINT16): add
	the 16-bit types so people don't have to stuff them in 32-bit or
	byte arrays.
parent 4506b659
2005-01-27 Havoc Pennington <hp@redhat.com>
* dbus/dbus-arch-deps.h.in: add 16/32-bit types
* configure.in: find the right type for 16 and 32 bit ints as well
as 64
* dbus/dbus-protocol.h (DBUS_TYPE_INT16, DBUS_TYPE_UINT16): add
the 16-bit types so people don't have to stuff them in 32-bit or
byte arrays.
2005-01-27 Havoc Pennington <hp@redhat.com>
* dbus/dbus-message.c: byteswap the message if you init an
......
......@@ -369,6 +369,53 @@ AC_SUBST(DBUS_INT64_CONSTANT)
AC_SUBST(DBUS_UINT64_CONSTANT)
AC_SUBST(DBUS_HAVE_INT64)
### see what 32-bit int is called
AC_MSG_CHECKING([32-bit integer type])
case 4 in
$ac_cv_sizeof_short)
dbusint32=int
;;
$ac_cv_sizeof_int)
dbusint32=int
;;
$ac_cv_sizeof_long)
dbusint32=long
;;
esac
if test -z "$dbusint32" ; then
DBUS_INT32_TYPE="no_int32_type_detected"
AC_MSG_ERROR([No 32-bit integer type found])
else
DBUS_INT32_TYPE="$dbusint32"
AC_MSG_RESULT($DBUS_INT32_TYPE)
fi
AC_SUBST(DBUS_INT32_TYPE)
### see what 16-bit int is called
AC_MSG_CHECKING([16-bit integer type])
case 2 in
$ac_cv_sizeof_short)
dbusint16=short
;;
$ac_cv_sizeof_int)
dbusint16=int
;;
esac
if test -z "$dbusint16" ; then
DBUS_INT16_TYPE="no_int16_type_detected"
AC_MSG_ERROR([No 16-bit integer type found])
else
DBUS_INT16_TYPE="$dbusint16"
AC_MSG_RESULT($DBUS_INT16_TYPE)
fi
AC_SUBST(DBUS_INT16_TYPE)
## byte order
AC_C_BIGENDIAN
......@@ -1194,6 +1241,8 @@ echo "
cppflags: ${CPPFLAGS}
cxxflags: ${CXXFLAGS}
64-bit int: ${DBUS_INT64_TYPE}
32-bit int: ${DBUS_INT32_TYPE}
16-bit int: ${DBUS_INT16_TYPE}
Doxygen: ${DOXYGEN}
xmlto: ${XMLTO}"
......
......@@ -27,7 +27,6 @@
#ifndef DBUS_ARCH_DEPS_H
#define DBUS_ARCH_DEPS_H
#include <dbus/dbus-types.h>
#include <dbus/dbus-macros.h>
DBUS_BEGIN_DECLS;
......@@ -46,6 +45,12 @@ typedef unsigned @DBUS_INT64_TYPE@ dbus_uint64_t;
#undef DBUS_UINT64_CONSTANT
#endif
typedef @DBUS_INT32_TYPE@ dbus_int32_t;
typedef unsigned @DBUS_INT32_TYPE@ dbus_uint32_t;
typedef @DBUS_INT16_TYPE@ dbus_int16_t;
typedef unsigned @DBUS_INT16_TYPE@ dbus_uint16_t;
DBUS_END_DECLS;
#endif /* DBUS_ARCH_DEPS_H */
......@@ -26,6 +26,7 @@
#include "dbus-protocol.h"
#include "dbus-internals.h"
#include "dbus-message.h"
#include "dbus-marshal-validate.h"
#include <string.h>
/**
......
......@@ -97,6 +97,38 @@
*
* @param object the object to be zeroed.
*/
/**
* @def _DBUS_INT16_MIN
*
* Minimum value of type "int16"
*/
/**
* @def _DBUS_INT16_MAX
*
* Maximum value of type "int16"
*/
/**
* @def _DBUS_UINT16_MAX
*
* Maximum value of type "uint16"
*/
/**
* @def _DBUS_INT32_MIN
*
* Minimum value of type "int32"
*/
/**
* @def _DBUS_INT32_MAX
*
* Maximum value of type "int32"
*/
/**
* @def _DBUS_UINT32_MAX
*
* Maximum value of type "uint32"
*/
/**
* @def _DBUS_INT_MIN
*
......@@ -107,6 +139,11 @@
*
* Maximum value of type "int"
*/
/**
* @def _DBUS_UINT_MAX
*
* Maximum value of type "uint"
*/
/**
* @typedef DBusForeachFunction
......
......@@ -183,11 +183,18 @@ dbus_bool_t _dbus_string_array_contains (const char **array,
const char *str);
char** _dbus_dup_string_array (const char **array);
#define _DBUS_INT_MIN (-_DBUS_INT_MAX - 1)
#define _DBUS_INT_MAX 2147483647
#define _DBUS_UINT_MAX 0xffffffff
#define _DBUS_INT16_MIN ((dbus_int16_t) 0x8000)
#define _DBUS_INT16_MAX ((dbus_int16_t) 0x7fff)
#define _DBUS_UINT16_MAX ((dbus_uint16_t)0xffff)
#define _DBUS_INT32_MIN ((dbus_int32_t) 0x80000000)
#define _DBUS_INT32_MAX ((dbus_int32_t) 0x7fffffff)
#define _DBUS_UINT32_MAX ((dbus_uint32_t)0xffffffff)
/* using 32-bit here is sort of bogus */
#define _DBUS_INT_MIN _DBUS_INT32_MIN
#define _DBUS_INT_MAX _DBUS_INT32_MAX
#define _DBUS_UINT_MAX _DBUS_UINT32_MAX
#ifdef DBUS_HAVE_INT64
#define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (9223372036854775807)
#define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (0x7fffffffffffffff)
#define _DBUS_UINT64_MAX DBUS_UINT64_CONSTANT (0xffffffffffffffff)
#endif
#define _DBUS_ONE_KILOBYTE 1024
......
......@@ -489,7 +489,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
continue;
}
if (val > _DBUS_INT_MAX || val < 0)
if (val > _DBUS_INT32_MAX || val < 0)
{
_dbus_verbose ("invalid secret key ID at start of line\n");
continue;
......
......@@ -42,6 +42,19 @@
* @{
*/
static void
pack_2_octets (dbus_uint16_t value,
int byte_order,
unsigned char *data)
{
_dbus_assert (_DBUS_ALIGN_ADDRESS (data, 2) == data);
if ((byte_order) == DBUS_LITTLE_ENDIAN)
*((dbus_uint16_t*)(data)) = DBUS_UINT16_TO_LE (value);
else
*((dbus_uint16_t*)(data)) = DBUS_UINT16_TO_BE (value);
}
static void
pack_4_octets (dbus_uint32_t value,
int byte_order,
......@@ -147,6 +160,27 @@ unpack_8_octets (int byte_order,
}
#endif
#ifndef _dbus_unpack_uint16
/**
* Unpacks a 16 bit unsigned integer from a data pointer
*
* @param byte_order The byte order to use
* @param data the data pointer
* @returns the integer
*/
dbus_uint16_t
_dbus_unpack_uint16 (int byte_order,
const unsigned char *data)
{
_dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
if (byte_order == DBUS_LITTLE_ENDIAN)
return DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)data);
else
return DBUS_UINT16_FROM_BE (*(dbus_uint16_t*)data);
}
#endif /* _dbus_unpack_uint16 */
#ifndef _dbus_unpack_uint32
/**
* Unpacks a 32 bit unsigned integer from a data pointer
......@@ -168,6 +202,22 @@ _dbus_unpack_uint32 (int byte_order,
}
#endif /* _dbus_unpack_uint32 */
static void
set_2_octets (DBusString *str,
int offset,
dbus_uint16_t value,
int byte_order)
{
char *data;
_dbus_assert (byte_order == DBUS_LITTLE_ENDIAN ||
byte_order == DBUS_BIG_ENDIAN);
data = _dbus_string_get_data_len (str, offset, 2);
pack_2_octets (value, byte_order, data);
}
static void
set_4_octets (DBusString *str,
int offset,
......@@ -181,7 +231,7 @@ set_4_octets (DBusString *str,
data = _dbus_string_get_data_len (str, offset, 4);
_dbus_pack_uint32 (value, byte_order, data);
pack_4_octets (value, byte_order, data);
}
static void
......@@ -350,6 +400,16 @@ _dbus_marshal_set_basic (DBusString *str,
*new_end_pos = pos + 1;
return TRUE;
break;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
pos = _DBUS_ALIGN_VALUE (pos, 2);
set_2_octets (str, pos, vp->u16, byte_order);
if (old_end_pos)
*old_end_pos = pos + 2;
if (new_end_pos)
*new_end_pos = pos + 2;
return TRUE;
break;
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
......@@ -460,6 +520,14 @@ _dbus_marshal_read_basic (const DBusString *str,
vp->byt = _dbus_string_get_byte (str, pos);
(pos)++;
break;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
pos = _DBUS_ALIGN_VALUE (pos, 2);
vp->u16 = *(dbus_uint16_t *)(str_data + pos);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
vp->u16 = DBUS_UINT16_SWAP_LE_BE (vp->u16);
pos += 2;
break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_BOOLEAN:
......@@ -570,6 +638,35 @@ _dbus_marshal_read_fixed_multi (const DBusString *str,
*new_pos = pos + array_len;
}
static dbus_bool_t
marshal_2_octets (DBusString *str,
int insert_at,
dbus_uint16_t value,
int byte_order,
int *pos_after)
{
dbus_bool_t retval;
int orig_len;
_dbus_assert (sizeof (value) == 2);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
value = DBUS_UINT16_SWAP_LE_BE (value);
orig_len = _dbus_string_get_length (str);
retval = _dbus_string_insert_2_aligned (str, insert_at,
(const unsigned char *)&value);
if (pos_after)
{
*pos_after = insert_at + (_dbus_string_get_length (str) - orig_len);
_dbus_assert (*pos_after <= _dbus_string_get_length (str));
}
return retval;
}
static dbus_bool_t
marshal_4_octets (DBusString *str,
int insert_at,
......@@ -762,6 +859,11 @@ _dbus_marshal_write_basic (DBusString *str,
*pos_after = insert_at + 1;
return TRUE;
break;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
return marshal_2_octets (str, insert_at, vp->u16,
byte_order, pos_after);
break;
case DBUS_TYPE_BOOLEAN:
return marshal_4_octets (str, insert_at, vp->u32 != FALSE,
byte_order, pos_after);
......@@ -855,16 +957,24 @@ _dbus_swap_array (unsigned char *data,
d += 8;
}
}
else
else if (alignment == 4)
{
_dbus_assert (alignment == 4);
while (d != end)
{
*((dbus_uint32_t*)d) = DBUS_UINT32_SWAP_LE_BE (*((dbus_uint32_t*)d));
d += 4;
}
}
else
{
_dbus_assert (alignment == 2);
while (d != end)
{
*((dbus_uint16_t*)d) = DBUS_UINT16_SWAP_LE_BE (*((dbus_uint16_t*)d));
d += 2;
}
}
}
static void
......@@ -979,6 +1089,9 @@ _dbus_marshal_write_fixed_multi (DBusString *str,
case DBUS_TYPE_BYTE:
return marshal_1_octets_array (str, insert_at, vp, n_elements, byte_order, pos_after);
break;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 2, pos_after);
/* FIXME: we canonicalize to 0 or 1 for the single boolean case
* should we here too ? */
case DBUS_TYPE_BOOLEAN:
......@@ -1024,6 +1137,11 @@ _dbus_marshal_skip_basic (const DBusString *str,
case DBUS_TYPE_BYTE:
(*pos)++;
break;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
*pos = _DBUS_ALIGN_VALUE (*pos, 2);
*pos += 2;
break;
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
......@@ -1109,6 +1227,9 @@ _dbus_type_get_alignment (int typecode)
case DBUS_TYPE_VARIANT:
case DBUS_TYPE_SIGNATURE:
return 1;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
return 2;
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
......@@ -1150,6 +1271,8 @@ _dbus_type_is_valid (int typecode)
{
case DBUS_TYPE_BYTE:
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT64:
......@@ -1232,6 +1355,8 @@ _dbus_type_is_fixed (int typecode)
{
case DBUS_TYPE_BYTE:
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT64:
......@@ -1260,6 +1385,10 @@ _dbus_type_to_string (int typecode)
return "boolean";
case DBUS_TYPE_BYTE:
return "byte";
case DBUS_TYPE_INT16:
return "int16";
case DBUS_TYPE_UINT16:
return "uint16";
case DBUS_TYPE_INT32:
return "int32";
case DBUS_TYPE_UINT32:
......@@ -1558,6 +1687,7 @@ _dbus_marshal_test (void)
DBusString str;
int pos, dump_pos;
unsigned char array1[5] = { 3, 4, 0, 1, 9 };
dbus_int16_t array2[3] = { 124, 457, 780 };
dbus_int32_t array4[3] = { 123, 456, 789 };
#ifdef DBUS_HAVE_INT64
dbus_int64_t array8[3] = { DBUS_INT64_CONSTANT (0x123ffffffff),
......@@ -1566,11 +1696,16 @@ _dbus_marshal_test (void)
dbus_int64_t *v_ARRAY_INT64;
#endif
unsigned char *v_ARRAY_BYTE;
dbus_int16_t *v_ARRAY_INT16;
dbus_uint16_t *v_ARRAY_UINT16;
dbus_int32_t *v_ARRAY_INT32;
dbus_uint32_t *v_ARRAY_UINT32;
double *v_ARRAY_DOUBLE;
DBusString t;
double v_DOUBLE;
double t_DOUBLE;
dbus_int16_t v_INT16;
dbus_uint16_t v_UINT16;
dbus_int32_t v_INT32;
dbus_uint32_t v_UINT32;
dbus_int64_t v_INT64;
......@@ -1600,6 +1735,14 @@ _dbus_marshal_test (void)
if (!_DBUS_DOUBLES_BITWISE_EQUAL (t_DOUBLE, v_DOUBLE))
_dbus_assert_not_reached ("got wrong double value");
/* Marshal signed 16 integers */
MARSHAL_TEST (INT16, DBUS_BIG_ENDIAN, -12345);
MARSHAL_TEST (INT16, DBUS_LITTLE_ENDIAN, -12345);
/* Marshal unsigned 16 integers */
MARSHAL_TEST (UINT16, DBUS_BIG_ENDIAN, 0x1234);
MARSHAL_TEST (UINT16, DBUS_LITTLE_ENDIAN, 0x1234);
/* Marshal signed integers */
MARSHAL_TEST (INT32, DBUS_BIG_ENDIAN, -12345678);
MARSHAL_TEST (INT32, DBUS_LITTLE_ENDIAN, -12345678);
......@@ -1645,8 +1788,15 @@ _dbus_marshal_test (void)
MARSHAL_TEST_STRCMP (SIGNATURE, DBUS_LITTLE_ENDIAN, "a(ii)");
/* Arrays */
MARSHAL_TEST_FIXED_ARRAY (INT16, DBUS_BIG_ENDIAN, array2);
MARSHAL_TEST_FIXED_ARRAY (INT16, DBUS_LITTLE_ENDIAN, array2);
MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_BIG_ENDIAN, array2);
MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_LITTLE_ENDIAN, array2);
MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_BIG_ENDIAN, array4);
MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_LITTLE_ENDIAN, array4);
MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_BIG_ENDIAN, array4);
MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_LITTLE_ENDIAN, array4);
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_BIG_ENDIAN, array1);
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_LITTLE_ENDIAN, array1);
......
......@@ -41,6 +41,10 @@
#define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
#endif
#define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val) ((dbus_uint16_t) ( \
(dbus_uint16_t) ((dbus_uint16_t) (val) >> 8) | \
(dbus_uint16_t) ((dbus_uint16_t) (val) << 8)))
#define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
......@@ -68,48 +72,66 @@
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
#endif /* DBUS_HAVE_INT64 */
#define DBUS_UINT16_SWAP_LE_BE(val) (DBUS_UINT16_SWAP_LE_BE_CONSTANT (val))
#define DBUS_INT16_SWAP_LE_BE(val) ((dbus_int16_t)DBUS_UINT16_SWAP_LE_BE_CONSTANT (val))
#define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
#define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
#ifdef DBUS_HAVE_INT64
#define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
#define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
# define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
# define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
#endif /* DBUS_HAVE_INT64 */
#ifdef WORDS_BIGENDIAN
#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
#define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
#define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
#define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
# define DBUS_INT16_TO_BE(val) ((dbus_int16_t) (val))
# define DBUS_UINT16_TO_BE(val) ((dbus_uint16_t) (val))
# define DBUS_INT16_TO_LE(val) (DBUS_INT16_SWAP_LE_BE (val))
# define DBUS_UINT16_TO_LE(val) (DBUS_UINT16_SWAP_LE_BE (val))
# define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
# define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
# define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
# define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
# ifdef DBUS_HAVE_INT64
#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
#define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
#define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
#define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
# define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
# define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
# define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
# endif /* DBUS_HAVE_INT64 */
#else
#define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
#define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
#define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
#else /* WORDS_BIGENDIAN */
# define DBUS_INT16_TO_LE(val) ((dbus_int16_t) (val))
# define DBUS_UINT16_TO_LE(val) ((dbus_uint16_t) (val))
# define DBUS_INT16_TO_BE(val) ((dbus_int16_t) DBUS_UINT16_SWAP_LE_BE (val))
# define DBUS_UINT16_TO_BE(val) (DBUS_UINT16_SWAP_LE_BE (val))
# define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
# define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
# define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
# define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
# ifdef DBUS_HAVE_INT64
#define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
#define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
#define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
# define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
# define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
# define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
# endif /* DBUS_HAVE_INT64 */
#endif
/* The transformation is symmetric, so the FROM just maps to the TO. */
#define DBUS_INT16_FROM_LE(val) (DBUS_INT16_TO_LE (val))
#define DBUS_UINT16_FROM_LE(val) (DBUS_UINT16_TO_LE (val))
#define DBUS_INT16_FROM_BE(val) (DBUS_INT16_TO_BE (val))
#define DBUS_UINT16_FROM_BE(val) (DBUS_UINT16_TO_BE (val))
#define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
#define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
#define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
#define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
#ifdef DBUS_HAVE_INT64
#define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
#define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
#define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
#define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
# define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
# define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
# define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
# define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
#endif /* DBUS_HAVE_INT64 */
#ifndef DBUS_HAVE_INT64
......@@ -131,11 +153,13 @@ typedef struct
*/
typedef union
{
dbus_int16_t i16; /**< as int16 */
dbus_uint16_t u16; /**< as int16 */
dbus_int32_t i32; /**< as int32 */
dbus_uint32_t u32; /**< as int32 */
#ifdef DBUS_HAVE_INT64
dbus_int64_t i64; /**< as int32 */
dbus_uint64_t u64; /**< as int32 */
dbus_int64_t i64; /**< as int64 */
dbus_uint64_t u64; /**< as int64 */
#else
DBus8ByteStruct u64; /**< as 8-byte-struct */
#endif
......@@ -145,12 +169,22 @@ typedef union
} DBusBasicValue;
#ifdef DBUS_DISABLE_ASSERT
#define _dbus_unpack_uint16(byte_order, data) \
(((byte_order) == DBUS_LITTLE_ENDIAN) ? \
DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)(data)) : \
DBUS_UINT16_FROM_BE (*(dbus_uint16_t*)(data)))
#define _dbus_unpack_uint32(byte_order, data) \
(((byte_order) == DBUS_LITTLE_ENDIAN) ? \
DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)(data)) : \
DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(data)))
#endif
#ifndef _dbus_unpack_uint16
dbus_uint16_t _dbus_unpack_uint16 (int byte_order,
const unsigned char *data);
#endif
void _dbus_pack_uint32 (dbus_uint32_t value,
int byte_order,
unsigned char *data);
......
......@@ -47,6 +47,15 @@ byteswap_body_helper (DBusTypeReader *reader,
++p;
break;
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
{
p = _DBUS_ALIGN_ADDRESS (p, 2);
*((dbus_uint16_t*)p) = DBUS_UINT16_SWAP_LE_BE (*((dbus_uint16_t*)p));
p += 2;
}
break;
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
......
......@@ -672,7 +672,7 @@ _dbus_header_have_message_untrusted (int max_message_length,
dbus_uint32_t body_len_unsigned;
_dbus_assert (start >= 0);
_dbus_assert (start < _DBUS_INT_MAX / 2);
_dbus_assert (start < _DBUS_INT32_MAX / 2);
_dbus_assert (len >= 0);
_dbus_assert (start == (int) _DBUS_ALIGN_VALUE (start, 8));
......@@ -711,16 +711,16 @@ _dbus_header_have_message_untrusted (int max_message_length,
/* overflow should be impossible since the lengths aren't allowed to
* be huge.
*/
_dbus_assert (max_message_length < _DBUS_INT_MAX / 2);
_dbus_assert (max_message_length < _DBUS_INT32_MAX / 2);
if (body_len_unsigned + header_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_MESSAGE_TOO_LONG;
return FALSE;
}
_dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT_MAX);
_dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT_MAX);
_dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT_MAX);
_dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT32_MAX);
_dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT32_MAX);
_dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT32_MAX);
*body_len = body_len_unsigned;
*fields_array_len = fields_array_len_unsigned;
......
......@@ -396,6 +396,26 @@ struct TestTypeNodeContainerClass
* and by merging read_value and set_value into one function
* taking a flag argument.
*/
static dbus_bool_t int16_write_value (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
int seed);
static dbus_bool_t int16_read_value (TestTypeNode *node,
DBusTypeReader *reader,
int seed);
static dbus_bool_t int16_set_value (TestTypeNode *node,
DBusTypeReader *reader,
DBusTypeReader *realign_root,
int seed);
static dbus_bool_t int16_write_multi (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
int seed,
int count);
static dbus_bool_t int16_read_multi (TestTypeNode *node,
DBusTypeReader *reader,
int seed,
int count);
static dbus_bool_t int32_write_value (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
......@@ -533,6 +553,34 @@ static dbus_bool_t variant_set_value (TestTypeNode *node,
static void container_destroy (TestTypeNode *node);
static const TestTypeNodeClass int16_class = {
DBUS_TYPE_INT16,
sizeof (TestTypeNode),
0,
NULL,
NULL,
int16_write_value,
int16_read_value,
int16_set_value,
NULL,
int16_write_multi,
int16_read_multi
};
static const TestTypeNodeClass uint16_class = {
DBUS_TYPE_UINT16,
sizeof (TestTypeNode),
0,
NULL,
NULL,
int16_write_value, /* recycle from int16 */
int16_read_value, /* recycle from int16 */
int16_set_value, /* recycle from int16 */
NULL,
int16_write_multi, /* recycle from int16 */
int16_read_multi /* recycle from int16 */
};
static const TestTypeNodeClass int32_class = {
DBUS_TYPE_INT32,
sizeof (TestTypeNode),
......@@ -819,6 +867,8 @@ static const TestTypeNodeClass variant_class = {
static const TestTypeNodeClass* const
basic_nodes[] = {
&int16_class,
&uint16_class,
&int32_class,
&uint32_class,
&int64_class,
......@@ -1978,6 +2028,142 @@ _dbus_marshal_recursive_test (void)
*/
#define MAX_MULTI_COUNT 5
#define SAMPLE_INT16 1234
#define SAMPLE_INT16_ALTERNATE 6785
static dbus_int16_t
int16_from_seed (int seed)
{
/* Generate an integer value that's predictable from seed. We could