2005-01-27 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Fri, 28 Jan 2005 03:06:56 +0000 (03:06 +0000)
committerHavoc Pennington <hp@redhat.com>
Fri, 28 Jan 2005 03:06:56 +0000 (03:06 +0000)
* 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.

25 files changed:
ChangeLog
configure.in
dbus/dbus-arch-deps.h.in
dbus/dbus-bus.c
dbus/dbus-internals.c
dbus/dbus-internals.h
dbus/dbus-keyring.c
dbus/dbus-marshal-basic.c
dbus/dbus-marshal-basic.h
dbus/dbus-marshal-byteswap.c
dbus/dbus-marshal-header.c
dbus/dbus-marshal-recursive-util.c
dbus/dbus-marshal-validate-util.c
dbus/dbus-marshal-validate.c
dbus/dbus-message-util.c
dbus/dbus-protocol.h
dbus/dbus-string-private.h
dbus/dbus-string.c
dbus/dbus-string.h
dbus/dbus-test.c
dbus/dbus-transport.c
dbus/dbus-types.h
glib/dbus-gparser.c
glib/dbus-gutils.c
glib/dbus-gvalue.c

index c1d2465..137ebe2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 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
        iterator to read/write from it
        
index 95ab6d1..71efb27 100644 (file)
@@ -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}"
 
index 9d0d597..b5891e6 100644 (file)
@@ -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 */
index bc6a3bf..92e9f96 100644 (file)
@@ -26,6 +26,7 @@
 #include "dbus-protocol.h"
 #include "dbus-internals.h"
 #include "dbus-message.h"
+#include "dbus-marshal-validate.h"
 #include <string.h>
 
 /**
index 8d0a968..1e1753d 100644 (file)
  * @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
  *
  * Minimum value of type "int"
  *
  * Maximum value of type "int"
  */
+/**
+ * @def _DBUS_UINT_MAX
+ *
+ * Maximum value of type "uint"
+ */
 
 /**
  * @typedef DBusForeachFunction
index 2ffd234..3f0a34f 100644 (file)
@@ -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
index 615a145..8fbfd68 100644 (file)
@@ -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;
index cd5d4e4..e4f6720 100644 (file)
  */
 
 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,
                unsigned char  *data)
@@ -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
@@ -169,6 +203,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,
               dbus_uint32_t        value,
@@ -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:
@@ -571,6 +639,35 @@ _dbus_marshal_read_fixed_multi  (const DBusString *str,
 }
 
 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,
                   dbus_uint32_t value,
@@ -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);
index 375f2a3..f25d38c 100644 (file)
 #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) |     \
        (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);
