}
-# define SET_NEXT_VAL(dbustype, vargtype, sigtype, fmt) \
+# define SET_NEXT_VAL(dbustype, vargtype, arrtype, sigtype, fmt) \
do { \
dbustype x; \
if (arrayref) { \
- vargtype *valarray = arrayptr; \
+ arrtype valarray = arrayptr; \
x = (dbustype)*valarray; \
valarray++; \
arrayptr = valarray; \
switch (*t) {
case DBUS_TYPE_BYTE:
- SET_NEXT_VAL(unsigned char, int, *t, "%d");
+ SET_NEXT_VAL(unsigned char, int, unsigned char *, *t, "%d");
break;
case DBUS_TYPE_BOOLEAN:
- SET_NEXT_VAL(dbus_bool_t, int, *t, "%d");
+ SET_NEXT_VAL(dbus_bool_t, int, bool *, *t, "%d");
break;
case DBUS_TYPE_INT16:
- SET_NEXT_VAL(dbus_int16_t, int, *t, "%d");
+ SET_NEXT_VAL(dbus_int16_t, int, short *, *t, "%d");
break;
case DBUS_TYPE_UINT16:
- SET_NEXT_VAL(dbus_uint16_t, unsigned int, *t, "%d");
+ SET_NEXT_VAL(dbus_uint16_t, unsigned int, unsigned short *,
+ *t, "%d");
break;
case DBUS_TYPE_INT32:
- SET_NEXT_VAL(dbus_int32_t, int, *t, "%d");
+ SET_NEXT_VAL(dbus_int32_t, int, int *, *t, "%d");
break;
case DBUS_TYPE_UINT32:
- SET_NEXT_VAL(dbus_uint32_t, unsigned int, *t, "%u");
+ SET_NEXT_VAL(dbus_uint32_t, unsigned int, unsigned int *,
+ *t, "%u");
break;
case DBUS_TYPE_INT64:
- SET_NEXT_VAL(dbus_int64_t, long long, *t, "%lld");
+ SET_NEXT_VAL(dbus_int64_t, long long, long long *, *t, "%lld");
break;
case DBUS_TYPE_UINT64:
- SET_NEXT_VAL(dbus_uint64_t, unsigned long long, *t, "%llu");
+ SET_NEXT_VAL(dbus_uint64_t, unsigned long long,
+ unsigned long long *, *t, "%llu");
break;
case DBUS_TYPE_DOUBLE:
- SET_NEXT_VAL(double, double, *t, "%lf");
+ SET_NEXT_VAL(double, double, double *, *t, "%lf");
break;
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_SIGNATURE:
- SET_NEXT_VAL(char *, char *, *t, "%s");
+ SET_NEXT_VAL(char *, char *, char **, *t, "%s");
break;
case DBUS_TYPE_ARRAY:
# define GET_NEXT_VAL(dbustype, member, vargtype, fmt) \
do { \
- dbustype *x; \
DBusBasicValue v; \
+ dbustype *x = (dbustype *)&v.member; \
+ vargtype *y; \
if (arrayref) { \
VIR_DEBUG("Use arrayref"); \
vargtype **xptrptr = arrayptr; \
if (VIR_EXPAND_N(*xptrptr, *narrayptr, 1) < 0) \
goto cleanup; \
- x = (dbustype *)(*xptrptr + (*narrayptr - 1)); \
+ y = (*xptrptr + (*narrayptr - 1)); \
VIR_DEBUG("Expanded to %zu", *narrayptr); \
} else { \
- x = (dbustype *)&(v.member); \
+ y = va_arg(args, vargtype *); \
} \
dbus_message_iter_get_basic(iter, x); \
- if (!arrayref) \
- *va_arg(args, vargtype *) = v.member; \
+ *y = *x; \
VIR_DEBUG("Read basic type '" #dbustype "' varg '" #vargtype \
- "' val '" fmt "'", (vargtype)*x); \
+ "' val '" fmt "'", (vargtype)*y); \
} while (0)
int in_int32a = 1000000000, out_int32a = 0;
int in_int32b = 2000000000, out_int32b = 0;
int in_int32c = -2000000000, out_int32c = 0;
+ bool in_bool[] = { true, false, true }, out_bool[] = { false, true, false};
const char *in_str2 = "World";
char *out_str1 = NULL, *out_str2 = NULL;
}
if (virDBusMessageEncode(msg,
- "sais",
+ "saiabs",
in_str1,
3, in_int32a, in_int32b, in_int32c,
+ 3, in_bool[0], in_bool[1], in_bool[2],
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
goto cleanup;
}
if (virDBusMessageDecode(msg,
- "sais",
+ "saiabs",
&out_str1,
3, &out_int32a, &out_int32b, &out_int32c,
+ 3, &out_bool[0], &out_bool[1], &out_bool[2],
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments");
goto cleanup;
VERIFY("int32a", in_int32a, out_int32a, "%d");
VERIFY("int32b", in_int32b, out_int32b, "%d");
VERIFY("int32c", in_int32c, out_int32c, "%d");
+ VERIFY("bool[0]", in_bool[0], out_bool[0], "%d");
+ VERIFY("bool[1]", in_bool[1], out_bool[1], "%d");
+ VERIFY("bool[2]", in_bool[2], out_bool[2], "%d");
VERIFY_STR("str2", in_str2, out_str2, "%s");
ret = 0;
int in_int32[] = {
100000000, 2000000000, -2000000000
};
+ bool in_bool[] = { true, false, true };
const char *in_strv1[] = {
"Fishfood",
};
};
int *out_int32 = NULL;
size_t out_nint32 = 0;
+ bool *out_bool = NULL;
+ size_t out_nbool = 0;
char **out_strv1 = NULL;
char **out_strv2 = NULL;
size_t out_nstrv1 = 0;
}
if (virDBusMessageEncode(msg,
- "sa&sa&ia&ss",
+ "sa&sa&ia&ba&ss",
in_str1,
1, in_strv1,
3, in_int32,
+ 3, in_bool,
2, in_strv2,
in_str2) < 0) {
VIR_DEBUG("Failed to encode arguments");
}
if (virDBusMessageDecode(msg,
- "sa&sa&ia&ss",
+ "sa&sa&ia&ba&ss",
&out_str1,
&out_nstrv1, &out_strv1,
&out_nint32, &out_int32,
+ &out_nbool, &out_bool,
&out_nstrv2, &out_strv2,
&out_str2) < 0) {
VIR_DEBUG("Failed to decode arguments");
VERIFY("int32b", in_int32[1], out_int32[1], "%d");
VERIFY("int32c", in_int32[2], out_int32[2], "%d");
+ if (out_nbool != 3) {
+ fprintf(stderr, "Expected 3 bools, but got %zu\n",
+ out_nbool);
+ goto cleanup;
+ }
+ VERIFY("bool[0]", in_bool[0], out_bool[0], "%d");
+ VERIFY("bool[1]", in_bool[1], out_bool[1], "%d");
+ VERIFY("bool[2]", in_bool[2], out_bool[2], "%d");
+
if (out_nstrv2 != 2) {
fprintf(stderr, "Expected 2 strings, but got %zu\n",
out_nstrv2);
cleanup:
VIR_FREE(out_int32);
+ VIR_FREE(out_bool);
VIR_FREE(out_str1);
VIR_FREE(out_str2);
for (i = 0; i < out_nstrv1; i++)