@@ -241,6 +241,46 @@ class aligned_t(struct):
241241 self .assertEqual (s2 .b .value , 42 )
242242
243243
244+ class ArrayAlignmentTest (unittest .TestCase ):
245+ def test_alignment_of_array_field (self ):
246+ """alignment_of(array_of(c_int, N)) should be 4 (element alignment), not 1."""
247+ from libdestruct import array_of
248+
249+ arr = array_of (c_int , 3 )
250+ self .assertEqual (alignment_of (arr ), 4 )
251+
252+ def test_aligned_struct_with_array (self ):
253+ """Array field in aligned struct should be aligned to element alignment."""
254+ from libdestruct import array_of
255+
256+ class s_t (struct ):
257+ _aligned_ = True
258+ a : c_char
259+ arr : list [c_int ] = array_of (c_int , 3 )
260+
261+ # a at 0 (1 byte), padding 3, arr at 4 (12 bytes) = 16, tail padded to 4 = 16
262+ self .assertEqual (size_of (s_t ), 16 )
263+
264+ def test_aligned_struct_with_array_read (self ):
265+ """Values read correctly from aligned array in struct."""
266+ from libdestruct import array_of
267+
268+ class s_t (struct ):
269+ _aligned_ = True
270+ a : c_char
271+ arr : list [c_int ] = array_of (c_int , 3 )
272+
273+ memory = pystruct .pack ("<b" , 0x41 ) + b"\x00 " * 3
274+ for v in [10 , 20 , 30 ]:
275+ memory += pystruct .pack ("<i" , v )
276+
277+ s = s_t .from_bytes (memory )
278+ self .assertEqual (s .a .value , 0x41 )
279+ self .assertEqual (s .arr [0 ].value , 10 )
280+ self .assertEqual (s .arr [1 ].value , 20 )
281+ self .assertEqual (s .arr [2 ].value , 30 )
282+
283+
244284class BitfieldAlignmentTest (unittest .TestCase ):
245285 def test_bitfield_alignment_padding (self ):
246286 """Bitfield backing type is aligned in aligned structs."""
0 commit comments