index 434d7e4..7670ec4 100644 (file)
@@ -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:
index b5a8d3d..f32e7aa 100644 (file)
@@ -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;
index 08d030a..c607b04 100644 (file)
@@ -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
+   * just use seed itself, but that would only ever touch one byte of
+   * the int so would miss some kinds of bug.
+   */
+  dbus_int16_t v;
+
+  v = 42; /* just to quiet compiler afaik */
+  switch (seed % 5)
+    {
+    case 0:
+      v = SAMPLE_INT16;
+      break;
+    case 1:
+      v = SAMPLE_INT16_ALTERNATE;
+      break;
+    case 2:
+      v = -1;
+      break;
+    case 3:
+      v = _DBUS_INT16_MAX;
+      break;
+    case 4:
+      v = 1;
+      break;
+    }
+
+  if (seed > 1)
+    v *= seed; /* wraps around eventually, which is fine */
+
+  return v;
+}
+
+static dbus_bool_t
+int16_write_value (TestTypeNode   *node,
+                   DataBlock      *block,
+                   DBusTypeWriter *writer,
+                   int             seed)
+{
+  /* also used for uint16 */
+  dbus_int16_t v;
+
+  v = int16_from_seed (seed);
+
+  return _dbus_type_writer_write_basic (writer,
+                                        node->klass->typecode,
+                                        &v);
+}
+
+static dbus_bool_t
+int16_read_value (TestTypeNode   *node,
+                  DBusTypeReader *reader,
+                  int             seed)
+{
+  /* also used for uint16 */
+  dbus_int16_t v;
+
+  check_expected_type (reader, node->klass->typecode);
+
+  _dbus_type_reader_read_basic (reader,
+                                (dbus_int16_t*) &v);
+
+  _dbus_assert (v == int16_from_seed (seed));
+
+  return TRUE;
+}
+
+static dbus_bool_t
+int16_set_value (TestTypeNode   *node,
+                 DBusTypeReader *reader,
+                 DBusTypeReader *realign_root,
+                 int             seed)
+{
+  /* also used for uint16 */
+  dbus_int16_t v;
+
+  v = int16_from_seed (seed);
+
+  return _dbus_type_reader_set_basic (reader,
+                                      &v,
+                                      realign_root);
+}
+
+static dbus_bool_t
+int16_write_multi (TestTypeNode   *node,
+                   DataBlock      *block,
+                   DBusTypeWriter *writer,
+                   int             seed,
+                   int             count)
+{
+  /* also used for uint16 */
+  dbus_int16_t values[MAX_MULTI_COUNT];
+  dbus_int16_t *v_ARRAY_INT16 = values;
+  int i;
+
+  for (i = 0; i < count; ++i)
+    values[i] = int16_from_seed (seed + i);
+
+  return _dbus_type_writer_write_fixed_multi (writer,
+                                              node->klass->typecode,
+                                              &v_ARRAY_INT16, count);
+}
+
+static dbus_bool_t
+int16_read_multi (TestTypeNode   *node,
+                  DBusTypeReader *reader,
+                  int             seed,
+                  int             count)
+{
+  /* also used for uint16 */
+  dbus_int16_t *values;
+  int n_elements;
+  int i;
+
+  check_expected_type (reader, node->klass->typecode);
+
+  _dbus_type_reader_read_fixed_multi (reader,
+                                      &values,
+                                      &n_elements);
+
+  if (n_elements != count)
+    _dbus_warn ("got %d elements expected %d\n", n_elements, count);
+  _dbus_assert (n_elements == count);
+
+  for (i = 0; i < count; i++)
+    _dbus_assert (((int)_dbus_unpack_uint16 (reader->byte_order,
+                                             (const unsigned char*)values + (i * 2))) ==
+                  int16_from_seed (seed + i));
+
+  return TRUE;
+}
+
 
 #define SAMPLE_INT32           12345678
 #define SAMPLE_INT32_ALTERNATE 53781429
