sd-journal: avoid use of fake flex arrays

I tried to use DECLARE_FLEX_ARRAY like the kernel does, but it does not work
for anonymous structs (they cannot be declared inline), so an open-coded
version is used.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-02-05 21:15:52 +01:00
parent c8b960af14
commit da8587b24e
2 changed files with 36 additions and 18 deletions

View File

@@ -376,3 +376,15 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
(v) = UPDATE_FLAG(v, flag, b)
#define FLAGS_SET(v, flags) \
((~(v) & (flags)) == 0)
/* Declare a flexible array usable in a union.
* This is essentially a work-around for a pointless constraint in C99
* and might go away in some future version of the standard.
*
* See https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3080ea5553cc909b000d1f1d964a9041962f2c5b
*/
#define DECLARE_FLEX_ARRAY(type, name) \
struct { \
dummy_t __empty__ ## name; \
type name[]; \
}

View File

@@ -93,22 +93,28 @@ struct FieldObject FieldObject__contents;
struct FieldObject__packed FieldObject__contents _packed_;
assert_cc(sizeof(struct FieldObject) == sizeof(struct FieldObject__packed));
#define EntryObject__contents { \
ObjectHeader object; \
le64_t seqnum; \
le64_t realtime; \
le64_t monotonic; \
sd_id128_t boot_id; \
le64_t xor_hash; \
union { \
struct { \
le64_t object_offset; \
le64_t hash; \
} regular[0]; \
struct { \
le32_t object_offset; \
} compact[0]; \
} items; \
#define EntryObject__contents { \
ObjectHeader object; \
le64_t seqnum; \
le64_t realtime; \
le64_t monotonic; \
sd_id128_t boot_id; \
le64_t xor_hash; \
union { \
struct { \
dummy_t __empty__regular; \
struct { \
le64_t object_offset; \
le64_t hash; \
} regular[]; \
}; \
struct { \
dummy_t __empty_compact; \
struct { \
le32_t object_offset; \
} compact[]; \
}; \
} items; \
}
struct EntryObject EntryObject__contents;
@@ -129,8 +135,8 @@ struct EntryArrayObject {
ObjectHeader object;
le64_t next_entry_array_offset;
union {
le64_t regular[0];
le32_t compact[0];
DECLARE_FLEX_ARRAY(le64_t, regular);
DECLARE_FLEX_ARRAY(le32_t, compact);
} items;
} _packed_;