diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2023-10-30 15:36:54 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2023-10-30 15:36:54 +0000 |
commit | 10f31814c30f435808eb9a50fd55dc0e77c0294d (patch) | |
tree | e229007491cdb1497bf82c659671200133b7b37c | |
parent | 596448ac6da1e4b6d823f11755fa6528caecc69a (diff) |
mbim-codegen, struct: ensure items in ref-struct-array are padded
So that each new item in the struct array starts at the 4 byte
boundary.
This change allows supporting struct sizes which are not multiple of 4
bytes, e.g. if we are using unsized byte arrays.
-rw-r--r-- | build-aux/mbim-codegen/Struct.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/build-aux/mbim-codegen/Struct.py b/build-aux/mbim-codegen/Struct.py index bef352b..6aa0af6 100644 --- a/build-aux/mbim-codegen/Struct.py +++ b/build-aux/mbim-codegen/Struct.py @@ -1086,6 +1086,7 @@ class Struct: ' guint32 length;\n' ' guint32 offset_offset;\n' ' GByteArray *raw;\n' + ' static const guint8 padding = 0x00;\n' '\n' ' raw = _${name_underscore}_struct_new (values[i]);\n' ' g_assert (raw->len > 0);\n' @@ -1106,6 +1107,9 @@ class Struct: '\n' ' /* And finally, the bytearray itself to the variable buffer */\n' ' g_byte_array_append (builder->variable_buffer, (const guint8 *)raw->data, (guint)raw->len);\n' + ' /* Align the structs at 4 byte boundary, as we may have unsized byte arrays */\n' + ' while (builder->variable_buffer->len % 4 != 0)\n' + ' g_byte_array_append (builder->variable_buffer, &padding, sizeof (padding));\n' ' g_byte_array_unref (raw);\n' ' }\n' '}\n' |