index 6915c05..7a1648f 100644 (file)
@@ -68,7 +68,7 @@ static const ValidityTest signature_tests[] = {
   { "i", DBUS_VALID },
   { "ai", DBUS_VALID },
   { "(i)", DBUS_VALID },
-  { "q", DBUS_INVALID_UNKNOWN_TYPECODE },
+  { "w", DBUS_INVALID_UNKNOWN_TYPECODE },
   { "a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
   { "aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
   { "ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
index f15d281..b26adb2 100644 (file)
@@ -57,7 +57,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
   int array_depth;
 
   _dbus_assert (type_str != NULL);
-  _dbus_assert (type_pos < _DBUS_INT_MAX - len);
+  _dbus_assert (type_pos < _DBUS_INT32_MAX - len);
   _dbus_assert (len >= 0);
   _dbus_assert (type_pos >= 0);
 
@@ -76,6 +76,8 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
         {
         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:
@@ -159,8 +161,10 @@ validate_body_helper (DBusTypeReader       *reader,
         case DBUS_TYPE_BYTE:
           ++p;
           break;
-
+          
         case DBUS_TYPE_BOOLEAN:
+        case DBUS_TYPE_INT16:
+        case DBUS_TYPE_UINT16:
         case DBUS_TYPE_INT32:
         case DBUS_TYPE_UINT32:
         case DBUS_TYPE_INT64:
index 2d72f71..c646ebf 100644 (file)
@@ -591,6 +591,8 @@ message_iter_test (DBusMessage *message)
   DBusMessageIter iter, array, array2;
   const char *v_STRING;
   double v_DOUBLE;
+  dbus_int16_t v_INT16;
+  dbus_uint16_t v_UINT16;
   dbus_int32_t v_INT32;
   dbus_uint32_t v_UINT32;
 #ifdef DBUS_HAVE_INT64
@@ -656,6 +658,8 @@ verify_test_message (DBusMessage *message)
 {
   DBusMessageIter iter;
   DBusError error;
+  dbus_int16_t our_int16;
+  dbus_uint16_t our_uint16;
   dbus_int32_t our_int;
   dbus_uint32_t our_uint;
   const char *our_str;
@@ -686,6 +690,8 @@ verify_test_message (DBusMessage *message)
 
   dbus_error_init (&error);
   if (!dbus_message_iter_get_args (&iter, &error,
+                                   DBUS_TYPE_INT16, &our_int16,
+                                   DBUS_TYPE_UINT16, &our_uint16,
                                   DBUS_TYPE_INT32, &our_int,
                                    DBUS_TYPE_UINT32, &our_uint,
 #ifdef DBUS_HAVE_INT64
@@ -720,6 +726,12 @@ verify_test_message (DBusMessage *message)
       _dbus_assert_not_reached ("Could not get arguments");
     }
 
+  if (our_int16 != -0x123)
+    _dbus_assert_not_reached ("16-bit integers differ!");
+
+  if (our_uint16 != 0x123)
+    _dbus_assert_not_reached ("16-bit uints differ!");
+  
   if (our_int != -0x12345678)
     _dbus_assert_not_reached ("integers differ!");
 
@@ -860,6 +872,8 @@ _dbus_message_test (const char *test_data_dir)
   const char *s;
   const char *v_STRING;
   double v_DOUBLE;
+  dbus_int16_t v_INT16;
+  dbus_uint16_t v_UINT16;
   dbus_int32_t v_INT32;
   dbus_uint32_t v_UINT32;
 #ifdef DBUS_HAVE_INT64
@@ -974,6 +988,8 @@ _dbus_message_test (const char *test_data_dir)
   _dbus_message_set_serial (message, 1);
   dbus_message_set_reply_serial (message, 5678);
 
+  v_INT16 = -0x123;
+  v_UINT16 = 0x123;
   v_INT32 = -0x12345678;
   v_UINT32 = 0x12300042;
 #ifdef DBUS_HAVE_INT64
@@ -987,6 +1003,8 @@ _dbus_message_test (const char *test_data_dir)
   v2_BYTE = 24;
 
   dbus_message_append_args (message,
+                            DBUS_TYPE_INT16, &v_INT16,
+                            DBUS_TYPE_UINT16, &v_UINT16,
                            DBUS_TYPE_INT32, &v_INT32,
                             DBUS_TYPE_UINT32, &v_UINT32,
 #ifdef DBUS_HAVE_INT64
@@ -1017,6 +1035,8 @@ _dbus_message_test (const char *test_data_dir)
                            DBUS_TYPE_INVALID);
 
   i = 0;
+  sig[i++] = DBUS_TYPE_INT16;
+  sig[i++] = DBUS_TYPE_UINT16;
   sig[i++] = DBUS_TYPE_INT32;
   sig[i++] = DBUS_TYPE_UINT32;
 #ifdef DBUS_HAVE_INT64
index 9f569ec..d0a3d64 100644 (file)
@@ -49,9 +49,12 @@ extern "C" {
 #define DBUS_TYPE_BYTE_AS_STRING           "y"
 #define DBUS_TYPE_BOOLEAN       ((int) 'b')
 #define DBUS_TYPE_BOOLEAN_AS_STRING        "b"
+#define DBUS_TYPE_INT16         ((int) 'n')
+#define DBUS_TYPE_INT16_AS_STRING          "n"
+#define DBUS_TYPE_UINT16        ((int) 'q')
+#define DBUS_TYPE_UINT16_AS_STRING         "q"
 #define DBUS_TYPE_INT32         ((int) 'i')
 #define DBUS_TYPE_INT32_AS_STRING          "i"
-
 #define DBUS_TYPE_UINT32        ((int) 'u')
 #define DBUS_TYPE_UINT32_AS_STRING         "u"
 #define DBUS_TYPE_INT64         ((int) 'x')
@@ -81,7 +84,7 @@ extern "C" {
 #define DBUS_TYPE_STRUCT_AS_STRING         "r"
 
 /* Does not count INVALID */
-#define DBUS_NUMBER_OF_TYPES    (13)
+#define DBUS_NUMBER_OF_TYPES    (15)
 
 /* characters other than typecodes that appear in type signatures */
 #define DBUS_STRUCT_BEGIN_CHAR   ((int) '(')
index a4b7e8c..d26aabe 100644 (file)
@@ -68,7 +68,7 @@ typedef struct
  * This is the maximum max length (and thus also the maximum length)
  * of a DBusString
  */
-#define _DBUS_STRING_MAX_MAX_LENGTH (_DBUS_INT_MAX - _DBUS_STRING_ALLOCATION_PADDING)
+#define _DBUS_STRING_MAX_MAX_LENGTH (_DBUS_INT32_MAX - _DBUS_STRING_ALLOCATION_PADDING)
 
 /**
  * Checks a bunch of assertions about a string object
index 154193c..f64d474 100644 (file)
@@ -974,6 +974,9 @@ _dbus_string_append (DBusString *str,
   return append (real, buffer, buffer_len);
 }
 
+/** assign 2 bytes from one string to another */
+#define ASSIGN_2_OCTETS(p, octets) \
+  *((dbus_uint16_t*)(p)) = *((dbus_uint16_t*)(octets));
 
 /** assign 4 bytes from one string to another */
 #define ASSIGN_4_OCTETS(p, octets) \
@@ -1052,6 +1055,30 @@ _dbus_string_append_8_aligned (DBusString         *str,
 #endif /* DBUS_BUILD_TESTS */
 
 /**
+ * Inserts 2 bytes aligned on a 2 byte boundary
+ * with any alignment padding initialized to 0.
+ *
+ * @param str the DBusString
+ * @param insert_at where to insert
+ * @param octets 2 bytes to insert
+ * @returns #FALSE if not enough memory.
+ */
+dbus_bool_t
+_dbus_string_insert_2_aligned (DBusString         *str,
+                               int                 insert_at,
+                               const unsigned char octets[4])
+{
+  DBUS_STRING_PREAMBLE (str);
+  
+  if (!align_insert_point_then_open_gap (str, &insert_at, 2, 2))
+    return FALSE;
+
+  ASSIGN_2_OCTETS (real->str + insert_at, octets);
+
+  return TRUE;
+}
+
+/**
  * Inserts 4 bytes aligned on a 4 byte boundary
  * with any alignment padding initialized to 0.
  *
@@ -1109,7 +1136,7 @@ _dbus_string_insert_8_aligned (DBusString         *str,
  *
  * @param str the DBusString
  * @param insert_at location to be aligned
- * @param alignment alignment boundary (1, 4, or 8)
+ * @param alignment alignment boundary (1, 2, 4, or 8)
  * @returns #FALSE if not enough memory.
  */
 dbus_bool_t
index 5228121..8409822 100644 (file)
@@ -156,6 +156,9 @@ dbus_bool_t   _dbus_string_append_printf         (DBusString        *str,
 dbus_bool_t   _dbus_string_append_printf_valist  (DBusString        *str,
                                                   const char        *format,
                                                   va_list            args);
+dbus_bool_t   _dbus_string_insert_2_aligned      (DBusString        *str,
+                                                  int                insert_at,
+                                                  const unsigned char octets[2]);
 dbus_bool_t   _dbus_string_insert_4_aligned      (DBusString        *str,
                                                   int                insert_at,
                                                   const unsigned char octets[4]);
index eb2b878..4fdd8ce 100644 (file)
@@ -118,7 +118,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
 
   check_memleaks ();
 
-#if 0
+#if 1
   printf ("%s: running recursive marshalling tests\n", "dbus-test");
   if (!_dbus_marshal_recursive_test ())
     die ("recursive marshal");
@@ -140,7 +140,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
   
   check_memleaks ();
 
-#if 0
+#if 1
   printf ("%s: running memory pool tests\n", "dbus-test");
   if (!_dbus_mem_pool_test ())
     die ("memory pools");
index 1a9da4a..94d4a8a 100644 (file)
@@ -920,10 +920,10 @@ _dbus_transport_get_unix_user (DBusTransport *transport,
 {
   DBusCredentials auth_identity;
 
-  *uid = _DBUS_INT_MAX; /* better than some root or system user in
-                         * case of bugs in the caller. Caller should
-                         * never use this value on purpose, however.
-                         */
+  *uid = _DBUS_INT32_MAX; /* better than some root or system user in
+                           * case of bugs in the caller. Caller should
+                           * never use this value on purpose, however.
+                           */
   
   if (!transport->authenticated)
     return FALSE;
index 55ddf43..d45c251 100644 (file)
@@ -28,9 +28,8 @@
 #define DBUS_TYPES_H
 
 #include <stddef.h>
+#include <dbus/dbus-arch-deps.h>
 
-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;
index 2318c01..478dcdf 100644 (file)
@@ -437,6 +437,10 @@ basic_type_from_string (const char *str)
 {
   if (strcmp (str, "string") == 0)
     return DBUS_TYPE_STRING;
+  else if (strcmp (str, "int16") == 0)
+    return DBUS_TYPE_INT16;
+  else if (strcmp (str, "uint16") == 0)
+    return DBUS_TYPE_UINT16;
   else if (strcmp (str, "int32") == 0)
     return DBUS_TYPE_INT32;
   else if (strcmp (str, "uint32") == 0)
index 9e4a5cd..ff48e7f 100644 (file)
@@ -88,6 +88,10 @@ _dbus_gutils_type_to_string (int type)
       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:
index 1fed0cf..e2bf40b 100644 (file)
@@ -40,12 +40,29 @@ dbus_gvalue_demarshal (DBusMessageIter *iter, GValue *value)
   switch (dbus_message_iter_get_arg_type (iter))
     {
       MAP_BASIC (BOOLEAN, BOOLEAN);
-      MAP_BASIC (BYTE, UCHAR);
-      MAP_BASIC (INT32, INT);
-      MAP_BASIC (UINT32, UINT);
-      MAP_BASIC (INT64, INT64);
-      MAP_BASIC (UINT64, UINT64);
-      MAP_BASIC (DOUBLE, DOUBLE);
+      MAP_BASIC (BYTE,    UCHAR);
+      MAP_BASIC (INT32,   INT);
+      MAP_BASIC (UINT32,  UINT);
+      MAP_BASIC (INT64,   INT64);
+      MAP_BASIC (UINT64,  UINT64);
+      MAP_BASIC (DOUBLE,  DOUBLE);
+
+    case DBUS_TYPE_INT16:
+      {
+        dbus_int16_t v;
+        g_value_init (value, G_TYPE_INT);
+        dbus_message_iter_get_basic (iter, &v);
+        g_value_set_int (value, v);
+      }
+      break;
+    case DBUS_TYPE_UINT16:
+      {
+        dbus_uint16_t v;
+        g_value_init (value, G_TYPE_UINT);
+        dbus_message_iter_get_basic (iter, &v);
+        g_value_set_uint (value, v);
+      }
+      break;
       
     case DBUS_TYPE_STRING:
     case DBUS_TYPE_OBJECT_PATH: