qapi: pad GenericList value fields to 64 bits
authorMichael Roth <mdroth@linux.vnet.ibm.com>
Mon, 27 May 2013 03:20:58 +0000 (22:20 -0500)
committerLuiz Capitulino <lcapitulino@redhat.com>
Thu, 30 May 2013 13:08:38 +0000 (09:08 -0400)
With the introduction of native list types, we now have types such as
int64List where the 'value' field is not a pointer, but the actual
64-bit value.

On 32-bit architectures, this can lead to situations where 'next' field
offset in GenericList does not correspond to the 'next' field in the
types that we cast to GenericList when using the visit_next_list()
interface, causing issues when we attempt to traverse linked list
structures of these types.

To fix this, pad the 'value' field of GenericList and other
schema-defined/native *List types out to 64-bits.

This is less memory-efficient for 32-bit architectures, but allows us to
continue to rely on list-handling interfaces that target GenericList to
simply visitor implementations.

In the future we can improve efficiency by defaulting to using native C
array backends to handle list of non-pointer types, which would be more
memory efficient in itself and allow us to roll back this change.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
include/qapi/visitor.h
scripts/qapi-types.py
tests/test-qmp-output-visitor.c

index 1fef18c08fa90e0207d860d40c030deda7858e57..28c21d8338e707d9a9eaedfb93d821323f90e3a1 100644 (file)
 
 typedef struct GenericList
 {
-    void *value;
+    union {
+        void *value;
+        uint64_t padding;
+    };
     struct GenericList *next;
 } GenericList;
 
index fd42d71da1784356635af47cedd85d82f0986ff2..ddcfed9f4bbde0b9ac7a934493ada57e6fdd4c59 100644 (file)
@@ -22,7 +22,10 @@ def generate_fwd_struct(name, members, builtin_type=False):
 
 typedef struct %(name)sList
 {
-    %(type)s value;
+    union {
+        %(type)s value;
+        uint64_t padding;
+    };
     struct %(name)sList *next;
 } %(name)sList;
 ''',
@@ -35,7 +38,10 @@ typedef struct %(name)s %(name)s;
 
 typedef struct %(name)sList
 {
-    %(name)s *value;
+    union {
+        %(name)s *value;
+        uint64_t padding;
+    };
     struct %(name)sList *next;
 } %(name)sList;
 ''',
index 0942a41875c6811a2fd4e7c3373ddc858b3ec477..b2fa9a74f67ea368234fbc660ba26c4b060d2080 100644 (file)
@@ -295,7 +295,10 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data,
 
 typedef struct TestStructList
 {
-    TestStruct *value;
+    union {
+        TestStruct *value;
+        uint64_t padding;
+    };
     struct TestStructList *next;
 } TestStructList;